Laura Abbott | 9680523 | 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 | |
| 20 | BLOCKING_NOTIFIER_HEAD(show_mem_notifier); |
| 21 | |
| 22 | int show_mem_notifier_register(struct notifier_block *nb) |
| 23 | { |
| 24 | return blocking_notifier_chain_register(&show_mem_notifier, nb); |
| 25 | } |
| 26 | |
| 27 | int show_mem_notifier_unregister(struct notifier_block *nb) |
| 28 | { |
| 29 | return blocking_notifier_chain_unregister(&show_mem_notifier, nb); |
| 30 | } |
| 31 | |
| 32 | void show_mem_call_notifiers(void) |
| 33 | { |
| 34 | blocking_notifier_call_chain(&show_mem_notifier, 0, NULL); |
| 35 | } |
| 36 | |
| 37 | static int show_mem_notifier_get(void *dat, u64 *val) |
| 38 | { |
| 39 | show_mem_call_notifiers(); |
| 40 | *val = 0; |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get, |
| 45 | NULL, "%llu\n"); |
| 46 | |
| 47 | int show_mem_notifier_debugfs_register(void) |
| 48 | { |
| 49 | debugfs_create_file("show_mem_notifier", 0664, NULL, NULL, |
| 50 | &show_mem_notifier_debug_ops); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | late_initcall(show_mem_notifier_debugfs_register); |