Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use kmalloc Kernel memory allocation function in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use the kmalloc kernel memory allocation function in Linux. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

Define static _ _ always_inline void * kmalloc (size_t size, gfp_t flags) {if (_ _ builtin_constant_p (size)) {if (size > KMALLOC_MAX_CACHE_SIZE) return kmalloc_large (size, flags); # ifndef CONFIG_SLOB if (! (flags & GFP_DMA)) {int index = kmalloc_index (size) If (! index) return ZERO_SIZE_PTR; return kmem_cache_alloc_trace (kmalloc_caches [index], flags, size);} # endif} return _ kmalloc (size, flags);}

Note:

1) the _ _ builtin_constant_p compiler inlines the function to determine whether the incoming parameter is constant. If it is a variable, call the _ _ kmalloc function directly.

2) KMALLOC_MAX_CACHE_SIZE means that the maximum value of slab cache created by the system is 8K, which is defined as follows:

# # include/linux/slab.h/* Maximum size for which we actually use a slab cache * / # define KMALLOC_MAX_CACHE_SIZE (1UL

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report