From patchwork Wed Jan 24 12:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13529175 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 B7CA7C47DDF for ; Wed, 24 Jan 2024 12:43:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 312696B0071; Wed, 24 Jan 2024 07:43:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C36B6B0072; Wed, 24 Jan 2024 07:43:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 164AA6B0074; Wed, 24 Jan 2024 07:43:30 -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 0928B6B0071 for ; Wed, 24 Jan 2024 07:43:30 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CEAFCA029F for ; Wed, 24 Jan 2024 12:43:29 +0000 (UTC) X-FDA: 81714170538.12.E68D303 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2106.outbound.protection.outlook.com [40.107.255.106]) by imf24.hostedemail.com (Postfix) with ESMTP id CDBCF180002 for ; Wed, 24 Jan 2024 12:43:25 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=JiEjYfOq; spf=pass (imf24.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.106 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=1706100206; 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=v4txKrtP0kZcCa/oe7j+wbX42JzdlRtRJtMtzfCObxM=; b=TwqTQBynnxm5T3CKGDsBpOV0XU2oURmgM7Wh6chROpsTc5pdJoMpieFK+O9Of4JN7LkoSF 8J6BvFBbz0X0ZuQ1n7E/OMFgCWUV6dqDEt6Wpb2I/44dVohoXLsIHUTod7voY2L4jACpl0 vY9hMouQ6FGQx+t7HU9zewbtNj0LJas= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=JiEjYfOq; spf=pass (imf24.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.106 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=1706100206; a=rsa-sha256; cv=pass; b=YhMyGbrpg8N2T3eJ9oTfBRzGdaxtn61mq6OjjoE1sWfJKLefNthqOqTGX48wqPjCZRbELj WY1E03YBxtGezcWneQiTkImtQ3r0H9iytNIwOYtHUBs8xUjo3dfcK3GaQOPgt/5xW+Odj+ XbgGnLfwafz5ebDe6+BRKTUXBIhN6KA= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eqUTJxLwjLI5O7DLUMzrw3I7q8Z0LNWFmHfXx79GD2Stg+JAzeVNiugrbvR5GTjoRmKgNjQ22/+wdgeaWfW6+SVH+Q3YZx2UY9zO8UB3kS4lZVi2Rztbjd+ro0C1K2RTzCmLVtF124Db9WB5gJUZvO1hVmJ8hxHG3ER4OX142EOx/eL4LNM4hq7wlIjeMJTiyfTfhJtoAg4KV72mOck4gqGm3z7eBB0xA67CKnfXBwdNKhsRkfKzpnRsxyxrbNzVtz4+xX74K0BkLiMm9BvoY6QfyJ8z1MH7PCSXN5kRrKsRSkHX12fUnDvvGxMJVjXUdKUI6o+P6W5oNFp2UqIC+w== 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=v4txKrtP0kZcCa/oe7j+wbX42JzdlRtRJtMtzfCObxM=; b=lilngLgXwxtr4DGngct2R8nKH/N3NYJQJYn+SgJ/pV7DA7Dnrwu6rcGH0sQZJhfwlmaFquUl1lFZFMQuyXMKXzdPSKV7xXu/F+QHgRHdBaU3iIXZZ5WYxd26v5mAmIde/1P6L/5anNPjo+lM9ErTUeMFJ3Pb12VnwfAbMVrv7baOawvV2t0vtyw+ToYxLZ+kujlML5i+KSqQkXdkS1jTviat1duKOSZ6qdizAj6T3n/SvgHOaDx456u4cfkToyT/0bmlr7lj8xnC6M7IpvqCHUEOD/2QEI2LTkhuR+ifLH+8guW00qf+a1fPaGbgB53bQ7DXwLNlCtQ0FfJTOFWIEw== 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=v4txKrtP0kZcCa/oe7j+wbX42JzdlRtRJtMtzfCObxM=; b=JiEjYfOqx8WrUavSE5EDLKHaDKbb1Sc0DgyJsbpkiySw/3gj81BeNyzB+ddCZHmeYjAJNQvaNKqKMQaUh7TFOWApkQNDBK5W5NG4goNe6Q2rK4lM4ISH8x18rTuDoZsL8uRKTzE7LORzAxo+aXMZ6xvZ6vgudQtMoJ40N8A9jud9BrTkyDgdw0X87crjLr55dQ4L07CtvdGEU38Y14sU9IWbdo1W0ZfrYtYUrPrwIk6XIcsxuOAVndaM5q9jwWW/5WlVcnvxlyZgE3Tcfw3eGqLurRqiUjOj19OkmxdawjGuRbl6LoZf+fju7A5SNQe6kUFuXvd+mTKCVDkhgB5WVA== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by JH0PR06MB7030.apcprd06.prod.outlook.com (2603:1096:990:6d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 12:43:20 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::1be0:ebf0:eb04:6bd3]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::1be0:ebf0:eb04:6bd3%4]) with mapi id 15.20.7202.035; Wed, 24 Jan 2024 12:43:20 +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: shrink skip folios in the exiting task Date: Wed, 24 Jan 2024 20:43:07 +0800 Message-ID: <20240124124308.461-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2P153CA0004.APCP153.PROD.OUTLOOK.COM (2603:1096::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_|JH0PR06MB7030:EE_ X-MS-Office365-Filtering-Correlation-Id: 30a842d0-506c-4538-7733-08dc1cda0b74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fKyihKWcJtA5zHPHEPVoOtFqoFMTolpSNgFXtj/xds5tLPLZXT9O0EZ6xeD0gaz4b06azlRHCVrukW7y22GBTDIjEBZWE78wkOzMNDPfNububJ0Pzvpkeni+Qsb/clg+S+4h64HBpA35dZ+GXm/Gnpo6OKMeOywk4ckanOJxcM6KFt2KxVjXdawJ9WZG7uWIuaECRLu7xJLZ6YMARrJcHnbZtGnCL1NcPpZdv9eAbP9puP461Q8fnq4BpEzzL3PxXrjWLhBv+jMYVvC3bZNZTZl9JgBA5XVgoq1T+2Nsw6tYdAO0IviDJsj7rwQb8jlhQ4lPWNYBt/AalyzvBngswr98cqwPbP7z0mEo91NyMT6qY73OjCW4/i99wYtOPOHFZAsAZc6l/SufN4cJW05f3N5AP/ukp+C7KvhKDhkJMiERWECjnpYbrO8F1NGn8ihDK1sUQHWpOW44zld9+h4c7WAROxTzV+obLZDmMLyY17jAbRrIZ16hrha03w7HqUSGZqxN9+BmOFNod0FToUIaveuwlPFyuyII2LeJWuF2NhkEfce4lCtM1t5sgMxb8Z4YjooU7D0ZYBFeqvyRf/i5OX9JSiSsIjWwlYA8dsqkfcu5FaAZLwjHzIQDyLb3ko9v 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)(396003)(376002)(366004)(136003)(346002)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(316002)(66946007)(66556008)(66476007)(6512007)(52116002)(26005)(107886003)(2616005)(478600001)(6486002)(38350700005)(6666004)(1076003)(38100700002)(6506007)(4326008)(8676002)(5660300002)(8936002)(86362001)(2906002)(36756003)(41300700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P/1NsiH6TviywoIjCrjG8bw8IJT4tg0nJo5aobGr1j7n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nBPVr5PlE+uyhGptuJrdPpyhlCD4p5qygGC06fBzbvqrafCIdI8o//wcd5+EBxNP+02DEgj37Urcxo5vt6g7zfGa1AMXbSq9Mqs66X3Bk+w2p9ZS6iyCozRYAdVzS0UZGQXOY/UN+sOt03O21vG2EY5MpdMHB5o9iPC584qwJlQt+l+KA6ehvtHHV7Ff+ypIGWt1h3vMbL6hpFzMHZK9L3QD9VT/GaAJiWw185LAdg6VzwPqX9OqtkcYAOzTQmOKxqhg9dqvok+0ZiqBXvxbPbt+eOiuw6JInazy6LA+0CDJsk5H2WHCdBVbUCFzjJXAeT+Q34NyP5L9Wf0inQeBHLGDn5Umv8fqNZpMSwfFfdqevAdWoXr88yToUw75JVgOH+mvpw1RMzcCliBDwfwFn+hgRiwIsTEQ8SfW9MXiqPgS3F2U+IXxLZn59q+vj6JJkRMAlcq+Ktt7NwvW3n141vc/sW X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30a842d0-506c-4538-7733-08dc1cda0b74 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 12:43:20.2067 (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: GVzCSIJQ9qRWfPR40yaqP9eUTv/GklZU3g4ud8qYeAauq5pwuBzvP1k/IxswsNFlYLA5artqTZaGupGYsRRvDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7030 X-Rspamd-Queue-Id: CDBCF180002 X-Rspam-User: X-Stat-Signature: on9mexf1h6g67kgfq5uscoqkfu4h16g5 X-Rspamd-Server: rspam01 X-HE-Tag: 1706100205-274752 X-HE-Meta: U2FsdGVkX1+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vOsPLjphDuFMplGIChTJNiLs2Nfd4HBUKgAjW+Bq1KwGzCYIn/z1/FwajsGxVYyiS2dEqkH5KNW09qrhyLE7o/UOEIDfNlgdqyDgNyOAQpioAMFnwD9X51cnivFh2STWtn7BJAoJoSvU7McKZRHBSINeEy6tirAIxKEbs+lyKkZwf0PmoP+q8Wu7ZzrJc3mU7dtg7QtqnHbZsd59WxZF7l45KgTyspxYSl/uSvzmsHJ2ezhEJAeBq6URNg== 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 shrinking folio is belong to the exiting task, this folio should be freed in the task exit flow rather than being reclaimed in the shrink flow, because the former takes less time. If the folio which is belong to the exiting task is reclaimed in the shrink flow, such as the anon folio, the anon folio needs to be first written to the swap partition by swap-in in shrink flow, and then the corresponding swap folio needs to be released in the task exiting flow. As is well known, releasing a swap folio will task more time than releasing directly an anon folio. In the scenarios of the low memory system and mutil backed-applications, the time-consuming problem caused by shrinking the exiting task's folios will be more severe. Signed-off-by: Zhiguo Jiang --- include/linux/mm.h | 1 + mm/rmap.c | 12 ++++++++++++ mm/vmscan.c | 4 ++++ 3 files changed, 17 insertions(+) mode change 100644 => 100755 include/linux/mm.h mode change 100644 => 100755 mm/rmap.c diff --git a/include/linux/mm.h b/include/linux/mm.h index 42652bc8ceca..67e84b7d1928 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -312,6 +312,7 @@ extern unsigned int kobjsize(const void *objp); #define VM_HUGEPAGE 0x20000000 /* MADV_HUGEPAGE marked this vma */ #define VM_NOHUGEPAGE 0x40000000 /* MADV_NOHUGEPAGE marked this vma */ #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */ +#define VM_EXITING 0x100000000 /* The task which this vma belongs to is exiting */ #ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS #define VM_HIGH_ARCH_BIT_0 32 /* bit only usable on 64-bit architectures */ diff --git a/mm/rmap.c b/mm/rmap.c index 1cf2bffa48ed..deb419fd095b --- a/mm/rmap.c +++ b/mm/rmap.c @@ -943,6 +943,18 @@ static bool invalid_folio_referenced_vma(struct vm_area_struct *vma, void *arg) if (memcg && !mm_match_cgroup(vma->vm_mm, memcg)) return true; + /* + * Skip counting references of the folios in the exiting task, and + * these folios will be freeed in the task exit flow rather than being + * reclaimed in shrink flow, which is shorter time consumption. + */ + if (likely(vma->vm_mm) && + unlikely(!atomic_read(&vma->vm_mm->mm_users) || + test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags))) { + pra->vm_flags |= VM_EXITING; + return true; + } + return false; } diff --git a/mm/vmscan.c b/mm/vmscan.c index b3ed3c9c3e3d..40ea4128044c 100755 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -887,6 +887,10 @@ static enum folio_references folio_check_references(struct folio *folio, return FOLIOREF_KEEP; } + /* The folio belongs to the exiting task: rotate */ + if (vm_flags & VM_EXITING) + return FOLIOREF_KEEP; + /* Reclaim if clean, defer dirty folios to writeback */ if (referenced_folio && folio_is_file_lru(folio)) return FOLIOREF_RECLAIM_CLEAN;