In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the role of vmalloc in Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the role of vmalloc in Linux"?
Walk into vmalloc
From the previous series of articles, we know that buddy system is based on the page frame allocator, kmalloc is based on the slab allocator, and that these allocated addresses are contiguous in physical memory. However, with the accumulation of fragmentation, the allocation of continuous physical memory will become difficult. For those non-DMA access, if you do not necessarily need continuous physical memory, you can, like malloc, map discontiguous physical memory page frames to contiguous virtual address space, which is the source of vmap) (to provide mapping of discrete page to contiguous virtual address space). Vmalloc allocation is based on this mechanism.
Vmalloc allocates a minimum of one page, and the pages assigned are not guaranteed to be contiguous, because alloc_page is called within the vmalloc to allocate a single page multiple times.
The area of vmalloc is between VMALLOC_START-VMALLOC_END in the figure above, which can be viewed through / proc/vmallocinfo.
The data structure vmap_area describes the area of a virtual address, which can form a linked list of struct vm_struct and maintain multi-segment mapping. Struct vmap_area {
Unsigned long va_start; / / vmalloc the starting address returned by the application virtual address
Unsigned long va_end; / / vmalloc the end address returned by the virtual address of the application application
Unsigned long flags
/ / connect to the vmap_area_root red-black tree
Struct rb_node rb_node; / * address sorted rbtree * /
/ / connect to the vmap_area_list linked list
Struct list_head list; / * address sorted list * /
Struct llist_node purge_list; / * "lazy purge" list * /
/ / if the current VA is in use (that is, in the vmap_area_root-rooted red-black tree and the vmap_area_list linked list), the vm is valid, pointing to the descriptor used to manage the mapping between the virtual address and the physical page
Struct vm_struct * vm
Struct rcu_head rcu_head
}
Vm_struct manages the mapping between virtual addresses and physical pages struct vm_struct {
Struct vm_struct * next; / / points to the next vm structure
Void * addr; / / the starting address of the virtual address of the current vmalloc zone
Unsigned long size; / / the size of the virtual address of the current vmalloc zone
Unsigned long flags
/ / the physical pages obtained by vamlloc allocation are not contiguous. Each physical page is described by struct page. An vm_struct forms an array of struct page used to manage all physical pages, and pages is the pointer to this array.
Struct page * * pages
Number of page for unsigned int nr_pages; / / vmalloc mapping
Phys_addr_t phys_addr; / / is used to map the IO shared memory of hardware devices, otherwise 0
Const void * caller; / / address of the function that calls the vmalloc function
}
Vmalloc
It is mainly divided into the following three steps:
From VMALLOC_START to VMALLOC_END to find free virtual address space (hole) according to the assigned size, call alloc_page to allocate a single page in turn. Map the assigned individual pages to the contiguous virtual addresses found in the first step. Map the assigned individual pages to the contiguous virtual addresses found in the first step.
At this point, I believe you have a deeper understanding of "what is the role of vmalloc in Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.