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: Zhiguo Jiang X-Patchwork-Id: 154612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4502664vqb; Tue, 17 Oct 2023 18:31:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOICfTnMT1np47ffcJYkMzbC2Bav1mY5fnBy+Mi//Tbg9WiIbPvW5mbusi6HYKl4dwmL+P X-Received: by 2002:a17:90b:4c11:b0:27d:193f:2130 with SMTP id na17-20020a17090b4c1100b0027d193f2130mr4144858pjb.3.1697592671139; Tue, 17 Oct 2023 18:31:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697592671; cv=pass; d=google.com; s=arc-20160816; b=OsUzGoW5whVx5HOigYf0CIVq4e+F1PJlsjm9E0pn3iNYiRbTwzeNDLFZw9hwvkEYu3 2kwmEN6BhY+675erBdJ3fhgIKxGzrNcnGZddY9O+KmQCXGKDmFx9CjWFsOp3Yiq/qgOO UmMw58ypsbfcAHIPRR5dXkcA8mkxruIMnz0eDLqxehnm9M9sO6Y2MeyxyGBFvwRMwtr0 fWPVA80sgnaYBbZUcuCZzSBKuf19XCpgM6oNTOgPiEoFCQbfVCvXlN7a3cvY9QCdPYkp 1P0/cPIdIV7JFMRQLj02GH670ytY/LHFg53uBuDuZAGDOa4EBHPMxtXe4LTMRBckb9cf O7Tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=6yVZ0BIDjoJrLxb95hWZe1lpouF8PNNMU62WbPJonyg=; fh=c2eYxmN/YNr2ouhP31X3BrePKjLzNfOQt6lh5667ppQ=; b=KKzO5elw1VDSHt4l1GnrSbnZlYdyQlnAq/boMoZDA2Mpn/rC9HvybBLlLbv8nqW+c4 dX6VTMUGIhnOxNgi+I1UBFLHui7JKWNx9OuEOIKGDkae++NT1KMx5auun5f3jZLKqQT2 Y5kgDaWpVfJBLAYiHnb3bA9aSi+CHqspfC9zzYKrVvK8mHch6YdxsaXw5zKdc8tF8LwN bQup8+JE/fz8QOKmUnAlAfsnkwwmtiBGNznKevrtiiEw1nRcqyJ4/LBFl9lnvzomYnep exW6u+QpAv5OsEBTtGjQei8JTUwkt6FscJrauPvh9B6yhiXxsOOGRlPQzgMgXl5Yl64M U9aA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=gRDbmzN7; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id cm5-20020a17090afa0500b0027782fd462esi413528pjb.5.2023.10.17.18.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 18:31:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=gRDbmzN7; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6ED5C8079DD1; Tue, 17 Oct 2023 18:30:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbjJRBaX (ORCPT + 23 others); Tue, 17 Oct 2023 21:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjJRBaV (ORCPT ); Tue, 17 Oct 2023 21:30:21 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2092.outbound.protection.outlook.com [40.107.255.92]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2FF7B0 for ; Tue, 17 Oct 2023 18:30:19 -0700 (PDT) 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; 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: dFHgPDpX6vssO4HtSsovOZaI50969kNzy4gRMsF4/9g1HGIgnLYYopLbLxhaec8MMAdfsKb0A/G7TFrkfP/vkJP+YZ9Zo1jB5/jTMRQRnA93pCM7/SW2nn6Gi3jaq0/fzypqgXpTC6bI5AwDjeXWNtpQcZeI17rWY/ZTVS3I/+WvOA9IMvxwGs12zR7153a8sBGJsdnBX4uPTAUd6nMXbWjVvC+KzQhloZkSwOPIgfWrrtZ316GfepFgQogfLIKQH/qpuQ2d5Pg4wXB/jrDDOWVT33SQon48FzXaGy/sLGXytKDvVgn9weizXh269K51Vae+YpY6USangrp0X6GNWC8A/YDD2yiR4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CLi9WVqwkdpInmno49YTGlfnt/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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 18:30:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780054932721817852 X-GMAIL-MSGID: 1780054932721817852 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