showmem.c 1.5 KB

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