using ioremap over kernel memory boot time reservation

680 Views Asked by At

firstly i have to admit that i'm a newbie. so don't go hard on me plz. i want to reserve memory at boot time and then use this memory in a kernel module in order to be sure that this module is the only one using this space . i m going like this : add mem= , and memmap= to kerenl parameters to reserve memory @ boot time . my questions begin here :

  1. if i use ioremap over this space in my module code will it be accessible in other modules ? or other kernel subsystems cant still see it?
  2. second question : how can i be sure that this reserved memory will never move to swap space ?
  3. third one : how can i access this memory like block devices ? i mean like /dev/sda or ..... .
3

There are 3 best solutions below

0
On

(1) By using ioremap, you're establishing a kernel virtual address for the memory. Any other code in kernel space can access it simply by sticking the right value into a pointer variable. AFAIK, there's no way of "locking" any area of memory to a single kernel module. All parts of the kernel are all-powerful and hence can access any memory they like -- or at least, they can do all the operations that might be required to allow them to access any memory they like. By the same token, there is no reason that another piece of kernel code is going to access the memory unless you cause that somehow. After all, you've told the rest of the kernel that it's not normal memory.

(2) By excluding the memory from the kernel memory map, then using ioremap you're in effect telling the kernel that it's some kind of special "I/O" memory (think a PCI device's I/O memory region, for example), and hence wouldn't be considered for paging for that reason.

I don't know of any way you can achieve your goal in (3) without implementing your own device interface for the memory. However, if that's what you want to use it for, why not simply create a ramdisk filesystem? No (additional) kernel programming required for that. (See Documentation/blockdev/ramdisk.txt in the kernel source tree.)

0
On

I think ioremap() is unnecessrily dragged in discussion for reservation of memory at boot up time.

It better to use (indeed mostly used in kernel) is following API

memblock_reserve(phys_addr_t base, phys_addr_t size)

check file memblock.c for more understanding .

0
On
  1. ioremap for any physical address, will give a virtual address, which you can used to put some data there.
  2. Multiple modules can map this area and rewrite this all they need is start address(physical) and size
  3. Mem=/memmap= will hide this from linux kernel, so no swap-out etc
  4. Since io area so non-cacheable and non-cohherent will be attribute in most architecture