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: introduce a helper for retrieving cluster from offset

It's a common operation to retrieve the cluster info from offset,
introduce a helper for this.

Link: https://lkml.kernel.org/r/20250113175732.48099-12-ryncsn@gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Suggested-by: Chris Li <chrisl@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <v-songbaohua@oppo.com>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Hugh Dickens <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
3f641cf9 e3ae2dec

+10 -4
+10 -4
mm/swapfile.c
··· 424 424 return ci - si->cluster_info; 425 425 } 426 426 427 + static inline struct swap_cluster_info *offset_to_cluster(struct swap_info_struct *si, 428 + unsigned long offset) 429 + { 430 + return &si->cluster_info[offset / SWAPFILE_CLUSTER]; 431 + } 432 + 427 433 static inline unsigned int cluster_offset(struct swap_info_struct *si, 428 434 struct swap_cluster_info *ci) 429 435 { ··· 441 435 { 442 436 struct swap_cluster_info *ci; 443 437 444 - ci = &si->cluster_info[offset / SWAPFILE_CLUSTER]; 438 + ci = offset_to_cluster(si, offset); 445 439 spin_lock(&ci->lock); 446 440 447 441 return ci; ··· 1486 1480 unsigned char *map_end = map + nr_pages; 1487 1481 struct swap_cluster_info *ci; 1488 1482 1489 - /* It should never free entries across different clusters */ 1490 - VM_BUG_ON((offset / SWAPFILE_CLUSTER) != ((offset + nr_pages - 1) / SWAPFILE_CLUSTER)); 1491 - 1492 1483 ci = lock_cluster(si, offset); 1484 + 1485 + /* It should never free entries across different clusters */ 1486 + VM_BUG_ON(ci != offset_to_cluster(si, offset + nr_pages - 1)); 1493 1487 VM_BUG_ON(cluster_is_empty(ci)); 1494 1488 VM_BUG_ON(ci->count < nr_pages); 1495 1489