From patchwork Tue Aug 29 08:00:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13368647 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 ADA6FC83F12 for ; Tue, 29 Aug 2023 07:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE44A8E0023; Tue, 29 Aug 2023 03:06:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A93D18E001E; Tue, 29 Aug 2023 03:06:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 982E08E0023; Tue, 29 Aug 2023 03:06:53 -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 891F38E001E for ; Tue, 29 Aug 2023 03:06:53 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BEC0C120468 for ; Tue, 29 Aug 2023 07:06:51 +0000 (UTC) X-FDA: 81176259822.10.09825ED Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf24.hostedemail.com (Postfix) with ESMTP id C7B8018001F for ; Tue, 29 Aug 2023 07:06:48 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693292810; h=from:from: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: references; bh=VZateb11ZIin575JldES6hzP35XBSS08dBNUkkkk4Qc=; b=Y02vvTPy7u0riusqVGA3xzibWNaV8dH5n2ajTjrmF3f552S/K3B9IxHffnpo2uY/Zj3B5j 7RcZ2tIG0D78wA216swSU9Xw1UlIwloP1y5Qi2eGyUPAKrEWgrtrtzqf5fJmVC6o6n5n7+ Ox6cvZYj210KXSwPgF/Sy9WEd/zaMfw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693292810; a=rsa-sha256; cv=none; b=k7iQSqYPae7lECnZafhW/TyVBjJ6tBhZpee4vUnG7VEqa48U/U3Ne/PjrQXelvte94tA1S TLwqF4YHptZNVkuBQgorfMZmAASljXuyDMtvmGNzRki86UmqUy+Alo8HVIj3LEnKZtK4tO WNMF7xSrOLhko6GV4QCnb6SgJLXo+3Y= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RZdhw71jgz1L9Lt; Tue, 29 Aug 2023 15:04:48 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 29 Aug 2023 15:06:25 +0800 From: Liu Shixin To: Andrew Morton , Yu Zhao , Barry Song , Miaohe Lin , Matthew Wilcox , Johannes Weiner , Kefeng Wang CC: , , Jinjiang Tu , Liu Shixin Subject: [PATCH] mm: vmscan: use per-zone watermark when determine file_is_tiny Date: Tue, 29 Aug 2023 16:00:38 +0800 Message-ID: <20230829080038.1532308-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: C7B8018001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4mar5o3be54hm5ppewt8gbgaa5x4km88 X-HE-Tag: 1693292808-611385 X-HE-Meta: U2FsdGVkX1/rfiq82LBbm9TTGYkn4UOq+CNpv8m4cPC4YWcZmf5E8SSyh4NK3ezJx8vVJH9XorhH92xgUMJ54DSQF695xwZc3txtCxPxd1LzvYxQ0Xy/CDKYooMkHgjaqRM7l1hfc3BY1efRIT6ODMfbGwTwQ6S4gbZZ54IFX7oxgIt+F8zRAYBB39cGH4ng7FUkfuN1stCjOReqeokbEYSvoKhhB8iWJ1FPIaB2phMQDm/5F1LLsryGyAan9HABeRhoI35TnftgzMu8oqdW76UKSYT56hW5LVGIZEESAVzPO9RZjSeFWOP19EjAvyAhJhz/7PAsmBNhes+3VgEiVb7jqH55bRhBT9oKu/oQ7T3LEtyaT2oUQpc92gfrYpxfaLsXrH5M987wT0amRZnMRliWGIkXn1p4Z7EAyOCNvupLy31s4L/lIMiMTJpSbvQZ+qW672dFbmvkvuhT2GmXU4h5YL0bh11dkUJwc6OBKvM5BxF+BOosMA5KiqNpkIkUnHz1PEnj9RHnf/uxT5Lt/3jTmTO2eJdamyNxh6j2lQPgpbl1AzckpbEbNmmEpIqLt8nS00+lcDAHI3dwRC+wKMgLhnRPWPpGOVwaTrk1VYFpCkAq+0CmshjFD5t+xCFIDqt0TB2n3RE8d8I7qYVOCJcbp7zG5Oswq81mQbZZERI+93xEeK4ZkoTf5TIE2DpRdSRa0IM3mQrj6crkAIUNVi4rQEQXc0szzd21TeGNF6RFJJdssPLMuel2VmHr1ZV165UNjOWz6rKJ6KIPmqhzaDL+ZG61Dsq/MdgVtGVVIc9WlggfwISuZ92NLm/dYPI7Dz2MDASrhnpFby9PxgnZKQRM7FIR+DkSqMnF6Re9ZJ674AAI1YWifxsyog/hDRePgPmrCD1S4ptoPVP8ee6ZTQXFQqCFVZwHUKfoJNblTCG1otsSzTpG+AhBsZs/A4F8fWGBhajiJ4xKV+RhMMb ZIkgm96J cP/MmgqWwC4oPTti2lxuSNvFOkwlPOebo80clWT+ahP+ruj6QJND86F1ZiqCNr13YK/S8r2BB50nJUx3/AuAPPbyglOsRCpKHHLJZl9I6NQU/ZU5HwR94tEZhn6Xqqo+m8s/u8V1WevGoNu363OnyWzRuPNK4GFFtkLYZmJa37iDk2t3UUyR0XZIPKJES6+2UI6ow X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When setting swapiness to 0, the anon pages should be reclaimed if and only if the value of file_is_tiny is true. __zone_watermark_ok uses per-zone watermark and lowmem_reserve to determine whether allocating page from the zone. In the mean time, file_is_tiny is calculated by per-node watermark. There are inconsistencies between the two scenarios. If total free pages on node is enough, then file_is_tiny can not be true, so the anon pages can not be reclaimed. If the free pages in each zone is less than watermark + lowmem_reserve, then the allocation will failed too. Due to lowmem_reserve, these two cases can occur at the same time: zone_page_state(zone, NR_FREE_PAGES) < watermark + lowmem_reserve node_page_state(pgdat, NR_FREE_PAGES) > total_high_wmark When both are met, there will be many anon pages that can not be reclaimed because file_is_tiny is false, and in the same time, the allocation failed because per-zone watermark is not suitable. Split the condition (file + free <= high_wmark) to per-zone to fix it. Reported-and-tested-by: Jinjiang Tu Signed-off-by: Liu Shixin --- mm/vmscan.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e73e2df8828d..f1dc0dbf1cdb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3009,21 +3009,23 @@ static void prepare_scan_count(pg_data_t *pgdat, struct scan_control *sc) * anon pages. Try to detect this based on file LRU size. */ if (!cgroup_reclaim(sc)) { - unsigned long total_high_wmark = 0; unsigned long free, anon; int z; - free = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES); - file = node_page_state(pgdat, NR_ACTIVE_FILE) + - node_page_state(pgdat, NR_INACTIVE_FILE); - for (z = 0; z < MAX_NR_ZONES; z++) { struct zone *zone = &pgdat->node_zones[z]; if (!managed_zone(zone)) continue; - total_high_wmark += high_wmark_pages(zone); + free = zone_page_state(zone, NR_FREE_PAGES); + file = zone_page_state(zone, NR_ZONE_ACTIVE_FILE) + + zone_page_state(zone, NR_ZONE_INACTIVE_FILE); + + if (file + free <= high_wmark_pages(zone)) { + sc->file_is_tiny = true; + break; + } } /* @@ -3033,8 +3035,7 @@ static void prepare_scan_count(pg_data_t *pgdat, struct scan_control *sc) */ anon = node_page_state(pgdat, NR_INACTIVE_ANON); - sc->file_is_tiny = - file + free <= total_high_wmark && + sc->file_is_tiny = sc->file_is_tiny && !(sc->may_deactivate & DEACTIVATE_ANON) && anon >> sc->priority; }