Kzalloc, Kcalloc, Kmalloc, Vmalloc

Source: Internet
Author: User
The kernel code base is full of functions which allocate memory and Kmalloc (), then zero it with memset ().  Recently, Pekka Enberg concluded so much of the this code could is cleaned up by using kcalloc () instead. Kcalloc () has this prototype:

    void *kcalloc (size_t n, size_t size, unsigned int __nocast gfp_flags);

This function would allocate an array of n items, and would zero the entire array before returning it to the caller. Pekka ' s patch converted a number of Kmalloc ()/memset () pairs over to Kcalloc (), but this patch drew a complaint from Andre W Morton:

Notice how every conversion for you did passes in ' 1 ' in the ' the ' And that's going to happen again and again and again. Each callsite needlessly passing that silly third argument, adding text.

Very few callers actually need to allocate a array of items, so extra argument be unneeded in most. Each instance of this argument adds a bit to the size of the kernel, and, over time, which is adds up. The solution is to create yet another allocation function:

    void *kzalloc (size_t size, unsigned int __nocast gfp_flags);

This function is returns a single, zeroed item. It has been added to-mm, with its appearance in the mainline to likely for happen.

Kzalloc zeroes the memory before Returninga pointer

Kcalloc allocates memory for an array, itis not a replacement for Kcalloc:

void *kcalloc (size_t n, size_t size, gfp_tflags)

Vmalloc is the same as Kmalloc, except itallocates memory this is only virtually contiguous. The underling physicalmemory can be discontiguous.

So Kmalloc can eventually being replaced by Acall to Kzalloc, but it are unlikely to solve your

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.