From patchwork Fri Jun 9 03:25:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Liu X-Patchwork-Id: 13273220 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 6F100C7EE23 for ; Fri, 9 Jun 2023 03:26:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4E638E0002; Thu, 8 Jun 2023 23:26:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FEDF8E0001; Thu, 8 Jun 2023 23:26:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ED2F8E0002; Thu, 8 Jun 2023 23:26:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 808918E0001 for ; Thu, 8 Jun 2023 23:26:17 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 53DBE803BF for ; Fri, 9 Jun 2023 03:26:17 +0000 (UTC) X-FDA: 80881771194.19.2CE3720 Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.220]) by imf08.hostedemail.com (Postfix) with ESMTP id F1864160014 for ; Fri, 9 Jun 2023 03:26:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of liuq131@chinatelecom.cn designates 42.123.76.220 as permitted sender) smtp.mailfrom=liuq131@chinatelecom.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686281175; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=ryjHEM+1qk6QB2KAJPqTZaBQhMKptLKHxjn9a4g4AGE=; b=JyGGa69Q1ES74+M/au4mLHheh2kxYM61c8FZvI29P25yhg8REBDK2xAggvmOlsaSxcEaun sBL4zcL4gyWdyNl7CcR8zj8SHXv0UU6N6c6Abjb4wSP3gWRQF7ssSnDJZMELnOycaB0sPI i0jVDlqhkqU+IK/tYIHTrICrdd0hLjc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of liuq131@chinatelecom.cn designates 42.123.76.220 as permitted sender) smtp.mailfrom=liuq131@chinatelecom.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686281175; a=rsa-sha256; cv=none; b=leOOMkqulQ/XOZuegBuFC8wli44fmifyR5yGWrSNpxLLtRWxhBuFTD90BpCjjOZwVWrGo0 M7FvCqCGiCxPHs1dQ/8eqKxXOmf8z86KzHmbxKxyMCorbsScPZIXeyS3AkZ8rQ0mmDjCEf GoGLsooufZQ7OuDzEL4ohzHSvBImvfE= 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 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 X-Rspam-User: X-Stat-Signature: 895essfiduwkqd7sjzg4fqucgfibpyc7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F1864160014 X-HE-Tag: 1686281173-301957 X-HE-Meta: U2FsdGVkX1+1uYCsg+gIRLc/F3ikUDS8Yj+PkRAvMiMGiRz7i0Y6YOI3zvkyLWSksGuHOQxi8O1wfQfxoXzSw26pl3/dmE6tkvwt8ZYFwTP9nH1evrvQ7keL4789pNgfO6B4Vjka/35v8v5R5u0eUE6tZrssfl4kb2+XRSJCSv2P/rttJp9LgdpYR0NtMm6SbAzHEQPSppoOmGYa1PWg31iitSGjz+kB5MVBtxvxiOAWRnNRpX5mRKTcH7ISMnyIJEkrBSf/xORPDS61h/F2pvrrX2hbHwGaSWkoOTjG/9fT3W7g/A6y8s1vxdLJp2x7al6vEtfYMUQp2PlkEukBYXK7IgeES+yuwQRQr+U3T36DRKKNtSZBnor0fHXaGa6URct/X4+QQluAd8g9Tupyo8GHayKxcAa5snLaKONgbqTIAQk+y0sbz2dDfSA6Q61VfbXIagJaUbRIXv/FoDw4mAab3KlwORQWXlUPYJEMZ4rqc69DSR25TjJYuoHlujUdQ9RHhMULpldQaTFvA4T3NVm2NjwiJB8P4hGoi1G+hPGVG8Yv/dyDhtKZcgr7nnb2/gbkb25vOGIV+asNpETfQ2o0JcnpCrw63BSfy0coPv8nE99WTXVG4WrWUPrIFNy4tGcU9Xw4nIB6u2oiBKNEKYC1Iu31B94sEPK8rFMUmfD0e/EZuJVtBzbjpS2Yfs28lwwcK9BUaazveQzbzH0LrVz0FOqfQwTMFxFOAIPVylQzUzWJZLEym+fJ3eJOpV2ZN9GA+JMEpxC+HIGnEK6vACrg6jg7Y0/XbteMzgoTkE/Tm2PhQoEoPspnK5sspq1NdMGCq1vkSfvmJ5E86PrV6GQ5vLSMm6Z2Sd/avdmyNRidxNpoc14dpHhrfbfwZlJVVnrO6SDH8RE0QydXWGYDvGusNsqsCHx18JTbDQiWoPcUhWZPN2uU2+E3RIsx8jGfjZ4VOroipHk1Tp2WDyu KCk32YW8 qpfCLtTBQt5A4Ow3x9sBA8owMufnz9Nt03Le4rMPSGWeKGUW3ndAyuvV3XPIyELVeM8Kr/55EScOSWBnsvv2KZbqENu436vZ+U5UMkCByd0w2gQutd6GMS818ZhGjexmhkU7X8PSmPREhBY/w/0YqJ9SuYATYfLXMuLETV9Nm3s8jjUh6UtC5rCxZZ94pK4u5gBBaF1DPIRmxl6Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.035105, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); 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)