Skip to contentSkip to conversation

mm: page_alloc: Add debug log in free_reserved_area for static memory

PATCH Superseded Faiyaz Mohammed 3 participants 4 messages Oct 14, 2021

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mm: page_alloc: Add debug log in free_reserved_area for static memory

For INITRD and initmem memory is reserved through "memblock_reserve" during boot up but it is free via "free_reserved_area" instead of "memblock_free".
For example:

[    0.294848] Freeing initrd memory: 12K.
[    0.696688] Freeing unused kernel memory: 4096K.

To get the start and end address of the above freed memory and to account proper memblock added pr_debug log in "free_reserved_area". After adding log:

[    0.294837] 0x00000083600000-0x00000083603000 free_initrd_mem+0x20/0x28
[    0.294848] Freeing initrd memory: 12K.
[    0.695246] 0x00000081600000-0x00000081a00000 free_initmem+0x70/0xc8
[    0.696688] Freeing unused kernel memory: 4096K.

---
changes in v3:
- Update the format specifier.
changes in v2:
- To avoid confusion, remove the memblock_dbg print and drop the memblock_free string, now using pr_debug to print the address ranges.

 mm/page_alloc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
mm/page_alloc.c +6 -1
index b37435c..13adda5 100644
@@ -8097,6 +8097,8 @@ EXPORT_SYMBOL(adjust_managed_page_count);
 
 unsigned long free_reserved_area(void *start, void *end, int poison, const char *s)
 {
+	const phys_addr_t pstart = __pa(start);
+	const phys_addr_t pend = __pa(end);
 	void *pos;
 	unsigned long pages = 0;
 
@@ -8125,9 +8127,12 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 		free_reserved_page(page);
 	}
 
-	if (pages && s)
+	if (pages && s) {
 		pr_info("Freeing %s memory: %ldK\n",
 			s, pages << (PAGE_SHIFT - 10));
+		pr_debug("[%pa-%pa] %pS\n", &pstart, &pend,
+			(void *)__RET_IP_);
+	}
 
 	return pages;
 }
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
Acked-by on v3 1/1
#1 lore raw
Quoted 44 lines · Faiyaz Mohammed

For INITRD and initmem memory is reserved through "memblock_reserve" during boot up but it is free via "free_reserved_area" instead of "memblock_free".
For example:

[    0.294848] Freeing initrd memory: 12K.
[    0.696688] Freeing unused kernel memory: 4096K.

To get the start and end address of the above freed memory and to account proper memblock added pr_debug log in "free_reserved_area". After adding log:

[    0.294837] 0x00000083600000-0x00000083603000 free_initrd_mem+0x20/0x28
[    0.294848] Freeing initrd memory: 12K.
[    0.695246] 0x00000081600000-0x00000081a00000 free_initmem+0x70/0xc8
[    0.696688] Freeing unused kernel memory: 4096K.

---
changes in v3:
- Update the format specifier.
changes in v2:
- To avoid confusion, remove the memblock_dbg print and drop the memblock_free string, now using pr_debug to print the address ranges.

 mm/page_alloc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -0
index b37435c..13adda5 100644
@@ -8097,6 +8097,8 @@ EXPORT_SYMBOL(adjust_managed_page_count);
 
 unsigned long free_reserved_area(void *start, void *end, int poison, const char *s)
 {
+	const phys_addr_t pstart = __pa(start);
+	const phys_addr_t pend = __pa(end);
 	void *pos;
 	unsigned long pages = 0;
 
@@ -8125,9 +8127,12 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 		free_reserved_page(page);
 	}
 

mm/page_alloc.c unsigned long free_reserved_area(void *start, void *end, int poison, const char · line 8138

Quoted 10 lines
mm/page_alloc.c +4 -1
-	if (pages && s)
+	if (pages && s) {
 		pr_info("Freeing %s memory: %ldK\n",
 			s, pages << (PAGE_SHIFT - 10));
+		pr_debug("[%pa-%pa] %pS\n", &pstart, &pend,
+			(void *)__RET_IP_);
+	}
 
 	return pages;
 }

Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
In reply to Faiyaz Mohammed
Thank you for the patch! Yet something to improve:

