Article Title: Linux kernel module memory application and release. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Applied memory:
Void * kmalloc (size_t size, int flags)
The kmalloc function is similar to the malloc function. It has two parameters. One parameter is size, that is, the size of the memory block applied. This parameter is relatively simple, just like the parameter in malloc. The second parameter is a flag in which priority information can be specified. Linux has the following priorities:
GFP_KERNEL indicates that the memory allocation is called by a process running in kernel mode, that is, when the memory is lower than min_free_pages, the process can be sleep;
GFP_ATOMIC, atomic memory allocation allows the process to continue allocating memory when the actual memory is lower than min_free_pages.
GFP_DMA: this flag must be used together with GFP_KERNEL and GFP_ATOMIC to apply for memory pages for Direct Memory Access.
Release:
Kfree (const void * objp) const void * objp = is a pointer to the memory space to be released.