mm/swapfile.c: simplify the calculation of n_goal
Subsystems (2)
PATCH 1/2 mm/swapfile.c: simplify the calculation of n_goal
Use min3() to simplify the comparison and make it more self-explaining.
Signed-off-by Wei Yang <[email protected]>
--- mm/swapfile.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
mm/swapfile.c +1 -5
@@ -1004,11 +1004,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)if (avail_pgs <=0 ) goto noswap; -if (n_goal >SWAP_BATCH ) - n_goal =SWAP_BATCH ; - -if (n_goal > avail_pgs) - n_goal = avail_pgs; + n_goal =min3 ((long )n_goal, (long )SWAP_BATCH , avail_pgs);atomic_long_sub (n_goal * size, &nr_swap_pages);
Signature · 1 line
2.23.0
PATCH 2/2 mm/swapfile.c: remove the extra check in scan_swap_map_slots()
scan_swap_map_slots() is only called by scan_swap_map() and get_swap_pages(). Both ensure nr would not exceed SWAP_BATCH.
Just remove it.
Signed-off-by Wei Yang <[email protected]>
--- mm/swapfile.c | 3 --- 1 file changed, 3 deletions(-)
mm/swapfile.c +0 -3
@@ -740,9 +740,6 @@ static int scan_swap_map_slots(struct swap_info_struct *si,int latency_ration =LATENCY_LIMIT ;int n_ret =0 ; -if (nr >SWAP_BATCH ) - nr =SWAP_BATCH ; -/* * We try to cluster swap pages by allocating them sequentially * in swap. Once we've allocated SWAPFILE_CLUSTER pages this
Signature · 1 line
2.23.0