Skip to content

Commit 2770152

Browse files
ryncsnakpm00
authored andcommitted
mm, swap: clean up device availability check
Remove highest_bit and lowest_bit. After the HDD allocation path has been removed, the only purpose of these two fields is to determine whether the device is full or not, which can instead be determined by checking the inuse_pages. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kairui Song <[email protected]> Reviewed-by: Baoquan He <[email protected]> Cc: Barry Song <[email protected]> Cc: Chis Li <[email protected]> Cc: "Huang, Ying" <[email protected]> Cc: Hugh Dickens <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Kalesh Singh <[email protected]> Cc: Nhat Pham <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Yosry Ahmed <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0b310d9 commit 2770152

File tree

6 files changed

+8
-36
lines changed

6 files changed

+8
-36
lines changed

fs/btrfs/inode.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10110,7 +10110,6 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
1011010110
*span = bsi.highest_ppage - bsi.lowest_ppage + 1;
1011110111
sis->max = bsi.nr_pages;
1011210112
sis->pages = bsi.nr_pages - 1;
10113-
sis->highest_bit = bsi.nr_pages - 1;
1011410113
return bsi.nr_extents;
1011510114
}
1011610115
#else

fs/f2fs/data.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4043,7 +4043,6 @@ static int check_swap_activate(struct swap_info_struct *sis,
40434043
cur_lblock = 1; /* force Empty message */
40444044
sis->max = cur_lblock;
40454045
sis->pages = cur_lblock - 1;
4046-
sis->highest_bit = cur_lblock - 1;
40474046
out:
40484047
if (not_aligned)
40494048
f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)",

fs/iomap/swapfile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
189189
*pagespan = 1 + isi.highest_ppage - isi.lowest_ppage;
190190
sis->max = isi.nr_pages;
191191
sis->pages = isi.nr_pages - 1;
192-
sis->highest_bit = isi.nr_pages - 1;
193192
return isi.nr_extents;
194193
}
195194
EXPORT_SYMBOL_GPL(iomap_swapfile_activate);

