linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: liuq <liuq131@chinatelecom.cn>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	liuq <liuq131@chinatelecom.cn>
Subject: [PATCH] mm/min_free_kbytes: modify min_free_kbytes calculation rules
Date: Fri,  9 Jun 2023 11:25:52 +0800	[thread overview]
Message-ID: <20230609032552.218010-1-liuq131@chinatelecom.cn> (raw)

The current calculation of min_free_kbytes only uses ZONE_DMA and
ZONE_NORMAL pages,but the ZONE_MOVABLE zone->_watermark[WMARK_MIN]
will also divide part of min_free_kbytes.This will cause the min
watermark of ZONE_NORMAL to be too small in the presence of ZONE_MOVEABLE.

Signed-off-by: liuq <liuq131@chinatelecom.cn>
---
 include/linux/mm.h |  1 +
 mm/khugepaged.c    |  2 +-
 mm/page_alloc.c    | 15 ++++++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index cf3d0d673f6b..1f91d035bcaf 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -863,6 +863,7 @@ void split_page(struct page *page, unsigned int order);
 void folio_copy(struct folio *dst, struct folio *src);
 
 unsigned long nr_free_buffer_pages(void);
+unsigned long nr_free_pagecache_pages(void);
 
 /*
  * Compound pages have a destructor function.  Provide a
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 16be62d493cd..6632264b951c 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2342,7 +2342,7 @@ static void set_recommended_min_free_kbytes(void)
 
 	/* don't ever allow to reserve more than 5% of the lowmem */
 	recommended_min = min(recommended_min,
-			      (unsigned long) nr_free_buffer_pages() / 20);
+			      (unsigned long) nr_free_pagecache_pages() / 20);
 	recommended_min <<= (PAGE_SHIFT-10);
 
 	if (recommended_min > min_free_kbytes) {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e008a3df0485..489b564526dd 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5775,6 +5775,19 @@ unsigned long nr_free_buffer_pages(void)
 }
 EXPORT_SYMBOL_GPL(nr_free_buffer_pages);
 
+/**
+ * nr_free_pagecache_pages - count number of pages beyond high watermark
+ *
+ * nr_free_pagecache_pages() counts the number of pages which are beyond the
+ * high watermark within all zones.
+ *
+ * Return: number of pages beyond high watermark within all zones.
+ */
+unsigned long nr_free_pagecache_pages(void)
+{
+	return nr_free_zone_pages(gfp_zone(GFP_HIGHUSER_MOVABLE));
+}
+
 static inline void show_node(struct zone *zone)
 {
 	if (IS_ENABLED(CONFIG_NUMA))
@@ -8651,7 +8664,7 @@ void calculate_min_free_kbytes(void)
 	unsigned long lowmem_kbytes;
 	int new_min_free_kbytes;
 
-	lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10);
+	lowmem_kbytes = nr_free_pagecache_pages() * (PAGE_SIZE >> 10);
 	new_min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
 
 	if (new_min_free_kbytes > user_min_free_kbytes)
-- 
2.27.0



             reply	other threads:[~2023-06-09  3:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  3:25 liuq [this message]
2023-06-19  3:25 ` [PATCH] mm/min_free_kbytes: modify min_free_kbytes calculation rules Huang, Ying
2023-06-19 12:42   ` liuq
2023-06-20  5:50     ` Huang, Ying

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=20230609032552.218010-1-liuq131@chinatelecom.cn \
    --to=liuq131@chinatelecom.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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;
as well as URLs for NNTP newsgroup(s).