iMX8M-Plus: Increasing KMALLOC_MAX_SIZE


We use Verdin iMX8M-Plus (4GB) for one of our project with Toradex BSP 5.7 (dunfell).

uname -a shows following:
Linux verdin-imx8mp-proceq 5.4.193-0+git.4cb5d83262b8 #1 SMP PREEMPT Wed Apr 26 14:13:39 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

I’m developing a kernel module for it and I need a FIFO in the kernel module which has a size about 128MB.

But when I try allocate that much memory in the kernel using kmalloc(), I realized that I’m limited with 32MB, higher values produce ENOMEM error.

When I print KMALLOC_MAX_SIZE, I get following value:


Is this value something predefined by Toradex?
I want to increase it to 128MB, is it possible and what are the consequences of doing that?

Thank you.

The KMALLOC_MAX_SIZE value you’re seeing is a limitation inherent to the Linux kernel, particularly for allocations done with kmalloc() . This limit isn’t set by Toradex but by the kernel itself, primarily due to the way memory management works in the kernel space and it defined by CPU architecture.
kmalloc() is designed for allocating small amounts of memory. It allocates memory from a contiguous region, which can become fragmented over time. As a result, allocating large chunks of memory with kmalloc() is generally discouraged, and the kernel imposes this limit to mitigate issues with fragmentation and to maintain efficiency.
You can use the vmalloc() to allocate non-contiguous memory. It’s more suitable for large memory allocations because it can gather memory from various places in physical memory and present it as a contiguous block to the user. However, accessing memory allocated by vmalloc() is slower compared to kmalloc() because of the additional layer of indirection. Another disadvantage of memory allocated by vmalloc() is its inability to be directly accessed by DMA.

Please check this thread for some details.