"MEM=" Kernel paramater (limiting the total amount of memory available to the kernel)
In this post, I would like to demonstrate experiment on how to restrict memory to be considered by kernel and use/claim that memory later.
The mem= limits the total amount of memory available to the kernel, rather than reserving a specific region of memory for special purposes.
What it does: Limits the total memory the kernel sees and uses.
Effect: The kernel will ignore any memory beyond the specified amount. For example, if you pass mem=512M, the kernel will only use the first 512 MB of RAM and ignore the rest of the memory.
Use case: Testing scenarios with reduced memory or debugging purposes, but not suitable for reserving specific memory regions for custom uses.
Here is my Ubuntu System setting where 8GB memory is configured.
Now I would pass MEM=4G as kernel command line parameter through bootloader which happens to be GRUB in this case. here are the typical steps:
- sudo vi /etc/default/grub
- Update with mem=, e.g. GRUB_CMDLINE_LINUX_DEFAULT="quiet splash mem=4G"
- sudo update-grub
- sudo reboot
Once the system is booted up, we can observe that Kernel
can only see ~4GB though the memory configured is 8GB.
ioremap is the key API to claim this memory back.
Here is the sample kernel module.
And Makefile.
Once we deploy the module, we can see prints in dmesg confirming the memory claim.
Comments
Post a Comment