In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
The main content of this article is to explain "what is the memory fragmentation of the Linux page frame allocator", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what is the memory fragmentation of the Linux page frame allocator?"
The page frame allocator includes memory fragmentation and memory recovery in slow allocation, as follows:
Static inline struct page * _ alloc_pages_slowpath (gfp_t gfp_mask, unsigned int order, struct alloc_context * ac) {page = _ _ alloc_pages_direct_compact (gfp_mask, order, alloc_flags, ac, INIT_COMPACT_PRIORITY, & compact_result); Page = _ alloc_pages_direct_reclaim (gfp_mask, order, alloc_flags, ac, & did_some_progress);. }
For the sake of space design, this time we will only talk about the fragmentation of memory, and we will talk about memory recycling below.
What is memory fragmentation?
There are two types of Linux physical memory fragmentation: internal fragmentation and external fragmentation.
Internal fragmentation:
The unused portion of the memory space allocated to the user. For example, a process needs to use 3Kbytes physical memory, so it requests memory equal to 3Kbytes from the system, but because the smallest particle of the Linux kernel partner system algorithm is 4Kbytes, it allocates 4Kbytes memory, so the unused memory of 1K bytes is memory fragments.
External fragmentation:
Refers to small blocks of memory that cannot be used in the system. For example, the remaining memory of the system is 16K bytes, but the 16K bytes memory is composed of four 4K bytes pages, that is, the 16K physical page frame number # 1 is not contiguous. In the case of 16K bytes memory left in the system, the system cannot successfully allocate more than 4K continuous physical memory, which is caused by external memory fragmentation.
Fragmentation finishing algorithm
The fragmentation sorting algorithm of Linux memory mainly applies the page migration mechanism of the kernel, which is a method to free up continuous physical memory after migrating movable pages.
Suppose there is a very small memory domain as follows:
Blue indicates free pages, white indicates pages that have been allocated, and you can see that the free pages (blue) in the memory domain above are very scattered and cannot allocate more than two pages of continuous physical memory.
The kernel runs two separate scan actions: the first scan starts at the bottom of the memory domain and records the allocated MOVABLE pages in a list while scanning:
In addition, the second scan starts at the top of the memory domain, scans for free page locations that can be the target of page migration, and then records them in a list:
When the two scans meet in the middle of the domain, it means that the scan is over, and then migrate the allocated page from the left scan to the free page on the right, and the left side forms a continuous piece of physical memory to complete the page tidiness.
Three ways of fragmentation finishing
Static struct page * _ alloc_pages_direct_compact (gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags, const struct alloc_context * ac, enum compact_priority prio, enum compact_result * compact_result) {struct page * page; unsigned int noreclaim_flag; if (! order) return NULL; noreclaim_flag = memalloc_noreclaim_save (); * compact_result = try_to_compact_pages (gfp_mask, order, alloc_flags, ac, prio) Memalloc_noreclaim_restore (noreclaim_flag); if (* compact_result compact_blockskip_flush = false; compaction_defer_reset (zone, order, true); count_vm_event (COMPACTSUCCESS); return page;} count_vm_event (COMPACTFAIL); cond_resched (); return NULL;}
This is also the code implementation of the above memory compaction algorithm.
There are three ways of fragmentation in the linux kernel, which we summarize as follows:
At this point, I believe that everyone on the "Linux page frame allocator memory fragmentation finishing is what" have a deeper understanding, might as well to the actual operation of it! 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.