Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux kernel memory management?

Will Linux Kernel free kmalloc'ed and not kfree'd in kernel module memory after module release just like it's work with user space apps?

like image 845
Ilay Avatar asked Jan 18 '11 18:01

Ilay


People also ask

How does Linux kernel manage memory?

The Linux kernel provides each process with an independent virtual address space, and this address space is contiguous. In this way, the process can easily access memory, more precisely the virtual memory. The interior of the virtual address space is divided into two parts: kernel space and user space.

Does kernel handle memory management?

The Windows kernel-mode memory manager component manages physical memory for the operating system. This memory is primarily in the form of random access memory (RAM). The memory manager manages memory by performing the following major tasks: Managing the allocation and deallocation of memory virtually and dynamically.

What memory management does Linux use?

Linux uses demand paging to load executable images into a processes virtual memory. Whenever a command is executed, the file containing it is opened and its contents are mapped into the processes virtual memory.

What is kernel memory in Linux?

pages. The kernel has full access to the system's memory and allows processes to safely access this memory as they require it. Often the first step in doing this is virtual addressing, usually achieved by paging and/or segmentation.


2 Answers

The kernel will not do any garbage collection for a module. If the module kmallocs a chunk of memory and doesn't kfree it before the module is unloaded, that chunk will stay allocated and inaccessible until the next reboot.

like image 85
Karmastan Avatar answered Sep 21 '22 17:09

Karmastan


As others said, the kernel will not do any garbage collection for a module but device drivers can use devm_* types of resource allocations (called managed resource allocation functions) and the kernel will do all the required cleanups after there is no more reference to the device.

See here for the commented source code in the kernel source for devm_kmalloc.

like image 41
EmbeddedDeveloper Avatar answered Sep 22 '22 17:09

EmbeddedDeveloper