Skip to content

Commit a09ed5e

Browse files
yinghantorvalds
authored andcommitted
vmscan: change shrink_slab() interfaces by passing shrink_control
Consolidate the existing parameters to shrink_slab() into a new shrink_control struct. This is needed later to pass the same struct to shrinkers. Signed-off-by: Ying Han <yinghan@google.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Minchan Kim <minchan.kim@gmail.com> Acked-by: Pavel Emelyanov <xemul@openvz.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Mel Gorman <mel@csn.ul.ie> Acked-by: Rik van Riel <riel@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Hugh Dickins <hughd@google.com> Cc: Dave Hansen <dave@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7b1de58 commit a09ed5e

4 files changed

Lines changed: 55 additions & 17 deletions

File tree

‎fs/drop_caches.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
4040
static void drop_slab(void)
4141
{
4242
int nr_objects;
43+
struct shrink_control shrink = {
44+
.gfp_mask = GFP_KERNEL,
45+
.nr_scanned = 1000,
46+
};
4347

4448
do {
45-
nr_objects = shrink_slab(1000, GFP_KERNEL, 1000);
49+
nr_objects = shrink_slab(&shrink, 1000);
4650
} while (nr_objects > 10);
4751
}
4852

‎include/linux/mm.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
11611161
}
11621162
#endif
11631163

1164+
/*
1165+
* This struct is used to pass information from page reclaim to the shrinkers.
1166+
* We consolidate the values for easier extention later.
1167+
*/
1168+
struct shrink_control {
1169+
unsigned long nr_scanned;
1170+
gfp_t gfp_mask;
1171+
};
1172+
11641173
/*
11651174
* A callback you can register to apply pressure to ageable caches.
11661175
*
@@ -1630,8 +1639,8 @@ int in_gate_area_no_mm(unsigned long addr);
16301639

16311640
int drop_caches_sysctl_handler(struct ctl_table *, int,
16321641
void __user *, size_t *, loff_t *);
1633-
unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
1634-
unsigned long lru_pages);
1642+
unsigned long shrink_slab(struct shrink_control *shrink,
1643+
unsigned long lru_pages);
16351644

16361645
#ifndef CONFIG_MMU
16371646
#define randomize_va_space 0

‎mm/memory-failure.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ void shake_page(struct page *p, int access)
239239
if (access) {
240240
int nr;
241241
do {
242-
nr = shrink_slab(1000, GFP_KERNEL, 1000);
242+
struct shrink_control shrink = {
243+
.gfp_mask = GFP_KERNEL,
244+
.nr_scanned = 1000,
245+
};
246+
247+
nr = shrink_slab(&shrink, 1000);
243248
if (page_count(p) == 1)
244249
break;
245250
} while (nr > 10);

‎mm/vmscan.c‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,13 @@ EXPORT_SYMBOL(unregister_shrinker);
222222
*
223223
* Returns the number of slab objects which we shrunk.
224224
*/
225-
unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
226-
unsigned long lru_pages)
225+
unsigned long shrink_slab(struct shrink_control *shrink,
226+
unsigned long lru_pages)
227227
{
228228
struct shrinker *shrinker;
229229
unsigned long ret = 0;
230+
unsigned long scanned = shrink->nr_scanned;
231+
gfp_t gfp_mask = shrink->gfp_mask;
230232

231233
if (scanned == 0)
232234
scanned = SWAP_CLUSTER_MAX;
@@ -2035,7 +2037,8 @@ static bool all_unreclaimable(struct zonelist *zonelist,
20352037
* else, the number of pages reclaimed
20362038
*/
20372039
static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
2038-
struct scan_control *sc)
2040+
struct scan_control *sc,
2041+
struct shrink_control *shrink)
20392042
{
20402043
int priority;
20412044
unsigned long total_scanned = 0;
@@ -2069,7 +2072,8 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
20692072
lru_pages += zone_reclaimable_pages(zone);
20702073
}
20712074

2072-
shrink_slab(sc->nr_scanned, sc->gfp_mask, lru_pages);
2075+
shrink->nr_scanned = sc->nr_scanned;
2076+
shrink_slab(shrink, lru_pages);
20732077
if (reclaim_state) {
20742078
sc->nr_reclaimed += reclaim_state->reclaimed_slab;
20752079
reclaim_state->reclaimed_slab = 0;
@@ -2141,12 +2145,15 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
21412145
.mem_cgroup = NULL,
21422146
.nodemask = nodemask,
21432147
};
2148+
struct shrink_control shrink = {
2149+
.gfp_mask = sc.gfp_mask,
2150+
};
21442151

