Check out the new USENIX Web site. next up previous
Next: 3.3 Freeing a Page Up: 3 Prototype Description Previous: 3.1 Data Structures

3.2 Getting Free Space (get_swap_page)

In the original kernel, this function returned the disk offset where the page would be stored but this offset was used as an identifier for the swapped page. Only the swap code used it to access the disk. As we need to know the size of the compressed page before assigning it to a disk block (it has to fit in it), we will return an index to the virtual_swap_info table. To the rest of the kernel, this function behaves as always and the system believes that the swap partition is a larger one.

To return this index, the system searches for a free entry in the virtual_swap_info array. A given entry is free when no process is using it (swap_map[i] == 0) and when there are no operations remaining to be done on this page ( virtual_swap_info[i].rw_remaining == 0).

Another important issues is that the system cannot return an index unless it is sure that there will be enough disk space to keep the page. For this reason, the system will always assume the worst case. Until it knows the real compressed size, the system will assume that the page needs a full disk block to be stored. As soon as the system knows its real size, it will update this information.

Toni Cortes
Tue Apr 27 17:43:22 MET DST 1999