In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1 Which pages to recycle
Page cache;
Memory mapped pages of user address space;
Slab cache: such as dentry and inode cache;
Anonymous pages: process stack and mmap anonymous mapping memory area; swap to swap before recycling;
2 When to recover
Kswapd periodic wake-up: when the free memory of the system is less than the threshold, page recycling is carried out;
Direct page reclamation: Suppose the operating system needs to allocate a large block of memory to the user process through the partner system, or needs to create a large buffer, and the memory in the system cannot provide enough physical memory to satisfy this memory request. At this time, the operating system must perform page reclamation as soon as possible.
If the OS still cannot get enough pages after trying to reclaim memory, call find_bad_process and OOM kill;
3 How to recover
Based on LRU algorithm; each zone maintains two LRU lists
struct zone {
……
spinlock_t lru_lock;
struct list_head active_list;
struct list_head inactive_list;
unsigned long nr_active;
unsigned long nr_inactive;
……
}
PG_active/PG_referenced is used to identify page activity, the former identifies when the page is active; the latter indicates whether the page has been recently visited, and will be set every time it is visited;
Note: If only a flag is used, the flag is set when the page is accessed, and the page remains active thereafter, if the operating system does not clear the flag, the page will remain active even if it is not or rarely accessed for a long time. In order to be able to clear the flag effectively, support for a timer is required so that the flag can be cleared automatically after a timeout period. However, many Linux supported architectures do not provide such hardware support, so Linux uses two flags to determine how active a page is.
Linux moves pages between active_list and inactive_list based on these two fields;
Note: 1 represents the function mark_page_accessed(), 2 represents the function page_referenced(), 3 represents the function activate_page(), 4 represents the function shrink_active_list()
Either kswapd or direct page recycling, eventually shrink_slab and shrink_zone are called;
Direct page recovery: Repeatedly call these two functions. If N pages cannot be successfully released within a certain number of cycles, OOM killer will be called.
Kswapd: Call shrink_zone() for each zone;
3.1 Shrink_slab Principle
Registering the shrinker function with the operating system kernel will actively free up some of the space occupied by the disk cache when memory is low.
The shrink_slab() function iterates through the shrink list, processing all disk caches registered with the shrink function.
Registering a shrinker is achieved through the function set_shrinker(), and deregistering a shrinker is achieved through the function remove_shrinker(). Currently, the main shrinker functions in Linux operating systems are as follows:
shrink_dcache_memory(): This shrink function is responsible for the dentry cache.
shrink_icache_memory(): This shrink function is responsible for inode caching.
mb_cache_shrink_fn(): This shrink function is responsible for caching metadata for the file system.
3.2 Shrink_zone principle
1 Move the page from active to inactive list with shrink_active_list();
2 Call shrink_inactive_list() to put the pages of inactive list into temporary list, and finally call shrink_page_list() to recycle
3.2.1 Meaning of Swappiness
The shrink_zone() mentioned above calls shrink_lruvec(), and the active/inactive list is divided into anon anonymous pages and file cache mapping page lists, totaling 4 LRUs;
Swappines only works on anon pages, and even if it is 0, it is possible to execute swap.
get_scan_coun() in vmscan.c
1. First, if swap is disabled or there is no swap space, only file-based linked lists are scanned, that is, anonymous page linked lists are not scanned.
Code:
if (! sc->may_swap || (get_nr_swap_pages() priority && vmscan_swappiness(sc)) {
scan_balance = SCAN_EQUAL;
goto out;
}
4. If it is a global page collection, and the sum of the current free memory and the number of all file-based linked lists is less than the high watermark of the system, anonymous page collection must be performed, and swap must occur.
Code:
anon = get_lru_size(lruvec, LRU_ACTIVE_ANON) +
get_lru_size(lruvec, LRU_INACTIVE_ANON);
file = get_lru_size(lruvec, LRU_ACTIVE_FILE) +
get_lru_size(lruvec, LRU_INACTIVE_FILE);
if (global_reclaim(sc)) {
free = zone_page_state(zone, NR_FREE_PAGES);
if (unlikely(file + free
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.