How to allocate more than 4M large memory in the Linux kernel

Source: Internet
Author: User

In the kernel, Kmalloc is able to allocate a maximum contiguous memory of 2 ( MAX_ORDER -1) page (see alloc_pages function, "if (Unlikely (order >= Max_order)) return N ULL; "), the page size is generally 4K bytes, the MAX_ORDER default is defined as 11, so if you do not modify the kernel, Kmalloc can allocate the maximum contiguous memory is generally 4M bytes.

There are three ways to get more than 4M of large memory in the kernel:

1. Modify MAX_ORDER , recompile the kernel

2. The kernel starts the selection pass " mem= " parameter, such as "mem=80m", reserves some memory, and then maps the reserved memory to the module through Request_mem_region and Ioremap_nocache. The kernel boot parameters need to be modified, No need to recompile the kernel. However, this method does not support the x86 architecture, only the arm, PowerPC and other non-x86 architectures are supported.

3. Calling the Alloc_boot_mem function to pre-allocate large chunks of memory before mem_init the function in Start_kernel requires recompiling the kernel.


Without recompiling the kernel, the kernel in the x86 schema can only get up to 4M of contiguous memory, or use Vmalloc to get more than 4M of non-contiguous memory. Moreover, whether it is Kmalloc or vmalloc, the larger the allocated memory, the greater the likelihood of failure; The sooner the system starts allocating memory (the more free memory, the more regular the division), the greater the likelihood of success.

How to allocate more than 4M large memory in the Linux kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.