According to Documentation/admin-guide/kernel-parameters.txt,
the kernel command-line parameter mem= means "Force usage of
a specific amount of memory", but when add "mem=3G" to the
command-line, kernel boot hangs in sparse_init().
This commit is similar with the implementation of the other
archs such as arm64, powerpc and riscv, refactor the function
early_parse_mem() and then use memblock_enforce_memory_limit()
to limit the memory size.
With this patch, when add "mem=3G" to the command-line, the
kernel boots successfully, we can see the following messages:
[ 0.000000] Memory limited to 3072MB
...
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000000200000-0x000000000effffff]
[ 0.000000] node 0: [mem 0x0000000090200000-0x00000000ffffffff]
[ 0.000000] node 0: [mem 0x0000000120000000-0x00000001613fffff]
...
[ 0.000000] Memory: 3005280K/3145728K available (...)
After login, the output of free command is consistent with the
above log.
Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/mips/kernel/setup.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index f979adf..6b6d718 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -339,27 +339,15 @@ static void __init bootmem_init(void)
#endif /* CONFIG_SGI_IP27 */
static int usermem __initdata;
+static phys_addr_t memory_limit;
static int __init early_parse_mem(char *p)
{
- phys_addr_t start, size;
-
- /*
- * If a user specifies memory size, we
- * blow away any automatically generated
- * size.
- */
- if (usermem == 0) {
- usermem = 1;
- memblock_remove(memblock_start_of_DRAM(),
- memblock_end_of_DRAM() - memblock_start_of_DRAM());
- }
- start = 0;
- size = memparse(p, &p);
- if (*p == '@')
- start = memparse(p + 1, &p);
+ if (!p)
+ return 1;
- memblock_add(start, size);
+ memory_limit = memparse(p, &p) & PAGE_MASK;
+ pr_notice("Memory limited to %lldMB\n", memory_limit >> 20);
return 0;
}
@@ -678,6 +666,10 @@ static void __init arch_mem_init(char **cmdline_p)
memblock_reserve(__pa_symbol(&__nosave_begin),
__pa_symbol(&__nosave_end) - __pa_symbol(&__nosave_begin));
+ /* Limit the memory. */
+ memblock_enforce_memory_limit(memory_limit);
+ memblock_allow_resize();
+
early_memtest(PFN_PHYS(ARCH_PFN_OFFSET), PFN_PHYS(max_low_pfn));
}
--
2.1.0
Hi Tiezhu,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on hnaz-mm/master]
[also build test WARNING on linus/master v5.17-rc6 next-20220225]
[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/Tiezhu-Yang/MIPS-Modify-mem-and-memmap-parameter/20220228-143251
base: https://github.com/hnaz/linux-mm master
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20220228/[email protected]/config)
compiler: mips-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/ed304f835ff384c8fe9b788e13d3ec4d93878416
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tiezhu-Yang/MIPS-Modify-mem-and-memmap-parameter/20220228-143251
git checkout ed304f835ff384c8fe9b788e13d3ec4d93878416
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash arch/mips/kernel/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
In file included from include/asm-generic/bug.h:22,
from arch/mips/include/asm/bug.h:42,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/mm.h:6,
from include/linux/memblock.h:12,
from arch/mips/kernel/setup.c:17:
arch/mips/kernel/setup.c: In function 'early_parse_mem':
>> include/linux/kern_levels.h:5:25: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:25: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:509:9: note: in expansion of macro 'printk'
509 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:13:25: note: in expansion of macro 'KERN_SOH'
13 | #define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
| ^~~~~~~~
include/linux/printk.h:509:16: note: in expansion of macro 'KERN_NOTICE'
509 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~
arch/mips/kernel/setup.c:350:9: note: in expansion of macro 'pr_notice'
350 | pr_notice("Memory limited to %lldMB\n", memory_limit >> 20);
| ^~~~~~~~~
vim +5 include/linux/kern_levels.h
314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]