Skip to content
Snippets Groups Projects
  1. Feb 22, 2023
    • Qi Zheng's avatar
      mm: shrinkers: fix deadlock in shrinker debugfs · 86e3baf6
      Qi Zheng authored
      commit badc28d4 upstream.
      
      The debugfs_remove_recursive() is invoked by unregister_shrinker(), which
      is holding the write lock of shrinker_rwsem.  It will waits for the
      handler of debugfs file complete.  The handler also needs to hold the read
      lock of shrinker_rwsem to do something.  So it may cause the following
      deadlock:
      
       	CPU0				CPU1
      
      debugfs_file_get()
      shrinker_debugfs_count_show()/shrinker_debugfs_scan_write()
      
           				unregister_shrinker()
      				--> down_write(&shrinker_rwsem);
      				    debugfs_remove_recursive()
      					// wait for (A)
      				    --> wait_for_completion();
      
          // wait for (B)
      --> down_read_killable(&shrinker_rwsem)
      debugfs_file_put() -- (A)
      
      				    up_write() -- (B)
      
      The down_read_killable() can be killed, so that the above deadlock can be
      recovered.  But it still requires an extra kill action, otherwise it will
      block all subsequent shrinker-related operations, so it's better to fix
      it.
      
      [akpm@linux-foundation.org: fix CONFIG_SHRINKER_DEBUG=n stub]
      Link: https://lkml.kernel.org/r/20230202105612.64641-1-zhengqi.arch@bytedance.com
      
      
      Fixes: 5035ebc6 ("mm: shrinkers: introduce debugfs interface for memory shrinkers")
      Signed-off-by: default avatarQi Zheng <zhengqi.arch@bytedance.com>
      Reviewed-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Cc: Kent Overstreet <kent.overstreet@gmail.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      86e3baf6
  2. Jul 30, 2022
  3. Jul 04, 2022
    • Roman Gushchin's avatar
      mm: shrinkers: add scan interface for shrinker debugfs · bbf535fd
      Roman Gushchin authored
      Add a scan interface which allows to trigger scanning of a particular
      shrinker and specify memcg and numa node.  It's useful for testing,
      debugging and profiling of a specific scan_objects() callback.  Unlike
      alternatives (creating a real memory pressure and dropping caches via
      /proc/sys/vm/drop_caches) this interface allows to interact with only one
      shrinker at once.  Also, if a shrinker is misreporting the number of
      objects (as some do), it doesn't affect scanning.
      
      [roman.gushchin@linux.dev: improve typing, fix arg count checking]
        Link: https://lkml.kernel.org/r/YpgKttTowT22mKPQ@carbon
      [akpm@linux-foundation.org: fix arg count checking]
      Link: https://lkml.kernel.org/r/20220601032227.4076670-7-roman.gushchin@linux.dev
      
      
      Signed-off-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Acked-by: default avatarMuchun Song <songmuchun@bytedance.com>
      Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
      Cc: Dave Chinner <dchinner@redhat.com>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Kent Overstreet <kent.overstreet@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      bbf535fd
    • Roman Gushchin's avatar
      mm: shrinkers: provide shrinkers with names · e33c267a
      Roman Gushchin authored
      Currently shrinkers are anonymous objects.  For debugging purposes they
      can be identified by count/scan function names, but it's not always
      useful: e.g.  for superblock's shrinkers it's nice to have at least an
      idea of to which superblock the shrinker belongs.
      
      This commit adds names to shrinkers.  register_shrinker() and
      prealloc_shrinker() functions are extended to take a format and arguments
      to master a name.
      
      In some cases it's not possible to determine a good name at the time when
      a shrinker is allocated.  For such cases shrinker_debugfs_rename() is
      provided.
      
      The expected format is:
          <subsystem>-<shrinker_type>[:<instance>]-<id>
      For some shrinkers an instance can be encoded as (MAJOR:MINOR) pair.
      
      After this change the shrinker debugfs directory looks like:
        $ cd /sys/kernel/debug/shrinker/
        $ ls
          dquota-cache-16     sb-devpts-28     sb-proc-47       sb-tmpfs-42
          mm-shadow-18        sb-devtmpfs-5    sb-proc-48       sb-tmpfs-43
          mm-zspool:zram0-34  sb-hugetlbfs-17  sb-pstore-31     sb-tmpfs-44
          rcu-kfree-0         sb-hugetlbfs-33  sb-rootfs-2      sb-tmpfs-49
          sb-aio-20           sb-iomem-12      sb-securityfs-6  sb-tracefs-13
          sb-anon_inodefs-15  sb-mqueue-21     sb-selinuxfs-22  sb-xfs:vda1-36
          sb-bdev-3           sb-nsfs-4        sb-sockfs-8      sb-zsmalloc-19
          sb-bpf-32           sb-pipefs-14     sb-sysfs-26      thp-deferred_split-10
          sb-btrfs:vda2-24    sb-proc-25       sb-tmpfs-1       thp-zero-9
          sb-cgroup2-30       sb-proc-39       sb-tmpfs-27      xfs-buf:vda1-37
          sb-configfs-23      sb-proc-41       sb-tmpfs-29      xfs-inodegc:vda1-38
          sb-dax-11           sb-proc-45       sb-tmpfs-35
          sb-debugfs-7        sb-proc-46       sb-tmpfs-40
      
      [roman.gushchin@linux.dev: fix build warnings]
        Link: https://lkml.kernel.org/r/Yr+ZTnLb9lJk6fJO@castle
      
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Link: https://lkml.kernel.org/r/20220601032227.4076670-4-roman.gushchin@linux.dev
      
      
      Signed-off-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
      Cc: Dave Chinner <dchinner@redhat.com>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Kent Overstreet <kent.overstreet@gmail.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      e33c267a
    • Roman Gushchin's avatar
      mm: shrinkers: introduce debugfs interface for memory shrinkers · 5035ebc6
      Roman Gushchin authored
      
      This commit introduces the /sys/kernel/debug/shrinker debugfs interface
      which provides an ability to observe the state of individual kernel memory
      shrinkers.
      
      Because the feature adds some memory overhead (which shouldn't be large
      unless there is a huge amount of registered shrinkers), it's guarded by a
      config option (enabled by default).
      
      This commit introduces the "count" interface for each shrinker registered
      in the system.
      
      The output is in the following format:
      <cgroup inode id> <nr of objects on node 0> <nr of objects on node 1>...
      <cgroup inode id> <nr of objects on node 0> <nr of objects on node 1>...
      ...
      
      To reduce the size of output on machines with many thousands cgroups, if
      the total number of objects on all nodes is 0, the line is omitted.
      
      If the shrinker is not memcg-aware or CONFIG_MEMCG is off, 0 is printed as
      cgroup inode id.  If the shrinker is not numa-aware, 0's are printed for
      all nodes except the first one.
      
      This commit gives debugfs entries simple numeric names, which are not very
      convenient.  The following commit in the series will provide shrinkers
      with more meaningful names.
      
      [akpm@linux-foundation.org: remove WARN_ON_ONCE(), per Roman]
      Reported-by: default avatar <syzbot+300d27c79fe6d4cbcc39@syzkaller.appspotmail.com>
      Link: https://lkml.kernel.org/r/20220601032227.4076670-3-roman.gushchin@linux.dev
      
      
      Signed-off-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
      Reviewed-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
      Acked-by: default avatarMuchun Song <songmuchun@bytedance.com>
      Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
      Cc: Dave Chinner <dchinner@redhat.com>
      Cc: Hillf Danton <hdanton@sina.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      5035ebc6
Loading