From 23a81af2839a25b6a48484b261661a17132b72d2 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 22 Sep 2014 13:26:28 -0700 Subject: mm: Add notifier framework for showing memory There are many drivers in the kernel which can hold on to lots of memory. It can be useful to dump out all those drivers at key points in the kernel. Introduct a notifier framework for dumping this information. When the notifiers are called, drivers can dump out the state of any memory they may be using. Change-Id: Ifb2946964bf5d072552dd56d8d6dfdd794af6d84 Signed-off-by: Laura Abbott --- include/linux/show_mem_notifier.h | 20 +++++++++++++++ mm/Makefile | 3 ++- mm/showmem.c | 54 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 include/linux/show_mem_notifier.h create mode 100644 mm/showmem.c diff --git a/include/linux/show_mem_notifier.h b/include/linux/show_mem_notifier.h new file mode 100644 index 000000000..b1265f87e --- /dev/null +++ b/include/linux/show_mem_notifier.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include + +int show_mem_notifier_register(struct notifier_block *nb); + +int show_mem_notifier_unregister(struct notifier_block *nb); + +void show_mem_call_notifiers(void); diff --git a/mm/Makefile b/mm/Makefile index 30e403700..ba25726ce 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -17,7 +17,8 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ util.o mmzone.o vmstat.o backing-dev.o \ mm_init.o mmu_context.o percpu.o slab_common.o \ compaction.o balloon_compaction.o \ - interval_tree.o $(mmu-y) + interval_tree.o $(mmu-y) \ + showmem.o obj-y += init-mm.o diff --git a/mm/showmem.c b/mm/showmem.c new file mode 100644 index 000000000..ddad34ebb --- /dev/null +++ b/mm/showmem.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +BLOCKING_NOTIFIER_HEAD(show_mem_notifier); + +int show_mem_notifier_register(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&show_mem_notifier, nb); +} + +int show_mem_notifier_unregister(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&show_mem_notifier, nb); +} + +void show_mem_call_notifiers(void) +{ + blocking_notifier_call_chain(&show_mem_notifier, 0, NULL); +} + +static int show_mem_notifier_get(void *dat, u64 *val) +{ + show_mem_call_notifiers(); + *val = 0; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get, + NULL, "%llu\n"); + +int show_mem_notifier_debugfs_register(void) +{ + debugfs_create_file("show_mem_notifier", 0664, NULL, NULL, + &show_mem_notifier_debug_ops); + + return 0; +} +late_initcall(show_mem_notifier_debugfs_register); -- cgit v1.2.3