Laura Abbott | b6f42a1 | 2014-09-22 13:26:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/notifier.h> |
| 16 | #include <linux/debugfs.h> |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/module.h> |
| 20 | |
| 21 | BLOCKING_NOTIFIER_HEAD(show_mem_notifier); |
| 22 | |
| 23 | int show_mem_notifier_register(struct notifier_block *nb) |
| 24 | { |
| 25 | return blocking_notifier_chain_register(&show_mem_notifier, nb); |
| 26 | } |
| 27 | |
| 28 | int show_mem_notifier_unregister(struct notifier_block *nb) |
| 29 | { |
| 30 | return blocking_notifier_chain_unregister(&show_mem_notifier, nb); |
| 31 | } |
| 32 | |
| 33 | void show_mem_call_notifiers(void) |
| 34 | { |
| 35 | blocking_notifier_call_chain(&show_mem_notifier, 0, NULL); |
| 36 | } |
| 37 | |
| 38 | static int show_mem_notifier_get(void *dat, u64 *val) |
| 39 | { |
| 40 | show_mem_call_notifiers(); |
| 41 | *val = 0; |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get, |
| 46 | NULL, "%llu\n"); |
| 47 | |
| 48 | int show_mem_notifier_debugfs_register(void) |
| 49 | { |
| 50 | debugfs_create_file("show_mem_notifier", 0664, NULL, NULL, |
| 51 | &show_mem_notifier_debug_ops); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | late_initcall(show_mem_notifier_debugfs_register); |