showmem.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2014, 2016, 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. #include <linux/kernel.h>
  14. #include <linux/notifier.h>
  15. #include <linux/debugfs.h>
  16. #include <linux/fs.h>
  17. #include <linux/init.h>
  18. ATOMIC_NOTIFIER_HEAD(show_mem_notifier);
  19. int show_mem_notifier_register(struct notifier_block *nb)
  20. {
  21. return atomic_notifier_chain_register(&show_mem_notifier, nb);
  22. }
  23. int show_mem_notifier_unregister(struct notifier_block *nb)
  24. {
  25. return atomic_notifier_chain_unregister(&show_mem_notifier, nb);
  26. }
  27. void show_mem_call_notifiers(void)
  28. {
  29. atomic_notifier_call_chain(&show_mem_notifier, 0, NULL);
  30. }
  31. static int show_mem_notifier_get(void *dat, u64 *val)
  32. {
  33. show_mem_call_notifiers();
  34. *val = 0;
  35. return 0;
  36. }
  37. DEFINE_SIMPLE_ATTRIBUTE(show_mem_notifier_debug_ops, show_mem_notifier_get,
  38. NULL, "%llu\n");
  39. int show_mem_notifier_debugfs_register(void)
  40. {
  41. debugfs_create_file("show_mem_notifier", 0664, NULL, NULL,
  42. &show_mem_notifier_debug_ops);
  43. return 0;
  44. }
  45. late_initcall(show_mem_notifier_debugfs_register);