Skip to content

Commit 1d21229

Browse files
Baoquan Heakpm00
authored andcommitted
mm/swapfile.c: open code cluster_alloc_swap()
It's only called in scan_swap_map_slots(). And also remove the stale code comment in scan_swap_map_slots() because it's not fit for the current cluster allocation mechanism. Link: https://lkml.kernel.org/r/20250205092721.9395-13-bhe@redhat.com Signed-off-by: Baoquan He <bhe@redhat.com> Cc: Chris Li <chrisl@kernel.org> Cc: Kairui Song <ryncsn@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 4ccd415 commit 1d21229

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

mm/swapfile.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,39 +1163,13 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset,
11631163
swap_usage_sub(si, nr_entries);
11641164
}
11651165

1166-
static int cluster_alloc_swap(struct swap_info_struct *si,
1167-
unsigned char usage, int nr,
1168-
swp_entry_t slots[], int order)
1169-
{
1170-
int n_ret = 0;
1171-
1172-
while (n_ret < nr) {
1173-
unsigned long offset = cluster_alloc_swap_entry(si, order, usage);
1174-
1175-
if (!offset)
1176-
break;
1177-
slots[n_ret++] = swp_entry(si->type, offset);
1178-
}
1179-
1180-
return n_ret;
1181-
}
1182-
11831166
static int scan_swap_map_slots(struct swap_info_struct *si,
11841167
unsigned char usage, int nr,
11851168
swp_entry_t slots[], int order)
11861169
{
11871170
unsigned int nr_pages = 1 << order;
1171+
int n_ret = 0;
11881172

1189-
/*
1190-
* We try to cluster swap pages by allocating them sequentially
1191-
* in swap. Once we've allocated SWAPFILE_CLUSTER pages this
1192-
* way, however, we resort to first-free allocation, starting
1193-
* a new cluster. This prevents us from scattering swap pages
1194-
* all over the entire swap partition, so that we reduce
1195-
* overall disk seek times between swap pages. -- sct
1196-
* But we do now try to find an empty cluster. -Andrea
1197-
* And we let swap pages go all over an SSD partition. Hugh
1198-
*/
11991173
if (order > 0) {
12001174
/*
12011175
* Should not even be attempting large allocations when huge
@@ -1215,7 +1189,15 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
12151189
return 0;
12161190
}
12171191

1218-
return cluster_alloc_swap(si, usage, nr, slots, order);
1192+
while (n_ret < nr) {
1193+
unsigned long offset = cluster_alloc_swap_entry(si, order, usage);
1194+
1195+
if (!offset)
1196+
break;
1197+
slots[n_ret++] = swp_entry(si->type, offset);
1198+
}
1199+
1200+
return n_ret;
12191201
}
12201202

12211203
static bool get_swap_device_info(struct swap_info_struct *si)

0 commit comments

Comments
 (0)