diff mbox series

[1/5] mm: move some shrinker-related function declarations to mm/internal.h

Message ID 20230816083419.41088-2-zhengqi.arch@bytedance.com (mailing list archive)
State New
Headers show
Series use refcount+RCU method to implement lockless slab shrink (part 1) | expand

Commit Message

Qi Zheng Aug. 16, 2023, 8:34 a.m. UTC
The following functions are only used inside the mm subsystem, so it's
better to move their declarations to the mm/internal.h file.

1. shrinker_debugfs_add()
2. shrinker_debugfs_detach()
3. shrinker_debugfs_remove()

Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
---
 include/linux/shrinker.h | 19 -------------------
 mm/internal.h            | 26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 19 deletions(-)

Comments

kernel test robot Aug. 16, 2023, 1:14 p.m. UTC | #1
Hi Qi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on linus/master v6.5-rc6 next-20230816]
[cannot apply to akpm-mm/mm-everything drm-misc/drm-misc-next vfs-idmapping/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Zheng/mm-move-some-shrinker-related-function-declarations-to-mm-internal-h/20230816-163833
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20230816083419.41088-2-zhengqi.arch%40bytedance.com
patch subject: [PATCH 1/5] mm: move some shrinker-related function declarations to mm/internal.h
config: riscv-randconfig-r015-20230816 (https://download.01.org/0day-ci/archive/20230816/202308162118.motJd6aG-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce: (https://download.01.org/0day-ci/archive/20230816/202308162118.motJd6aG-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308162118.motJd6aG-lkp@intel.com/

All warnings (new ones prefixed by >>):

                                            ~~~~~~~~~~ ^
   In file included from mm/shrinker_debug.c:7:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:136:
   include/asm-generic/io.h:751:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           insw(addr, buffer, count);
           ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/io.h:105:53: note: expanded from macro 'insw'
   #define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count)
                                            ~~~~~~~~~~ ^
   In file included from mm/shrinker_debug.c:7:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:136:
   include/asm-generic/io.h:759:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           insl(addr, buffer, count);
           ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/io.h:106:53: note: expanded from macro 'insl'
   #define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count)
                                            ~~~~~~~~~~ ^
   In file included from mm/shrinker_debug.c:7:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:136:
   include/asm-generic/io.h:768:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           outsb(addr, buffer, count);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/io.h:118:55: note: expanded from macro 'outsb'
   #define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count)
                                              ~~~~~~~~~~ ^
   In file included from mm/shrinker_debug.c:7:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:136:
   include/asm-generic/io.h:777:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           outsw(addr, buffer, count);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/io.h:119:55: note: expanded from macro 'outsw'
   #define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count)
                                              ~~~~~~~~~~ ^
   In file included from mm/shrinker_debug.c:7:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:136:
   include/asm-generic/io.h:786:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           outsl(addr, buffer, count);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/io.h:120:55: note: expanded from macro 'outsl'
   #define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count)
                                              ~~~~~~~~~~ ^
   In file included from mm/shrinker_debug.c:7:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/riscv/include/asm/io.h:136:
   include/asm-generic/io.h:1134:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
                                                     ~~~~~~~~~~ ^
>> mm/shrinker_debug.c:174:5: warning: no previous prototype for function 'shrinker_debugfs_add' [-Wmissing-prototypes]
   int shrinker_debugfs_add(struct shrinker *shrinker)
       ^
   mm/shrinker_debug.c:174:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int shrinker_debugfs_add(struct shrinker *shrinker)
   ^
   static 
>> mm/shrinker_debug.c:249:16: warning: no previous prototype for function 'shrinker_debugfs_detach' [-Wmissing-prototypes]
   struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
                  ^
   mm/shrinker_debug.c:249:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
   ^
   static 
>> mm/shrinker_debug.c:265:6: warning: no previous prototype for function 'shrinker_debugfs_remove' [-Wmissing-prototypes]
   void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
        ^
   mm/shrinker_debug.c:265:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
   ^
   static 
   16 warnings generated.


vim +/shrinker_debugfs_add +174 mm/shrinker_debug.c

bbf535fd6f06b94 Roman Gushchin     2022-05-31  173  
5035ebc644aec92 Roman Gushchin     2022-05-31 @174  int shrinker_debugfs_add(struct shrinker *shrinker)
5035ebc644aec92 Roman Gushchin     2022-05-31  175  {
5035ebc644aec92 Roman Gushchin     2022-05-31  176  	struct dentry *entry;
e33c267ab70de42 Roman Gushchin     2022-05-31  177  	char buf[128];
5035ebc644aec92 Roman Gushchin     2022-05-31  178  	int id;
5035ebc644aec92 Roman Gushchin     2022-05-31  179  
47a7c01c3efc658 Qi Zheng           2023-06-09  180  	lockdep_assert_held(&shrinker_rwsem);
5035ebc644aec92 Roman Gushchin     2022-05-31  181  
5035ebc644aec92 Roman Gushchin     2022-05-31  182  	/* debugfs isn't initialized yet, add debugfs entries later. */
5035ebc644aec92 Roman Gushchin     2022-05-31  183  	if (!shrinker_debugfs_root)
5035ebc644aec92 Roman Gushchin     2022-05-31  184  		return 0;
5035ebc644aec92 Roman Gushchin     2022-05-31  185  
5035ebc644aec92 Roman Gushchin     2022-05-31  186  	id = ida_alloc(&shrinker_debugfs_ida, GFP_KERNEL);
5035ebc644aec92 Roman Gushchin     2022-05-31  187  	if (id < 0)
5035ebc644aec92 Roman Gushchin     2022-05-31  188  		return id;
5035ebc644aec92 Roman Gushchin     2022-05-31  189  	shrinker->debugfs_id = id;
5035ebc644aec92 Roman Gushchin     2022-05-31  190  
e33c267ab70de42 Roman Gushchin     2022-05-31  191  	snprintf(buf, sizeof(buf), "%s-%d", shrinker->name, id);
5035ebc644aec92 Roman Gushchin     2022-05-31  192  
5035ebc644aec92 Roman Gushchin     2022-05-31  193  	/* create debugfs entry */
5035ebc644aec92 Roman Gushchin     2022-05-31  194  	entry = debugfs_create_dir(buf, shrinker_debugfs_root);
5035ebc644aec92 Roman Gushchin     2022-05-31  195  	if (IS_ERR(entry)) {
5035ebc644aec92 Roman Gushchin     2022-05-31  196  		ida_free(&shrinker_debugfs_ida, id);
5035ebc644aec92 Roman Gushchin     2022-05-31  197  		return PTR_ERR(entry);
5035ebc644aec92 Roman Gushchin     2022-05-31  198  	}
5035ebc644aec92 Roman Gushchin     2022-05-31  199  	shrinker->debugfs_entry = entry;
5035ebc644aec92 Roman Gushchin     2022-05-31  200  
2124f79de6a9096 John Keeping       2023-04-18  201  	debugfs_create_file("count", 0440, entry, shrinker,
5035ebc644aec92 Roman Gushchin     2022-05-31  202  			    &shrinker_debugfs_count_fops);
2124f79de6a9096 John Keeping       2023-04-18  203  	debugfs_create_file("scan", 0220, entry, shrinker,
bbf535fd6f06b94 Roman Gushchin     2022-05-31  204  			    &shrinker_debugfs_scan_fops);
5035ebc644aec92 Roman Gushchin     2022-05-31  205  	return 0;
5035ebc644aec92 Roman Gushchin     2022-05-31  206  }
5035ebc644aec92 Roman Gushchin     2022-05-31  207  
e33c267ab70de42 Roman Gushchin     2022-05-31  208  int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
e33c267ab70de42 Roman Gushchin     2022-05-31  209  {
e33c267ab70de42 Roman Gushchin     2022-05-31  210  	struct dentry *entry;
e33c267ab70de42 Roman Gushchin     2022-05-31  211  	char buf[128];
e33c267ab70de42 Roman Gushchin     2022-05-31  212  	const char *new, *old;
e33c267ab70de42 Roman Gushchin     2022-05-31  213  	va_list ap;
e33c267ab70de42 Roman Gushchin     2022-05-31  214  	int ret = 0;
e33c267ab70de42 Roman Gushchin     2022-05-31  215  
e33c267ab70de42 Roman Gushchin     2022-05-31  216  	va_start(ap, fmt);
e33c267ab70de42 Roman Gushchin     2022-05-31  217  	new = kvasprintf_const(GFP_KERNEL, fmt, ap);
e33c267ab70de42 Roman Gushchin     2022-05-31  218  	va_end(ap);
e33c267ab70de42 Roman Gushchin     2022-05-31  219  
e33c267ab70de42 Roman Gushchin     2022-05-31  220  	if (!new)
e33c267ab70de42 Roman Gushchin     2022-05-31  221  		return -ENOMEM;
e33c267ab70de42 Roman Gushchin     2022-05-31  222  
47a7c01c3efc658 Qi Zheng           2023-06-09  223  	down_write(&shrinker_rwsem);
e33c267ab70de42 Roman Gushchin     2022-05-31  224  
e33c267ab70de42 Roman Gushchin     2022-05-31  225  	old = shrinker->name;
e33c267ab70de42 Roman Gushchin     2022-05-31  226  	shrinker->name = new;
e33c267ab70de42 Roman Gushchin     2022-05-31  227  
e33c267ab70de42 Roman Gushchin     2022-05-31  228  	if (shrinker->debugfs_entry) {
e33c267ab70de42 Roman Gushchin     2022-05-31  229  		snprintf(buf, sizeof(buf), "%s-%d", shrinker->name,
e33c267ab70de42 Roman Gushchin     2022-05-31  230  			 shrinker->debugfs_id);
e33c267ab70de42 Roman Gushchin     2022-05-31  231  
e33c267ab70de42 Roman Gushchin     2022-05-31  232  		entry = debugfs_rename(shrinker_debugfs_root,
e33c267ab70de42 Roman Gushchin     2022-05-31  233  				       shrinker->debugfs_entry,
e33c267ab70de42 Roman Gushchin     2022-05-31  234  				       shrinker_debugfs_root, buf);
e33c267ab70de42 Roman Gushchin     2022-05-31  235  		if (IS_ERR(entry))
e33c267ab70de42 Roman Gushchin     2022-05-31  236  			ret = PTR_ERR(entry);
e33c267ab70de42 Roman Gushchin     2022-05-31  237  		else
e33c267ab70de42 Roman Gushchin     2022-05-31  238  			shrinker->debugfs_entry = entry;
e33c267ab70de42 Roman Gushchin     2022-05-31  239  	}
e33c267ab70de42 Roman Gushchin     2022-05-31  240  
47a7c01c3efc658 Qi Zheng           2023-06-09  241  	up_write(&shrinker_rwsem);
e33c267ab70de42 Roman Gushchin     2022-05-31  242  
e33c267ab70de42 Roman Gushchin     2022-05-31  243  	kfree_const(old);
e33c267ab70de42 Roman Gushchin     2022-05-31  244  
e33c267ab70de42 Roman Gushchin     2022-05-31  245  	return ret;
e33c267ab70de42 Roman Gushchin     2022-05-31  246  }
e33c267ab70de42 Roman Gushchin     2022-05-31  247  EXPORT_SYMBOL(shrinker_debugfs_rename);
e33c267ab70de42 Roman Gushchin     2022-05-31  248  
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03 @249  struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  250  				       int *debugfs_id)
5035ebc644aec92 Roman Gushchin     2022-05-31  251  {
badc28d4924bfed Qi Zheng           2023-02-02  252  	struct dentry *entry = shrinker->debugfs_entry;
badc28d4924bfed Qi Zheng           2023-02-02  253  
47a7c01c3efc658 Qi Zheng           2023-06-09  254  	lockdep_assert_held(&shrinker_rwsem);
5035ebc644aec92 Roman Gushchin     2022-05-31  255  
e33c267ab70de42 Roman Gushchin     2022-05-31  256  	kfree_const(shrinker->name);
14773bfa70e67f4 Tetsuo Handa       2022-07-20  257  	shrinker->name = NULL;
e33c267ab70de42 Roman Gushchin     2022-05-31  258  
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  259  	*debugfs_id = entry ? shrinker->debugfs_id : -1;
badc28d4924bfed Qi Zheng           2023-02-02  260  	shrinker->debugfs_entry = NULL;
badc28d4924bfed Qi Zheng           2023-02-02  261  
badc28d4924bfed Qi Zheng           2023-02-02  262  	return entry;
5035ebc644aec92 Roman Gushchin     2022-05-31  263  }
5035ebc644aec92 Roman Gushchin     2022-05-31  264  
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03 @265  void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  266  {
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  267  	debugfs_remove_recursive(debugfs_entry);
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  268  	ida_free(&shrinker_debugfs_ida, debugfs_id);
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  269  }
26e239b37ebdfd1 Joan Bruguera Micó 2023-05-03  270
kernel test robot Aug. 16, 2023, 1:57 p.m. UTC | #2
Hi Qi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on linus/master v6.5-rc6 next-20230816]
[cannot apply to akpm-mm/mm-everything drm-misc/drm-misc-next vfs-idmapping/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Zheng/mm-move-some-shrinker-related-function-declarations-to-mm-internal-h/20230816-163833
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20230816083419.41088-2-zhengqi.arch%40bytedance.com
patch subject: [PATCH 1/5] mm: move some shrinker-related function declarations to mm/internal.h
config: m68k-randconfig-r013-20230816 (https://download.01.org/0day-ci/archive/20230816/202308162105.y9XrlTA7-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230816/202308162105.y9XrlTA7-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308162105.y9XrlTA7-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/shrinker_debug.c:174:5: warning: no previous prototype for 'shrinker_debugfs_add' [-Wmissing-prototypes]
     174 | int shrinker_debugfs_add(struct shrinker *shrinker)
         |     ^~~~~~~~~~~~~~~~~~~~
>> mm/shrinker_debug.c:249:16: warning: no previous prototype for 'shrinker_debugfs_detach' [-Wmissing-prototypes]
     249 | struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
         |                ^~~~~~~~~~~~~~~~~~~~~~~
>> mm/shrinker_debug.c:265:6: warning: no previous prototype for 'shrinker_debugfs_remove' [-Wmissing-prototypes]
     265 | void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
         |      ^~~~~~~~~~~~~~~~~~~~~~~


vim +/shrinker_debugfs_add +174 mm/shrinker_debug.c

bbf535fd6f06b9 Roman Gushchin     2022-05-31  173  
5035ebc644aec9 Roman Gushchin     2022-05-31 @174  int shrinker_debugfs_add(struct shrinker *shrinker)
5035ebc644aec9 Roman Gushchin     2022-05-31  175  {
5035ebc644aec9 Roman Gushchin     2022-05-31  176  	struct dentry *entry;
e33c267ab70de4 Roman Gushchin     2022-05-31  177  	char buf[128];
5035ebc644aec9 Roman Gushchin     2022-05-31  178  	int id;
5035ebc644aec9 Roman Gushchin     2022-05-31  179  
47a7c01c3efc65 Qi Zheng           2023-06-09  180  	lockdep_assert_held(&shrinker_rwsem);
5035ebc644aec9 Roman Gushchin     2022-05-31  181  
5035ebc644aec9 Roman Gushchin     2022-05-31  182  	/* debugfs isn't initialized yet, add debugfs entries later. */
5035ebc644aec9 Roman Gushchin     2022-05-31  183  	if (!shrinker_debugfs_root)
5035ebc644aec9 Roman Gushchin     2022-05-31  184  		return 0;
5035ebc644aec9 Roman Gushchin     2022-05-31  185  
5035ebc644aec9 Roman Gushchin     2022-05-31  186  	id = ida_alloc(&shrinker_debugfs_ida, GFP_KERNEL);
5035ebc644aec9 Roman Gushchin     2022-05-31  187  	if (id < 0)
5035ebc644aec9 Roman Gushchin     2022-05-31  188  		return id;
5035ebc644aec9 Roman Gushchin     2022-05-31  189  	shrinker->debugfs_id = id;
5035ebc644aec9 Roman Gushchin     2022-05-31  190  
e33c267ab70de4 Roman Gushchin     2022-05-31  191  	snprintf(buf, sizeof(buf), "%s-%d", shrinker->name, id);
5035ebc644aec9 Roman Gushchin     2022-05-31  192  
5035ebc644aec9 Roman Gushchin     2022-05-31  193  	/* create debugfs entry */
5035ebc644aec9 Roman Gushchin     2022-05-31  194  	entry = debugfs_create_dir(buf, shrinker_debugfs_root);
5035ebc644aec9 Roman Gushchin     2022-05-31  195  	if (IS_ERR(entry)) {
5035ebc644aec9 Roman Gushchin     2022-05-31  196  		ida_free(&shrinker_debugfs_ida, id);
5035ebc644aec9 Roman Gushchin     2022-05-31  197  		return PTR_ERR(entry);
5035ebc644aec9 Roman Gushchin     2022-05-31  198  	}
5035ebc644aec9 Roman Gushchin     2022-05-31  199  	shrinker->debugfs_entry = entry;
5035ebc644aec9 Roman Gushchin     2022-05-31  200  
2124f79de6a909 John Keeping       2023-04-18  201  	debugfs_create_file("count", 0440, entry, shrinker,
5035ebc644aec9 Roman Gushchin     2022-05-31  202  			    &shrinker_debugfs_count_fops);
2124f79de6a909 John Keeping       2023-04-18  203  	debugfs_create_file("scan", 0220, entry, shrinker,
bbf535fd6f06b9 Roman Gushchin     2022-05-31  204  			    &shrinker_debugfs_scan_fops);
5035ebc644aec9 Roman Gushchin     2022-05-31  205  	return 0;
5035ebc644aec9 Roman Gushchin     2022-05-31  206  }
5035ebc644aec9 Roman Gushchin     2022-05-31  207  
e33c267ab70de4 Roman Gushchin     2022-05-31  208  int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
e33c267ab70de4 Roman Gushchin     2022-05-31  209  {
e33c267ab70de4 Roman Gushchin     2022-05-31  210  	struct dentry *entry;
e33c267ab70de4 Roman Gushchin     2022-05-31  211  	char buf[128];
e33c267ab70de4 Roman Gushchin     2022-05-31  212  	const char *new, *old;
e33c267ab70de4 Roman Gushchin     2022-05-31  213  	va_list ap;
e33c267ab70de4 Roman Gushchin     2022-05-31  214  	int ret = 0;
e33c267ab70de4 Roman Gushchin     2022-05-31  215  
e33c267ab70de4 Roman Gushchin     2022-05-31  216  	va_start(ap, fmt);
e33c267ab70de4 Roman Gushchin     2022-05-31  217  	new = kvasprintf_const(GFP_KERNEL, fmt, ap);
e33c267ab70de4 Roman Gushchin     2022-05-31  218  	va_end(ap);
e33c267ab70de4 Roman Gushchin     2022-05-31  219  
e33c267ab70de4 Roman Gushchin     2022-05-31  220  	if (!new)
e33c267ab70de4 Roman Gushchin     2022-05-31  221  		return -ENOMEM;
e33c267ab70de4 Roman Gushchin     2022-05-31  222  
47a7c01c3efc65 Qi Zheng           2023-06-09  223  	down_write(&shrinker_rwsem);
e33c267ab70de4 Roman Gushchin     2022-05-31  224  
e33c267ab70de4 Roman Gushchin     2022-05-31  225  	old = shrinker->name;
e33c267ab70de4 Roman Gushchin     2022-05-31  226  	shrinker->name = new;
e33c267ab70de4 Roman Gushchin     2022-05-31  227  
e33c267ab70de4 Roman Gushchin     2022-05-31  228  	if (shrinker->debugfs_entry) {
e33c267ab70de4 Roman Gushchin     2022-05-31  229  		snprintf(buf, sizeof(buf), "%s-%d", shrinker->name,
e33c267ab70de4 Roman Gushchin     2022-05-31  230  			 shrinker->debugfs_id);
e33c267ab70de4 Roman Gushchin     2022-05-31  231  
e33c267ab70de4 Roman Gushchin     2022-05-31  232  		entry = debugfs_rename(shrinker_debugfs_root,
e33c267ab70de4 Roman Gushchin     2022-05-31  233  				       shrinker->debugfs_entry,
e33c267ab70de4 Roman Gushchin     2022-05-31  234  				       shrinker_debugfs_root, buf);
e33c267ab70de4 Roman Gushchin     2022-05-31  235  		if (IS_ERR(entry))
e33c267ab70de4 Roman Gushchin     2022-05-31  236  			ret = PTR_ERR(entry);
e33c267ab70de4 Roman Gushchin     2022-05-31  237  		else
e33c267ab70de4 Roman Gushchin     2022-05-31  238  			shrinker->debugfs_entry = entry;
e33c267ab70de4 Roman Gushchin     2022-05-31  239  	}
e33c267ab70de4 Roman Gushchin     2022-05-31  240  
47a7c01c3efc65 Qi Zheng           2023-06-09  241  	up_write(&shrinker_rwsem);
e33c267ab70de4 Roman Gushchin     2022-05-31  242  
e33c267ab70de4 Roman Gushchin     2022-05-31  243  	kfree_const(old);
e33c267ab70de4 Roman Gushchin     2022-05-31  244  
e33c267ab70de4 Roman Gushchin     2022-05-31  245  	return ret;
e33c267ab70de4 Roman Gushchin     2022-05-31  246  }
e33c267ab70de4 Roman Gushchin     2022-05-31  247  EXPORT_SYMBOL(shrinker_debugfs_rename);
e33c267ab70de4 Roman Gushchin     2022-05-31  248  
26e239b37ebdfd Joan Bruguera Micó 2023-05-03 @249  struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  250  				       int *debugfs_id)
5035ebc644aec9 Roman Gushchin     2022-05-31  251  {
badc28d4924bfe Qi Zheng           2023-02-02  252  	struct dentry *entry = shrinker->debugfs_entry;
badc28d4924bfe Qi Zheng           2023-02-02  253  
47a7c01c3efc65 Qi Zheng           2023-06-09  254  	lockdep_assert_held(&shrinker_rwsem);
5035ebc644aec9 Roman Gushchin     2022-05-31  255  
e33c267ab70de4 Roman Gushchin     2022-05-31  256  	kfree_const(shrinker->name);
14773bfa70e67f Tetsuo Handa       2022-07-20  257  	shrinker->name = NULL;
e33c267ab70de4 Roman Gushchin     2022-05-31  258  
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  259  	*debugfs_id = entry ? shrinker->debugfs_id : -1;
badc28d4924bfe Qi Zheng           2023-02-02  260  	shrinker->debugfs_entry = NULL;
badc28d4924bfe Qi Zheng           2023-02-02  261  
badc28d4924bfe Qi Zheng           2023-02-02  262  	return entry;
5035ebc644aec9 Roman Gushchin     2022-05-31  263  }
5035ebc644aec9 Roman Gushchin     2022-05-31  264  
26e239b37ebdfd Joan Bruguera Micó 2023-05-03 @265  void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  266  {
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  267  	debugfs_remove_recursive(debugfs_entry);
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  268  	ida_free(&shrinker_debugfs_ida, debugfs_id);
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  269  }
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  270
kernel test robot Aug. 16, 2023, 3:01 p.m. UTC | #3
Hi Qi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on linus/master v6.5-rc6 next-20230816]
[cannot apply to akpm-mm/mm-everything drm-misc/drm-misc-next vfs-idmapping/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Zheng/mm-move-some-shrinker-related-function-declarations-to-mm-internal-h/20230816-163833
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20230816083419.41088-2-zhengqi.arch%40bytedance.com
patch subject: [PATCH 1/5] mm: move some shrinker-related function declarations to mm/internal.h
config: x86_64-buildonly-randconfig-r003-20230816 (https://download.01.org/0day-ci/archive/20230816/202308162208.cQBnGoER-lkp@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce: (https://download.01.org/0day-ci/archive/20230816/202308162208.cQBnGoER-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308162208.cQBnGoER-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/shrinker_debug.c:174:5: warning: no previous declaration for 'shrinker_debugfs_add' [-Wmissing-declarations]
    int shrinker_debugfs_add(struct shrinker *shrinker)
        ^~~~~~~~~~~~~~~~~~~~
>> mm/shrinker_debug.c:249:16: warning: no previous declaration for 'shrinker_debugfs_detach' [-Wmissing-declarations]
    struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
                   ^~~~~~~~~~~~~~~~~~~~~~~
>> mm/shrinker_debug.c:265:6: warning: no previous declaration for 'shrinker_debugfs_remove' [-Wmissing-declarations]
    void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
         ^~~~~~~~~~~~~~~~~~~~~~~


vim +/shrinker_debugfs_add +174 mm/shrinker_debug.c

bbf535fd6f06b9 Roman Gushchin     2022-05-31  173  
5035ebc644aec9 Roman Gushchin     2022-05-31 @174  int shrinker_debugfs_add(struct shrinker *shrinker)
5035ebc644aec9 Roman Gushchin     2022-05-31  175  {
5035ebc644aec9 Roman Gushchin     2022-05-31  176  	struct dentry *entry;
e33c267ab70de4 Roman Gushchin     2022-05-31  177  	char buf[128];
5035ebc644aec9 Roman Gushchin     2022-05-31  178  	int id;
5035ebc644aec9 Roman Gushchin     2022-05-31  179  
47a7c01c3efc65 Qi Zheng           2023-06-09  180  	lockdep_assert_held(&shrinker_rwsem);
5035ebc644aec9 Roman Gushchin     2022-05-31  181  
5035ebc644aec9 Roman Gushchin     2022-05-31  182  	/* debugfs isn't initialized yet, add debugfs entries later. */
5035ebc644aec9 Roman Gushchin     2022-05-31  183  	if (!shrinker_debugfs_root)
5035ebc644aec9 Roman Gushchin     2022-05-31  184  		return 0;
5035ebc644aec9 Roman Gushchin     2022-05-31  185  
5035ebc644aec9 Roman Gushchin     2022-05-31  186  	id = ida_alloc(&shrinker_debugfs_ida, GFP_KERNEL);
5035ebc644aec9 Roman Gushchin     2022-05-31  187  	if (id < 0)
5035ebc644aec9 Roman Gushchin     2022-05-31  188  		return id;
5035ebc644aec9 Roman Gushchin     2022-05-31  189  	shrinker->debugfs_id = id;
5035ebc644aec9 Roman Gushchin     2022-05-31  190  
e33c267ab70de4 Roman Gushchin     2022-05-31  191  	snprintf(buf, sizeof(buf), "%s-%d", shrinker->name, id);
5035ebc644aec9 Roman Gushchin     2022-05-31  192  
5035ebc644aec9 Roman Gushchin     2022-05-31  193  	/* create debugfs entry */
5035ebc644aec9 Roman Gushchin     2022-05-31  194  	entry = debugfs_create_dir(buf, shrinker_debugfs_root);
5035ebc644aec9 Roman Gushchin     2022-05-31  195  	if (IS_ERR(entry)) {
5035ebc644aec9 Roman Gushchin     2022-05-31  196  		ida_free(&shrinker_debugfs_ida, id);
5035ebc644aec9 Roman Gushchin     2022-05-31  197  		return PTR_ERR(entry);
5035ebc644aec9 Roman Gushchin     2022-05-31  198  	}
5035ebc644aec9 Roman Gushchin     2022-05-31  199  	shrinker->debugfs_entry = entry;
5035ebc644aec9 Roman Gushchin     2022-05-31  200  
2124f79de6a909 John Keeping       2023-04-18  201  	debugfs_create_file("count", 0440, entry, shrinker,
5035ebc644aec9 Roman Gushchin     2022-05-31  202  			    &shrinker_debugfs_count_fops);
2124f79de6a909 John Keeping       2023-04-18  203  	debugfs_create_file("scan", 0220, entry, shrinker,
bbf535fd6f06b9 Roman Gushchin     2022-05-31  204  			    &shrinker_debugfs_scan_fops);
5035ebc644aec9 Roman Gushchin     2022-05-31  205  	return 0;
5035ebc644aec9 Roman Gushchin     2022-05-31  206  }
5035ebc644aec9 Roman Gushchin     2022-05-31  207  
e33c267ab70de4 Roman Gushchin     2022-05-31  208  int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
e33c267ab70de4 Roman Gushchin     2022-05-31  209  {
e33c267ab70de4 Roman Gushchin     2022-05-31  210  	struct dentry *entry;
e33c267ab70de4 Roman Gushchin     2022-05-31  211  	char buf[128];
e33c267ab70de4 Roman Gushchin     2022-05-31  212  	const char *new, *old;
e33c267ab70de4 Roman Gushchin     2022-05-31  213  	va_list ap;
e33c267ab70de4 Roman Gushchin     2022-05-31  214  	int ret = 0;
e33c267ab70de4 Roman Gushchin     2022-05-31  215  
e33c267ab70de4 Roman Gushchin     2022-05-31  216  	va_start(ap, fmt);
e33c267ab70de4 Roman Gushchin     2022-05-31  217  	new = kvasprintf_const(GFP_KERNEL, fmt, ap);
e33c267ab70de4 Roman Gushchin     2022-05-31  218  	va_end(ap);
e33c267ab70de4 Roman Gushchin     2022-05-31  219  
e33c267ab70de4 Roman Gushchin     2022-05-31  220  	if (!new)
e33c267ab70de4 Roman Gushchin     2022-05-31  221  		return -ENOMEM;
e33c267ab70de4 Roman Gushchin     2022-05-31  222  
47a7c01c3efc65 Qi Zheng           2023-06-09  223  	down_write(&shrinker_rwsem);
e33c267ab70de4 Roman Gushchin     2022-05-31  224  
e33c267ab70de4 Roman Gushchin     2022-05-31  225  	old = shrinker->name;
e33c267ab70de4 Roman Gushchin     2022-05-31  226  	shrinker->name = new;
e33c267ab70de4 Roman Gushchin     2022-05-31  227  
e33c267ab70de4 Roman Gushchin     2022-05-31  228  	if (shrinker->debugfs_entry) {
e33c267ab70de4 Roman Gushchin     2022-05-31  229  		snprintf(buf, sizeof(buf), "%s-%d", shrinker->name,
e33c267ab70de4 Roman Gushchin     2022-05-31  230  			 shrinker->debugfs_id);
e33c267ab70de4 Roman Gushchin     2022-05-31  231  
e33c267ab70de4 Roman Gushchin     2022-05-31  232  		entry = debugfs_rename(shrinker_debugfs_root,
e33c267ab70de4 Roman Gushchin     2022-05-31  233  				       shrinker->debugfs_entry,
e33c267ab70de4 Roman Gushchin     2022-05-31  234  				       shrinker_debugfs_root, buf);
e33c267ab70de4 Roman Gushchin     2022-05-31  235  		if (IS_ERR(entry))
e33c267ab70de4 Roman Gushchin     2022-05-31  236  			ret = PTR_ERR(entry);
e33c267ab70de4 Roman Gushchin     2022-05-31  237  		else
e33c267ab70de4 Roman Gushchin     2022-05-31  238  			shrinker->debugfs_entry = entry;
e33c267ab70de4 Roman Gushchin     2022-05-31  239  	}
e33c267ab70de4 Roman Gushchin     2022-05-31  240  
47a7c01c3efc65 Qi Zheng           2023-06-09  241  	up_write(&shrinker_rwsem);
e33c267ab70de4 Roman Gushchin     2022-05-31  242  
e33c267ab70de4 Roman Gushchin     2022-05-31  243  	kfree_const(old);
e33c267ab70de4 Roman Gushchin     2022-05-31  244  
e33c267ab70de4 Roman Gushchin     2022-05-31  245  	return ret;
e33c267ab70de4 Roman Gushchin     2022-05-31  246  }
e33c267ab70de4 Roman Gushchin     2022-05-31  247  EXPORT_SYMBOL(shrinker_debugfs_rename);
e33c267ab70de4 Roman Gushchin     2022-05-31  248  
26e239b37ebdfd Joan Bruguera Micó 2023-05-03 @249  struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  250  				       int *debugfs_id)
5035ebc644aec9 Roman Gushchin     2022-05-31  251  {
badc28d4924bfe Qi Zheng           2023-02-02  252  	struct dentry *entry = shrinker->debugfs_entry;
badc28d4924bfe Qi Zheng           2023-02-02  253  
47a7c01c3efc65 Qi Zheng           2023-06-09  254  	lockdep_assert_held(&shrinker_rwsem);
5035ebc644aec9 Roman Gushchin     2022-05-31  255  
e33c267ab70de4 Roman Gushchin     2022-05-31  256  	kfree_const(shrinker->name);
14773bfa70e67f Tetsuo Handa       2022-07-20  257  	shrinker->name = NULL;
e33c267ab70de4 Roman Gushchin     2022-05-31  258  
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  259  	*debugfs_id = entry ? shrinker->debugfs_id : -1;
badc28d4924bfe Qi Zheng           2023-02-02  260  	shrinker->debugfs_entry = NULL;
badc28d4924bfe Qi Zheng           2023-02-02  261  
badc28d4924bfe Qi Zheng           2023-02-02  262  	return entry;
5035ebc644aec9 Roman Gushchin     2022-05-31  263  }
5035ebc644aec9 Roman Gushchin     2022-05-31  264  
26e239b37ebdfd Joan Bruguera Micó 2023-05-03 @265  void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  266  {
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  267  	debugfs_remove_recursive(debugfs_entry);
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  268  	ida_free(&shrinker_debugfs_ida, debugfs_id);
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  269  }
26e239b37ebdfd Joan Bruguera Micó 2023-05-03  270
Qi Zheng Aug. 17, 2023, 3:04 a.m. UTC | #4
On 2023/8/16 23:01, kernel test robot wrote:
> Hi Qi,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on brauner-vfs/vfs.all]
> [also build test WARNING on linus/master v6.5-rc6 next-20230816]
> [cannot apply to akpm-mm/mm-everything drm-misc/drm-misc-next vfs-idmapping/for-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Zheng/mm-move-some-shrinker-related-function-declarations-to-mm-internal-h/20230816-163833
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
> patch link:    https://lore.kernel.org/r/20230816083419.41088-2-zhengqi.arch%40bytedance.com
> patch subject: [PATCH 1/5] mm: move some shrinker-related function declarations to mm/internal.h
> config: x86_64-buildonly-randconfig-r003-20230816 (https://download.01.org/0day-ci/archive/20230816/202308162208.cQBnGoER-lkp@intel.com/config)
> compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
> reproduce: (https://download.01.org/0day-ci/archive/20230816/202308162208.cQBnGoER-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202308162208.cQBnGoER-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>>> mm/shrinker_debug.c:174:5: warning: no previous declaration for 'shrinker_debugfs_add' [-Wmissing-declarations]
>      int shrinker_debugfs_add(struct shrinker *shrinker)
>          ^~~~~~~~~~~~~~~~~~~~
>>> mm/shrinker_debug.c:249:16: warning: no previous declaration for 'shrinker_debugfs_detach' [-Wmissing-declarations]
>      struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
>                     ^~~~~~~~~~~~~~~~~~~~~~~
>>> mm/shrinker_debug.c:265:6: warning: no previous declaration for 'shrinker_debugfs_remove' [-Wmissing-declarations]
>      void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
>           ^~~~~~~~~~~~~~~~~~~~~~~

Compiling with W=1 will report this warning, will fix it by including
"internal.h" in the mm/shrinker_debug.c.

Thanks,
Qi

> 
> 
> vim +/shrinker_debugfs_add +174 mm/shrinker_debug.c
> 
> bbf535fd6f06b9 Roman Gushchin     2022-05-31  173
> 5035ebc644aec9 Roman Gushchin     2022-05-31 @174  int shrinker_debugfs_add(struct shrinker *shrinker)
> 5035ebc644aec9 Roman Gushchin     2022-05-31  175  {
> 5035ebc644aec9 Roman Gushchin     2022-05-31  176  	struct dentry *entry;
> e33c267ab70de4 Roman Gushchin     2022-05-31  177  	char buf[128];
> 5035ebc644aec9 Roman Gushchin     2022-05-31  178  	int id;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  179
> 47a7c01c3efc65 Qi Zheng           2023-06-09  180  	lockdep_assert_held(&shrinker_rwsem);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  181
> 5035ebc644aec9 Roman Gushchin     2022-05-31  182  	/* debugfs isn't initialized yet, add debugfs entries later. */
> 5035ebc644aec9 Roman Gushchin     2022-05-31  183  	if (!shrinker_debugfs_root)
> 5035ebc644aec9 Roman Gushchin     2022-05-31  184  		return 0;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  185
> 5035ebc644aec9 Roman Gushchin     2022-05-31  186  	id = ida_alloc(&shrinker_debugfs_ida, GFP_KERNEL);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  187  	if (id < 0)
> 5035ebc644aec9 Roman Gushchin     2022-05-31  188  		return id;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  189  	shrinker->debugfs_id = id;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  190
> e33c267ab70de4 Roman Gushchin     2022-05-31  191  	snprintf(buf, sizeof(buf), "%s-%d", shrinker->name, id);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  192
> 5035ebc644aec9 Roman Gushchin     2022-05-31  193  	/* create debugfs entry */
> 5035ebc644aec9 Roman Gushchin     2022-05-31  194  	entry = debugfs_create_dir(buf, shrinker_debugfs_root);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  195  	if (IS_ERR(entry)) {
> 5035ebc644aec9 Roman Gushchin     2022-05-31  196  		ida_free(&shrinker_debugfs_ida, id);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  197  		return PTR_ERR(entry);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  198  	}
> 5035ebc644aec9 Roman Gushchin     2022-05-31  199  	shrinker->debugfs_entry = entry;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  200
> 2124f79de6a909 John Keeping       2023-04-18  201  	debugfs_create_file("count", 0440, entry, shrinker,
> 5035ebc644aec9 Roman Gushchin     2022-05-31  202  			    &shrinker_debugfs_count_fops);
> 2124f79de6a909 John Keeping       2023-04-18  203  	debugfs_create_file("scan", 0220, entry, shrinker,
> bbf535fd6f06b9 Roman Gushchin     2022-05-31  204  			    &shrinker_debugfs_scan_fops);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  205  	return 0;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  206  }
> 5035ebc644aec9 Roman Gushchin     2022-05-31  207
> e33c267ab70de4 Roman Gushchin     2022-05-31  208  int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
> e33c267ab70de4 Roman Gushchin     2022-05-31  209  {
> e33c267ab70de4 Roman Gushchin     2022-05-31  210  	struct dentry *entry;
> e33c267ab70de4 Roman Gushchin     2022-05-31  211  	char buf[128];
> e33c267ab70de4 Roman Gushchin     2022-05-31  212  	const char *new, *old;
> e33c267ab70de4 Roman Gushchin     2022-05-31  213  	va_list ap;
> e33c267ab70de4 Roman Gushchin     2022-05-31  214  	int ret = 0;
> e33c267ab70de4 Roman Gushchin     2022-05-31  215
> e33c267ab70de4 Roman Gushchin     2022-05-31  216  	va_start(ap, fmt);
> e33c267ab70de4 Roman Gushchin     2022-05-31  217  	new = kvasprintf_const(GFP_KERNEL, fmt, ap);
> e33c267ab70de4 Roman Gushchin     2022-05-31  218  	va_end(ap);
> e33c267ab70de4 Roman Gushchin     2022-05-31  219
> e33c267ab70de4 Roman Gushchin     2022-05-31  220  	if (!new)
> e33c267ab70de4 Roman Gushchin     2022-05-31  221  		return -ENOMEM;
> e33c267ab70de4 Roman Gushchin     2022-05-31  222
> 47a7c01c3efc65 Qi Zheng           2023-06-09  223  	down_write(&shrinker_rwsem);
> e33c267ab70de4 Roman Gushchin     2022-05-31  224
> e33c267ab70de4 Roman Gushchin     2022-05-31  225  	old = shrinker->name;
> e33c267ab70de4 Roman Gushchin     2022-05-31  226  	shrinker->name = new;
> e33c267ab70de4 Roman Gushchin     2022-05-31  227
> e33c267ab70de4 Roman Gushchin     2022-05-31  228  	if (shrinker->debugfs_entry) {
> e33c267ab70de4 Roman Gushchin     2022-05-31  229  		snprintf(buf, sizeof(buf), "%s-%d", shrinker->name,
> e33c267ab70de4 Roman Gushchin     2022-05-31  230  			 shrinker->debugfs_id);
> e33c267ab70de4 Roman Gushchin     2022-05-31  231
> e33c267ab70de4 Roman Gushchin     2022-05-31  232  		entry = debugfs_rename(shrinker_debugfs_root,
> e33c267ab70de4 Roman Gushchin     2022-05-31  233  				       shrinker->debugfs_entry,
> e33c267ab70de4 Roman Gushchin     2022-05-31  234  				       shrinker_debugfs_root, buf);
> e33c267ab70de4 Roman Gushchin     2022-05-31  235  		if (IS_ERR(entry))
> e33c267ab70de4 Roman Gushchin     2022-05-31  236  			ret = PTR_ERR(entry);
> e33c267ab70de4 Roman Gushchin     2022-05-31  237  		else
> e33c267ab70de4 Roman Gushchin     2022-05-31  238  			shrinker->debugfs_entry = entry;
> e33c267ab70de4 Roman Gushchin     2022-05-31  239  	}
> e33c267ab70de4 Roman Gushchin     2022-05-31  240
> 47a7c01c3efc65 Qi Zheng           2023-06-09  241  	up_write(&shrinker_rwsem);
> e33c267ab70de4 Roman Gushchin     2022-05-31  242
> e33c267ab70de4 Roman Gushchin     2022-05-31  243  	kfree_const(old);
> e33c267ab70de4 Roman Gushchin     2022-05-31  244
> e33c267ab70de4 Roman Gushchin     2022-05-31  245  	return ret;
> e33c267ab70de4 Roman Gushchin     2022-05-31  246  }
> e33c267ab70de4 Roman Gushchin     2022-05-31  247  EXPORT_SYMBOL(shrinker_debugfs_rename);
> e33c267ab70de4 Roman Gushchin     2022-05-31  248
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03 @249  struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  250  				       int *debugfs_id)
> 5035ebc644aec9 Roman Gushchin     2022-05-31  251  {
> badc28d4924bfe Qi Zheng           2023-02-02  252  	struct dentry *entry = shrinker->debugfs_entry;
> badc28d4924bfe Qi Zheng           2023-02-02  253
> 47a7c01c3efc65 Qi Zheng           2023-06-09  254  	lockdep_assert_held(&shrinker_rwsem);
> 5035ebc644aec9 Roman Gushchin     2022-05-31  255
> e33c267ab70de4 Roman Gushchin     2022-05-31  256  	kfree_const(shrinker->name);
> 14773bfa70e67f Tetsuo Handa       2022-07-20  257  	shrinker->name = NULL;
> e33c267ab70de4 Roman Gushchin     2022-05-31  258
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  259  	*debugfs_id = entry ? shrinker->debugfs_id : -1;
> badc28d4924bfe Qi Zheng           2023-02-02  260  	shrinker->debugfs_entry = NULL;
> badc28d4924bfe Qi Zheng           2023-02-02  261
> badc28d4924bfe Qi Zheng           2023-02-02  262  	return entry;
> 5035ebc644aec9 Roman Gushchin     2022-05-31  263  }
> 5035ebc644aec9 Roman Gushchin     2022-05-31  264
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03 @265  void shrinker_debugfs_remove(struct dentry *debugfs_entry, int debugfs_id)
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  266  {
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  267  	debugfs_remove_recursive(debugfs_entry);
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  268  	ida_free(&shrinker_debugfs_ida, debugfs_id);
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  269  }
> 26e239b37ebdfd Joan Bruguera Micó 2023-05-03  270
>
diff mbox series

Patch

diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
index 224293b2dd06..8dc15aa37410 100644
--- a/include/linux/shrinker.h
+++ b/include/linux/shrinker.h
@@ -106,28 +106,9 @@  extern void free_prealloced_shrinker(struct shrinker *shrinker);
 extern void synchronize_shrinkers(void);
 
 #ifdef CONFIG_SHRINKER_DEBUG
-extern int shrinker_debugfs_add(struct shrinker *shrinker);
-extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
-					      int *debugfs_id);
-extern void shrinker_debugfs_remove(struct dentry *debugfs_entry,
-				    int debugfs_id);
 extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker,
 						  const char *fmt, ...);
 #else /* CONFIG_SHRINKER_DEBUG */
