--- 2.3.13-pre8-tmp/mm/swapfile.c.~1~ Thu Jul 22 01:07:28 1999 +++ 2.3.13-pre8-tmp/mm/swapfile.c Mon Aug 9 02:30:21 1999 @@ -46,16 +46,36 @@ } } si->cluster_nr = SWAPFILE_CLUSTER; + + /* try to find an empty (even not aligned) cluster. */ + offset = si->lowest_bit; + check_next_cluster: + if (offset+SWAPFILE_CLUSTER-1 <= si->highest_bit) + { + int nr; + for (nr = offset; nr < offset+SWAPFILE_CLUSTER; nr++) + if (si->swap_map[nr]) + { + offset = nr+1; + goto check_next_cluster; + } + /* We found a completly empty cluster, so start + * using it. + */ + goto got_page; + } + /* No luck, so now go finegrined as usual. -Andrea */ for (offset = si->lowest_bit; offset <= si->highest_bit ; offset++) { if (si->swap_map[offset]) continue; - si->lowest_bit = offset; -got_page: - si->swap_map[offset] = 1; - nr_swap_pages--; + got_page: + if (offset == si->lowest_bit) + si->lowest_bit++; if (offset == si->highest_bit) si->highest_bit--; - si->cluster_next = offset; + si->swap_map[offset] = 1; + nr_swap_pages--; + si->cluster_next = offset+1; return offset; } return 0;