From patchwork Wed Feb 21 11:49:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13565473 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 1DACFC48BC3 for ; Wed, 21 Feb 2024 11:49:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 871FF6B0075; Wed, 21 Feb 2024 06:49:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 821C46B0078; Wed, 21 Feb 2024 06:49:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 674626B007B; Wed, 21 Feb 2024 06:49:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5433E6B0075 for ; Wed, 21 Feb 2024 06:49:27 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EE1401C0B1D for ; Wed, 21 Feb 2024 11:49:26 +0000 (UTC) X-FDA: 81815640732.04.F7770C3 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2081.outbound.protection.outlook.com [40.107.255.81]) by imf17.hostedemail.com (Postfix) with ESMTP id E242740011 for ; Wed, 21 Feb 2024 11:49:23 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=Lj142i8s; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf17.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.81 as permitted sender) smtp.mailfrom=justinjiang@vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708516164; 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=/KJ03FaJ/3uEXK47Hm5p2n7vmyqiFkW4NlaTtjJn3Nw=; b=NPsXQq4on6AI1BuRlFYig2mJL5Cgxe7zMxFfOCMaThFLlKjUiYaJDPgFmsVb/4yfevW2TM MZNChLrfbdDRdgU5GUy9R0FzsWOHOu/ner0lxDhvOhaRGc0CNGIH4TiGkDQ62JwSkxUPwe WmiiY23uEgxx7f/9RjIyYLeK/y4lqS4= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=Lj142i8s; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf17.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.81 as permitted sender) smtp.mailfrom=justinjiang@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1708516164; a=rsa-sha256; cv=pass; b=B5CoV4uGDO33N3DzYHIFeyalGEi+AuS28rxLGTFd+OIMKeR/Fb+BuG3cugI/nVhFV/mHE9 xU4OgkgJp1i61M57gO6qXdDCeaFtCwfErHxJEC4dOl65mCBOrmD8NF/Q3Q9jFnxegDAgre oirkmCqKGHMSLgqHFIfEdn0Eqcesjls= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RkCf8RARbHv8565CgWdR6cKSqXznu+lnz9WQTp4eTyFezIBaJ+895HYICDG2SDJuzkaiOSG/bAbCrk80aNmVipEzH5kQDfIEaj4IX4vi7dTYwD3YJ12xsT0r+EgkTX00yeyFJZ90JlyZd8eaAaZp8J1MCbdCWHBKJzlzpkufqLXpFPNmVqCQjorEF3Nn+vH3w55U8A8babCPLQxMepqHJE/Z9k0cbarK5o3A28pZssH1glihezlru0NKt1ntEhLpGmsYjYZObuAFP37A4DnV2nQByZLgH/gS6xIFrqDPXmSWvJosVXxHY+PkMbf/Tv+hO27IEMcxE7i3zWeG7nqyyQ== 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=/KJ03FaJ/3uEXK47Hm5p2n7vmyqiFkW4NlaTtjJn3Nw=; b=HF8DoQ0KPBLpIcqlKcw6ajqut7lzLkksTqShRMXRpm4opbWVPDNoS3Zswxad4z+d9F+Mvmn+pMsTUKYUmPNAy8Z/+D6U28Lddv15E69wils93hHH2rFkRfzPl263tfPvlv/QahxoCBnnPiqpwjuxNooizufq9JBXoYjGlbd0TsVQR2fHFeix2hqsNRsYeO1tMglNBsqjN2QNPem+ES3DQxF4IysrAM/bQ6GhVdkfPArOkw/sM7wnm9hgTh/734I8N6HbYF+Dhqd9DpPZIQOGp3o++N0H8W8XSCN0wojh+Pot4rXJ8N2KFhVpW80icH/lxYN2D56ORqqy20a/0vROBg== 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=/KJ03FaJ/3uEXK47Hm5p2n7vmyqiFkW4NlaTtjJn3Nw=; b=Lj142i8sZSi7ORLiWQcewdaigoQOQxiSXwD+0GRjJHrSSYcNu1102ckRdGhPP5B8WwSkYuxJMnbBVNt3ApkiT9OwDqRNDyihPr6tkWgmYwfw8EQDWo0wLcurCIT1muNuVOQs+wxzH+f5Evp/nmNYQdkL2COfklP041DcFkK/DBMEz1j6ToJlZ9n7xCpcy5RFTQKO+yTZFKGvBHOFuf53jkHUaadhSOb5xw+WxzUsHlggr3JoPmku5oL6Lp4wlCwljjDCAPNXWgAWgAg2qb6wRkY4leJmDBt8V3fA7Dgo/aUq9yWILS99u1JOoZGKJaaKiohTSAFOnqql02oVBPAGOA== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by SEZPR06MB7523.apcprd06.prod.outlook.com (2603:1096:101:244::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.39; Wed, 21 Feb 2024 11:49:16 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::462c:f70b:5282:9037]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::462c:f70b:5282:9037%7]) with mapi id 15.20.7292.033; Wed, 21 Feb 2024 11:49:16 +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: shrink skip folio mapped by an exiting task Date: Wed, 21 Feb 2024 19:49:04 +0800 Message-ID: <20240221114904.1849-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2PR06CA0251.apcprd06.prod.outlook.com (2603:1096:4:ac::35) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SEZPR06MB7523:EE_ X-MS-Office365-Filtering-Correlation-Id: c7203eb6-45e9-4325-48ac-08dc32d32167 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: InSJ3XhaB02/GjorA744Vc5AR6fsGQMkS1FUKl7cIrhS5fZ7asekW4fMC8dFYv8XNmwZn+TGCkiYA2qHZZjK/UD+sKcDTQi8cLgQ64xzV3Psehfx79X8gbP8WVdwNIt/9/XSRiMkdoCYdYiW1F7OAUO+HcJEHrp5kJ3Y1df96fBHya+pLkdNGLc5+veoZYEo/g1OJOUxiiSNsNm1aWSWpk/4PXhJpkJl2wn578VK+RbHfnypA8U4DdKSJ3ZYnWLfZU3GLQTkx+YDZsRBshQbtYgoTMOPzWuSL83bRupjTpf57NRvKXDfbga4+zCwUsNTBNmKUKl1IYVzHvJJlB3kBTLrnZtrzcwR7IP8ACXt+VndGWOoIeRiIpykf49FkpwqfA5GG7Q7TXvcAGlt94xB/80oTwXfYzAQKiBmCGXlm3tCD6lLSXMp74MXLZ3R2bioDhntBF7TEiCqVzUyVL4hxBS+xpIMuGA8VlGxcZowcPkP1AK6z/rutWv41Qn9+zXntBDlU3uGXkQgNAq5OdsuffP6h+W4YcRS21uyxiiNm97k945JP+vwRhbLIYUVQH9hvPaVpRlrHYNcZiQq+fpQjGsSeGeo0oE9LkQQtjNMLXRNZwOgNaaFcbyKCIdgCwZK 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)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: buXcU6hcuiH2ux83hEi55PKdYlrly23dHJ0tO7Kzg+xx6boPThpp1yh8y/8Q15IK6ZGtUoJ+TAn8TZs8GpKZUDgRT7Rhk4kR7WiqDUQ3fkRtYIzb/W6YyDlWqPa1QdbW7TDXmPohAGGwUgu45mabzdg5Le5ZSXz9F7tRynGXMjpSDRS4LKBYNc4nOwDzWqlO6FBoNeQp4BWZdWHG7FtKFc8WhcS21s7wFn33qaav+ABn/pvWcVQRdXET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+ukbgEmdAFrwXVqiy6lhjOE5QtViIzQibb7TpLYZO3in3BJ/1H6p5ljnOleLjdgLaT9750TvlMXPRCb7shY/0+bZ97A18r7QbMgqPLwJAlc8D8WMxwwEQqSy76EoGTs6iIQ/AtlYMK50BSrJbY7T/ID2zj1cAQwRa88zxZSlNry6idhmPpHgBTyCREoGlWMkSThJxuhtS/57pEQfzZn7R0SPqVZmhjcR13W9mzmoTYCgAJG2TbDiKeeicjCe7GfaAn+0d8a1knKXG/Z3JN X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7203eb6-45e9-4325-48ac-08dc32d32167 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2024 11:49:16.0993 (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: HrSEpTS+7aWCWV8UrtTxGD/qd9siPrjr2Ur9AVwpGU+fLr8cSyO722Tdu/p8bJHOY3+OoIVgCxwXCB4be4Ex7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB7523 X-Rspamd-Queue-Id: E242740011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: t7x8k4br7or9u3f3qdu5bus3zr9nyeao X-HE-Tag: 1708516163-1200 X-HE-Meta: U2FsdGVkX1+DI72eObMOLz71PpwOCVTygAl0UGkhrpCm2jXqyCsrvggzLDxdJtPoxAHHawXqFiBAwloJBE6OUukf/Vf5uYzH8be3DJWLKLdjhN0BTLmRReVgg8EVsMb1tvoGKYS/leJbzDfnOr3jOXZ97v1FEHjoXkFHWjj7jdGKCwWTZwrRg+tYHME+Dm+mQWtyjEOxjQKZKq8W6sjoPVN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ux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar. And when system is low memory, it more likely to occur, because more backend applidatuions will be killed. This patch can alleviate the load of the tasks exiting process. Signed-off-by: Zhiguo Jiang --- 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 3746a5531018..146e5f4ec069 --- 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;