Skip to content

Commit

Permalink
mm/swapfile.c: unify normal/huge code path in swap_page_trans_huge_sw…
Browse files Browse the repository at this point in the history
…apped()

As suggested by Dave, we should unify the code path for normal and huge
swap support if possible to avoid duplicated code, bugs, etc.  and make
it easier to review code.

In this patch, the normal/huge code path in
swap_page_trans_huge_swapped() is unified, the added and removed lines
are same.  And the binary size is kept almost same when
CONFIG_TRANSPARENT_HUGEPAGE=n.

		 text	   data	    bss	    dec	    hex	filename
base:		24179	   2028	    340	  26547	   67b3	mm/swapfile.o
unified:	24215	   2028	    340	  26583	   67d7	mm/swapfile.o

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: "Huang, Ying" <[email protected]>
Suggested-and-acked-by: Dave Hansen <[email protected]>
Reviewed-by: Daniel Jordan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Shaohua Li <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
yhuang-intel authored and torvalds committed Aug 22, 2018
1 parent afa4711 commit 33ee011
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ static inline void cluster_set_null(struct swap_cluster_info *info)

static inline bool cluster_is_huge(struct swap_cluster_info *info)
{
return info->flags & CLUSTER_FLAG_HUGE;
if (IS_ENABLED(CONFIG_THP_SWAP))
return info->flags & CLUSTER_FLAG_HUGE;
return false;
}

static inline void cluster_clear_huge(struct swap_cluster_info *info)
Expand Down Expand Up @@ -1424,9 +1426,6 @@ static bool swap_page_trans_huge_swapped(struct swap_info_struct *si,
int i;
bool ret = false;

if (!IS_ENABLED(CONFIG_THP_SWAP))
return swap_swapcount(si, entry) != 0;

ci = lock_cluster_or_swap_info(si, offset);
if (!ci || !cluster_is_huge(ci)) {
if (swap_count(map[roffset]))
Expand Down

0 comments on commit 33ee011

Please sign in to comment.