Ticket #7742: swap-kernel-v2.diff

File swap-kernel-v2.diff, 1.8 KB (added by kallisti5, 12 years ago)
  • src/system/kernel/vm/VMAnonymousCache.cpp

    diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp b/src/system/kernel/vm/VMAnonymousCache.cpp
    index 4c597d9..ae0d979 100644
    a b swap_init_post_modules()  
    14931493
    14941494    if (swapAutomatic) {
    14951495        swapEnabled = true;
    1496         swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE * 2;
     1496        swapSize = (off_t)vm_page_num_pages() * B_PAGE_SIZE;
     1497        if (swapSize <= (1024 * 1024 * 1024)) {
     1498            // Memory under 1GB? double the swap
     1499            swapSize *= 2;
     1500        }
    14971501    }
    14981502
    14991503    if (!swapEnabled || swapSize < B_PAGE_SIZE)
    swap_init_post_modules()  
    15571561    const char* swapPath = path.Path();
    15581562
    15591563    // Swap size limits prevent oversized swap files
    1560     off_t existingSwapSize = 0;
    1561     struct stat existingSwapStat;
    1562     if (stat(swapPath, &existingSwapStat) == 0)
    1563         existingSwapSize = existingSwapStat.st_size;
    1564 
    1565     off_t freeSpace = info.free_blocks * info.block_size + existingSwapSize;
    1566     off_t maxSwap = freeSpace;
    15671564    if (swapAutomatic) {
     1565        off_t existingSwapSize = 0;
     1566        struct stat existingSwapStat;
     1567        if (stat(swapPath, &existingSwapStat) == 0)
     1568            existingSwapSize = existingSwapStat.st_size;
     1569
     1570        off_t freeSpace = info.free_blocks * info.block_size + existingSwapSize;
     1571
    15681572        // Adjust automatic swap to a maximum of 25% of the free space
    1569         maxSwap = (off_t)(0.25 * freeSpace);
    1570     } else {
    1571         // If user specified, leave 10% of the disk free
    1572         maxSwap = freeSpace - (off_t)(0.10 * freeSpace);
    1573         dprintf("%s: Warning: User specified swap file consumes over 90%% of "
    1574             "the available free space, limiting to 90%%\n", __func__);
     1573        if (swapSize > (freeSpace / 4))
     1574            swapSize = (freeSpace / 4);
    15751575    }
    15761576
    1577     if (swapSize > maxSwap)
    1578         swapSize = maxSwap;
    1579 
    15801577    // Create swap file
    15811578    int fd = open(swapPath, O_RDWR | O_CREAT | O_NOCACHE, S_IRUSR | S_IWUSR);
    15821579    if (fd < 0) {