21452152
trace_mm_vmscan_direct_reclaim_begin(order,
21462153
sc.may_writepage,
21472154
gfp_mask);
21482155

2149-
nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
2156+
nr_reclaimed = do_try_to_free_pages(zonelist, &sc, &shrink);
21502157

21512158
trace_mm_vmscan_direct_reclaim_end(nr_reclaimed);
21522159

@@ -2206,17 +2213,20 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
22062213
.order = 0,
22072214
.mem_cgroup = mem_cont,
22082215
.nodemask = NULL, /* we don't care the placement */
2216+
.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
2217+
(GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK),
2218+
};
2219+
struct shrink_control shrink = {
2220+
.gfp_mask = sc.gfp_mask,
22092221
};
22102222

2211-
sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
2212-
(GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK);
22132223
zonelist = NODE_DATA(numa_node_id())->node_zonelists;
22142224

22152225
trace_mm_vmscan_memcg_reclaim_begin(0,
22162226
sc.may_writepage,
22172227
sc.gfp_mask);
22182228

2219-
nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
2229+
nr_reclaimed = do_try_to_free_pages(zonelist, &sc, &shrink);
22202230

22212231
trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed);
22222232

@@ -2344,6 +2354,9 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
23442354
.order = order,
23452355
.mem_cgroup = NULL,
23462356
};
2357+
struct shrink_control shrink = {
2358+
.gfp_mask = sc.gfp_mask,
2359+
};
23472360
loop_again:
23482361
total_scanned = 0;
23492362
sc.nr_reclaimed = 0;
@@ -2443,8 +2456,8 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
24432456
end_zone, 0))
24442457
shrink_zone(priority, zone, &sc);
24452458
reclaim_state->reclaimed_slab = 0;
2446-
nr_slab = shrink_slab(sc.nr_scanned, GFP_KERNEL,
2447-
lru_pages);
2459+
shrink.nr_scanned = sc.nr_scanned;
2460+
nr_slab = shrink_slab(&shrink, lru_pages);
24482461
sc.nr_reclaimed += reclaim_state->reclaimed_slab;
24492462
total_scanned += sc.nr_scanned;
24502463

@@ -2796,7 +2809,10 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
27962809
.swappiness = vm_swappiness,
27972810
.order = 0,
27982811
};
2799-
struct zonelist * zonelist = node_zonelist(numa_node_id(), sc.gfp_mask);
2812+
struct shrink_control shrink = {
2813+
.gfp_mask = sc.gfp_mask,
2814+
};
2815+
struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask);
28002816
struct task_struct *p = current;
28012817
unsigned long nr_reclaimed;
28022818

@@ -2805,7 +2821,7 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
28052821
reclaim_state.reclaimed_slab = 0;
28062822
p->reclaim_state = &reclaim_state;
28072823

2808-
nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
2824+
nr_reclaimed = do_try_to_free_pages(zonelist, &sc, &shrink);
28092825

28102826
p->reclaim_state = NULL;
28112827
lockdep_clear_current_reclaim_state();
@@ -2980,6 +2996,9 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
29802996
.swappiness = vm_swappiness,
29812997
.order = order,
29822998
};
2999+
struct shrink_control shrink = {
3000+
.gfp_mask = sc.gfp_mask,
3001+
};
29833002
unsigned long nr_slab_pages0, nr_slab_pages1;
29843003

29853004
cond_resched();
@@ -3006,6 +3025,7 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
30063025
}
30073026

30083027
nr_slab_pages0 = zone_page_state(zone, NR_SLAB_RECLAIMABLE);
3028+
shrink.nr_scanned = sc.nr_scanned;
30093029
if (nr_slab_pages0 > zone->min_slab_pages) {
30103030
/*
30113031
* shrink_slab() does not currently allow us to determine how
@@ -3021,7 +3041,7 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
30213041
unsigned long lru_pages = zone_reclaimable_pages(zone);
30223042

30233043
/* No reclaimable slab or very low memory pressure */
3024-
if (!shrink_slab(sc.nr_scanned, gfp_mask, lru_pages))
3044+
if (!shrink_slab(&shrink, lru_pages))
30253045
break;
30263046

30273047
/* Freed enough memory */

0 commit comments

Comments
 (0)