From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FABEEB64DB for ; Mon, 19 Jun 2023 12:43:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAB848D0003; Mon, 19 Jun 2023 08:43:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C65918D0001; Mon, 19 Jun 2023 08:43:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFC3D8D0003; Mon, 19 Jun 2023 08:43:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9B89B8D0001 for ; Mon, 19 Jun 2023 08:43:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 717D8160894 for ; Mon, 19 Jun 2023 12:43:08 +0000 (UTC) X-FDA: 80919462456.12.9B401BF Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.219]) by imf01.hostedemail.com (Postfix) with ESMTP id 6599F40009 for ; Mon, 19 Jun 2023 12:43:03 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of liuq131@chinatelecom.cn designates 42.123.76.219 as permitted sender) smtp.mailfrom=liuq131@chinatelecom.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687178585; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=baUwi9sZajPZoxtUw+7M9VPpKX+IwTy3tItJvAl+AVw=; b=NKtAZyGO5vgXaq2fvy2W0l4D2qHT+BZ51TEUjsZl6h5mB7uhB82QDsl/qzjm4djC3i8kec PEJ/TgwrySRPSV+WOQswraolaMHQOfM9+Z2GGRyKNnBlsyquMx8sk47wtpBp7D2aaymAUZ BQdZpp5QxyCQvJIVyC94ff/wEzNuNyU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687178585; a=rsa-sha256; cv=none; b=A7WyaEehlkAhJthqQATQeVeSHqf+D1DXuG+y9djfmE6ZsqKZf2vOrZj9TApkuCVvwDfT9H 0IL4B2YjeqLOxiG2Z9rKRBoSk/yLBf0yiqsbnagefHAfvrV0sVn51hGLQSuH1yYuQlM23K ZtFvlKoqU5Ch386IfG3zPCWDQMmW31M= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of liuq131@chinatelecom.cn designates 42.123.76.219 as permitted sender) smtp.mailfrom=liuq131@chinatelecom.cn; dmarc=none HMM_SOURCE_IP:172.18.0.218:51431.826311313 HMM_ATTACHE_NUM:0000 HMM_SOURCE_TYPE:SMTP Received: from clientip-36.111.64.84 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id 2CE112800AF; Mon, 19 Jun 2023 20:42:52 +0800 (CST) X-189-SAVE-TO-SEND: liuq131@chinatelecom.cn Received: from ([36.111.64.84]) by app0025 with ESMTP id 1ab8e237609f49c095ccbc84f2f25768 for ying.huang@intel.com; Mon, 19 Jun 2023 20:42:56 CST X-Transaction-ID: 1ab8e237609f49c095ccbc84f2f25768 X-Real-From: liuq131@chinatelecom.cn X-Receive-IP: 36.111.64.84 X-MEDUSA-Status: 0 Message-ID: <4f3bac46-6dbe-653b-bcb9-ace46c4d4c9e@chinatelecom.cn> Date: Mon, 19 Jun 2023 20:42:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] mm/min_free_kbytes: modify min_free_kbytes calculation rules To: "Huang, Ying" Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Mel Gorman References: <20230609032552.218010-1-liuq131@chinatelecom.cn> <87edm88765.fsf@yhuang6-desk2.ccr.corp.intel.com> From: liuq In-Reply-To: <87edm88765.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6599F40009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: eeb1oxbbbkt4ntyq3cmugkw1fkksdane X-HE-Tag: 1687178583-353932 X-HE-Meta: U2FsdGVkX1+0PlZ80wnYhXokeeNjwW63cR8vsK7MoEll9H9zUWCpCH2vu9mjY+LBYiOUp+4znAidYqPT4/mUXUCxZa2GfebRT0GhsEbdNAIuPy4cI3gYMLJOhhVGCrvgnsnAA/vHkbZo46SytxRDm3I/JBCWZCG8I6jLJu6CMHqliQKYnXAG+d1mCMHNnL9Y+nzgGMaG+yZnQrr4yIq5QeLgsuHaAtDRT1Am4g5yuchzGBZqzl5XuRKuznBe/cWrx7ZP0W4zQ2fKNZtDTegg4fksFoagfacMzLNilwDd05efhqSNYZ5BpOPKr7mVuaEGqe3sN7Ntb9Dl9oaM3oN3/i0Lv29yqT5ELJSvXWD0Xhopasu3+j0+Wmtrobf4+UkBB0pHbUHlwDPTWNOaBgyg+v1gKUCLjjiKrHvU/TJib5HAGhUYAQBk4dYz2uJD0GWTOTx0iS0nYJxh3ZpDlJoKA2isf4sZr+YILXIuqKeqiTPgUUmi30eg81c3krWX52d4Aa4vkxHbLKOfQJazFf2XMeNWLA91PuVhNFqvxKDna9yKIOFnqglSJf9VRpg/X3lhDlaXwAWnpwSlinkehewZk2fREJHnThKMQulV4pXEAJb2M9fWrMNwJD0L+kdRLpR0gO0Dzwd6foJct7XvuCkGDfiS1ulaRltR5aTuIkam52GsmPisWevB7Ia0U1/oIuq+x7M25N2PeV6hkk6LCsX0fV0pVqO3kY190+QF79VhcUsPNKHXMd4AXta3dhXQta8MxHXqFI9KqNN3ducv5HRLtLIi1bjSCFZN0Lc525P1hGmHgc/FvKe5NeVIgqDyRkeumzKpQfdepP2dccTobmchlAqVN/K6HvkiLfgJW9Eup8aVa3f8Pyxv5BrlcUFiqxhfdnQaheZ8a3pr45cYofB7ulO2FfoKeZbmdHQEL29mxLFvhCQwiHNfQDXA9CYKDF5TC+559HpbjjLg8YzzKcq jWD/YRH4 XvodNd89O6WNJEhQ5VjZlbWEP+Sj0Ni6P/4ZYCqPlfy+dGMQnd0paFlM0Ayy4SIFEYDMhAlk+VQzg64xRVq1rYKFt2ncOSD2zBIhvu4DrjZ5FF6vwHTnxnImkfLuQeLRK6WmGE8hAes5Y/HvRs7/NwHXottR6ut2bIi55 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 在 2023/6/19 11:25, Huang, Ying 写道: > Added Mel and Vlastimil. > > liuq writes: > >> 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. > This seems like a real problem per my understanding. Can you show the > contents of /proc/zoneinfo on a problem system? > > But, per my understanding, min_free_kbytes are used for __GFP_HIGH and > PF_MEMALLOC allocations. While ZONE_MOVABLE will not be used for them > usually. So I think we should treat ZONE_MOVABLE as ZONE_HIGHMEM in > __setup_per_zone_wmarks(). > > Best Regards, > Huang, Ying On my testing machine with 16GB of memory (transparent hugepage is turned off by default), when movable zone is not configured, min_free_kbytes  is 15806 (15806*15806/16=15614352kbytes, approximatel y 16G). The detailed info is as follows: [root@lq-workstation ~]# cat /proc/cmdline BOOT_IMAGE=/vmlinuz-6.2.0-rc7-00018-g0983f6bf2bfc-dirty root=/dev/mapper/ctyunos00-root ro resume=/dev/mapper/ctyunos00-swap rd.lvm.lv=ctyunos00/root rd.lvm.lv=ctyunos00/swap crashkernel=512M [root@lq-workstation ~]#  cat /proc/zoneinfo |grep -A 5 min         min      3         low      6         high     9         spanned  4095         present  3998         managed  3840 --         min      328         low      652         high     976         spanned  1044480         present  478802         managed  330969 --         min      3618         low      7193         high     10768         spanned  3655680         present  3655680         managed  3575787 --         min      0         low      0         high     0         spanned  0         present  0         managed  0 [root@lq-workstation ~]# cat /proc/sys/vm/min_free_kbytes 15806 If movablecore=12G is configured, at this time, min_free_kbytes is 7326 (7326 * 7326/16=3354392, approximately 16G-12G) The detailed info is as follows: [root@lq-workstation ~]# cat /proc/cmdline BOOT_IMAGE=/vmlinuz-6.2.0-rc7-00018-g0983f6bf2bfc-dirty root=/dev/mapper/ctyunos00-root ro resume=/dev/mapper/ctyunos00-swap rd.lvm.lv=ctyunos00/root rd.lvm.lv=ctyunos00/swap crashkernel=512M movablecore=12G [root@lq-workstation ~]# cat /proc/zoneinfo |grep -A 5 min         min      1         low      4         high     7         spanned  4095         present  3998         managed  3840 --         min      152         low      476         high     800         spanned  1044480         present  478802         managed  330969 --         min      239         low      748         high     1257         spanned  509952         present  509952         managed  509952 --         min      1437         low      4502         high     7567         spanned  3145728         present  3145728         managed  3065833 [root@lq-workstation ~]# cat /proc/sys/vm/min_free_kbytes 7326 After this patch is added, the configuration of the movable zone no longer affects the size of the min_free_kbytes, which is only affected by the size of the available memory. >> 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); >> >> 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)