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 d996846697ef..372e1aac9be6 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -42,7 +42,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);