shrinker_debugfs.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ==========================
  2. Shrinker Debugfs Interface
  3. ==========================
  4. Shrinker debugfs interface provides a visibility into the kernel memory
  5. shrinkers subsystem and allows to get information about individual shrinkers
  6. and interact with them.
  7. For each shrinker registered in the system a directory in **<debugfs>/shrinker/**
  8. is created. The directory's name is composed from the shrinker's name and an
  9. unique id: e.g. *kfree_rcu-0* or *sb-xfs:vda1-36*.
  10. Each shrinker directory contains **count** and **scan** files, which allow to
  11. trigger *count_objects()* and *scan_objects()* callbacks for each memcg and
  12. numa node (if applicable).
  13. Usage:
  14. ------
  15. 1. *List registered shrinkers*
  16. ::
  17. $ cd /sys/kernel/debug/shrinker/
  18. $ ls
  19. dquota-cache-16 sb-devpts-28 sb-proc-47 sb-tmpfs-42
  20. mm-shadow-18 sb-devtmpfs-5 sb-proc-48 sb-tmpfs-43
  21. mm-zspool:zram0-34 sb-hugetlbfs-17 sb-pstore-31 sb-tmpfs-44
  22. rcu-kfree-0 sb-hugetlbfs-33 sb-rootfs-2 sb-tmpfs-49
  23. sb-aio-20 sb-iomem-12 sb-securityfs-6 sb-tracefs-13
  24. sb-anon_inodefs-15 sb-mqueue-21 sb-selinuxfs-22 sb-xfs:vda1-36
  25. sb-bdev-3 sb-nsfs-4 sb-sockfs-8 sb-zsmalloc-19
  26. sb-bpf-32 sb-pipefs-14 sb-sysfs-26 thp-deferred_split-10
  27. sb-btrfs:vda2-24 sb-proc-25 sb-tmpfs-1 thp-zero-9
  28. sb-cgroup2-30 sb-proc-39 sb-tmpfs-27 xfs-buf:vda1-37
  29. sb-configfs-23 sb-proc-41 sb-tmpfs-29 xfs-inodegc:vda1-38
  30. sb-dax-11 sb-proc-45 sb-tmpfs-35
  31. sb-debugfs-7 sb-proc-46 sb-tmpfs-40
  32. 2. *Get information about a specific shrinker*
  33. ::
  34. $ cd sb-btrfs\:vda2-24/
  35. $ ls
  36. count scan
  37. 3. *Count objects*
  38. Each line in the output has the following format::
  39. <cgroup inode id> <nr of objects on node 0> <nr of objects on node 1> ...
  40. <cgroup inode id> <nr of objects on node 0> <nr of objects on node 1> ...
  41. ...
  42. If there are no objects on all numa nodes, a line is omitted. If there
  43. are no objects at all, the output might be empty.
  44. If the shrinker is not memcg-aware or CONFIG_MEMCG is off, 0 is printed
  45. as cgroup inode id. If the shrinker is not numa-aware, 0's are printed
  46. for all nodes except the first one.
  47. ::
  48. $ cat count
  49. 1 224 2
  50. 21 98 0
  51. 55 818 10
  52. 2367 2 0
  53. 2401 30 0
  54. 225 13 0
  55. 599 35 0
  56. 939 124 0
  57. 1041 3 0
  58. 1075 1 0
  59. 1109 1 0
  60. 1279 60 0
  61. 1313 7 0
  62. 1347 39 0
  63. 1381 3 0
  64. 1449 14 0
  65. 1483 63 0
  66. 1517 53 0
  67. 1551 6 0
  68. 1585 1 0
  69. 1619 6 0
  70. 1653 40 0
  71. 1687 11 0
  72. 1721 8 0
  73. 1755 4 0
  74. 1789 52 0
  75. 1823 888 0
  76. 1857 1 0
  77. 1925 2 0
  78. 1959 32 0
  79. 2027 22 0
  80. 2061 9 0
  81. 2469 799 0
  82. 2537 861 0
  83. 2639 1 0
  84. 2707 70 0
  85. 2775 4 0
  86. 2877 84 0
  87. 293 1 0
  88. 735 8 0
  89. 4. *Scan objects*
  90. The expected input format::
  91. <cgroup inode id> <numa id> <number of objects to scan>
  92. For a non-memcg-aware shrinker or on a system with no memory
  93. cgrups **0** should be passed as cgroup id.
  94. ::
  95. $ cd /sys/kernel/debug/shrinker/
  96. $ cd sb-btrfs\:vda2-24/
  97. $ cat count | head -n 5
  98. 1 212 0
  99. 21 97 0
  100. 55 802 5
  101. 2367 2 0
  102. 225 13 0
  103. $ echo "55 0 200" > scan
  104. $ cat count | head -n 5
  105. 1 212 0
  106. 21 96 0
  107. 55 752 5
  108. 2367 2 0
  109. 225 13 0