include/linux/swap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ struct swap_info_struct {
305305
struct list_head frag_clusters[SWAP_NR_ORDERS];
306306
/* list of cluster that are fragmented or contented */
307307
unsigned int frag_cluster_nr[SWAP_NR_ORDERS];
308-
unsigned int lowest_bit; /* index of first free in swap_map */
309-
unsigned int highest_bit; /* index of last free in swap_map */
310308
unsigned int pages; /* total of usable pages of swap */
311309
unsigned int inuse_pages; /* number of those currently in use */
312310
struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */

mm/page_io.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ int generic_swapfile_activate(struct swap_info_struct *sis,
163163
page_no = 1; /* force Empty message */
164164
sis->max = page_no;
165165
sis->pages = page_no - 1;
166-
sis->highest_bit = page_no - 1;
167166
out:
168167
return ret;
169168
bad_bmap:

mm/swapfile.c

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
5555
static void free_swap_count_continuations(struct swap_info_struct *);
5656
static void swap_entry_range_free(struct swap_info_struct *si, swp_entry_t entry,
5757
unsigned int nr_pages);
58-
static void swap_range_alloc(struct swap_info_struct *si, unsigned long offset,
58+
static void swap_range_alloc(struct swap_info_struct *si,
5959
unsigned int nr_entries);
6060
static bool folio_swapcache_freeable(struct folio *folio);
6161
static struct swap_cluster_info *lock_cluster(struct swap_info_struct *si,
@@ -650,7 +650,7 @@ static bool cluster_alloc_range(struct swap_info_struct *si, struct swap_cluster
650650
}
651651

652652
memset(si->swap_map + start, usage, nr_pages);
653-
swap_range_alloc(si, start, nr_pages);
653+
swap_range_alloc(si, nr_pages);
654654
ci->count += nr_pages;
655655

656656
if (ci->count == SWAPFILE_CLUSTER) {
@@ -888,19 +888,11 @@ static void del_from_avail_list(struct swap_info_struct *si)
888888
spin_unlock(&swap_avail_lock);
889889
}
890890

891-
static void swap_range_alloc(struct swap_info_struct *si, unsigned long offset,
891+
static void swap_range_alloc(struct swap_info_struct *si,
892892
unsigned int nr_entries)
893893
{
894-
unsigned int end = offset + nr_entries - 1;
895-
896-
if (offset == si->lowest_bit)
897-
si->lowest_bit += nr_entries;
898-
if (end == si->highest_bit)
899-
WRITE_ONCE(si->highest_bit, si->highest_bit - nr_entries);
900894
WRITE_ONCE(si->inuse_pages, si->inuse_pages + nr_entries);
901895
if (si->inuse_pages == si->pages) {
902-
si->lowest_bit = si->max;
903-
si->highest_bit = 0;
904896
del_from_avail_list(si);
905897

906898
if (vm_swap_full())
@@ -933,15 +925,8 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset,
933925
for (i = 0; i < nr_entries; i++)
934926
clear_bit(offset + i, si->zeromap);
935927

936-
if (offset < si->lowest_bit)
937-
si->lowest_bit = offset;
938-
if (end > si->highest_bit) {
939-
bool was_full = !si->highest_bit;
940-
941-
WRITE_ONCE(si->highest_bit, end);
942-
if (was_full && (si->flags & SWP_WRITEOK))
943-
add_to_avail_list(si);
944-
}
928+
if (si->inuse_pages == si->pages)
929+
add_to_avail_list(si);
945930
if (si->flags & SWP_BLKDEV)
946931
swap_slot_free_notify =
947932
si->bdev->bd_disk->fops->swap_slot_free_notify;
@@ -1051,15 +1036,12 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_order)
10511036
plist_requeue(&si->avail_lists[node], &swap_avail_heads[node]);
10521037
spin_unlock(&swap_avail_lock);
10531038
spin_lock(&si->lock);
1054-
if (!si->highest_bit || !(si->flags & SWP_WRITEOK)) {
1039+
if ((si->inuse_pages == si->pages) || !(si->flags & SWP_WRITEOK)) {
10551040
spin_lock(&swap_avail_lock);
10561041
if (plist_node_empty(&si->avail_lists[node])) {
10571042
spin_unlock(&si->lock);
10581043
goto nextsi;
10591044
}
1060-
WARN(!si->highest_bit,
1061-
"swap_info %d in list but !highest_bit\n",
1062-
si->type);
10631045
WARN(!(si->flags & SWP_WRITEOK),
10641046
"swap_info %d in list but !SWP_WRITEOK\n",
10651047
si->type);
@@ -2441,8 +2423,8 @@ static void _enable_swap_info(struct swap_info_struct *si)
24412423
*/
24422424
plist_add(&si->list, &swap_active_head);
24432425

2444-
/* add to available list iff swap device is not full */
2445-
if (si->highest_bit)
2426+
/* add to available list if swap device is not full */
2427+
if (si->inuse_pages < si->pages)
24462428
add_to_avail_list(si);
24472429
}
24482430

@@ -2606,7 +2588,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
26062588
drain_mmlist();
26072589

26082590
/* wait for anyone still in scan_swap_map_slots */
2609-
p->highest_bit = 0; /* cuts scans short */
26102591
while (p->flags >= SWP_SCANNING) {
26112592
spin_unlock(&p->lock);
26122593
spin_unlock(&swap_lock);
@@ -2941,8 +2922,6 @@ static unsigned long read_swap_header(struct swap_info_struct *si,
29412922
return 0;
29422923
}
29432924

2944-
si->lowest_bit = 1;
2945-
29462925
maxpages = swapfile_maximum_size;
29472926
last_page = swap_header->info.last_page;
29482927
if (!last_page) {
@@ -2959,7 +2938,6 @@ static unsigned long read_swap_header(struct swap_info_struct *si,
29592938
if ((unsigned int)maxpages == 0)
29602939
maxpages = UINT_MAX;
29612940
}
2962-
si->highest_bit = maxpages - 1;
29632941

29642942
if (!maxpages)
29652943
return 0;

0 commit comments

Comments
 (0)