From 4a24d23163aabf8945972599be762dd4c9ce0510 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Mon, 22 Sep 2014 13:26:28 -0700 Subject: [PATCH] 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. Introduce 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 Signed-off-by: Patrick Daly [swatsrid@codeaurora.org: Fix merge conflicts and errors] Signed-off-by: Swathi Sridhar [isaacm@codeaurora.org: Fix merge conflicts/licensing/scope issues] Signed-off-by: Isaac J. Manjarres --- include/linux/show_mem_notifier.h | 12 ++++++++ mm/Makefile | 2 +- mm/showmem.c | 47 +++++++++++++++++++++++++++++++ 3 files changed, 60 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 000000000000..231b40184e13 --- /dev/null +++ b/include/linux/show_mem_notifier.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + */ + +#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 d0b295c3b764..7b8212b0ac53 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ mm_init.o mmu_context.o percpu.o slab_common.o \ compaction.o vmacache.o \ interval_tree.o list_lru.o workingset.o \ - debug.o gup.o $(mmu-y) + debug.o gup.o $(mmu-y) showmem.o # Give 'page_alloc' its own module-parameter namespace page-alloc-y := page_alloc.o diff --git a/mm/showmem.c b/mm/showmem.c new file mode 100644 index 000000000000..24180c536972 --- /dev/null +++ b/mm/showmem.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include + +static 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_DEBUGFS_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get, + NULL, "%llu\n"); + +static 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);