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

Configure Feed

Select the types of activity you want to include in your feed.

mm: swap: clean up initialization helper

At this point, alloc_cluster is never called already, and
inc_cluster_info_page is called by initialization only, a lot of dead code
can be dropped.

Link: https://lkml.kernel.org/r/20240730-swap-allocator-v5-4-cb9c148b9297@kernel.org
Signed-off-by: Kairui Song <kasong@tencent.com>
Reported-by: Barry Song <21cnbao@gmail.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
3b2561b5 5f843a9a

+14 -38
+14 -38
mm/swapfile.c
··· 438 438 complete(&si->comp); 439 439 } 440 440 441 - static struct swap_cluster_info *alloc_cluster(struct swap_info_struct *si, unsigned long idx) 442 - { 443 - struct swap_cluster_info *ci = list_first_entry(&si->free_clusters, 444 - struct swap_cluster_info, list); 445 - 446 - lockdep_assert_held(&si->lock); 447 - lockdep_assert_held(&ci->lock); 448 - VM_BUG_ON(cluster_index(si, ci) != idx); 449 - VM_BUG_ON(ci->count); 450 - list_del(&ci->list); 451 - ci->flags = 0; 452 - return ci; 453 - } 454 - 455 441 static void free_cluster(struct swap_info_struct *si, struct swap_cluster_info *ci) 456 442 { 457 443 VM_BUG_ON(ci->count != 0); ··· 458 472 } 459 473 460 474 /* 461 - * The cluster corresponding to page_nr will be used. The cluster will be 462 - * removed from free cluster list and its usage counter will be increased by 463 - * count. 464 - */ 465 - static void add_cluster_info_page(struct swap_info_struct *p, 466 - struct swap_cluster_info *cluster_info, unsigned long page_nr, 467 - unsigned long count) 468 - { 469 - unsigned long idx = page_nr / SWAPFILE_CLUSTER; 470 - struct swap_cluster_info *ci = cluster_info + idx; 471 - 472 - if (!cluster_info) 473 - return; 474 - if (cluster_is_free(ci)) 475 - alloc_cluster(p, idx); 476 - 477 - VM_BUG_ON(ci->count + count > SWAPFILE_CLUSTER); 478 - ci->count += count; 479 - } 480 - 481 - /* 482 - * The cluster corresponding to page_nr will be used. The cluster will be 483 - * removed from free cluster list and its usage counter will be increased by 1. 475 + * The cluster corresponding to page_nr will be used. The cluster will not be 476 + * added to free cluster list and its usage counter will be increased by 1. 477 + * Only used for initialization. 484 478 */ 485 479 static void inc_cluster_info_page(struct swap_info_struct *p, 486 480 struct swap_cluster_info *cluster_info, unsigned long page_nr) 487 481 { 488 - add_cluster_info_page(p, cluster_info, page_nr, 1); 482 + unsigned long idx = page_nr / SWAPFILE_CLUSTER; 483 + struct swap_cluster_info *ci; 484 + 485 + if (!cluster_info) 486 + return; 487 + 488 + ci = cluster_info + idx; 489 + ci->count++; 490 + 491 + VM_BUG_ON(ci->count > SWAPFILE_CLUSTER); 492 + VM_BUG_ON(ci->flags); 489 493 } 490 494 491 495 /*