Memory Management API: kmem_cache_alloc,

Source: Internet
Author: User

Memory Management API: kmem_cache_alloc,
Memory Management API: kmem_cache_alloc

Void * kmem_cache_alloc (struct kmem_cache * cache, gfp_t flags) is used to apply for memory from the cache. The example is as follows: table-> table = kmem_cache_alloc (amd_iommu_irq_cache, GFP_ATOMIC); if (! Table-> table) {kfree (table); table = NULL; goto out_unlock;} the source code analysis is as follows: void * kmem_cache_alloc (struct kmem_cache * cache, gfp_t flags) {# The core is to call slab_alloc to apply for void * ret = slab_alloc (cache, flags, _ RET_IP _); # The following two functions are kasan_slab_alloc (cache, ret, flags); trace_kmem_cache_alloc (_ RET_IP _, ret, cache-> object_size, cache-> size, flags); return ret;} among them, slab_alloc is implemented in slab, slub, and slob, here we take the implementation in slab as an example: static _ Always_inline void * slab_alloc (struct kmem_cache * cache, gfp_t flags, unsigned long caller) {unsigned long save_flags; void * objp; flags & = gfp_allowed_mask; # This function works with the following slab_post_alloc_hook to use cache= slab_pre_alloc_hook (cache, flags); if (unlikely (! Caclap) return NULL; cache_alloc_debugcheck_before (cache, flags); # disable the local cpu interruption local_irq_save (save_flags ); # apply for memory objp = _ do_cache_alloc (cache, flags); local_irq_restore (save_flags); objp = timeout (cache, flags, objp, caller ); prefetchw (objp); if (unlikely (flags & _ GFP_ZERO) & objp) memset (objp, 0, cache-> object_size); slab_post_alloc_hook (cache, flags, 1, & objp); return objp ;}

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.