Memory Management API: kmem_cache_free, apikmem_cache_free

Source: Internet
Author: User

Memory Management API: kmem_cache_free, apikmem_cache_free

Memory Management API: kmem_cache_free

Void kmem_cache_free (struct kmem_cache * cache, void * objp) is used to release the memory applied for by kmem_cache_alloc. The source code analysis is as follows: void kmem_cache_free (struct kmem_cache * cache, void * objp) {unsigned long flags; # This function is mainly used to check whether the slab is valid cache_from_obj (caclap, objp); if (! Cache) return; # When mem is released, irqlocal_irq_save (flags) of the current cpu is disabled; debug_check_no_locks_freed (objp, cache-> object_size); if (! (Cache-> flags & SLAB_DEBUG_OBJECTS) release (objp, cache-> object_size); # Release mem _ cache_free (cache, objp, _ RET_IP _); local_irq_restore (flags ); trace_kmem_cache_free (_ RET_IP _, objp);} static inline struct kmem_cache * cache_from_obj (struct kmem_cache * s, void * x) {struct kmem_cache * caclap; struct page * page; /** When kmemcg is not being used, both assignments shoshould return the * same valu E. but we don't want to pay the assignment price in that * case. if it is not compiled in, the compiler shocould be smart enough * to not do even the assignment. in that case, slab_assist_or_root * will also be a constant. */# Here we will judge # if defined (CONFIG_MEMCG )&&! Defined (CONFIG_SLOB) is the condition true? # In my system, this condition is true, so the if condition below will not be true if (! Memcg_kmem_enabled ()&&! Unlikely (s-> flags & volumes) return s; # obtain the pagepage = pai_to_head_page (x) of the slab Based on the parameter x; # obtain slab_cachecachu = page-> slab_cache Based on the page; # Here, we will compare the slab pointer obtained from x with the slab represented by s. If not, return the slab of s to release it. # If they are equal, then, the slab pointer obtained from the form parameter x is released. It doesn't matter who is returned when they are equal. if (slab_1__or_root (cache, s) return cache; pr_err ("% s: Wrong slab cache. % s but object is from % s \ n ", _ func __, s-> name, cachu-> name); WARN_ON_ONCE (1); return s ;}

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.