Skip to contentSkip to conversation

page map aging & improved kswap logic

PATCH Rik van Riel 3 participants 3 messages Feb 27, 1998 1 message not in the archive Memory management

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 11 lines · Dr. Werner Fink
Quoted 4 lines

The kswapd logic is almost completely redone. Basically, kswapd tries (free_pages_high - nr_free_pages) times to free a page, but when memory becomes tighter, the number of tries become even higher.

Is the explicit call of run_task_queue(&tq_disk) really needed? Maybe setting of the __GFP_WAIT flag would work in the same manner:

        gfp_mask = __GFP_IO;
        if (atomic_read(&nr_async_pages) >= SWAP_CLUSTER_MAX)
                gfp_mask |= __GFP_WAIT;

Wouldn't that just mean that the pages that are swapped out from now on will be done synchronously?

What I wanted kswapd to do, was to select SWAP_CLUSTER_MAX pages and swap them out in _one_ I/O operation. Because this should save head movement, it might give us an improvement over syncing each swapped page seperately.

Rik.

+-----------------------------+------------------------------+
| For Linux mm-patches, go to | "I'm busy managing memory.." |
| my homepage (via LinuxHQ).  | [email protected]       |
| ...submissions welcome...   | http://www.fys.ruu.nl/~riel/ |
+-----------------------------+------------------------------+
#2 lore raw

Hi,

Quoted 4 lines · Rik van Riel

What I wanted kswapd to do, was to select SWAP_CLUSTER_MAX pages and swap them out in _one_ I/O operation. Because this should save head movement, it might give us an improvement over syncing each swapped page seperately.

I'm working towards it, and yes, this is a very important thing to have. It's more than just head movement --- disk requests, especially on SCSI, simply go much faster if you can amalgamate a number of physically adjacent IO requests into a single operation (scatter-gather allows you to do this even if the memory for the data is not physically contiguous).

The biggest problem is avoiding blocking while we do the work in try_to_swap_out(). That is a rather tricky piece of code, since it has to deal with the fact that the process it is swapping can actually be killed if we sleep for any reason, so it will not necessarily still be there when we wake up again. We've really got to do the entire custering operation for write within try_to_swap_out() and then start up the IO for those pages.

However, at least with the new swap cache stuff we can make things easier, since it is now possible to set up swap cache associations atomically on all the pages we want to swapout, and then take as much time as we want performing the actual writes. All we need to do is make sure that we lock all the pages for IO without the risk of blocking.

Cheers,
Stephen.

#3 lore raw

On Fri, 27 Feb 1998, Stephen C. Tweedie wrote:
...

Quoted 7 lines

The biggest problem is avoiding blocking while we do the work in try_to_swap_out(). That is a rather tricky piece of code, since it has to deal with the fact that the process it is swapping can actually be killed if we sleep for any reason, so it will not necessarily still be there when we wake up again. We've really got to do the entire custering operation for write within try_to_swap_out() and then start up the IO for those pages.

The code I'm hoping to complete this weekend should solve this problem nicely -- vm_ops->swapout is now completely integrated within the swapper for 'normal' shared/private pages and won't sleep until all ptes that reference a page have been replaced with the swap entry. So it's just a small step to batch up the pages to be written out.

Quoted 5 lines

However, at least with the new swap cache stuff we can make things easier, since it is now possible to set up swap cache associations atomically on all the pages we want to swapout, and then take as much time as we want performing the actual writes. All we need to do is make sure that we lock all the pages for IO without the risk of blocking.

At your suggestion, my work in progress now includes a per private vma inode, which essentially makes the swap-cache disappear since all pages are now in the page cache. There is a concern with this: on swapin, each pte that pointed to the page on disk has to be replaced with the page's entry. Unfortunately this means that the swap entry is now lost! I'm tempted to revert back to the old swap_cache_entry, and will have to unless someone has an ingenious idea about where the swap entry could be stored. (The inode, offset pair can't be used for the swap cache as they're used to find the appropriate pte in the page tables.)

One possibility is to store the swap entries in a structure attached to the inode - right now affs is using a whopping ~80 longs for its private inode data. Or the data could just be stored in swap-cache entries tied to the inode - actually that might work well as a page would need to be allocated on swapin of an entry. Hmmm...

-ben