[RFC][PATCH] oom: Be less verbose if the oom_control event fd has listeners

From: Richard Weinberger
Date: Thu Jun 05 2014 - 10:01:01 EST


Don't spam the kernel logs if the oom_control event fd has listeners.
In this case there is no need to print that much lines as user space
will anyway notice that the memory cgroup has reached its limit.

Signed-off-by: Richard Weinberger <richard@xxxxxx>
---
include/linux/memcontrol.h | 6 ++++++
mm/memcontrol.c | 20 ++++++++++++++++++++
mm/oom_kill.c | 2 +-
3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index b569b8b..506a1a9 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -131,6 +131,7 @@ int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec);
int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list);
void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int);
+extern int mem_cgroup_has_listeners(struct mem_cgroup *memcg);
extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
struct task_struct *p);
extern void mem_cgroup_replace_page_cache(struct page *oldpage,
@@ -358,6 +359,11 @@ mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
{
}

+static inline int mem_cgroup_has_listeners(struct mem_cgroup *memcg)
+{
+ return 0;
+}
+
static inline void
mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
{
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5177c6d..3864c6a 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5777,6 +5777,26 @@ static void mem_cgroup_oom_unregister_event(struct mem_cgroup *memcg,
spin_unlock(&memcg_oom_lock);
}

+/**
+ * mem_cgroup_has_listeners: Returns true in case we have one ore more
+ * listeners on our oom notifier event fd.
+ * @memcg: The memory cgroup that went over limit
+ */
+int mem_cgroup_has_listeners(struct mem_cgroup *memcg)
+{
+ int ret = 0;
+
+ if (!memcg)
+ goto out;
+
+ spin_lock(&memcg_oom_lock);
+ ret = !list_empty(&memcg->oom_notify);
+ spin_unlock(&memcg_oom_lock);
+
+out:
+ return ret;
+}
+
static int mem_cgroup_oom_control_read(struct seq_file *sf, void *v)
{
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(sf));
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 3291e82..b5c9433 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -434,7 +434,7 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
return;
}

- if (__ratelimit(&oom_rs))
+ if (__ratelimit(&oom_rs) && !mem_cgroup_has_listeners(memcg))
dump_header(p, gfp_mask, order, memcg, nodemask);

task_lock(p);
--
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/