aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/vmpressure.h
diff options
context:
space:
mode:
authorAnton Vorontsov <anton.vorontsov@linaro.org>2013-04-29 18:08:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 18:54:38 -0400
commit70ddf637eebe47e61fb2be08a59315581b6d2f38 (patch)
tree7fdb9e04da11c191daa225cad2314e440effc176 /include/linux/vmpressure.h
parent84d96d897671cfb386e722acbefdb3a79e115a8a (diff)
memcg: add memory.pressure_level events
With this patch userland applications that want to maintain the interactivity/memory allocation cost can use the pressure level notifications. The levels are defined like this: The "low" level means that the system is reclaiming memory for new allocations. Monitoring this reclaiming activity might be useful for maintaining cache level. Upon notification, the program (typically "Activity Manager") might analyze vmstat and act in advance (i.e. prematurely shutdown unimportant services). The "medium" level means that the system is experiencing medium memory pressure, the system might be making swap, paging out active file caches, etc. Upon this event applications may decide to further analyze vmstat/zoneinfo/memcg or internal memory usage statistics and free any resources that can be easily reconstructed or re-read from a disk. The "critical" level means that the system is actively thrashing, it is about to out of memory (OOM) or even the in-kernel OOM killer is on its way to trigger. Applications should do whatever they can to help the system. It might be too late to consult with vmstat or any other statistics, so it's advisable to take an immediate action. The events are propagated upward until the event is handled, i.e. the events are not pass-through. Here is what this means: for example you have three cgroups: A->B->C. Now you set up an event listener on cgroups A, B and C, and suppose group C experiences some pressure. In this situation, only group C will receive the notification, i.e. groups A and B will not receive it. This is done to avoid excessive "broadcasting" of messages, which disturbs the system and which is especially bad if we are low on memory or thrashing. So, organize the cgroups wisely, or propagate the events manually (or, ask us to implement the pass-through events, explaining why would you need them.) Performance wise, the memory pressure notifications feature itself is lightweight and does not require much of bookkeeping, in contrast to the rest of memcg features. Unfortunately, as of current memcg implementation, pages accounting is an inseparable part and cannot be turned off. The good news is that there are some efforts[1] to improve the situation; plus, implementing the same, fully API-compatible[2] interface for CONFIG_MEMCG=n case (e.g. embedded) is also a viable option, so it will not require any changes on the userland side. [1] http://permalink.gmane.org/gmane.linux.kernel.cgroups/6291 [2] http://lkml.org/lkml/2013/2/21/454 [akpm@linux-foundation.org: coding-style fixes] [akpm@linux-foundation.org: fix CONFIG_CGROPUPS=n warnings] Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org> Acked-by: Kirill A. Shutemov <kirill@shutemov.name> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Tejun Heo <tj@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Glauber Costa <glommer@parallels.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Luiz Capitulino <lcapitulino@redhat.com> Cc: Greg Thelen <gthelen@google.com> Cc: Leonid Moiseichuk <leonid.moiseichuk@nokia.com> Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Cc: John Stultz <john.stultz@linaro.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/vmpressure.h')
-rw-r--r--include/linux/vmpressure.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h
new file mode 100644
index 000000000000..76be077340ea
--- /dev/null
+++ b/include/linux/vmpressure.h
@@ -0,0 +1,47 @@
1#ifndef __LINUX_VMPRESSURE_H
2#define __LINUX_VMPRESSURE_H
3
4#include <linux/mutex.h>
5#include <linux/list.h>
6#include <linux/workqueue.h>
7#include <linux/gfp.h>
8#include <linux/types.h>
9#include <linux/cgroup.h>
10
11struct vmpressure {
12 unsigned long scanned;
13 unsigned long reclaimed;
14 /* The lock is used to keep the scanned/reclaimed above in sync. */
15 struct mutex sr_lock;
16
17 /* The list of vmpressure_event structs. */
18 struct list_head events;
19 /* Have to grab the lock on events traversal or modifications. */
20 struct mutex events_lock;
21
22 struct work_struct work;
23};
24
25struct mem_cgroup;
26
27#ifdef CONFIG_MEMCG
28extern void vmpressure(gfp_t gfp, struct mem_cgroup *memcg,
29 unsigned long scanned, unsigned long reclaimed);
30extern void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio);
31
32extern void vmpressure_init(struct vmpressure *vmpr);
33extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
34extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
35extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css);
36extern int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
37 struct eventfd_ctx *eventfd,
38 const char *args);
39extern void vmpressure_unregister_event(struct cgroup *cg, struct cftype *cft,
40 struct eventfd_ctx *eventfd);
41#else
42static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg,
43 unsigned long scanned, unsigned long reclaimed) {}
44static inline void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg,
45 int prio) {}
46#endif /* CONFIG_MEMCG */
47#endif /* __LINUX_VMPRESSURE_H */