@@ -55,7 +55,7 @@ static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
5555static void free_swap_count_continuations (struct swap_info_struct * );
5656static 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 );
6060static bool folio_swapcache_freeable (struct folio * folio );
6161static 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