Swapped Out Page Identifier

A swapped-out page is uniquely identified quite simply by specifying the index of the swap area in the swap_info array and the page slot index inside the swap area. Since the first page (with index 0) of the swap area is reserved for the swap_header union discussed earlier, the first useful page slot has index 1. The format of a swapped-out page identifier is illustrated in Figure 16-2.

Figure 16-2. Swapped-out page identifier

Figure 16-2. Swapped-out page identifier

The SWP_ENTRY(type,offset) macro constructs a swapped-out page identifier from the swap area index type and the page slot index offset. Conversely, the swp_type and SWP_OFFSET macros extract from a swapped-out page identifier the swap area index and the page slot index, respectively.

When a page is swapped out, its identifier is inserted as the page's entry into the Page Table so the page can be found again when needed. Notice that the least-significant bit of such an identifier, which corresponds to the Present flag, is always cleared to denote the fact that the page is not currently in RAM. However, at least one of the remaining 31 bits has to be set because no page is ever stored in slot 0 of swap area 0. It is therefore possible to identify three different cases from the value of a Page Table entry:

Null entry

The page does not belong to the process address space.

First 31 most-significant bits not all equal to 0, last bit equal to 0

The page is currently swapped out.

Least-significant bit equal to 1

Notice that the maximum size of a swap area is determined by the number of bits available to identify a slot. On the 80 x 86 architecture, the 24 bits available limit the size of a swap area to 224 slots (that is, to 64 GB).

Since a page may belong to the address spaces of several processes (see the later section Section 16.3), it may be swapped out from the address space of one process and still remain in main memory; therefore, it is possible to swap out the same page several times. A page is physically swapped out and stored just once, of course, but each subsequent attempt to swap it out increments the swap_map counter.

The swap_duplicate( ) function is usually invoked while trying to swap out an already swapped-out page. It just verifies that the swapped-out page identifier passed as its parameter is valid and increments the corresponding swap_map counter. More precisely, it performs the following actions:

1. Uses the swp_type and swp_offset macros to extract the swap area number type and the page slot index offset from the parameter.

2. Checks whether the swap area is activated; if not, it returns 0 (invalid identifier).

3. Checks whether the page slot is valid and not free (its swap_map counter is greater than 0 and less than swap_max_bad); if not, returns 0 (invalid identifier).

4. Otherwise, the swapped-out page identifier locates a valid page. Increments the swap_map counter of the page slot if it has not already reached the value


5. Returns 1 (valid identifier).

Was this article helpful?

0 0

Post a comment