Skip to content

Commit

Permalink
mm/swapfile.c: offset is only used when there is more slots
Browse files Browse the repository at this point in the history
scan_swap_map_slots() is used to iterate swap_map[] array for an
available swap entry.  While after several optimizations, e.g.  for ssd
case, the logic of this function is a little not easy to catch.

This patchset tries to clean up the logic a little:

  * shows the ssd/non-ssd case is handled mutually exclusively
  * remove some unnecessary goto for ssd case

This patch (of 3):

When si->cluster_nr is zero, function would reach done and return.  The
increased offset would not be used any more.  This means we can move the
offset increment into the if clause.

This brings a further code cleanup possibility.

Signed-off-by: Wei Yang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Tim Chen <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
RichardWeiYang authored and torvalds committed Jun 2, 2020
1 parent ebc5951 commit ca2c55a
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,9 @@ static int scan_swap_map_slots(struct swap_info_struct *si,
else
goto done;
}
/* non-ssd case */
++offset;

/* non-ssd case, still more slots in cluster? */
if (si->cluster_nr && !si->swap_map[offset]) {
if (si->cluster_nr && !si->swap_map[++offset]) {
--si->cluster_nr;
goto checks;
}
Expand Down

0 comments on commit ca2c55a

Please sign in to comment.