From nobody Mon Feb 9 00:26:30 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 503DBC7EE25 for ; Fri, 9 Jun 2023 03:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbjFIDe4 (ORCPT ); Thu, 8 Jun 2023 23:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237753AbjFIDev (ORCPT ); Thu, 8 Jun 2023 23:34:51 -0400 X-Greylist: delayed 513 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 08 Jun 2023 20:34:45 PDT Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7AF930FD for ; Thu, 8 Jun 2023 20:34:45 -0700 (PDT) HMM_SOURCE_IP: 172.18.0.218:59564.1727155665 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-36.111.64.85 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id CE8C72800B7; Fri, 9 Jun 2023 11:26:04 +0800 (CST) X-189-SAVE-TO-SEND: +liuq131@chinatelecom.cn Received: from ([36.111.64.85]) by app0025 with ESMTP id b3a94a8e8d4e468aa458479e5c11cc05 for akpm@linux-foundation.org; Fri, 09 Jun 2023 11:26:07 CST X-Transaction-ID: b3a94a8e8d4e468aa458479e5c11cc05 X-Real-From: liuq131@chinatelecom.cn X-Receive-IP: 36.111.64.85 X-MEDUSA-Status: 0 Sender: liuq131@chinatelecom.cn From: liuq To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, liuq Subject: [PATCH] mm/min_free_kbytes: modify min_free_kbytes calculation rules Date: Fri, 9 Jun 2023 11:25:52 +0800 Message-Id: <20230609032552.218010-1-liuq131@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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); =20 unsigned long nr_free_buffer_pages(void); +unsigned long nr_free_pagecache_pages(void); =20 /* * 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) =20 /* don't ever allow to reserve more than 5% of the lowmem */ recommended_min =3D min(recommended_min, - (unsigned long) nr_free_buffer_pages() / 20); + (unsigned long) nr_free_pagecache_pages() / 20); recommended_min <<=3D (PAGE_SHIFT-10); =20 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); =20 +/** + * nr_free_pagecache_pages - count number of pages beyond high watermark + * + * nr_free_pagecache_pages() counts the number of pages which are beyond t= he + * 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; =20 - lowmem_kbytes =3D nr_free_buffer_pages() * (PAGE_SIZE >> 10); + lowmem_kbytes =3D nr_free_pagecache_pages() * (PAGE_SIZE >> 10); new_min_free_kbytes =3D int_sqrt(lowmem_kbytes * 16); =20 if (new_min_free_kbytes > user_min_free_kbytes) --=20 2.27.0