The kernel uses several functions to handle the swap cache; they are based mainly on those discussed in Section 14.1. We show later how these relatively low-level functions are invoked by higher-level functions to swap pages in and out as needed. The main functions that handle the swap cache are:
Finds a page in the swap cache through its swapped-out page identifier passed as a parameter and returns the page address. It returns 0 if the page is not present in the cache. It invokes find_ get_page( ), passing as parameters the address of the swapper_space page address space object and the swapped-out page identifier to find the required page.
Inserts a page into the swap cache. It essentially invokes swap_duplicate( ) to check whether the page slot passed as a parameter is valid and to increment the page slot usage counter; find_get_page( ) to make sure that no other page with the same address_space object and offset already exists; add_to_page_cache( ) to insert the page into the cache; and lru_cache_add( ) to insert the page in the inactive list (see the later section Section 16.7.2).
delete from swap cache( )
Removes a page from the swap cache by flushing its content to disk, clearing the PG dirty flag, and invoking remove page from inode queue( ) and remove page from hash queue( ) (see Section 14.1.2).
Releases a page by invoking__free_page( ). If the caller is the only process that owns the page, this function also removes the page from the active or inactive list (see the later section Section 16.7.2), removes the page from the swap cache by invoking delete_from_swap_cache( ), and frees the page slot on the swap area by flushing the page contents to disk and invoking swap_free( ) .
Was this article helpful?