blob: e2ebbd50ac55ded0c0bd01e6232328db62aa1885 [file] [log] [blame]
Anton Vorontsov70ddf632013-04-29 15:08:31 -07001/*
2 * Linux VM pressure
3 *
4 * Copyright 2012 Linaro Ltd.
5 * Anton Vorontsov <anton.vorontsov@linaro.org>
6 *
7 * Based on ideas from Andrew Morton, David Rientjes, KOSAKI Motohiro,
8 * Leonid Moiseichuk, Mel Gorman, Minchan Kim and Pekka Enberg.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15#include <linux/cgroup.h>
16#include <linux/fs.h>
17#include <linux/log2.h>
18#include <linux/sched.h>
19#include <linux/mm.h>
20#include <linux/vmstat.h>
21#include <linux/eventfd.h>
Tejun Heo1ff6bbf2014-01-28 18:10:37 -050022#include <linux/slab.h>
Anton Vorontsov70ddf632013-04-29 15:08:31 -070023#include <linux/swap.h>
24#include <linux/printk.h>
Vinayak Menon13088ad2015-03-04 16:38:28 +053025#include <linux/notifier.h>
26#include <linux/init.h>
Vinayak Menon58091092015-03-31 11:06:29 +053027#include <linux/module.h>
Anton Vorontsov70ddf632013-04-29 15:08:31 -070028#include <linux/vmpressure.h>
29
30/*
31 * The window size (vmpressure_win) is the number of scanned pages before
32 * we try to analyze scanned/reclaimed ratio. So the window is used as a
33 * rate-limit tunable for the "low" level notification, and also for
34 * averaging the ratio for medium/critical levels. Using small window
35 * sizes can cause lot of false positives, but too big window size will
36 * delay the notifications.
37 *
38 * As the vmscan reclaimer logic works with chunks which are multiple of
39 * SWAP_CLUSTER_MAX, it makes sense to use it for the window size as well.
40 *
41 * TODO: Make the window size depend on machine size, as we do for vmstat
42 * thresholds. Currently we set it to 512 pages (2MB for 4KB pages).
43 */
44static const unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16;
45
46/*
47 * These thresholds are used when we account memory pressure through
48 * scanned/reclaimed ratio. The current values were chosen empirically. In
49 * essence, they are percents: the higher the value, the more number
50 * unsuccessful reclaims there were.
51 */
52static const unsigned int vmpressure_level_med = 60;
53static const unsigned int vmpressure_level_critical = 95;
54
Vinayak Menon58091092015-03-31 11:06:29 +053055static unsigned long vmpressure_scale_max = 100;
56module_param_named(vmpressure_scale_max, vmpressure_scale_max,
57 ulong, 0644);
58
Vinayak Menon44778e52015-08-19 16:16:39 +053059/* vmpressure values >= this will be scaled based on allocstalls */
60static unsigned long allocstall_threshold = 70;
61module_param_named(allocstall_threshold, allocstall_threshold,
62 ulong, 0644);
63
Vinayak Menon13088ad2015-03-04 16:38:28 +053064static struct vmpressure global_vmpressure;
65static BLOCKING_NOTIFIER_HEAD(vmpressure_notifier);
66
67int vmpressure_notifier_register(struct notifier_block *nb)
68{
69 return blocking_notifier_chain_register(&vmpressure_notifier, nb);
70}
71
72int vmpressure_notifier_unregister(struct notifier_block *nb)
73{
74 return blocking_notifier_chain_unregister(&vmpressure_notifier, nb);
75}
76
77static void vmpressure_notify(unsigned long pressure)
78{
79 blocking_notifier_call_chain(&vmpressure_notifier, pressure, NULL);
80}
81
Anton Vorontsov70ddf632013-04-29 15:08:31 -070082/*
83 * When there are too little pages left to scan, vmpressure() may miss the
84 * critical pressure as number of pages will be less than "window size".
85 * However, in that case the vmscan priority will raise fast as the
86 * reclaimer will try to scan LRUs more deeply.
87 *
88 * The vmscan logic considers these special priorities:
89 *
90 * prio == DEF_PRIORITY (12): reclaimer starts with that value
91 * prio <= DEF_PRIORITY - 2 : kswapd becomes somewhat overwhelmed
92 * prio == 0 : close to OOM, kernel scans every page in an lru
93 *
94 * Any value in this range is acceptable for this tunable (i.e. from 12 to
95 * 0). Current value for the vmpressure_level_critical_prio is chosen
96 * empirically, but the number, in essence, means that we consider
97 * critical level when scanning depth is ~10% of the lru size (vmscan
98 * scans 'lru_size >> prio' pages, so it is actually 12.5%, or one
99 * eights).
100 */
101static const unsigned int vmpressure_level_critical_prio = ilog2(100 / 10);
102
103static struct vmpressure *work_to_vmpressure(struct work_struct *work)
104{
105 return container_of(work, struct vmpressure, work);
106}
107
Vinayak Menon13088ad2015-03-04 16:38:28 +0530108#ifdef CONFIG_MEMCG
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700109static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr)
110{
Tejun Heo182446d2013-08-08 20:11:24 -0400111 struct cgroup_subsys_state *css = vmpressure_to_css(vmpr);
112 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700113
114 memcg = parent_mem_cgroup(memcg);
115 if (!memcg)
116 return NULL;
117 return memcg_to_vmpressure(memcg);
118}
Vinayak Menon13088ad2015-03-04 16:38:28 +0530119#else
120static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr)
121{
122 return NULL;
123}
124#endif
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700125
126enum vmpressure_levels {
127 VMPRESSURE_LOW = 0,
128 VMPRESSURE_MEDIUM,
129 VMPRESSURE_CRITICAL,
130 VMPRESSURE_NUM_LEVELS,
131};
132
133static const char * const vmpressure_str_levels[] = {
134 [VMPRESSURE_LOW] = "low",
135 [VMPRESSURE_MEDIUM] = "medium",
136 [VMPRESSURE_CRITICAL] = "critical",
137};
138
139static enum vmpressure_levels vmpressure_level(unsigned long pressure)
140{
141 if (pressure >= vmpressure_level_critical)
142 return VMPRESSURE_CRITICAL;
143 else if (pressure >= vmpressure_level_med)
144 return VMPRESSURE_MEDIUM;
145 return VMPRESSURE_LOW;
146}
147
Vinayak Menon13088ad2015-03-04 16:38:28 +0530148static unsigned long vmpressure_calc_pressure(unsigned long scanned,
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700149 unsigned long reclaimed)
150{
151 unsigned long scale = scanned + reclaimed;
Vinayak Menon58d1dbb2017-02-24 14:59:39 -0800152 unsigned long pressure = 0;
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700153
154 /*
Vinayak Menon58d1dbb2017-02-24 14:59:39 -0800155 * reclaimed can be greater than scanned in cases
156 * like THP, where the scanned is 1 and reclaimed
157 * could be 512
158 */
159 if (reclaimed >= scanned)
160 goto out;
161 /*
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700162 * We calculate the ratio (in percents) of how many pages were
163 * scanned vs. reclaimed in a given time frame (window). Note that
164 * time is in VM reclaimer's "ticks", i.e. number of pages
165 * scanned. This makes it possible to set desired reaction time
166 * and serves as a ratelimit.
167 */
168 pressure = scale - (reclaimed * scale / scanned);
169 pressure = pressure * 100 / scale;
170
Vinayak Menon58d1dbb2017-02-24 14:59:39 -0800171out:
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700172 pr_debug("%s: %3lu (s: %lu r: %lu)\n", __func__, pressure,
173 scanned, reclaimed);
174
Vinayak Menon13088ad2015-03-04 16:38:28 +0530175 return pressure;
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700176}
177
Vinayak Menon58091092015-03-31 11:06:29 +0530178static unsigned long vmpressure_account_stall(unsigned long pressure,
179 unsigned long stall, unsigned long scanned)
180{
Vinayak Menon44778e52015-08-19 16:16:39 +0530181 unsigned long scale;
182
183 if (pressure < allocstall_threshold)
184 return pressure;
185
186 scale = ((vmpressure_scale_max - pressure) * stall) / scanned;
Vinayak Menon58091092015-03-31 11:06:29 +0530187
188 return pressure + scale;
189}
190
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700191struct vmpressure_event {
192 struct eventfd_ctx *efd;
193 enum vmpressure_levels level;
194 struct list_head node;
195};
196
197static bool vmpressure_event(struct vmpressure *vmpr,
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800198 enum vmpressure_levels level)
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700199{
200 struct vmpressure_event *ev;
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700201 bool signalled = false;
202
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700203 mutex_lock(&vmpr->events_lock);
204
205 list_for_each_entry(ev, &vmpr->events, node) {
206 if (level >= ev->level) {
207 eventfd_signal(ev->efd, 1);
208 signalled = true;
209 }
210 }
211
212 mutex_unlock(&vmpr->events_lock);
213
214 return signalled;
215}
216
217static void vmpressure_work_fn(struct work_struct *work)
218{
219 struct vmpressure *vmpr = work_to_vmpressure(work);
220 unsigned long scanned;
221 unsigned long reclaimed;
Vinayak Menon13088ad2015-03-04 16:38:28 +0530222 unsigned long pressure;
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800223 enum vmpressure_levels level;
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700224
Andrew Morton91b57192014-12-02 15:59:28 -0800225 spin_lock(&vmpr->sr_lock);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700226 /*
227 * Several contexts might be calling vmpressure(), so it is
228 * possible that the work was rescheduled again before the old
229 * work context cleared the counters. In that case we will run
230 * just after the old work returns, but then scanned might be zero
231 * here. No need for any locks here since we don't care if
232 * vmpr->reclaimed is in sync.
233 */
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800234 scanned = vmpr->tree_scanned;
Andrew Morton91b57192014-12-02 15:59:28 -0800235 if (!scanned) {
236 spin_unlock(&vmpr->sr_lock);
237 return;
238 }
239
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800240 reclaimed = vmpr->tree_reclaimed;
241 vmpr->tree_scanned = 0;
242 vmpr->tree_reclaimed = 0;
Michal Hocko22f20202013-07-31 13:53:48 -0700243 spin_unlock(&vmpr->sr_lock);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700244
Vinayak Menon13088ad2015-03-04 16:38:28 +0530245 pressure = vmpressure_calc_pressure(scanned, reclaimed);
246 level = vmpressure_level(pressure);
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800247
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700248 do {
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800249 if (vmpressure_event(vmpr, level))
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700250 break;
251 /*
252 * If not handled, propagate the event upward into the
253 * hierarchy.
254 */
255 } while ((vmpr = vmpressure_parent(vmpr)));
256}
257
Vinayak Menon13088ad2015-03-04 16:38:28 +0530258#ifdef CONFIG_MEMCG
259static void vmpressure_memcg(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700260 unsigned long scanned, unsigned long reclaimed)
261{
262 struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
263
264 /*
265 * Here we only want to account pressure that userland is able to
266 * help us with. For example, suppose that DMA zone is under
267 * pressure; if we notify userland about that kind of pressure,
268 * then it will be mostly a waste as it will trigger unnecessary
269 * freeing of memory by userland (since userland is more likely to
270 * have HIGHMEM/MOVABLE pages instead of the DMA fallback). That
271 * is why we include only movable, highmem and FS/IO pages.
272 * Indirect reclaim (kswapd) sets sc->gfp_mask to GFP_KERNEL, so
273 * we account it too.
274 */
275 if (!(gfp & (__GFP_HIGHMEM | __GFP_MOVABLE | __GFP_IO | __GFP_FS)))
276 return;
277
278 /*
279 * If we got here with no pages scanned, then that is an indicator
280 * that reclaimer was unable to find any shrinkable LRUs at the
281 * current scanning depth. But it does not mean that we should
282 * report the critical pressure, yet. If the scanning priority
283 * (scanning depth) goes too high (deep), we will be notified
284 * through vmpressure_prio(). But so far, keep calm.
285 */
286 if (!scanned)
287 return;
288
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800289 if (tree) {
290 spin_lock(&vmpr->sr_lock);
Vladimir Davydov3c1da7b2016-02-02 16:57:49 -0800291 scanned = vmpr->tree_scanned += scanned;
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800292 vmpr->tree_reclaimed += reclaimed;
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800293 spin_unlock(&vmpr->sr_lock);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700294
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800295 if (scanned < vmpressure_win)
296 return;
297 schedule_work(&vmpr->work);
298 } else {
299 enum vmpressure_levels level;
Vinayak Menon13088ad2015-03-04 16:38:28 +0530300 unsigned long pressure;
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800301
302 /* For now, no users for root-level efficiency */
Hugh Dickins686739f2016-01-14 15:21:37 -0800303 if (!memcg || memcg == root_mem_cgroup)
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800304 return;
305
306 spin_lock(&vmpr->sr_lock);
307 scanned = vmpr->scanned += scanned;
308 reclaimed = vmpr->reclaimed += reclaimed;
309 if (scanned < vmpressure_win) {
310 spin_unlock(&vmpr->sr_lock);
311 return;
312 }
313 vmpr->scanned = vmpr->reclaimed = 0;
314 spin_unlock(&vmpr->sr_lock);
315
Vinayak Menon13088ad2015-03-04 16:38:28 +0530316 pressure = vmpressure_calc_pressure(scanned, reclaimed);
317 level = vmpressure_level(pressure);
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800318
319 if (level > VMPRESSURE_LOW) {
320 /*
321 * Let the socket buffer allocator know that
322 * we are having trouble reclaiming LRU pages.
323 *
324 * For hysteresis keep the pressure state
325 * asserted for a second in which subsequent
326 * pressure events can occur.
327 */
328 memcg->socket_pressure = jiffies + HZ;
329 }
330 }
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700331}
Vinayak Menon13088ad2015-03-04 16:38:28 +0530332#else
333static void vmpressure_memcg(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
334 unsigned long scanned, unsigned long reclaimed) { }
335#endif
336
337static void vmpressure_global(gfp_t gfp, unsigned long scanned,
338 unsigned long reclaimed)
339{
340 struct vmpressure *vmpr = &global_vmpressure;
341 unsigned long pressure;
Vinayak Menon58091092015-03-31 11:06:29 +0530342 unsigned long stall;
Vinayak Menon13088ad2015-03-04 16:38:28 +0530343
344 if (!(gfp & (__GFP_HIGHMEM | __GFP_MOVABLE | __GFP_IO | __GFP_FS)))
345 return;
346
347 if (!scanned)
348 return;
349
350 spin_lock(&vmpr->sr_lock);
351 vmpr->scanned += scanned;
352 vmpr->reclaimed += reclaimed;
Vinayak Menon58091092015-03-31 11:06:29 +0530353
354 if (!current_is_kswapd())
355 vmpr->stall += scanned;
356
357 stall = vmpr->stall;
Vinayak Menon13088ad2015-03-04 16:38:28 +0530358 scanned = vmpr->scanned;
359 reclaimed = vmpr->reclaimed;
360 spin_unlock(&vmpr->sr_lock);
361
362 if (scanned < vmpressure_win)
363 return;
364
365 spin_lock(&vmpr->sr_lock);
366 vmpr->scanned = 0;
367 vmpr->reclaimed = 0;
Vinayak Menon58091092015-03-31 11:06:29 +0530368 vmpr->stall = 0;
Vinayak Menon13088ad2015-03-04 16:38:28 +0530369 spin_unlock(&vmpr->sr_lock);
370
371 pressure = vmpressure_calc_pressure(scanned, reclaimed);
Vinayak Menon58091092015-03-31 11:06:29 +0530372 pressure = vmpressure_account_stall(pressure, stall, scanned);
Vinayak Menon13088ad2015-03-04 16:38:28 +0530373 vmpressure_notify(pressure);
374}
375
376/**
377 * vmpressure() - Account memory pressure through scanned/reclaimed ratio
378 * @gfp: reclaimer's gfp mask
379 * @memcg: cgroup memory controller handle
380 * @tree: legacy subtree mode
381 * @scanned: number of pages scanned
382 * @reclaimed: number of pages reclaimed
383 *
384 * This function should be called from the vmscan reclaim path to account
385 * "instantaneous" memory pressure (scanned/reclaimed ratio). The raw
386 * pressure index is then further refined and averaged over time.
387 *
388 * If @tree is set, vmpressure is in traditional userspace reporting
389 * mode: @memcg is considered the pressure root and userspace is
390 * notified of the entire subtree's reclaim efficiency.
391 *
392 * If @tree is not set, reclaim efficiency is recorded for @memcg, and
393 * only in-kernel users are notified.
394 *
395 * This function does not return any value.
396 */
397void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
398 unsigned long scanned, unsigned long reclaimed)
399{
400 if (!memcg)
401 vmpressure_global(gfp, scanned, reclaimed);
402
403 if (IS_ENABLED(CONFIG_MEMCG))
404 vmpressure_memcg(gfp, memcg, tree, scanned, reclaimed);
405}
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700406
407/**
408 * vmpressure_prio() - Account memory pressure through reclaimer priority level
409 * @gfp: reclaimer's gfp mask
410 * @memcg: cgroup memory controller handle
411 * @prio: reclaimer's priority
412 *
413 * This function should be called from the reclaim path every time when
414 * the vmscan's reclaiming priority (scanning depth) changes.
415 *
416 * This function does not return any value.
417 */
418void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
419{
420 /*
421 * We only use prio for accounting critical level. For more info
422 * see comment for vmpressure_level_critical_prio variable above.
423 */
424 if (prio > vmpressure_level_critical_prio)
425 return;
426
427 /*
428 * OK, the prio is below the threshold, updating vmpressure
429 * information before shrinker dives into long shrinking of long
430 * range vmscan. Passing scanned = vmpressure_win, reclaimed = 0
431 * to the vmpressure() basically means that we signal 'critical'
432 * level.
433 */
Johannes Weiner8e8ae642016-01-14 15:21:32 -0800434 vmpressure(gfp, memcg, true, vmpressure_win, 0);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700435}
436
437/**
438 * vmpressure_register_event() - Bind vmpressure notifications to an eventfd
Tejun Heo59b6f872013-11-22 18:20:43 -0500439 * @memcg: memcg that is interested in vmpressure notifications
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700440 * @eventfd: eventfd context to link notifications with
441 * @args: event arguments (used to set up a pressure level threshold)
442 *
443 * This function associates eventfd context with the vmpressure
444 * infrastructure, so that the notifications will be delivered to the
445 * @eventfd. The @args parameter is a string that denotes pressure level
446 * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
447 * "critical").
448 *
Tejun Heo347c4a82013-11-22 18:20:43 -0500449 * To be used as memcg event method.
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700450 */
Tejun Heo59b6f872013-11-22 18:20:43 -0500451int vmpressure_register_event(struct mem_cgroup *memcg,
Tejun Heo347c4a82013-11-22 18:20:43 -0500452 struct eventfd_ctx *eventfd, const char *args)
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700453{
Tejun Heo59b6f872013-11-22 18:20:43 -0500454 struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700455 struct vmpressure_event *ev;
456 int level;
457
458 for (level = 0; level < VMPRESSURE_NUM_LEVELS; level++) {
459 if (!strcmp(vmpressure_str_levels[level], args))
460 break;
461 }
462
463 if (level >= VMPRESSURE_NUM_LEVELS)
464 return -EINVAL;
465
466 ev = kzalloc(sizeof(*ev), GFP_KERNEL);
467 if (!ev)
468 return -ENOMEM;
469
470 ev->efd = eventfd;
471 ev->level = level;
472
473 mutex_lock(&vmpr->events_lock);
474 list_add(&ev->node, &vmpr->events);
475 mutex_unlock(&vmpr->events_lock);
476
477 return 0;
478}
479
480/**
481 * vmpressure_unregister_event() - Unbind eventfd from vmpressure
Tejun Heo59b6f872013-11-22 18:20:43 -0500482 * @memcg: memcg handle
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700483 * @eventfd: eventfd context that was used to link vmpressure with the @cg
484 *
485 * This function does internal manipulations to detach the @eventfd from
486 * the vmpressure notifications, and then frees internal resources
487 * associated with the @eventfd (but the @eventfd itself is not freed).
488 *
Tejun Heo347c4a82013-11-22 18:20:43 -0500489 * To be used as memcg event method.
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700490 */
Tejun Heo59b6f872013-11-22 18:20:43 -0500491void vmpressure_unregister_event(struct mem_cgroup *memcg,
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700492 struct eventfd_ctx *eventfd)
493{
Tejun Heo59b6f872013-11-22 18:20:43 -0500494 struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700495 struct vmpressure_event *ev;
496
497 mutex_lock(&vmpr->events_lock);
498 list_for_each_entry(ev, &vmpr->events, node) {
499 if (ev->efd != eventfd)
500 continue;
501 list_del(&ev->node);
502 kfree(ev);
503 break;
504 }
505 mutex_unlock(&vmpr->events_lock);
506}
507
508/**
509 * vmpressure_init() - Initialize vmpressure control structure
510 * @vmpr: Structure to be initialized
511 *
512 * This function should be called on every allocated vmpressure structure
513 * before any usage.
514 */
515void vmpressure_init(struct vmpressure *vmpr)
516{
Michal Hocko22f20202013-07-31 13:53:48 -0700517 spin_lock_init(&vmpr->sr_lock);
Anton Vorontsov70ddf632013-04-29 15:08:31 -0700518 mutex_init(&vmpr->events_lock);
519 INIT_LIST_HEAD(&vmpr->events);
520 INIT_WORK(&vmpr->work, vmpressure_work_fn);
521}
Michal Hocko33cb8762013-07-31 13:53:51 -0700522
523/**
524 * vmpressure_cleanup() - shuts down vmpressure control structure
525 * @vmpr: Structure to be cleaned up
526 *
527 * This function should be called before the structure in which it is
528 * embedded is cleaned up.
529 */
530void vmpressure_cleanup(struct vmpressure *vmpr)
531{
532 /*
533 * Make sure there is no pending work before eventfd infrastructure
534 * goes away.
535 */
536 flush_work(&vmpr->work);
537}
Vinayak Menon13088ad2015-03-04 16:38:28 +0530538
539static int vmpressure_global_init(void)
540{
541 vmpressure_init(&global_vmpressure);
542 return 0;
543}
544late_initcall(vmpressure_global_init);