From: Kairui Song <kasong@tencent.com>
It was used for calculating the iteration number when the swap allocator
wants to scan the whole fragment list. Now the allocator only scans one
fragment cluster at a time, so no one uses this counter anymore.
Remove it as a cleanup; the performance change is marginal:
Build linux kernel using 10G ZRAM, make -j96, defconfig with 2G cgroup
memory limit, on top of tmpfs, 64kB mTHP enabled:
Before: sys time: 6278.45s
After: sys time: 6176.34s
Change to 8G ZRAM:
Before: sys time: 5572.85s
After: sys time: 5531.49s
Signed-off-by: Kairui Song <kasong@tencent.com>
---
include/linux/swap.h | 1 -
mm/swapfile.c | 7 -------
2 files changed, 8 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 2fe6ed2cc3fd..a060d102e0d1 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -310,7 +310,6 @@ struct swap_info_struct {
/* list of cluster that contains at least one free slot */
struct list_head frag_clusters[SWAP_NR_ORDERS];
/* list of cluster that are fragmented or contented */
- atomic_long_t frag_cluster_nr[SWAP_NR_ORDERS];
unsigned int pages; /* total of usable pages of swap */
atomic_long_t inuse_pages; /* number of those currently in use */
struct swap_sequential_cluster *global_cluster; /* Use one global cluster for rotating device */
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 1f1110e37f68..5fdb3cb2b8b7 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -470,11 +470,6 @@ static void move_cluster(struct swap_info_struct *si,
else
list_move_tail(&ci->list, list);
spin_unlock(&si->lock);
-
- if (ci->flags == CLUSTER_FLAG_FRAG)
- atomic_long_dec(&si->frag_cluster_nr[ci->order]);
- else if (new_flags == CLUSTER_FLAG_FRAG)
- atomic_long_inc(&si->frag_cluster_nr[ci->order]);
ci->flags = new_flags;
}
@@ -965,7 +960,6 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, int o
* allocation, but reclaim may drop si->lock and race with another user.
*/
while ((ci = isolate_lock_cluster(si, &si->frag_clusters[o]))) {
- atomic_long_dec(&si->frag_cluster_nr[o]);
found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci),
0, usage);
if (found)
@@ -3217,7 +3211,6 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
for (i = 0; i < SWAP_NR_ORDERS; i++) {
INIT_LIST_HEAD(&si->nonfull_clusters[i]);
INIT_LIST_HEAD(&si->frag_clusters[i]);
- atomic_long_set(&si->frag_cluster_nr[i], 0);
}
/*
--
2.50.1
Acked-by: Chris Li <chrisl@kernel.org> Chris On Wed, Aug 6, 2025 at 9:18 AM Kairui Song <ryncsn@gmail.com> wrote: > > From: Kairui Song <kasong@tencent.com> > > It was used for calculating the iteration number when the swap allocator > wants to scan the whole fragment list. Now the allocator only scans one > fragment cluster at a time, so no one uses this counter anymore. > > Remove it as a cleanup; the performance change is marginal: > > Build linux kernel using 10G ZRAM, make -j96, defconfig with 2G cgroup > memory limit, on top of tmpfs, 64kB mTHP enabled: > > Before: sys time: 6278.45s > After: sys time: 6176.34s > > Change to 8G ZRAM: > > Before: sys time: 5572.85s > After: sys time: 5531.49s > > Signed-off-by: Kairui Song <kasong@tencent.com> > --- > include/linux/swap.h | 1 - > mm/swapfile.c | 7 ------- > 2 files changed, 8 deletions(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index 2fe6ed2cc3fd..a060d102e0d1 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -310,7 +310,6 @@ struct swap_info_struct { > /* list of cluster that contains at least one free slot */ > struct list_head frag_clusters[SWAP_NR_ORDERS]; > /* list of cluster that are fragmented or contented */ > - atomic_long_t frag_cluster_nr[SWAP_NR_ORDERS]; > unsigned int pages; /* total of usable pages of swap */ > atomic_long_t inuse_pages; /* number of those currently in use */ > struct swap_sequential_cluster *global_cluster; /* Use one global cluster for rotating device */ > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 1f1110e37f68..5fdb3cb2b8b7 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -470,11 +470,6 @@ static void move_cluster(struct swap_info_struct *si, > else > list_move_tail(&ci->list, list); > spin_unlock(&si->lock); > - > - if (ci->flags == CLUSTER_FLAG_FRAG) > - atomic_long_dec(&si->frag_cluster_nr[ci->order]); > - else if (new_flags == CLUSTER_FLAG_FRAG) > - atomic_long_inc(&si->frag_cluster_nr[ci->order]); > ci->flags = new_flags; > } > > @@ -965,7 +960,6 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, int o > * allocation, but reclaim may drop si->lock and race with another user. > */ > while ((ci = isolate_lock_cluster(si, &si->frag_clusters[o]))) { > - atomic_long_dec(&si->frag_cluster_nr[o]); > found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), > 0, usage); > if (found) > @@ -3217,7 +3211,6 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si, > for (i = 0; i < SWAP_NR_ORDERS; i++) { > INIT_LIST_HEAD(&si->nonfull_clusters[i]); > INIT_LIST_HEAD(&si->frag_clusters[i]); > - atomic_long_set(&si->frag_cluster_nr[i], 0); > } > > /* > -- > 2.50.1 >
Acked-by: Chris Li <chrisl@kernel.org> Chris On Wed, Aug 6, 2025 at 9:18 AM Kairui Song <ryncsn@gmail.com> wrote: > > From: Kairui Song <kasong@tencent.com> > > It was used for calculating the iteration number when the swap allocator > wants to scan the whole fragment list. Now the allocator only scans one > fragment cluster at a time, so no one uses this counter anymore. > > Remove it as a cleanup; the performance change is marginal: > > Build linux kernel using 10G ZRAM, make -j96, defconfig with 2G cgroup > memory limit, on top of tmpfs, 64kB mTHP enabled: > > Before: sys time: 6278.45s > After: sys time: 6176.34s > > Change to 8G ZRAM: > > Before: sys time: 5572.85s > After: sys time: 5531.49s > > Signed-off-by: Kairui Song <kasong@tencent.com> > --- > include/linux/swap.h | 1 - > mm/swapfile.c | 7 ------- > 2 files changed, 8 deletions(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index 2fe6ed2cc3fd..a060d102e0d1 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -310,7 +310,6 @@ struct swap_info_struct { > /* list of cluster that contains at least one free slot */ > struct list_head frag_clusters[SWAP_NR_ORDERS]; > /* list of cluster that are fragmented or contented */ > - atomic_long_t frag_cluster_nr[SWAP_NR_ORDERS]; > unsigned int pages; /* total of usable pages of swap */ > atomic_long_t inuse_pages; /* number of those currently in use */ > struct swap_sequential_cluster *global_cluster; /* Use one global cluster for rotating device */ > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 1f1110e37f68..5fdb3cb2b8b7 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -470,11 +470,6 @@ static void move_cluster(struct swap_info_struct *si, > else > list_move_tail(&ci->list, list); > spin_unlock(&si->lock); > - > - if (ci->flags == CLUSTER_FLAG_FRAG) > - atomic_long_dec(&si->frag_cluster_nr[ci->order]); > - else if (new_flags == CLUSTER_FLAG_FRAG) > - atomic_long_inc(&si->frag_cluster_nr[ci->order]); > ci->flags = new_flags; > } > > @@ -965,7 +960,6 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, int o > * allocation, but reclaim may drop si->lock and race with another user. > */ > while ((ci = isolate_lock_cluster(si, &si->frag_clusters[o]))) { > - atomic_long_dec(&si->frag_cluster_nr[o]); > found = alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), > 0, usage); > if (found) > @@ -3217,7 +3211,6 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si, > for (i = 0; i < SWAP_NR_ORDERS; i++) { > INIT_LIST_HEAD(&si->nonfull_clusters[i]); > INIT_LIST_HEAD(&si->frag_clusters[i]); > - atomic_long_set(&si->frag_cluster_nr[i], 0); > } > > /* > -- > 2.50.1 > >
On Wed, Aug 6, 2025 at 9:18 AM Kairui Song <ryncsn@gmail.com> wrote: > > From: Kairui Song <kasong@tencent.com> > > It was used for calculating the iteration number when the swap allocator > wants to scan the whole fragment list. Now the allocator only scans one > fragment cluster at a time, so no one uses this counter anymore. > > Remove it as a cleanup; the performance change is marginal: > > Build linux kernel using 10G ZRAM, make -j96, defconfig with 2G cgroup > memory limit, on top of tmpfs, 64kB mTHP enabled: > > Before: sys time: 6278.45s > After: sys time: 6176.34s > > Change to 8G ZRAM: > > Before: sys time: 5572.85s > After: sys time: 5531.49s > > Signed-off-by: Kairui Song <kasong@tencent.com> Reviewed-by: Nhat Pham <nphamcs@gmail.com>
© 2016 - 2025 Red Hat, Inc.