LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-22-2023, 07:44 AM   #1
jineshparakh
LQ Newbie
 
Registered: May 2023
Posts: 2

Rep: Reputation: 0
Learn more about MemAvailable's correctness from /proc/meminfo


I am currently trying to understand some fields from /proc/meminfo and am still a newbie at it.

With respect to the documentation,
"MemAvailable is an estimate of how much memory is available for starting new applications, without swapping. Calculated from MemFree, SReclaimable, the size of the file LRU lists, and the low watermarks in each zone. The estimate takes into account that the system needs some page cache to function well, and that not all reclaimable slab will be reclaimable, due to items being in use. The impact of those factors will vary from system to system."

Code:
long si_mem_available(void)

{

	long available;
	
	unsigned long pagecache;
	
	unsigned long wmark_low = 0;
	
	unsigned long pages[NR_LRU_LISTS];
	
	unsigned long reclaimable;
	
	struct zone *zone;
	
	int lru;

  

	for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
	
	pages[lru] = global_node_page_state(NR_LRU_BASE + lru);

  

	for_each_zone(zone)
	
	wmark_low += low_wmark_pages(zone);

  

	/*
	
	* Estimate the amount of memory available for userspace allocations,
	
	* without causing swapping or OOM.
	
	*/
	
	available = global_zone_page_state(NR_FREE_PAGES) - totalreserve_pages;
	
	  
	
	/*
	
	* Not all the page cache can be freed, otherwise the system will
	
	* start swapping or thrashing. Assume at least half of the page
	
	* cache, or the low watermark worth of cache, needs to stay.
	
	*/
	
	pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
	
	pagecache -= min(pagecache / 2, wmark_low);
	
	available += pagecache;
	
	  
	
	/*
	
	* Part of the reclaimable slab and other kernel memory consists of
	
	* items that are in use, and cannot be freed. Cap this estimate at the
	
	* low watermark.
	
	*/
	
	reclaimable = global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B) +
	
	global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE);
	
	available += reclaimable - min(reclaimable / 2, wmark_low);
	
	  
	
	if (available < 0)
	
	available = 0;
	
	return available;

}

During MemAvailable's calculation in the function si_mem_available(), we cap the reclaimable slab which should stay to least of half of reclaimable or the low watermark because of items in use. The remaining part can be freed.
Similar kind of capping is followed for pagecache.

My questions wrt this are:
1. What is the probability of this estimation of reclaimable/pagecache cap going wrong because of kernel not being able to free the part of reclaimable/pagecache which we are expecting to be freed?
2. What are the probable scenarios in which this could happen and what could be the implications?
3. Does MemAvailable's estimates have any further drawbacks that I should be aware of before trusting it?
 
Old 05-22-2023, 02:11 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
code is copied from here: https://github.com/torvalds/linux/bl..._alloc.c#L5146
https://superuser.com/questions/1544...m-proc-meminfo
https://git.kernel.org/pub/scm/linux...c700722c9da773
what kind of exam is it?
 
Old 05-23-2023, 01:32 AM   #3
jineshparakh
LQ Newbie
 
Registered: May 2023
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks a lot.
This is not for any exam.
I'm just trying to understand the probability of under estimation and over estimation of MemAvailable.
I'd read the superuser thread earlier.
Even after reading it, I'm unable know the frequency of inaccuracy of the estimation.
Can you please help?

Last edited by jineshparakh; 05-23-2023 at 04:02 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Format for reading /proc/self/status and /proc/meminfo ldmarks Linux - Kernel 1 11-09-2018 05:45 PM
/proc/meminfo VS /proc/kcore Fill Linux - Newbie 2 08-04-2011 04:13 AM
Oracle Developer 10G /proc/meminfo problem sockman Linux - Enterprise 3 12-19-2004 11:17 AM
Maximum memory reported by /proc/meminfo in vanilla 2.4.26 kobica Linux - General 0 11-15-2004 05:49 AM
What's the difference between the upper and lower portions of /proc/meminfo? undercrawler Linux - Hardware 0 03-26-2004 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration