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/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>

authored by

Baoquan He and committed by
Andrew Morton
1d212293 4ccd4154

+10 -28
+10 -28
mm/swapfile.c
··· 1163 1163 swap_usage_sub(si, nr_entries); 1164 1164 } 1165 1165 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 - 1183 1166 static int scan_swap_map_slots(struct swap_info_struct *si, 1184 1167 unsigned char usage, int nr, 1185 1168 swp_entry_t slots[], int order) 1186 1169 { 1187 1170 unsigned int nr_pages = 1 << order; 1171 + int n_ret = 0; 1188 1172 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 - */ 1199 1173 if (order > 0) { 1200 1174 /* 1201 1175 * Should not even be attempting large allocations when huge ··· 1189 1215 return 0; 1190 1216 } 1191 1217 1192 - return cluster_alloc_swap(si, usage, nr, slots, order); 1218 + while (n_ret < nr) { 1219 + unsigned long offset = cluster_alloc_swap_entry(si, order, usage); 1220 + 1221 + if (!offset) 1222 + break; 1223 + slots[n_ret++] = swp_entry(si->type, offset); 1224 + } 1225 + 1226 + return n_ret; 1193 1227 } 1194 1228 1195 1229 static bool get_swap_device_info(struct swap_info_struct *si)