Skip to content

Commit 2e2e425

Browse files
kosakitorvalds
authored andcommitted
vmscan,memcg: reintroduce sc->may_swap
Commit a6dc60f ("vmscan: rename sc.may_swap to may_unmap") removed the may_swap flag, but memcg had used it as a flag for "we need to use swap?", as the name indicate. And in the current implementation, memcg cannot reclaim mapped file caches when mem+swap hits the limit. re-introduce may_swap flag and handle it at get_scan_ratio(). This patch doesn't influence any scan_control users other than memcg. Signed-off-by: KOSAKI Motohiro <[email protected]> Signed-off-by: Daisuke Nishimura <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Balbir Singh <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 55e5750 commit 2e2e425

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mm/vmscan.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct scan_control {
6363
/* Can mapped pages be reclaimed? */
6464
int may_unmap;
6565

66+
/* Can pages be swapped as part of reclaim? */
67+
int may_swap;
68+
6669
/* This context's SWAP_CLUSTER_MAX. If freeing memory for
6770
* suspend, we effectively ignore SWAP_CLUSTER_MAX.
6871
* In this context, it doesn't matter that we scan the
@@ -1380,7 +1383,7 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
13801383
struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
13811384

13821385
/* If we have no swap space, do not bother scanning anon pages. */
1383-
if (nr_swap_pages <= 0) {
1386+
if (!sc->may_swap || (nr_swap_pages <= 0)) {
13841387
percent[0] = 0;
13851388
percent[1] = 100;
13861389
return;
@@ -1697,6 +1700,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
16971700
.may_writepage = !laptop_mode,
16981701
.swap_cluster_max = SWAP_CLUSTER_MAX,
16991702
.may_unmap = 1,
1703+
.may_swap = 1,
17001704
.swappiness = vm_swappiness,
17011705
.order = order,
17021706
.mem_cgroup = NULL,
@@ -1717,6 +1721,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
17171721
struct scan_control sc = {
17181722
.may_writepage = !laptop_mode,
17191723
.may_unmap = 1,
1724+
.may_swap = !noswap,
17201725
.swap_cluster_max = SWAP_CLUSTER_MAX,
17211726
.swappiness = swappiness,
17221727
.order = 0,
@@ -1726,9 +1731,6 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
17261731
};
17271732
struct zonelist *zonelist;
17281733

1729-
if (noswap)
1730-
sc.may_unmap = 0;
1731-
17321734
sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
17331735
(GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK);
17341736
zonelist = NODE_DATA(numa_node_id())->node_zonelists;
@@ -1767,6 +1769,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order)
17671769
struct scan_control sc = {
17681770
.gfp_mask = GFP_KERNEL,
17691771
.may_unmap = 1,
1772+
.may_swap = 1,
17701773
.swap_cluster_max = SWAP_CLUSTER_MAX,
17711774
.swappiness = vm_swappiness,
17721775
.order = order,
@@ -2298,6 +2301,7 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
22982301
struct scan_control sc = {
22992302
.may_writepage = !!(zone_reclaim_mode & RECLAIM_WRITE),
23002303
.may_unmap = !!(zone_reclaim_mode & RECLAIM_SWAP),
2304+
.may_swap = 1,
23012305
.swap_cluster_max = max_t(unsigned long, nr_pages,
23022306
SWAP_CLUSTER_MAX),
23032307
.gfp_mask = gfp_mask,

0 commit comments

Comments
 (0)