Ioremap
Void * ioremap (unsigned long offset, unsigned Long SIZE) ioremap is a more direct memory "Allocation" method, which directly specifies the physical start address and the size of memory to be allocated, then, map the physical address segment to the kernel address space. The physical address space used by ioremap is determined in advance, which is not the same as the above memory allocation methods, rather than allocating a new physical memory. Ioremap is mostly used by device drivers to allow the CPU to directly access the I/O space of external devices. The memory that ioremap can map is determined by the original physical memory space, so no tests are conducted. Linux training boot memory if you want to allocate a large amount of continuous physical memory, the above allocation functions cannot meet, you can only use a special method, in the Linux Kernel boot phase to reserve part of the memory. During kernel boot, allocate the memory void * alloc_bootmem (unsigned Long SIZE) to bypass the partner system during Linux kernel boot to allocate large blocks of memory. You can use the alloc_bootmem function to apply for memory of the specified size before calling the mem_init function during Linux kernel boot. If you need to call this memory elsewhere, you can export the first address of the memory returned by alloc_bootmem through export_symbol, and then you can use this memory. The disadvantage of this memory allocation method is that the Code for applying for memory must be linked to the Code in the kernel before it can be used. Therefore, the kernel must be re-compiled, and the memory management system cannot see this part of the memory, you need to manage it on your own. The test results show that, after the kernel is re-compiled and restarted, the allocated memory block can be accessed during boot. When the kernel boot parameter is used to reserve the top memory for Linux kernel boot, the input parameter "mem = size" is used to reserve the top memory range. For example, if the system has 800000 MB memory, the parameter "mem = 248m" reserves 8 MB memory at the top. after entering the system, you can call ioremap (0xf800000, 0 x) to apply for this memory. Comparison of several allocation functions allocation principle maximum memory others _ get_free_pages direct operations on the page Box 4 MB suitable for allocating a large number of continuous physical memory kmem_cache_alloc Based on slab mechanism to achieve kb suitable for frequent application and release of the same kmalloc is used to allocate kb Based on kmem_cache_alloc in memory blocks, when the memory size is smaller than the page size, you can use vmalloc to establish non-consecutive physical memory ing to virtual addresses physically discontinuous, suitable for large memory, however, for scenarios where address continuity is not required, Linux training dma_alloc_coherent implements 4 MB Based on _ alloc_pages for DMA Operation ioremap to map known physical addresses to virtual addresses, for example, when the device driver alloc_bootmem starts the kernel, it reserves a memory segment. The kernel cannot be seen as smaller than the physical memory size, and the memory management requirements are high.