Mmswapfilec

si->cluster_nr = SWAPFILE_CLUSTER - 1; if (si->pages - si->inuse_pages < SWAPFILE_CLUSTER) goto lowest;

offset = si->lowest_bit;

last_in_cluster = offset + SWAPFILE_CLUSTER - 1;

/* Locate the first empty (unaligned) cluster */ for (; last_in_cluster <= si->highest_bit; offset++) { if (si->swap_map[offset])

last_in_cluster = offset + SWAPFILE_CLUSTER; else if (offset == last_in_cluster) {

si->cluster_next = offset-SWAPFILE_CLUSTER-1; goto cluster;

goto lowest;

When there are not enough free slots to create a new cluster, the kernel branches to the lowest label and starts an entry-by-entry search there.

Starting at the current position, the kernel checks whether all subsequent slots — swapfile_cluster in number — are free; this check is performed by the for loop within the if query. If the kernel finds an allocated entry whose swap_map entry is greater than 0, the search for a free cluster is resumed at the next slot position. This is repeated until a position is finally reached at which there is insufficient space to create a cluster.

If the kernel is successful in its search for a new cluster, it jumps to the lowest label, as above.

Continue reading here: Allocating Swap Space

Was this article helpful?

0 0