sector_t map_swap_page(struct swap_info_struct *sis, pgoff_t offset) {

struct swap_extent *se = sis->curr_swap_extent; struct swap_extent *start_se = se;

struct list_head *lh;

offset < (se->start_page + se->nr_pages)) { return se->start_block + (offset - se->start_page);

lh = lh->next; se = list_entry(lh, struct swap_extent, list); sis->curr_swap_extent = se;

The search does not begin at the start of the list but at the list element last used. This is stored in curr_swap_extent since in most cases, access is made to slots that are next to or at least close to each other. The address can be calculated with the help of the same extent list element.

A page slot is held in a list element when the offset number — that is, the number of the searched page slot — is equal to or greater than se->start_page but less than se->start_page + se->nr_pages. If this does not apply, the list is searched sequentially until the matching element is found. As a matching element must exist, the search can be performed in an endless loop that is terminated when the sector number is returned.

Once the bio instance has been filled with the appropriate data, the PG_writeback flag must be set for the page using SetPageWriteback before the write request is forwarded to the block layer by means of bio_submit.

When the write request has been executed, the block layer invokes the end_swap_bio_write function (which is based on the standard function end_page_writeback) to remove the PG_writeback flag from the page structure.

Notice that writing the contents of a page to the page slot in the swap area is not sufficient to fully swap out a page! Before a page can be considered to be completely removed from RAM, the page tables need to be updated. The page table entry needs, on the one hand, to specify that the page is not in memory and must, on the other hand, point to the location in the swap space. Since the change must be performed for all current users of the page, this is an involved task discussed in Section 18.6.7.

Continue reading here: Page Reclaim

Was this article helpful?

0 0