-static inline int shrinker_debugfs_add(struct shrinker *shrinker)
-{
-	return 0;
-}
-static inline struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
-						     int *debugfs_id)
-{
-	*debugfs_id = -1;
-	return NULL;
-}
-static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry,
-					   int debugfs_id)
-{
-}
 static inline __printf(2, 3)
 int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
 {
diff --git a/mm/internal.h b/mm/internal.h
index 0b0029e4db87..dc9c81ff1b27 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1153,4 +1153,30 @@  struct vma_prepare {
 	struct vm_area_struct *remove;
 	struct vm_area_struct *remove2;
 };
+
+/* shrinker related functions */
+
+#ifdef CONFIG_SHRINKER_DEBUG
+extern int shrinker_debugfs_add(struct shrinker *shrinker);
+extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
+					      int *debugfs_id);
+extern void shrinker_debugfs_remove(struct dentry *debugfs_entry,
+				    int debugfs_id);
+#else /* CONFIG_SHRINKER_DEBUG */
+static inline int shrinker_debugfs_add(struct shrinker *shrinker)
+{
+	return 0;
+}
+static inline struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker,
+						     int *debugfs_id)
+{
+	*debugfs_id = -1;
+	return NULL;
+}
+static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry,
+					   int debugfs_id)
+{
+}
+#endif /* CONFIG_SHRINKER_DEBUG */
+
 #endif	/* __MM_INTERNAL_H */