Skip to content

Commit 5d5e8f1

Browse files
yhuang-inteltorvalds
authored andcommitted
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>
1 parent a448f2d commit 5d5e8f1

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

include/linux/swap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ extern void si_swapinfo(struct sysinfo *);
447447
extern swp_entry_t get_swap_page(struct page *page);
448448
extern void put_swap_page(struct page *page, swp_entry_t entry);
449449
extern swp_entry_t get_swap_page_of_type(int);
450-
extern int get_swap_pages(int n, bool cluster, swp_entry_t swp_entries[]);
450+
extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size);
451451
extern int add_swap_count_continuation(swp_entry_t, gfp_t);
452452
extern void swap_shmem_alloc(swp_entry_t);
453453
extern int swap_duplicate(swp_entry_t);

mm/swap_slots.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ static int refill_swap_slots_cache(struct swap_slots_cache *cache)
269269

270270
cache->cur = 0;
271271
if (swap_slot_cache_active)
272-
cache->nr = get_swap_pages(SWAP_SLOTS_CACHE_SIZE, false,
273-
cache->slots);
272+
cache->nr = get_swap_pages(SWAP_SLOTS_CACHE_SIZE,
273+
cache->slots, 1);
274274

275275
return cache->nr;
276276
}
@@ -316,7 +316,7 @@ swp_entry_t get_swap_page(struct page *page)
316316

317317
if (PageTransHuge(page)) {
318318
if (IS_ENABLED(CONFIG_THP_SWAP))
319-
get_swap_pages(1, true, &entry);
319+
get_swap_pages(1, &entry, HPAGE_PMD_NR);
320320
goto out;
321321
}
322322

@@ -350,7 +350,7 @@ swp_entry_t get_swap_page(struct page *page)
350350
goto out;
351351
}
352352

353-
get_swap_pages(1, false, &entry);
353+
get_swap_pages(1, &entry, 1);
354354
out:
355355
if (mem_cgroup_try_charge_swap(page, entry)) {
356356
put_swap_page(page, entry);

mm/swapfile.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,18 +940,18 @@ static unsigned long scan_swap_map(struct swap_info_struct *si,
940940

941941
}
942942

943-
int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
943+
int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)
944944
{
945-
unsigned long nr_pages = cluster ? SWAPFILE_CLUSTER : 1;
945+
unsigned long size = swap_entry_size(entry_size);
946946
struct swap_info_struct *si, *next;
947947
long avail_pgs;
948948
int n_ret = 0;
949949
int node;
950950

951951
/* Only single cluster request supported */
952-
WARN_ON_ONCE(n_goal > 1 && cluster);
952+
WARN_ON_ONCE(n_goal > 1 && size == SWAPFILE_CLUSTER);
953953

954-
avail_pgs = atomic_long_read(&nr_swap_pages) / nr_pages;
954+
avail_pgs = atomic_long_read(&nr_swap_pages) / size;
955955
if (avail_pgs <= 0)
956956
goto noswap;
957957

@@ -961,7 +961,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
961961
if (n_goal > avail_pgs)
962962
n_goal = avail_pgs;
963963

964-
atomic_long_sub(n_goal * nr_pages, &nr_swap_pages);
964+
atomic_long_sub(n_goal * size, &nr_swap_pages);
965965

966966
spin_lock(&swap_avail_lock);
967967

@@ -988,14 +988,14 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
988988
spin_unlock(&si->lock);
989989
goto nextsi;
990990
}
991-
if (cluster) {
991+
if (size == SWAPFILE_CLUSTER) {
992992
if (!(si->flags & SWP_FILE))
993993
n_ret = swap_alloc_cluster(si, swp_entries);
994994
} else
995995
n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE,
996996
n_goal, swp_entries);
997997
spin_unlock(&si->lock);
998-
if (n_ret || cluster)
998+
if (n_ret || size == SWAPFILE_CLUSTER)
999999
goto check_out;
10001000
pr_debug("scan_swap_map of si %d failed to find offset\n",
10011001
si->type);
@@ -1021,7 +1021,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[])
10211021

10221022
check_out:
10231023
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,
10251025
&nr_swap_pages);
10261026
noswap:
10271027
return n_ret;

0 commit comments

Comments
 (0)