The difference and connection between Malloc,vmalloc and Kmalloc,kfree and Vfree

Source: Internet
Author: User

Kmalloc and Vmalloc are allocated kernel memory, and malloc allocates the user's memory
Kmalloc guarantees that the internal existence of the allocation is physically continuous, and that the Vmalloc guarantees the continuity of the virtual address space
Kmalloc can allocate a limited size, vmalloc and malloc can allocate a relatively large size
Memory needs to be physically contiguous only when it is being accessed by DMA
Vmalloc is slower than Kmalloc.
1) The physical address assigned by Kmalloc has only one page-offset offset from the virtual address and does not need to modify the page table for the address segment.
Vmalloc class function address is completely virtual, each allocation needs to set the page table, of course, inefficient.
2) The correct place to use the Vmalloc is to allocate a chunk, continuous, only in the software that exists to buffer the memory area. Cannot be used outside the microprocessor.
3) Kmalloc (Gfp-kernel) is called in Vmalloc and therefore cannot be applied to an atomic context.
Kmalloc and Kfree manage the allocated memory within the kernel segment, which is the actual physical memory block known to the real address. Vmalloc and Vfree are allocations and releases of virtual memory used by the kernel. The memory returned by Kmalloc is physical, continuous, and more suitable for use by similar device-driven programs. But Vmalloc can use more resources, because Vmalloc can also handle swap space.
Kmalloc () allocates memory in more than 0xbfffffff-0xffffffff of memory, driver generally uses it to complete the allocation of the DS
Vmalloc () is located in the physical address discontinuous, virtual address contiguous region, the starting position is determined by the Vmallol_start, generally as the swap area, module allocation
The kmalloc corresponds to the kfree and can allocate continuous physical memory;
The vmalloc corresponds to the Vfree, allocating contiguous virtual memory, but not necessarily physically contiguous.

Vmalloc the logical address is contiguous when allocating memory, but the physical address is generally discontinuous and is suitable for situations where large amounts of memory need to be allocated, such as insert modules. This allocation mode performance is kmalloc.
Kmalloc allocated memory is based on slab, so some features of slab, including coloring, alignment, etc., have good performance. Both physical and logical addresses are contiguous

The main difference is
The problem of allocation size.
For example you need 28 bytes, that must use Kmalloc, if use Vmalloc, allocate not many times the machine strikes.

The difference and connection between Malloc,vmalloc and Kmalloc,kfree and Vfree

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.