Hi Faiyaz,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.15-rc5]
[cannot apply to hnaz-mm/master next-20211013]
[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]

url:    https://github.com/0day-ci/linux/commits/Faiyaz-Mohammed/mm-page_alloc-Add-debug-log-in-free_reserved_area-for-static-memory/20211014-151427
base:    64570fbc14f8d7cb3fe3995f20e26bc25ce4b2cc
config: nios2-defconfig (attached as .config)
compiler: nios2-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/009729e4f858e64537a4a144369b155f8d69d62f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Faiyaz-Mohammed/mm-page_alloc-Add-debug-log-in-free_reserved_area-for-static-memory/20211014-151427 git checkout 009729e4f858e64537a4a144369b155f8d69d62f
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

mm/page_alloc.c:3810:15: warning: no previous prototype for 'should_fail_alloc_page' [-Wmissing-prototypes]
3810 | noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
| ^~~~~~~~~~~~~~~~~~~~~~
In file included from include/asm-generic/bug.h:22,

                    from ./arch/nios2/include/generated/asm/bug.h:1,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/mm.h:9,
                    from mm/page_alloc.c:19:
   mm/page_alloc.c: In function 'free_reserved_area':
>> mm/page_alloc.c:8134:33: error: '__RET_IP_' undeclared (first use in this function)
    8134 |                         (void *)__RET_IP_);
         |                                 ^~~~~~~~~
   include/linux/printk.h:418:33: note: in definition of macro 'printk_index_wrap'
     418 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   include/linux/printk.h:132:17: note: in expansion of macro 'printk'
     132 |                 printk(fmt, ##__VA_ARGS__);             \
         |                 ^~~~~~
   include/linux/printk.h:576:9: note: in expansion of macro 'no_printk'
     576 |         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~
   mm/page_alloc.c:8133:17: note: in expansion of macro 'pr_debug'
    8133 |                 pr_debug("[%pa-%pa] %pS\n", &pstart, &pend,
         |                 ^~~~~~~~
   mm/page_alloc.c:8134:33: note: each undeclared identifier is reported only once for each function it appears in
    8134 |                         (void *)__RET_IP_);
         |                                 ^~~~~~~~~
   include/linux/printk.h:418:33: note: in definition of macro 'printk_index_wrap'
     418 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   include/linux/printk.h:132:17: note: in expansion of macro 'printk'
     132 |                 printk(fmt, ##__VA_ARGS__);             \
         |                 ^~~~~~
   include/linux/printk.h:576:9: note: in expansion of macro 'no_printk'
     576 |         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~
   mm/page_alloc.c:8133:17: note: in expansion of macro 'pr_debug'
    8133 |                 pr_debug("[%pa-%pa] %pS\n", &pstart, &pend,
         |                 ^~~~~~~~

vim +/__RET_IP_ +8134 mm/page_alloc.c

8097
8098 unsigned long free_reserved_area(void *start, void *end, int poison, const char *s)
8099 {
8100 const phys_addr_t pstart = __pa(start);
8101 const phys_addr_t pend = __pa(end);
8102 void *pos;
8103 unsigned long pages = 0;
8104
8105 start = (void *)PAGE_ALIGN((unsigned long)start);
8106 end = (void *)((unsigned long)end & PAGE_MASK);
8107 for (pos = start; pos < end; pos += PAGE_SIZE, pages++) {
8108 struct page *page = virt_to_page(pos);
8109 void *direct_map_addr;
8110
8111 /*
8112 * 'direct_map_addr' might be different from 'pos'
8113 * because some architectures' virt_to_page()
8114 * work with aliases. Getting the direct map
8115 * address ensures that we get a _writeable_
8116 * alias for the memset().
8117 */
8118 direct_map_addr = page_address(page);
8119 /*
8120 * Perform a kasan-unchecked memset() since this memory
8121 * has not been initialized.
8122 */
8123 direct_map_addr = kasan_reset_tag(direct_map_addr);
8124 if ((unsigned int)poison <= 0xFF)
8125 memset(direct_map_addr, poison, PAGE_SIZE);
8126
8127 free_reserved_page(page);
8128 }
8129
8130 if (pages && s) {
8131 pr_info("Freeing %s memory: %ldK\n",
8132 s, pages << (PAGE_SHIFT - 10));
8133 pr_debug("[%pa-%pa] %pS\n", &pstart, &pend,

> 8134				(void *)__RET_IP_);

8135 }
8136
8137 return pages;
8138 }
8139

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Faiyaz Mohammed
Thank you for the patch! Yet something to improve:

Hi Faiyaz,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.15-rc5]
[cannot apply to hnaz-mm/master next-20211013]
[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]

url:    https://github.com/0day-ci/linux/commits/Faiyaz-Mohammed/mm-page_alloc-Add-debug-log-in-free_reserved_area-for-static-memory/20211014-151427
base:    64570fbc14f8d7cb3fe3995f20e26bc25ce4b2cc
config: hexagon-randconfig-r004-20211014 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 6c76d0101193aa4eb891a6954ff047eda2f9cf71)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/009729e4f858e64537a4a144369b155f8d69d62f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Faiyaz-Mohammed/mm-page_alloc-Add-debug-log-in-free_reserved_area-for-static-memory/20211014-151427 git checkout 009729e4f858e64537a4a144369b155f8d69d62f
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

mm/page_alloc.c:3810:15: warning: no previous prototype for function 'should_fail_alloc_page' [-Wmissing-prototypes] noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)

                 ^
   mm/page_alloc.c:3810:10: note: declare 'static' if the function is not intended to be used outside of this translation unit
   noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
            ^
            static 
