Department of Computer Science
University of São Paulo
São Paulo, Brazil
Linux 2.4 Virtual Memory Overview
swap_state.c
On this page you can find some of our studies of Linux 2.4 VM
system. This page was created to help us out to visualize VM system
better. WARNING: this material is still very raw and some ideas may
have not been correctly understood. If you have any
suggestion or correction, please send an e-mail to us at [email protected].
description
In swap_state.c we have functions mainly to handle the VM's
swap cache and some stuff in swap itself (like
swap_out).
functions
- static int
swap_writepage(struct page *page)
description
This function just calls
rw_swap_page() , with a WRITE parameter and 0
wait. That will do an asynchronous write of this page on to the
swap device. This function is currently only called from page_launder() .
parameters
- page - The page in swap cache to swap out.
return value
- void
show_swap_cache_info (void)
description
All this function does is printk some swap cache
information. It's called from
show_free_areas_core() , but only if the
SWAP_CACHE_INFO symbol is defined.
parameters
return value
- void
add_to_swap_cache(struct page *page, swp_entry_t entry)
description
This function is called when we want to add a page to swap
cache. Basically what it does is set some flags
(page->flags), in special with the PG_swap_cache
attribute, and most importantly, add it to the page cache (using
add_to_page_cache_locked() ).
It is called from two places in VM:
- It is mainly called from try_to_swap_out()
, when we're trying to swap out a page and we've found
and dirty, swappable page.
- It is also called from
read_swap_cache_async() , when we're looking for a page
in swap cache, but it's not there anymore, so we get it
from swap and add it to the swap cache.
parameters
- page - the address of page to add in swap cache
- entry - the swap entry that contains the index for
this page
return value
- static inline void
remove_from_swap_cache (struct page *page)
description
This function is called when we are removing a page from
swap_cache. This is an internal function and is called only by __delete_from_swap_cache()
. It basically:
- Clears the PG_swap_cache modifier from the page's
flags.
- Clears the PG_dirty modifier from the page's
flags.
- Removes that page from the page_cache by calling __remove_inode_page()
.
parameters
- page - the page to remove from swap cache.
return value
- void
__delete_from_swap_cache(struct page *page)
description
This function is called to delete a page from swap_cache and is
used as a wrapper to
remove_from_swap_cache for external use, but must only be
called on pages that have been verified to be in swap_cache.
parameters
- page - page to be deleted from swap_cache.
return value
- void
delete_from_swap_cache_nolock(struct page *page)
description
This function does two things, primarily:
- Locks pagecache_lock
- Calls
__delete_from_swap_cache to remove it's
PG_swap_cache, and remove it from the page_cache.
- Clears PG_Dirty bit from the page's flags.
- Unlocks pagecache_lock
parameters
- page - page to be deleted from swap_cache.
return value
- void
delete_from_swap_cache(struct page *page)
description
This is just a wrapper to
delete_from_swap_cache_nolock() with calls to lock_page() and UnlockPage()
surrounding it.
This is a called from:
parameters
- page - page to be deleted from swap_cache.
return value
- void
free_page_and_swap_cache(struct page *page)
description
- It basicaly performs a free_page(), also freeing any swap
cache associated with this page if it is the last user of the
page.
parameters
- page - page to be deleted from swap_cache.
return value
- struct page *
lookup_swap_cache(swp_entry_t entry)
description
Lookup a swap entry in the swap cache.
- Call find_lock_page function to look for the page
- If not found, return 0
- Check then if it was removed by refill_inactive_scan,
etc. If it was, it is released and re-search.
- Otherwise, check if it is really a swapper swap page
- Unlock and return it
parameters
- entry - entry to be searched
return value
- 0 - not found
- found - pointer to the page found
- struct page *
read_swap_cache_async(swp_entry_t entry, int wait)
description
Locate a page of swap in physical memory, reserving swap cache
space and reading the disk if it is not already cached. If
wait==0, we are only doing readahead, so don't worry if the
page is already locked.
- Make sure the swap entry is still in use, through swap_duplicate().
- Look for the page in the swap cache calling lookup_swap_cache
- If found, swap entry is freed (swap_free())
- If not, a new page is obtained by calling
__get_free_page().
- Check the swap cache again, in case we stalled above.
- If it was found, besides freeing swap entry, the new page
is release (page_cache_release())
- Add it to the swap cache (add_to_swap_cache())
- Read its contents (rw_swap_page())
parameters
- entry - entry to be searched
- wait - passed as parameter to rw_swap_page(). If wait ==
1, we wait on page. Otherwise, we are only doing readahead.
return value
- 0 - new page allocated and read its contents
- 1 - found the page in swap cache
Page last updated on "Thu Apr 19 09:29:45 2001"
Send feedback to
Rodrigo S. de Castro<[email protected]>