From patchwork Thu Oct 19 13:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13429217 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 861D5CDB465 for ; Thu, 19 Oct 2023 13:42:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AF6A8009A; Thu, 19 Oct 2023 09:42:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 038408D0019; Thu, 19 Oct 2023 09:42:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF4778009A; Thu, 19 Oct 2023 09:42:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CD5668D0019 for ; Thu, 19 Oct 2023 09:42:35 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9F5271CB354 for ; Thu, 19 Oct 2023 13:42:35 +0000 (UTC) X-FDA: 81362325870.29.B246B5C Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2125.outbound.protection.outlook.com [40.107.117.125]) by imf25.hostedemail.com (Postfix) with ESMTP id 6AF54A0011 for ; Thu, 19 Oct 2023 13:42:32 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=PIHxwSfa; spf=pass (imf25.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.125 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697722952; 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:in-reply-to:references:references:dkim-signature; bh=ZVCbfCgY6uphg+FnjetqR8dr7AX+sQTlt8WYhEGY+o4=; b=dfVQnmyg/2zcADQ8z9+1x+/nfaxvbEKPv+6aGLGUHn0lTnjb0T0RQeiAhNCCLpwnb8/g0m LYjANw5UU7Yle2iOiWWiaSPIRyvJqwqkPhJkyuj5G0uKSkIhrdOlSeWzgAa81ypB+pvqaz S4J+zv/ZJtqppnIMCnNcCs/U62jQ1Ow= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=PIHxwSfa; spf=pass (imf25.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.125 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697722952; a=rsa-sha256; cv=pass; b=ixaM6AcCyfrArWaW4hGKNCessVXo5Gsvuqy1EogcQ+oLIvsAb73EtRW0QFHxo7XqDO16GT eW+B1lOhv1k7J2mzJY9lh8szCbklgU5QuVKOE436BeI7+l9DJ657KyraMlqI97U1/anCS1 r6lyxk9dTyqfmOfqDG42ZL+RWTA2uL4= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zq+O0aZ3bvv1b9R1LihihwBAtEmGba5r1vZjf5UXQZRXTZ/iVKZqLslW5jlGA+v0fTOabq2g6wix0B6wZILxFAgC2+c27K/qxpqmQ/FqtPkKBquac4Wt1mKjYXE6D9Ze0ci6Zudhdsh+0Josg32R/IF8YhQ1hmJj7rwVHaDZz5MYPEy201ntTAiCyNDMZ6xAL1rBo22BwJr8w28SuI7MepqH/Z8HzBW2Ga0DmH0bneGLPysop0w8tZWzuua1gGdz0EPYXaVAjHIIdqJ9hnS9iF7ByjbOFPtwiWnasbf95IVfRQLOZjsEFCqVH6SMU7I94BRRqyNcqUgMqOO89bfwbg== 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=ZVCbfCgY6uphg+FnjetqR8dr7AX+sQTlt8WYhEGY+o4=; b=khvHRX4tsy7+nPHcSZgo4mBTzMVR729TH6c09YTh4oJGxDE5ucrkl+iBt0hGx/oHBaZSB69OopgMIVAtRVxF9Te80upYJUROMKSnapp/wjD/VUjGGLt78kcc/3Tb7rKPbJfC9/uKbPitz+7rKbKlSai+DF+ozp0dVQC3TummcAT2yvfWzJZZlhfe9EiXoaEqa8XQ62TvczK/fZ8JvZQahh94EyGofPqRFInjDBi1+o3k0Z2WOcBu09G3zpB3SVyq1MbZCpB7FOtB2cZBEKM0lWthMyXCs4bCkKOtsE46mXWoqETQnFIMEua4GpNvYkidC85M6JG83WtQ0GX+wkmyRA== 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=ZVCbfCgY6uphg+FnjetqR8dr7AX+sQTlt8WYhEGY+o4=; b=PIHxwSfaITQXMCdj5dnqk3utlwjDvfASQ7KXYXvwF2nHvXF9l0cM1ze3SvuOW2j/Yd3Erqb/3yj+bQ4i2MSjweLTdb6GPmWnLs3tTT7GNf91G8g8ufjbm38P1QJMIbvxmD87dMjiC217DsfHLTz125kvNmuygv+r975cqvFtaKwvNQ7x5kwBJgitP06FxmkT9BPmajYxkIp9RkeGWFRs1dm8HAOFXx8FcUyZcUzx4i6Q0j3ixa8G/zes5Lu56pdnl68+1BeClrqRTzS/j3qCMDUvZTFoSyCdQ6CAXTNDvStnp7PkHqV6WLunVXbqnnT0b8yFGQMyyPHI2IOQ2kNv4A== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.24; Thu, 19 Oct 2023 13:42:25 +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.025; Thu, 19 Oct 2023 13:42:25 +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 v2 1/2] mm:vmscan: the dirty folio in folio list skip unmap Date: Thu, 19 Oct 2023 21:42:10 +0800 Message-ID: <20231019134211.329-2-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 In-Reply-To: <20231019134211.329-1-justinjiang@vivo.com> References: <20231019134211.329-1-justinjiang@vivo.com> X-ClientProxiedBy: SG2PR01CA0141.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::21) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 50b87a9b-9ba3-44b5-57f1-08dbd0a93a7b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vbiBw1XMl0txTun8RDH29Wd/0b2lj8DjVhJqQxuPf1yLycFSEvwg2u6F9Vi+xPpmJtxBs9zwq0TszyXKYoJH0hW5dCZZa2AxQyLhUzkBgD0SrGMselkBPd39k5eJTCcjadFVDwfSZceS2QaRGcAsRcA/vIMDu2mrmEQhmTO4ELiP4oCu3RKUshRpSEp+PMw/AhKO7i/0lhMA9S1oOZlKsdccgWh/rJ96qo5zsjtjSdLT2HLGTtudP1rLjg2MvY7w4fZmO8/KBONXv+2WZr72BQZm3IXKpZV+0x9c/5+6EE/A0Ao6RYnHu8vvo19ErQ0ntU+x3KFVv6KdbKQDnH8/AeXFlW1cQpEti2CHV0VztTHgHQtpS5RprKPWGRLpuJzEecIRDnvda1bIJpGO8b01QJ8PGc5nOTIlL0Y5QpnJCTvPy0vvRl1XRu8jNWejPPOlnrU5k38LJ6BwBbmS4SUv/j3SMpW46ueQYZjqRtS+j24opY5sNWGy6/KWHjNbgrZTogo0o1Iz+S+U7Yc4inpAYCiz9jkj+aBpPBxS1apa50ilx0u2heNRfk9fr81g1Y9lKrdrlHXKWTDxCLGEwr97Lu68Zn1Fkdx1ss/Gpc8dpiNQtndLd0jLUKfBvNhDabEWbvbHhJDuGIVP9XTxn1PoRA== 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)(346002)(396003)(376002)(136003)(366004)(39860400002)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(8676002)(52116002)(6666004)(2616005)(1076003)(6506007)(107886003)(26005)(66476007)(478600001)(316002)(66946007)(8936002)(4326008)(66556008)(6486002)(83380400001)(38100700002)(6512007)(2906002)(86362001)(41300700001)(5660300002)(38350700005)(36756003)(14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K1QrSENqjTk/xWtNXlRDTMPCDBJ3ULWiU3Z+oDZVhwL7M+e4Rn2sK/KBE9jKkEMAkv9YWoNpdckDVnkxrM8t2r9bFg6u5Ni+JAUivvoQqOWX/3kg6NkZMomwG2wxEAg5hglMGraL18JRfU77xuFbKgTQf8JM25umVZraHaYsmcrLbmmj9EKE4MzexgDt+d7PFLiNcucvjxblNnQRpr+dGxfol8Sr27OQi8oYb9tkEwLmK87uu6gHFY3jRxiCQXUtxbK50XqA/U3hfksfqBEY7vnWCC3oNsZ6mWdqlb6HLB4/Iumqxb5M4wDD1TuLFgU+2e7tgOsK5Y9o7vzVAF+06ZB1fGEYsV+JKZ26qp6Qkz0mi5NB188w5NGM42stIa2PIl3ZqOHG8hnbEuBFrCaBn3Ti+WKbv1+tXSrq8H3fME++XtQ+heJVDqy6aFbhZWdztloMHQUPcfgH1wsDOCImM9/TjFxzscySuXFemmmfasTZodOj4YEL0ZjvK4BgdUfzobk3byps8obu0ype6JKGYel2d+dVuELIaVU6/ppQOcEzcFOjd+63O8i8iGzFVVjCxOC4sAG4bxRnr X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50b87a9b-9ba3-44b5-57f1-08dbd0a93a7b X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 13:42:25.3689 (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: 1u3HQh8zdjHXZUEe6mnxqCoZ/17xYNYbHRcWwyAhznrP5CHjd205wVQqrjabqZvamJSUP4maVXoqyMpypyfjhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 X-Rspamd-Queue-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DHJlq+ Bu45Q9oiroJVSyRhoNiVyPE+oVApIO02RiIVkPsQB1sNPqKxi3dH7oxNj82clA4MvcPznpTDnTLBaDl9HvC1HqfXvVyd5LGMjdlC7jvqWLV9HgRWQYZbn36XTCfkzmOSfTphD4uTREl04fUkf1vKIkpavqBS2J6VJghuwb9pP6kRIPFUY/0G2yltjDm4t6kOjeHliEdL+mEdFdvdr3s8m3EDP3dQ7gEEJrJ1Fl2bwvOhibAsE/OVqPB+Xwrlk6Yf9f79EJhhRv/6YCn5122QJzK5RMEJZa8Rl75THvzqEWP32SWz6JZyi6N9kSSqctD7jVH7tGjwCD8eiXmVisIa8xF+tww== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000051, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In the shrink_folio_list() the sources of the file dirty folio include two ways below: 1. The dirty folio is from the incoming parameter folio_list, which is the inactive file lru. 2. The dirty folio is from the PTE dirty bit transferred by the try_to_unmap(). For the first source of the dirty folio, if the dirty folio does not support pageout, the dirty folio can skip unmap in advance to reduce recyling time. Signed-off-by: Zhiguo Jiang --- Changelog: v1->v2: 1. Keep the original judgment flow. 2. Add the interface of folio_check_pageout(). 3. The dirty folio which does not support pageout in inactive file lru skip unmap in advance. mm/vmscan.c | 103 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 37 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a68d01fcc307..e067269275a5 100755 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -925,6 +925,44 @@ static void folio_check_dirty_writeback(struct folio *folio, mapping->a_ops->is_dirty_writeback(folio, dirty, writeback); } +/* Check if a dirty folio can support pageout in the recyling process*/ +static bool folio_check_pageout(struct folio *folio, + struct pglist_data *pgdat) +{ + int ret = true; + + /* + * Anonymous folios are not handled by flushers and must be written + * from reclaim context. Do not stall reclaim based on them. + * MADV_FREE anonymous folios are put into inactive file list too. + * They could be mistakenly treated as file lru. So further anon + * test is needed. + */ + if (!folio_is_file_lru(folio) || + (folio_test_anon(folio) && !folio_test_swapbacked(folio))) + goto out; + + if (folio_test_dirty(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, + folio_nr_pages(folio)); + folio_set_reclaim(folio); + + ret = false; + } + +out: + return ret; +} + static struct folio *alloc_demote_folio(struct folio *src, unsigned long private) { @@ -1078,6 +1116,12 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (dirty && !writeback) stat->nr_unqueued_dirty += nr_pages; + /* If the dirty folio dose not support pageout, + * the dirty folio can skip this recycling. + */ + if (!folio_check_pageout(folio, pgdat)) + goto activate_locked; + /* * Treat this folio as congested if folios are cycling * through the LRU so quickly that the folios marked @@ -1261,43 +1305,6 @@ 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; @@ -1323,6 +1330,28 @@ 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) && + !folio_check_pageout(folio, pgdat)) + 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 From patchwork Thu Oct 19 13:42:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13429219 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 6B572CDB482 for ; Thu, 19 Oct 2023 13:42:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5A3E8009C; Thu, 19 Oct 2023 09:42:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE3338D0019; Thu, 19 Oct 2023 09:42:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE73C8009C; Thu, 19 Oct 2023 09:42:42 -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 96F5D8D0019 for ; Thu, 19 Oct 2023 09:42:42 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6032FC03F6 for ; Thu, 19 Oct 2023 13:42:42 +0000 (UTC) X-FDA: 81362326164.07.DD6D951 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2125.outbound.protection.outlook.com [40.107.117.125]) by imf25.hostedemail.com (Postfix) with ESMTP id 668A2A000B for ; Thu, 19 Oct 2023 13:42:38 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=qD+xncfi; spf=pass (imf25.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.125 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697722959; 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:in-reply-to:references:references:dkim-signature; bh=G+W6fmJ72ArZzY33LmCyBv0xsV450yR0iejgRMpA4iw=; b=wpjEKdrQPSZE/4L3kbXYZALxLXgs1uXEbHmEqrh+lhHCNHL4S/zi+e7N/KNsAlSMkkk77E ON1rYobiS0zAly0kzbrjxZTRA7rl3HiSPh+chEtSdwCOwpv2D+ZaiKFW9q9BPcTr/4mR3+ dd/wTA7psv47aA72J4/BlhwKH1A9CMw= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=qD+xncfi; spf=pass (imf25.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.125 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697722959; a=rsa-sha256; cv=pass; b=WioVopBUPuQz/atinYsGG5gS+gGYn2b1ntxiNHV7RiLOxuEoF6TlqfoZtKHlLh9nLI0VOI XwRyVmvSlfqpKwoOtmkgc8y8IJdsgz/gotFl/mOBomKzQGjYuygLDw7Be4QdEOl0toKiyN PbVCbbfLAmm4j1gJm+FD+UICBD1lC4k= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iHr84kSY07B+RSsphp5Ux0rn81eNb0ZCbK9Sn8gj915f+JwS0HzaIbCK2ULFFJzIfioZC49FKTXfObH74y1y9xWV5zRvtyjBJ2sMI5RqpU26CFHzEcCM7mO+jVqOISb6R+mWaG8YUWIsmTvilqVMpvxyFPFgEfZEFZx//monmzyijYA1/BlJu2ReSGaDS4O9m/CkCzZBa4yO5+OXfaFWDwEmsqsCywfS77itiJ4rX0l2vZgzXLOpCX0zRY+FXTBI2L0gKq8vhCo0sFtT2zCw+mINZO2ylETeG+E3vUrcdDCxGgDDoj+5nGo7NEomeNW5VuB8NlM4m0EDs8y1xmQWKg== 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=G+W6fmJ72ArZzY33LmCyBv0xsV450yR0iejgRMpA4iw=; b=mC64egYSKqv+/EvIFy7tGJsAD52Mu9lL2i/mZITg20Ey5lqnSLLiaf1Y78/U1gl6Mjm5JJBl0m4tSASDqwQFR/X4a04QfS627zo5Hms+bHAsnrQ+s2pUDB5zQ9Dwx8qZB3B8/P1MA5ZwHjvCXN7n/kJgHy9Yais0PUz8UWSIOnM4VbiFEb3OADtwUKwfqgxCd2cT9xwWz7N683wpD/Yv4KFQwSNpTXWatdf9Q80S0MN1Rlo0CkgACIjhbgHrkN5upvHbWq+gMB/o9RDEjpZ1JVgUVYq74sRNUVt+92tZphzoli+6JG3EbQjmjiCVViUFrPIvIGhg7Ioe1NWPuclr4w== 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=G+W6fmJ72ArZzY33LmCyBv0xsV450yR0iejgRMpA4iw=; b=qD+xncfiUk/9CmKZ/LpYvkfmwljnn/MWxnGJn0bxoOqd8ZjRt2Rd8LTsSX9FwijGHjEp07GA4QRQKelhbyWwNLy72x728Y9aSvmhUUXll+KhhcPF+kb2yDCw0gIWqxL60Og7ArFLcL66I0MxAhH545EYXQeYNiLS5WC0j/Ls0C+zw0yf1dWoiUnMo5sIeYcq0IaJrUoYjqwPtD72fFa6VE0an1XhjacYwL5xfT14x6bJ5mI8uc38O7+a+ziTWhOAElcCf4hRa6hc0uile0GTbxcyQiaYFQvslThy5hwkBJZ1UH2zkAhNZN1ENas41GRTrL3xN4nPhbjjbILz2ygBQA== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by KL1PR0601MB4100.apcprd06.prod.outlook.com (2603:1096:820:24::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.24; Thu, 19 Oct 2023 13:42:26 +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.025; Thu, 19 Oct 2023 13:42:26 +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 v2 2/2] mm:vmscan: the ref clean dirty folio skip unmap Date: Thu, 19 Oct 2023 21:42:11 +0800 Message-ID: <20231019134211.329-3-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 In-Reply-To: <20231019134211.329-1-justinjiang@vivo.com> References: <20231019134211.329-1-justinjiang@vivo.com> X-ClientProxiedBy: SG2PR01CA0141.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::21) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|KL1PR0601MB4100:EE_ X-MS-Office365-Filtering-Correlation-Id: 863f265c-b576-482c-42c0-08dbd0a93ae4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o85Ct6fU1hRIJlr4fvQgZ4xljBU6ZeMbcJOWw3UWvRHQxZU2BTYcwF+TFSDM7w6WfGAdUeWCnnC7Q4iLxBxqC1CX+WJTgfvVLqcs6ylH1XiJyqnRPXKMoE1ue+TpfUI1+X7GHJ3VH/qANNnWxzO82U5hR9E3HPs1eikVQDRHO87uOFuxmwlN6zsaVQ04gWLVcG+yWF0WlgICZXVa21glkFZc4PxSAI54e6UXOGc4uGUQp69YjWZCGF5E1Vhw2JPp7heWrZhp0UkN6ymygcCV/nzo8dELABQ5yCTPGSMlM6QSUFeV6TtIyP2iBOmhMmd4bPRaSMNGLdqzsjR41XsWjyDGSM5p2TLvaJandXp4ShbH2arohIc4r0O+D0fJCLzfBXIXbZsB4cIvGXWJ7ENpcNZ8iiQ8F5azMxi8PDu2wwd9jB8Yd346SEZUANsSw6mv3jqCb0o7+bwTU7Nd+h7oI8LsuafrcM4xa1K9NE3WhbJDFsVeQDReYG17qAQxnm0JuiFD/v0cT4hSwoMCPT/eUkGvbTnSvJqLpsUqzu8pnZNCwHfLXWQZsCrNXQpiMqvVMRC8LgC9g2jsgII+1NeY39UU3Zw3YIM3vih9Ut8CnZFuABmrKR3unC6/+gXTx4bEOSxEz+DzYUE1wBy88+0ilw== 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)(346002)(396003)(376002)(136003)(366004)(39860400002)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(8676002)(52116002)(6666004)(2616005)(1076003)(6506007)(107886003)(26005)(66476007)(478600001)(316002)(66946007)(8936002)(4326008)(66556008)(6486002)(83380400001)(38100700002)(6512007)(2906002)(86362001)(41300700001)(5660300002)(4744005)(38350700005)(36756003)(14143004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vxuWMr/qkh4P3rDyBNzchSrKLXEPXnT26oCMHv1XUzAtgWlqAYT+DitUl/0/rV8puTI8+NtJZkEuPOdB6yD/OmamNZaX7ChGg8GdfN8hxCr7Jk7hCmS/p6YLvISP5QfJ3nS+PxOHVPwBVAa8GrZKnGYiw0UQqUyrBQK0WJkA0wMppQuDqZNctHXJFpHikkU/CSwsbAwzfX5uPezpkePy+Lgdtq50yBEaX/4vtFbefPMNNJySZOwp1riWXXhLX5X3Djad0y46qts7+HC7KXx6jNQEgIgl0GFFBlATCuARWtQQPRBgQoSKDMBiybQ5Wr6d73kMZ5qVcukRzb6/JitMD3hWi4nS0LF0DI+98dB0r5nLMOHVJY4IA/eVwJkoiYIR+I33yVNK8edv7vl4pR33Os3sA4d3xS+azX9bkURkRlypurIQAExmkJc6lL1QTRP7Q6tlJpeTFEfguXqqOd9DbuZZhjiZmqHcZdEt4b1VdjSqTIAE5xaWnRQis7R37rM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Cy5+PLCKtlIIsaAGEsEzCzhE7 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 863f265c-b576-482c-42c0-08dbd0a93ae4 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 13:42:26.0515 (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: I2oQnwRFw01JwdmNEf2Q5NOLVoVehcOzW/SYCZoYsqrfydReH3QCkOJmsTdbUL2iFgPlnxFGGu+4m7alQdft+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4100 X-Rspamd-Queue-Id: 668A2A000B X-Rspam-User: X-Stat-Signature: uetc88f45ity77edcmbdb4c5kgxtyd3d X-Rspamd-Server: rspam01 X-HE-Tag: 1697722958-731269 X-HE-Meta: U2FsdGVkX18IvCHNhNk7FVQW78YlDtM5FE3tWz76aCD+Ph4iW5lHjqPm1LPtOf4AqMRudhifH3E8oq3Q3KyEwqo0CvrBW4EScUC8f0LaClrL38QPSBsgEL4TlWCuyDAWJx3QvNWJ4tkfC9ZOJiB+5r9kdU+bg3ApUo3GJO5MC9PRtnfnoO199SNTPwl9+92PeyDU/sWJrDr8714FLm1lk3ILvs72Tu4rzKc2NePZAAnUUONHqs/rAOdDLUhI6UT2IX8uo05t2V50bM+P56c46uclPNYh3Ly6uYxyAyvHE/CLPkhy+J6Y30+7WLRLpig/amY9PEMLcN/duAxEMpDK/aV4jKcFmOxKthN9CRNpz0GdNIHEyQx64iMNcQtPViCVBSpiJXNuyhFzDE77gAAsNpzNhKMC5BPQqKAVNE81mVwWH3X15e8OSXruHCcNX96Og6pHRk29hnk4HPEzKjLOF/es0FgRab4R4z+2AsUpOGEnZD+4U4kQeqb3EgrTQt3od8Mc3irqiLaWNGSaI9LJQhsrlFccr+hty6iCgJFgnkByoTagKA2mdJQicdIK2F6sFsr2k/IqrVfWT6OFAK99A353TJDeEa2dG12wsf0PbWWJh9547EjUu6GZTsexuHAnO9S+BILkyJuzOHmNiPdOpdgBkbpRYHaRFofltqQHWWLWh6HBU4+1NEdfRnJlTMkGalzTnYRbGqGv1uV3PAJZJmU3rkGjyGTzYIiEWqX5tzhoOc7FWZr0zMzz9g1nZFQvfG6hvsIl2wAdHRrJojvxWttrO4RxwmTIwamftocteJJ2gThrml/HBYI6deHYmmcXW06j/4mGCpYHO/USvjF/1+heWoDNqNxJmvnhYk5z77KjZD+ioiqpIR+HbWWmYAZTvK4ahKoC3Xq5NPRgC819XZaC/hGjmniAPyaVM3Xxtwa1gsfFkmBwNhjq/kXxgvD1FZfBkBLE+5fPFrMyNvy ULayI04B rePlCr2v+ep8zBqFfMwILcmucoefHZvwRtu/11v0Kb/TdPDPAyLp4SXp7oRyQ4Wbfk6qG7sNprLEd9aNyReaRtXZ3ilZ5vr8Pg/87ess0R5imYuRblgoh2AuxWsrIhtDNZAjR6YuksrSggoGwrqooIqpf7L4xppU7pRf7B7bCXZOieTCbTu3ijUArq+mhV7r4dG9o6tKIBGgat6dlHBwbN+rStCJ6cJWTeDSJK9tRQD+izQGoJwUYwW0MoIOIh1BPzyAkqdPvIVvjECnlPxuBwoKx2W3VlFiWb8W4U1Xzzg0khX3HVuO2wR0Efxs8RwBWpu7nE3O79PHK1Yg7qooJuvgF3A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.073895, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If the dirty folio in folio_list which is inactive file lru is FOLIOREF_RECLAIM_CLEAN, the dirty folio can skip unmap in advance to reduce recyling time. Signed-off-by: Zhiguo Jiang --- Changelog: v1->v2: 1. The dirty folio in folio_list wich FOLIOREF_RECLAIM_CLEAN skip unmap in advance. mm/vmscan.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index e067269275a5..e587dafeef94 100755 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1225,7 +1225,10 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, stat->nr_ref_keep += nr_pages; goto keep_locked; case FOLIOREF_RECLAIM: + break; case FOLIOREF_RECLAIM_CLEAN: + if (dirty) + goto activate_locked; ; /* try to reclaim the folio below */ }