>> mm/page_alloc.c:8134:12: error: use of undeclared identifier '__RET_IP_'
                           (void *)__RET_IP_);
                                   ^

1 warning and 1 error generated.

vim +/__RET_IP_ +8134 mm/page_alloc.c

8097
8098 unsigned long free_reserved_area(void *start, void *end, int poison, const char *s)
8099 {
8100 const phys_addr_t pstart = __pa(start);
8101 const phys_addr_t pend = __pa(end);
8102 void *pos;
8103 unsigned long pages = 0;
8104
8105 start = (void *)PAGE_ALIGN((unsigned long)start);
8106 end = (void *)((unsigned long)end & PAGE_MASK);
8107 for (pos = start; pos < end; pos += PAGE_SIZE, pages++) {
8108 struct page *page = virt_to_page(pos);
8109 void *direct_map_addr;
8110
8111 /*
8112 * 'direct_map_addr' might be different from 'pos'
8113 * because some architectures' virt_to_page()
8114 * work with aliases. Getting the direct map
8115 * address ensures that we get a _writeable_
8116 * alias for the memset().
8117 */
8118 direct_map_addr = page_address(page);
8119 /*
8120 * Perform a kasan-unchecked memset() since this memory
8121 * has not been initialized.
8122 */
8123 direct_map_addr = kasan_reset_tag(direct_map_addr);
8124 if ((unsigned int)poison <= 0xFF)
8125 memset(direct_map_addr, poison, PAGE_SIZE);
8126
8127 free_reserved_page(page);
8128 }
8129
8130 if (pages && s) {
8131 pr_info("Freeing %s memory: %ldK\n",
8132 s, pages << (PAGE_SHIFT - 10));
8133 pr_debug("[%pa-%pa] %pS\n", &pstart, &pend,

> 8134				(void *)__RET_IP_);

8135 }
8136
8137 return pages;
8138 }
8139

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org