From patchwork Wed Jan 31 13:12:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13539433 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 1C5EBC47258 for ; Wed, 31 Jan 2024 13:13:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95DBD6B007D; Wed, 31 Jan 2024 08:13:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90D2B6B007E; Wed, 31 Jan 2024 08:13:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AED06B0080; Wed, 31 Jan 2024 08:13:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 691D56B007D for ; Wed, 31 Jan 2024 08:13:01 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3E4BF1C14B6 for ; Wed, 31 Jan 2024 13:13:01 +0000 (UTC) X-FDA: 81739646562.11.193548F Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2083.outbound.protection.outlook.com [40.107.255.83]) by imf11.hostedemail.com (Postfix) with ESMTP id 5017F4000D for ; Wed, 31 Jan 2024 13:12:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=MCoWEpDH; spf=pass (imf11.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.83 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=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=1706706777; 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=YcOgv1/ZGnuxkd7W01ErLZH2VhE07WcMiDEbIrr2cr0=; b=KmUQ92lYj8Ht8qcWZCnTijmH4912wH1aCa1FGt8SSxoh79IPygkhKrWD3GMPL7iQxSbqsA CBxFs36G4dd5qRXUz4zLpGRZETJhBihc5IK7TWwrOjaz+eU4023hFMKQYtMnrL0bApxpz2 QVTtQA20j3tvlx380UnCRok5OqhVPTw= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1706706777; a=rsa-sha256; cv=pass; b=lncAdyI2IwC7UNa3nBchCudOxGNyuHjHV6RbfSx3NIV733PVFgbWRBS2SfhT06/BUZSIir OCkW9gVQ8GckXWzqjfNMGZqoNATk06+I8eo8HZP1MPJRvy6fq4sCVpX/Bm51ydJCXFMWvy NMNQN5WH8fiU0NxhLpSNORa8yVHhCBA= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=MCoWEpDH; spf=pass (imf11.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.83 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n/ripkVqyZjNp9wJQmWBbKcEidWzpzyL3EN+1BkJXw+GoXN2evrmlagRSCujicEha8hE/QfNaB4PoLPk4GR4EhpkJDI0sCKXUvOFdbpym30iQ7ouyNAG1oUyTIkyKkSq7IB5y/1Cq8eBjY8EcLWaJu8KaR1bIUnOT0F+RPR+QY/ByTCKUajPbPuyCdNwexsyYIRqfL1J6qx/8tMdq+TLUdnjmhXl5Av+3QEPMo2QMK4BNcPW/aqwaREncIrEM/7Ipv1q4vRyfgJ8Vu+cUK3CsFji4Qxv9eDCPEIvm1E7eov7WgpGjJfDeTS7YM2f3KhOd8fHl/b/+3PMawqPwCYRUg== 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=YcOgv1/ZGnuxkd7W01ErLZH2VhE07WcMiDEbIrr2cr0=; b=Bi60tm+qmoPfXvmIW1rSeYXzYY6IN2EvvrN1edWZYRY/E7ctF7L9LK5rtXE4SVThTjvmbZJoaTbF9eWHazSMuYIsp1TMylPBk6YzY6pAAOs1F7/L8HH9oOuG0VuIOEzcc0ivpP/7oTs7nExCzjYI6CxoTCi6yCPb1baTLhByybO0T5hNYjNtchRc6dl1KoinER3Q4Hf8QlB+XBY9cUP1yYiUSRyGMqvmu9BuOLBPjec83vh117RDZxNNH+yfAXSmSQFR5yWzkkd3OUiWpiPv4Rt6HVZa0b9BXMgGJI5fVwGFMTpYS++a9jd28LT0A/kYWV1+MUpmeRi6jrfCFmiJXg== 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=YcOgv1/ZGnuxkd7W01ErLZH2VhE07WcMiDEbIrr2cr0=; b=MCoWEpDHqOx/IdfUGz5pkuo5vgYmtbALy7lCUXvqvJQLS28/jkx+iBgxT+XoCP8PgtmdMTqUiVcFiW+5/RUaQO7L6eQhzfIb0hKii5pUOU2RfmCanz4NssyrMWpIkRlbUl2w80HWfAk8lQFowro3bzbcGumvAUM56wOpRfchuz1vS83kP5MEO0sg5/M6lSMy6+gBv7FbkItzHrDkNqUvlPRA7RwLVe7wD/MVQLbCFPa19hUkhaC2v1sSvEmkKjBc0eXEHJNunbCcSWhMQ9AZcYO9YjbOpdDi+6OyKj7iWZRiY/S8SM96KxFhjJK14hn7dSF59q1JS3FnZxntKlaPFA== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by JH0PR06MB7354.apcprd06.prod.outlook.com (2603:1096:990:a6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34; Wed, 31 Jan 2024 13:12:52 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::84c3:362b:bebe:87e2]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::84c3:362b:bebe:87e2%5]) with mapi id 15.20.7249.023; Wed, 31 Jan 2024 13:12:52 +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] mm:vmscan: shrink skip folio mapped by an exiting task Date: Wed, 31 Jan 2024 21:12:44 +0800 Message-ID: <20240131131244.1144-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2PR03CA0110.apcprd03.prod.outlook.com (2603:1096:4:91::14) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|JH0PR06MB7354:EE_ X-MS-Office365-Filtering-Correlation-Id: ebf97237-3913-4c5f-4c85-08dc225e54df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8Rygwt7sQk/1N/+B+fE8mQ3J0XbRVWLAs6JWa8hqnFo2mZ12b9ObRHiVCqjmpp4ngbqNpCAtAwKQd3FWbDSGqWcJjvrtFJt5cZZfLQM8NP5IIK8v6vB1NZT/OVkc/5xC8eQ825WJHUSrbmDBzNARGuNDoFgEO0ArzscjokJpWPvr5icbh3LqoKRAzC659cBrnSgqFfuEumUQw9t6am9tWNI3i2iU1YOgXhe3ycr7vuNC6Zu8HMM770td9ic7ttNtjmeYsYtF4MZB6gVF+1BiuGK+4HYI4GLrfXO8WFde/Q/6eEF+GRw06PKk1Ei0dBLE7e6DmKVXk70FYaV+sEMGSI1YGo3wbU+PBZTGxBVsbNIyRkOloRoopTXR3t0BroqDvbApQDXxvE0GtiNd8kINmSgPcnBi6aYvxHx8JH0WeJ10DHeZ/Fscgybhus5JthjYdwKcZ8IYazBpuYgMd0x0TBzWPlkOIqEBiQi43jGQtg8vb9Zlap2MSOnLYuA4o+xI+SCYGkgHc4rUnwVs3YJFuwmMpL8FricOtchSA+ZhEh6EWYKOKHPCbEh4afqHs7V66LLvVCgms7l6aTrPM5Mu/ei84JHyn1FWmtSIWx1ZjfxPZVDttzcs0MzZu2JGV1J5 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)(346002)(136003)(396003)(376002)(366004)(230922051799003)(186009)(64100799003)(451199024)(1800799012)(36756003)(86362001)(8936002)(4326008)(5660300002)(2906002)(66946007)(316002)(66556008)(66476007)(38350700005)(6486002)(478600001)(52116002)(6506007)(6666004)(6512007)(38100700002)(8676002)(26005)(107886003)(2616005)(41300700001)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tppp+YJyDlcGyLm97UXcXcfPvLRDjepHKe03EOIaMIve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hQJgX/2FL+gzsOsHWykGl707kaIe4t4IgxFEgMKZ10nNl4dqV/yOhvZ4+FNmaH/r7Hrih/Y4GcAUXFbDaaSuT5MoA9kOML+lhMyMNlbqFx2J0EmiBKO2iFNcNicTSOL+Zue2WN3n84NWnBZ4ElndtMDXEBk/544f53wW4JJKUs1o2z2KJhYXQ4TAvGkY885Z8C6JndxdAbK5BmbljESciG5vE/v+WSlwik+tcIQiTfmZoz2Nii0L0Vj4949HGG/UtoiEH8AHdqkPvMgSAMjkOFaktLHQMgcvdaBF5lMZj1vTKZnnerawgAxsTXQu1fdfmaZdJT36k/EtZH1BG8K7LjnyquWXDka41kMjg2mH9Yg0GvMUeJXr9GUbMpEjPLDllptEMpcQQFWfJUCtf6fnHE+hQhL1SGaQfvidhcurvW26iMPiu4ate0r/OJVOH8mhCWSJiH39uoIpiaoTHww X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebf97237-3913-4c5f-4c85-08dc225e54df X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 13:12:52.6685 (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: jpiFNTHZ2XMFJFX04bgu0M9EGtpK0sh7NxMvuQPC048JB6+S+i6paegBtAwDGjAJMIzQkWwaqr2Wqu24yO0X3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7354 X-Rspamd-Queue-Id: 5017F4000D X-Rspam-User: X-Stat-Signature: p6z1oo4gi48br3phh56pk6xmbkwsgsf1 X-Rspamd-Server: rspam03 X-HE-Tag: 1706706776-409781 X-HE-Meta: U2FsdGVkX19/Tthgpaazg6fdVeat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Lz5eMGRSueCzyzU9CFFYVz7DMBq+rWdp8k1w4bX8K+Tenrk0G1ZQK3KEgswOvoavN8FKtv4I6UEPbd9ZbdRmi/w2jL94zRP4ygvtGWNQE4Vb9/Orf5+xmiMj3TN+N+lRBFL7LG/Q/tE8aUH 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: List-Subscribe: List-Unsubscribe: If the folio shrinked by shrink_inactive_list is mapped by an exiting task, this folio should be freed in the task exit flow rather than be reclaimed in the shrink flow, because the former takes less time. When the exiting tasks and shrink_inactive_list occur at the same time, the lruvecs's folios which shrink_inactive_list reclaims may be mapped by the exiting tasks. And when system is low memory, it more likely to occur, because more backend applidatuions will be killed. The shrink_inactive_list reclaims the exiting tasks's folios in lruvecs and transforms the exiting tasks's anon folios into swap memory, which will lead to the increasing load of the current exiting tasks. This patch can alleviate the load of the tasks exiting process. Because it can make that the exiting tasks release its anon folios faster instead of releasing its swap memory from its anon folios swap-in in shrink_inactive_list. Signed-off-by: Zhiguo Jiang --- Change log: v1->v2: 1.The VM_EXITING added in v1 patch is removed, because it will fail to compile in 32-bit system. mm/rmap.c | 7 +++++++ 1 file changed, 7 insertions(+) mode change 100644 => 100755 mm/rmap.c diff --git a/mm/rmap.c b/mm/rmap.c index 1cf2bffa48ed..e6702bfafdde --- a/mm/rmap.c +++ b/mm/rmap.c @@ -840,6 +840,13 @@ static bool folio_referenced_one(struct folio *folio, int referenced = 0; unsigned long start = address, ptes = 0; + /* Skip this folio if it's mapped by an exiting task */ + if (unlikely(!atomic_read(&vma->vm_mm->mm_users)) || + unlikely(test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags))) { + pra->referenced = -1; + return false; + } + while (page_vma_mapped_walk(&pvmw)) { address = pvmw.address;