Memory Management API: kmem_cache_destroy,

Source: Internet
Author: User

Memory Management API: kmem_cache_destroy,

Memory Management API: kmem_cache_destroy

Void destroy (struct kmem_cache * s) is used to destroy the cache created through kmem_cache_create. Its source code analysis is as follows: void kmem_cache_destroy (struct kmem_cache * s) {int err; # The parameter s is null, exit directly, indicating that the parameter kmem_cache_destroy can be nullif (unlikely (! S) return; # Use get_online_mems and put_online_cpus together with put_online_cpus (); get_online_mems (); mutex_lock (& slab_mutex); # The cached application count is reduced by 1, if the reference count after the value of 1 is not zero, it indicates that someone else is using this cache and will exit directly. s-> refcount --; if (s-> refcount) goto out_unlock; # if the reference count is already zero, destroy memcg first. if yes, err is equal to zero, finally, use shutdown_cache to destroy the cache err = shutdown_memcg_caches (s); if (! Err) err = shutdown_cache (s); if (err) {pr_err ("kmem_cache_destroy % s: Slab cache still has objects \ n", s-> name ); dump_stack ();} out_unlock: mutex_unlock (& slab_mutex); put_online_mems (); put_online_cpus () ;}# destroy static int shutdown_cache (struct kmem_cache * s) {/* free export quarantined objects */kasan_cache_shutdown (s); # release all resources occupied by slab if (_ kmem_cache_shutdown (s )! = 0) return-EBUSY; # unlink and delete the listmemcg_unlink_cache (s); list_del (& s-> list); # If rcu exists, release if (s-> flags & SLAB_TYPESAFE_BY_RCU) {list_add_tail (& s-> list, & slab_caches_to_rcu_destroy); schedule_work (& activities );} else {# ifdef SLAB_SUPPORTS_SYSFS # reference count of kobject minus 1sysfs_slab_release (s); # elseslab_kmem_cache_release (s); # endif} return 0 ;} # Release the void Merge (struct kmem_cache * s) {__ kmem_cache_release (s); merge (s); kfree_const (s-> name); kmem_cache_free (kmem_cache, 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.