From: Qi Zheng <zhengqi.arch@bytedance.com>
To: akpm@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
songmuchun@bytedance.com, Qi Zheng <zhengqi.arch@bytedance.com>
Subject: [PATCH 2/2] mm: reimplement si_mem_available()
Date: Thu, 16 Dec 2021 20:46:55 +0800 [thread overview]
Message-ID: <20211216124655.32247-3-zhengqi.arch@bytedance.com> (raw)
In-Reply-To: <20211216124655.32247-1-zhengqi.arch@bytedance.com>
Reimplement si_mem_available() by reusing si_mem_available_node().
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
---
mm/page_alloc.c | 45 +++++++--------------------------------------
1 file changed, 7 insertions(+), 38 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 31f5e3e335cf..0982372c8e49 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5782,46 +5782,15 @@ long si_mem_available_node(struct sysinfo *val, int nid)
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.
- */
- available = global_zone_page_state(NR_FREE_PAGES) - totalreserve_pages;
-
- /*
- * Not all the page cache can be freed, otherwise the system will
- * start swapping. 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;
+ long available = 0;
+ struct sysinfo i;
+ int nid;
- /*
- * 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);
+ for_each_online_node(nid) {
+ si_meminfo_node(&i, nid);
+ available += si_mem_available_node(&i, nid);
+ }
- if (available < 0)
- available = 0;
return available;
}
EXPORT_SYMBOL_GPL(si_mem_available);
--
2.11.0
next prev parent reply other threads:[~2021-12-16 12:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-16 12:46 [PATCH 0/2] add MemAvailable to per-node meminfo Qi Zheng
2021-12-16 12:46 ` [PATCH 1/2] mm: " Qi Zheng
2021-12-16 13:16 ` Greg KH
2021-12-16 15:31 ` Qi Zheng
2021-12-16 15:37 ` Greg KH
2021-12-16 15:43 ` Qi Zheng
2021-12-16 12:46 ` Qi Zheng [this message]
2021-12-16 13:17 ` [PATCH 2/2] mm: reimplement si_mem_available() Greg KH
2021-12-16 15:39 ` Qi Zheng
2021-12-16 15:06 ` kernel test robot
2021-12-16 18:21 ` kernel test robot
2021-12-16 21:05 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211216124655.32247-3-zhengqi.arch@bytedance.com \
--to=zhengqi.arch@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rafael@kernel.org \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox