Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/swapfile.c: delete the "last_in_cluster < scan_base" loop in the body of scan_swap_map()

Via commit ebc2a1a69111 ("swap: make cluster allocation per-cpu"), we
can find that all SWP_SOLIDSTATE "seek is cheap"(SSD case) has already
gone to si->cluster_info scan_swap_map_try_ssd_cluster() route. So that
the "last_in_cluster < scan_base" loop in the body of scan_swap_map()
has already become a dead code snippet, and it should have been deleted.

This patch is to delete the redundant loop as Hugh and Shaohua
suggested.

[hughd@google.com: fix comment, simplify code]
Signed-off-by: Chen Yucong <slaoub@gmail.com>
Cc: Shaohua Li <shli@kernel.org>
Acked-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Chen Yucong and committed by
Linus Torvalds
50088c44 100873d7

+3 -26
+3 -26
mm/swapfile.c
··· 523 523 /* 524 524 * If seek is expensive, start searching for new cluster from 525 525 * start of partition, to minimize the span of allocated swap. 526 - * But if seek is cheap, search from our current position, so 527 - * that swap is allocated from all over the partition: if the 528 - * Flash Translation Layer only remaps within limited zones, 529 - * we don't want to wear out the first zone too quickly. 526 + * If seek is cheap, that is the SWP_SOLIDSTATE si->cluster_info 527 + * case, just handled by scan_swap_map_try_ssd_cluster() above. 530 528 */ 531 - if (!(si->flags & SWP_SOLIDSTATE)) 532 - scan_base = offset = si->lowest_bit; 529 + scan_base = offset = si->lowest_bit; 533 530 last_in_cluster = offset + SWAPFILE_CLUSTER - 1; 534 531 535 532 /* Locate the first empty (unaligned) cluster */ 536 533 for (; last_in_cluster <= si->highest_bit; offset++) { 537 - if (si->swap_map[offset]) 538 - last_in_cluster = offset + SWAPFILE_CLUSTER; 539 - else if (offset == last_in_cluster) { 540 - spin_lock(&si->lock); 541 - offset -= SWAPFILE_CLUSTER - 1; 542 - si->cluster_next = offset; 543 - si->cluster_nr = SWAPFILE_CLUSTER - 1; 544 - goto checks; 545 - } 546 - if (unlikely(--latency_ration < 0)) { 547 - cond_resched(); 548 - latency_ration = LATENCY_LIMIT; 549 - } 550 - } 551 - 552 - offset = si->lowest_bit; 553 - last_in_cluster = offset + SWAPFILE_CLUSTER - 1; 554 - 555 - /* Locate the first empty (unaligned) cluster */ 556 - for (; last_in_cluster < scan_base; offset++) { 557 534 if (si->swap_map[offset]) 558 535 last_in_cluster = offset + SWAPFILE_CLUSTER; 559 536 else if (offset == last_in_cluster) {