From patchwork Wed Oct 18 01:30:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13426224 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 624B1CDB474 for ; Wed, 18 Oct 2023 01:30:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F20588D012C; Tue, 17 Oct 2023 21:30:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECFF18D011E; Tue, 17 Oct 2023 21:30:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D97DC8D012C; Tue, 17 Oct 2023 21:30:25 -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 C979F8D011E for ; Tue, 17 Oct 2023 21:30:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9C496161094 for ; Wed, 18 Oct 2023 01:30:25 +0000 (UTC) X-FDA: 81356852010.24.4AA8E2C Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2116.outbound.protection.outlook.com [40.107.117.116]) by imf13.hostedemail.com (Postfix) with ESMTP id 3CAEB2000C for ; Wed, 18 Oct 2023 01:30:20 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=gRDbmzN7; dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf13.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.116 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697592622; 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:dkim-signature; bh=6yVZ0BIDjoJrLxb95hWZe1lpouF8PNNMU62WbPJonyg=; b=wMCymcs7UQrU0Cvf66/4sdHz5GGukH8PCa6eSJbwC7cdwaqdhmQMCnTY/51UaxFz7XqGEw NKGOJYmaGB5g6qiMEKjWr4v9DXluWjG1FLteDtCIYACbvDxmxR+GLrlxQO28u5CqVGmRoG DqWm+bW7pDD4ZxDFEQNuhmfVX0Iwr3k= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=gRDbmzN7; dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf13.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.116 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697592622; a=rsa-sha256; cv=pass; b=TbLpMCE0M5lH+byPVk/yUN/Fa/0AADcNEgYXEJo5PZCC7y1PHnVXX40TwQP217s4QluWm3 K4O96SBsLMM8R7XEcXhsGAHwGNYnUY5b7SN5Gv1RriAcyc9+XOMMRqNb9Vk31KYHo3wLUU C24bKMN75ZdlpKHILj7lAH/XuvOjMqM= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W/AVY3ucn7LHJg02fMB2JBV6F1BM7xorhrTqsgfS/jH5wVSpVmBB4B6NFXwqKROWgqjLvBVKBfmThK4IauVI+Wtv2aOP+X2iVo882B2wPtz5aFzSagZCk89bW+NEWmZb6hCS+1uz+jlvAXqtVjqXxnLAWSELPSgJyESFVyB68U2c4pn5wBgCXod9/UR3q+xcYsESVh6O/F08oPy/YlcQe/qtz2FoUx0ses6Kd2NPE9rnbCrlHKffJOyqtDPoK0TabIzokNaVQMPhieQQ9q1gn3CBYFBFoGH6x18ZajM1oVEX1nbl/x58R/KzE0iRTvlfv6FKCMPQc4Ahuip/MYAX5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6yVZ0BIDjoJrLxb95hWZe1lpouF8PNNMU62WbPJonyg=; b=ZpxDktEowjVMrTShiwx+rtbmJRse2EjbyZmY+Q1EkdA04+FscBe01BGY/f06FwH7JhISlN596mxMH5lBDMhUy2Ede0yRRxNeRJNOBBxdi6DwkZsQJjzIV0HYwwpJAhBY2JTbb49KTPeknZxugkBqDX89e7Ksc76Vy//VqDgUjD8K6m9hNlVtQLaeV188OG5sDTJKQdTl8dZkNEnUzEeoCYAiA9bFWT60BcASskBB5XSfKMwnd+hF89eLAXfG/L+py9kav1XI8+mUpIi+KGI0Cin+ffbirx18WGR3mkOXuv/aAkhFhDTE+7O6zX8puM/yLQK1D44dofmrSkaknW0idw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6yVZ0BIDjoJrLxb95hWZe1lpouF8PNNMU62WbPJonyg=; b=gRDbmzN7BSB4TOZK6dLdUnsBpccbHQ99CgPDmxvy1rwO2bYimNm/TXAWOmmQ+cjqazpqGmDcS023xL+CIfgeusm/Gc7/8UYw379sxQ6+0UeNDEyfnhub7lcMWg74T0lMO5eX0BpgFHmfv8ADGkV+JlxI9vd9wyUQsOQMQEEwMr5RhZ7XGa76XaAyEjyFFRXaeNbBqep4+n4KFsQA5Q9UVyIGX3TuiV7N87iR2S9dPozCw4OtAkToNjLXelFycSY/ecPvq/mp+bVuyc8OAjgvC/giE5sklLQ2sniaQtyzRySry2VTCJj0v5cvB7CKba0y0RJKZof0tbNI2ycO4mbUVQ== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by SEYPR06MB6432.apcprd06.prod.outlook.com (2603:1096:101:16f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.38; Wed, 18 Oct 2023 01:30:12 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::32d4:1209:6b36:86e5]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::32d4:1209:6b36:86e5%7]) with mapi id 15.20.6907.021; Wed, 18 Oct 2023 01:30:12 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Zhiguo Jiang Subject: [PATCH] mm: vmscan: the dirty folio unmap redundantly Date: Wed, 18 Oct 2023 09:30:03 +0800 Message-ID: <20231018013004.1569-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI2PR01CA0003.apcprd01.prod.exchangelabs.com (2603:1096:4:191::16) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SEYPR06MB6432:EE_ X-MS-Office365-Filtering-Correlation-Id: bd620673-d41f-4f36-320e-08dbcf79c61e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: db8U2WixJyn6lqh9hDCe9EGJZaGClXa4km0PLWtJJmPzpAT7mpJFFwLWiUOynEHyZK34Zfp2kQgqkgphy9fFaGEP9fsze4OYrYM2J35GNj8UYL9p9UV3CmgZ2ol02Xic5EMGhwsr7i1y9sXUdwFlN1iteD1Tjld6C2Y5+JFm32R1KspD8gPcqDJn7mnJ89kyOflaI2ZcVFhIMLKERvRc7eFcDGG2ie4y8dvZX5w+t15s7xg8zY/BPbZffnzi7QxkuedgyGQq392HQbwKNe27WFLWV2nlNolLxPl1RpbO5eQs7HcCZcMI/2xJ9ft1glQ6/b7/PZdtbL0/neMTXXm+TKv5qGNJWXW3qXw1ay4dtYhtC6XIR3C+aH5kjUDyZinaa9h1Uo3x8iAwwTWzmQ4wh4eP/c1nrSWRpstfhkarLmgqEOH1z+B4SflOOYiFM3/C55kXwACv53lLdhTBlrDuDPzCFl+fCl2e7RBOxtQmDkiUqvn2uY3JkLzzOpBBd+RqRSL+8C4981nx0FsZrtDdzTRlwnzaulHZ70r9g6FUPu1mZvnDFY6J1VGIcEbWr0ZMLFI0cAoq53iYxXdQ9C8hHpYTlTqa05tn4RTM4bqsn7+F5xPUpp5p5qGB1R6WXyMcYV/6QP1bC2Cf3TqwJ1RtXg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:JH0PR06MB6849.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(396003)(366004)(346002)(230922051799003)(1800799009)(451199024)(64100799003)(186009)(8676002)(8936002)(4326008)(38100700002)(41300700001)(5660300002)(86362001)(2906002)(6506007)(52116002)(6512007)(508600001)(6486002)(6666004)(107886003)(38350700005)(36756003)(26005)(83380400001)(1076003)(2616005)(66556008)(66476007)(66946007)(316002)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dFHgPDpX6vssO4HtSsovOZaI50969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va3l86P4pYIPDN2llfbD3EIHZ1uQYUh3ViZRRrwk25Tp0T6WyMuZZ06MnQw+pwVM6/qFFXJ9ZrR60mlDn4PtGAtVMPb1FmtpdOHQKARMjwcLG71DruUf/3AmopScHI62rl0vPZirglvSz0Maya9zz1o4cv2Lqi+0Pz0rtKDU+p0BTtdVa5cFLe0N+RHnQkjMoGHQuCKLif5bOQVoGxddcEgL/eRPj1sXGOVpgzle2AXVeszXAraDzEeLOl7UffaLhuuU72Jal62UKYfP7BBpsDDigVfYyznXX0bFEj6QXbOPI6gfveMnjwuKIo1gkw1smqPcRFCLi9WVqwkdpInmno49YTGlfnt/xjYO/DyR6sBumVsgygo5wnZe9aJbZ8EKjOQswPpeOlJzFpAsFwWPLRvz1xW43xHPSMEovowjVBsXHXuhTrEULgRqzp5kY7xeFO1KFK1JLvEAF45ygjFeKpiIkANeyMPllCK7oOa9i X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd620673-d41f-4f36-320e-08dbcf79c61e X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 01:30:12.6182 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: a2TbUyZh0O4ScRGAGIGHnsOCWRM6HASvPqgYkARtOY/+CK6XuP+2vcMS6IsOfZWnohM3l3abXrcJBSX02+2b6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB6432 X-Rspamd-Queue-Id: 3CAEB2000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: mr8jrdruy64i9kyt4x5iohuk9h6x7zjx X-HE-Tag: 1697592620-362484 X-HE-Meta: U2FsdGV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I8Je+Vyq/B89MqKlkBDU+3ej/hBpaj8LaTIVKF8rFbTyx//qJgcWr2okmLlIMdqOQy8HFU8ukkLdZtHG3nQzefg1iUnO9EDwDmMCThRkbo4TpRKCa4wdv6OH9nJfVHxoXQZbgFaPeQ0xLkDVGjwlISMFNnOJpwPC1xKb4fWps+nrUFEmIHhBsudiwDMDZCXe4T8ZJwvV97lSRISzkhpdapmVPJRN//UWHMsp+kECwcWw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If the dirty folio is not reclaimed in the shrink process, it do not need to unmap, which can save shrinking time during traversaling the dirty folio. Signed-off-by: Zhiguo Jiang --- mm/vmscan.c | 72 +++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) mode change 100644 => 100755 mm/vmscan.c diff --git a/mm/vmscan.c b/mm/vmscan.c index 2cc0cb41fb32..cf555cdfcefc --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1261,6 +1261,43 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, enum ttu_flags flags = TTU_BATCH_FLUSH; bool was_swapbacked = folio_test_swapbacked(folio); + if (folio_test_dirty(folio)) { + /* + * Only kswapd can writeback filesystem folios + * to avoid risk of stack overflow. But avoid + * injecting inefficient single-folio I/O into + * flusher writeback as much as possible: only + * write folios when we've encountered many + * dirty folios, and when we've already scanned + * the rest of the LRU for clean folios and see + * the same dirty folios again (with the reclaim + * flag set). + */ + if (folio_is_file_lru(folio) && + (!current_is_kswapd() || + !folio_test_reclaim(folio) || + !test_bit(PGDAT_DIRTY, &pgdat->flags))) { + /* + * Immediately reclaim when written back. + * Similar in principle to folio_deactivate() + * except we already have the folio isolated + * and know it's dirty + */ + node_stat_mod_folio(folio, NR_VMSCAN_IMMEDIATE, + nr_pages); + folio_set_reclaim(folio); + + goto activate_locked; + } + + if (references == FOLIOREF_RECLAIM_CLEAN) + goto keep_locked; + if (!may_enter_fs(folio, sc->gfp_mask)) + goto keep_locked; + if (!sc->may_writepage) + goto keep_locked; + } + if (folio_test_pmd_mappable(folio)) flags |= TTU_SPLIT_HUGE_PMD; @@ -1286,41 +1323,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, mapping = folio_mapping(folio); if (folio_test_dirty(folio)) { - /* - * Only kswapd can writeback filesystem folios - * to avoid risk of stack overflow. But avoid - * injecting inefficient single-folio I/O into - * flusher writeback as much as possible: only - * write folios when we've encountered many - * dirty folios, and when we've already scanned - * the rest of the LRU for clean folios and see - * the same dirty folios again (with the reclaim - * flag set). - */ - if (folio_is_file_lru(folio) && - (!current_is_kswapd() || - !folio_test_reclaim(folio) || - !test_bit(PGDAT_DIRTY, &pgdat->flags))) { - /* - * Immediately reclaim when written back. - * Similar in principle to folio_deactivate() - * except we already have the folio isolated - * and know it's dirty - */ - node_stat_mod_folio(folio, NR_VMSCAN_IMMEDIATE, - nr_pages); - folio_set_reclaim(folio); - - goto activate_locked; - } - - if (references == FOLIOREF_RECLAIM_CLEAN) - goto keep_locked; - if (!may_enter_fs(folio, sc->gfp_mask)) - goto keep_locked; - if (!sc->may_writepage) - goto keep_locked; - /* * Folio is dirty. Flush the TLB if a writable entry * potentially exists to avoid CPU writes after I/O