summaryrefslogtreecommitdiffstats
path: root/mm/swapfile.c
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2018-08-22 00:52:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-22 13:52:44 -0400
commit5d5e8f19544a35ae1609bd96ae6b28c9fcd1baf6 (patch)
tree56295e1b8079c068dbc751357126aeb9fb8218df /mm/swapfile.c
parenta448f2d07f891ac65cc48017f17735ec73086bf0 (diff)
mm, swap, get_swap_pages: use entry_size instead of cluster in parameter
As suggested by Matthew Wilcox, it is better to use "int entry_size" instead of "bool cluster" as parameter to specify whether to operate for huge or normal swap entries. Because this improve the flexibility to support other swap entry size. And Dave Hansen thinks that this improves code readability too. So in this patch, the "bool cluster" parameter of get_swap_pages() is replaced by "int entry_size". And nr_swap_entries() trick is used to reduce the binary size when !CONFIG_TRANSPARENT_HUGE_PAGE. text data bss dec hex filename base 24215 2028 340 26583 67d7 mm/swapfile.o head 24123 2004 340 26467 6763 mm/swapfile.o Link: http://lkml.kernel.org/r/20180720071845.17920-7-ying.huang@intel.com Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Suggested-by: Matthew Wilcox <willy@infradead.org> Acked-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Daniel Jordan <daniel.m.jordan@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Shaohua Li <shli@kernel.org> Cc: Hugh Dickins <hughd@google.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Rik van Riel <riel@redhat.com> Cc: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r--mm/swapfile.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 043645e7f0b5..b30dd0642ccf 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -940,18 +940,18 @@ static unsigned long scan_swap_map(struct swap_info_struct *si,
940 940
941} 941}
942 942
943int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) 943int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)
944{ 944{
945 unsigned long nr_pages = cluster ? SWAPFILE_CLUSTER : 1; 945 unsigned long size = swap_entry_size(entry_size);
946 struct swap_info_struct *si, *next; 946 struct swap_info_struct *si, *next;
947 long avail_pgs; 947 long avail_pgs;
948 int n_ret = 0; 948 int n_ret = 0;
949 int node; 949 int node;
950 950
951 /* Only single cluster request supported */ 951 /* Only single cluster request supported */
952 WARN_ON_ONCE(n_goal > 1 && cluster); 952 WARN_ON_ONCE(n_goal > 1 && size == SWAPFILE_CLUSTER);
953 953
954 avail_pgs = atomic_long_read(&nr_swap_pages) / nr_pages; 954 avail_pgs = atomic_long_read(&nr_swap_pages) / size;
955 if (avail_pgs <= 0) 955 if (avail_pgs <= 0)
956 goto noswap; 956 goto noswap;
957 957
@@ -961,7 +961,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
961 if (n_goal > avail_pgs) 961 if (n_goal > avail_pgs)
962 n_goal = avail_pgs; 962 n_goal = avail_pgs;
963 963
964 atomic_long_sub(n_goal * nr_pages, &nr_swap_pages); 964 atomic_long_sub(n_goal * size, &nr_swap_pages);
965 965
966 spin_lock(&swap_avail_lock); 966 spin_lock(&swap_avail_lock);
967 967
@@ -988,14 +988,14 @@ start_over:
988 spin_unlock(&si->lock); 988 spin_unlock(&si->lock);
989 goto nextsi; 989 goto nextsi;
990 } 990 }
991 if (cluster) { 991 if (size == SWAPFILE_CLUSTER) {
992 if (!(si->flags & SWP_FILE)) 992 if (!(si->flags & SWP_FILE))
993 n_ret = swap_alloc_cluster(si, swp_entries); 993 n_ret = swap_alloc_cluster(si, swp_entries);
994 } else 994 } else
995 n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE, 995 n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE,
996 n_goal, swp_entries); 996 n_goal, swp_entries);
997 spin_unlock(&si->lock); 997 spin_unlock(&si->lock);
998 if (n_ret || cluster) 998 if (n_ret || size == SWAPFILE_CLUSTER)
999 goto check_out; 999 goto check_out;
1000 pr_debug("scan_swap_map of si %d failed to find offset\n", 1000 pr_debug("scan_swap_map of si %d failed to find offset\n",
1001 si->type); 1001 si->type);
@@ -1021,7 +1021,7 @@ nextsi:
1021 1021
1022check_out: 1022check_out:
1023 if (n_ret < n_goal) 1023 if (n_ret < n_goal)
1024 atomic_long_add((long)(n_goal - n_ret) * nr_pages, 1024 atomic_long_add((long)(n_goal - n_ret) * size,
1025 &nr_swap_pages); 1025 &nr_swap_pages);
1026noswap: 1026noswap:
1027 return n_ret; 1027 return n_ret;