From patchwork Fri Mar 15 08:18:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5YiY5rW36b6ZKExhb0xpdSk=?= X-Patchwork-Id: 13593158 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 26E8AC54E66 for ; Fri, 15 Mar 2024 08:18:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADE7480104; Fri, 15 Mar 2024 04:18:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8E82800B4; Fri, 15 Mar 2024 04:18:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92E8E80104; Fri, 15 Mar 2024 04:18:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 836DF800B4 for ; Fri, 15 Mar 2024 04:18:25 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 278A91C0B3A for ; Fri, 15 Mar 2024 08:18:25 +0000 (UTC) X-FDA: 81898571370.28.D64B351 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2136.outbound.protection.outlook.com [40.107.117.136]) by imf03.hostedemail.com (Postfix) with ESMTP id E685E20005 for ; Fri, 15 Mar 2024 08:18:21 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b="Wu/A1eRF"; spf=pass (imf03.hostedemail.com: domain of liuhailong@oppo.com designates 40.107.117.136 as permitted sender) smtp.mailfrom=liuhailong@oppo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=oppo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710490702; 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=oSMQ+co08OZP1j4maPyd8Gzb5mLhE6B+G1tb7W0PLYg=; b=PPa0HH4Df6ndi9P8fNWicEw8EqwFWWH/IeGBTON1YJKlsfOJOpNg98WhIE3KftMIMnWTUR x2P4PPoSpG3x0mqwbTgJr+JSZKOzEcg7//oISuLhGON7X3Up27RoCKONA3KOz2cspb/V0H 17FvGIlZw8qK60do92EH4JfY2O5iS4A= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b="Wu/A1eRF"; spf=pass (imf03.hostedemail.com: domain of liuhailong@oppo.com designates 40.107.117.136 as permitted sender) smtp.mailfrom=liuhailong@oppo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=oppo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1710490702; a=rsa-sha256; cv=pass; b=GY1FYXxzK+ZUGTLO8MV6DpGJJEMeJKg1mQLKOHL04H4U4N+veEWJ0VBsST5pJOu+JJppSP O8lAddgOgTNq7qretSGl6EV60HjnvyPr8tl4cgLRtq9WszxlTIo/eaeBYqOFQae2Oxio6l uIlHN4BZsMOEeB9843K2VWUPaT6NzFg= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NYBsrmqH3U4xYncwxcgw8uzIWQEALiT0MhDA3e6tVzlvyL23LZTMVnhgj0UQ6pi0lscgLNich+bWQre9rYw9U53dedKjW3Pf8qVkV8EhlZH/FHyq+NWUZi7dEJW30mTtvoV1DiTsXMwnlGwc/n0/X5xYDfb3+JWrrERv0ytXxcEYqzquwUEXZ8PjbPgJYcTWo5d1W/VRhONjCFlplScyaRkg8duv85YWEqj9ruBjz0QuHJYrRoFaecgioFcRsA2EXzJlwTJKjT76QtKBIbsRaQO7eBGFaMdpXk5HFDNiATwRjfOl3Z57M7gxVctwyiyJEUoVhEqqrLB87ZHZPbICVQ== 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=oSMQ+co08OZP1j4maPyd8Gzb5mLhE6B+G1tb7W0PLYg=; b=PZDdnWNCdxW68AYMb1NacV1/B1vQ106Cc/GBtlLTCgToo00U4n4EvtGtdBj4IsRKSveApgPgMbUG4jHynBQdzY2rxPNLm+D/wnSRIdjGlIF/yzPZ02zJi7D6mnWoGNbjQIRinVEDOdI2uctD/RMTXSLr4e61ohUDItAmuAsVyL8V+7MNsfyn/YYVM6i1lsyh2WB3QwSzrcI/Iw4QVS6SrZoRLx6rvurUSmBpuFPqXE7VcW2NZ+ci73M78KhnBFa2Df3ImPEs5uYAtji+PozGCqdA17Ib2HeW6aqd9ZHMDGdzDHF22+vnV0jYu/b3bUsXKCdK2fIzEH3zKgDBL5CP1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 58.252.5.68) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=oppo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=oppo.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oSMQ+co08OZP1j4maPyd8Gzb5mLhE6B+G1tb7W0PLYg=; b=Wu/A1eRFcAYik9s3+xthcM4oqU3oAhui1lDrSB4tr+iH3zRMSJEQAEnLP4Ef9Uf7A2aKb5AqtTlfI3f3vL67EeZS+1En966PKe49yiRYrXt4SO7eP5K2IfY/Tnbk1dCX0WvLeJf2YVmbgh9KCklWv7kYXXVDXdT+v4N2iHyOLrs= Received: from PS2PR01CA0050.apcprd01.prod.exchangelabs.com (2603:1096:300:57::14) by SEYPR02MB6268.apcprd02.prod.outlook.com (2603:1096:101:d1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.19; Fri, 15 Mar 2024 08:18:17 +0000 Received: from HK3PEPF00000221.apcprd03.prod.outlook.com (2603:1096:300:57:cafe::fa) by PS2PR01CA0050.outlook.office365.com (2603:1096:300:57::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.20 via Frontend Transport; Fri, 15 Mar 2024 08:18:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 58.252.5.68) smtp.mailfrom=oppo.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=oppo.com; Received-SPF: Pass (protection.outlook.com: domain of oppo.com designates 58.252.5.68 as permitted sender) receiver=protection.outlook.com; client-ip=58.252.5.68; helo=mail.oppo.com; pr=C Received: from mail.oppo.com (58.252.5.68) by HK3PEPF00000221.mail.protection.outlook.com (10.167.8.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7386.12 via Frontend Transport; Fri, 15 Mar 2024 08:18:16 +0000 Received: from PH80250894.adc.com (172.16.40.118) by mailappw30.adc.com (172.16.56.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 15 Mar 2024 16:18:12 +0800 From: To: CC: , , , , , , , , , , Hailong.Liu Subject: [PATCH v2] Revert "mm: skip CMA pages when they are not available" Date: Fri, 15 Mar 2024 16:18:03 +0800 Message-ID: <20240315081803.2223-1-liuhailong@oppo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240314141516.31747-1-liuhailong@oppo.com> References: <20240314141516.31747-1-liuhailong@oppo.com> MIME-Version: 1.0 X-Originating-IP: [172.16.40.118] X-ClientProxiedBy: mailappw30.adc.com (172.16.56.197) To mailappw30.adc.com (172.16.56.197) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK3PEPF00000221:EE_|SEYPR02MB6268:EE_ X-MS-Office365-Filtering-Correlation-Id: 37714070-c11a-430d-f806-08dc44c87785 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lE/7HgiZ1CZ6thGpta3dc4DbpPflis2+ARATZOjgWUxxAf+6VuJqfrlhmLb2tMTOPmDlqpKm3kEW/Nj0VEyIGu5budE1PcMKrS49md3QTU+mPf+npmxVtVZn7wpCGtAHTSO1+aIvSTbloPMcjYtgRGD74ZnS0oW7lZLThBD5u/AnspxqnJzXiOMIMw5EgctCIwRmSxNtQHzINEsT0xyuIE9TFZRQeeBM7LfMLzUaPWqtC2sb+63wAUxr1GC2hzavP+S2RI0MMSPpAciU1ca+vmO9l5UkaVSwsQoX2t9nvNnMsFfrBhZdGSY55fPYkYANYax2lxXzhaRdG5Hd1Kw/XY6eV+YxIWfvXAaigpFICAsTIWMddwQa80ACuva64SwBxEWQJ81qXY1SuH8DBdPX7Pouz62FmCUZk6Fg6LQPWChg1PDFs5lCMQISd2ysRLA6ubszZv/5p5pbShnXi3PPHuIl/qEuI84QZD6MvFB+zMz81ep0O5rxlunFwi/0e9Q8myN5mvUw84kx4UEz4ou60X5ZynZ8OLSQqlsN60TvNFQReCDxhS8HrB0BdZgtj0So+ZtTE/lO6vSTvw6Km4kuRT55P1azmCj0uztaLngKMIra121BqaBSiOK8h1mAX3UfETCkrPz/NquQG6K3+d0k4Bn0ztzpAnkz2+4AdEsZKEc79cFdBe2eLBmKK+nf0fVaaOwcCyuwBDXYDTGOFbkPWihMFa6tY0Ty92SEd82eqyX/Ix5JJl32iiIbHq9bhsfF X-Forefront-Antispam-Report: CIP:58.252.5.68;CTRY:CN;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.oppo.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376005)(7416005)(1800799015)(82310400014)(36860700004);DIR:OUT;SFP:1102; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2024 08:18:16.7465 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37714070-c11a-430d-f806-08dc44c87785 X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f1905eb1-c353-41c5-9516-62b4a54b5ee6;Ip=[58.252.5.68];Helo=[mail.oppo.com] X-MS-Exchange-CrossTenant-AuthSource: HK3PEPF00000221.apcprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR02MB6268 X-Rspamd-Queue-Id: E685E20005 X-Rspam-User: X-Stat-Signature: bnigy8r5w9kjr36c8e7pjhzqii4odmob X-Rspamd-Server: rspam01 X-HE-Tag: 1710490701-326277 X-HE-Meta: U2FsdGVkX1/H77BugGgLjkFKkTZbJ6ZPWwD8B6lt4Mcb0gQuvC5PKzqvvR0w2uwJrd/7AJsuCiri1XXdKiC2z0/4T1uyZPe+aP1VdkRFc1p70OaZOLLPRoTfbHHAGqm6eUKhg4aFfEbrYPC1FG16KLTU5KR64NkAhou7XPXkG3UdO1eR/fGdjcJ4kwjqKUZ1V4JEIUsiPd5Xw+XVUfF1XAenGEMeOknsLV2j7Wg/VDAwZ9W2bYO3AI/2nt2EB7/J3J/0uvBRmtYFMruCx8NY1C93N1Q+cqgeiLFHDFK1w1VblIG+dOOpJUyMKP9gNFUz26sEBCYQzbOAwXRzMYSB2WjwDkQzMdARWFY0Q4v82eh8WXujc7QraF9JYo4tZ5vkgv6JAVmqqmwlgUEyo7CBfv5vgvX+zgLTLcKhKDdhjzAjq2+DU/bzBa+IqRIZ641zD1KPzxS8jth3k1F7FloGOoMyi4b46vxPdQEfrJhXU/hGo0oafH2b8+SjcfsCUpSfuYKqd+84CzdQ92KrrbfwUbxiMeLwAv27C78wnuHu1gWirKHgDFBmPS7tOrTHDtbg2XZrXQT3rB6XwmOcQfcxNshrKqHD/+RUm0QhLn2Ji1hj/f2OWPZi+fsJOq0qLcj13xfE5w8cYUc2C7/PZZUK/3ZCQr2B7GgL2ou3am8gEx35OQJ/I4RQ+zWR1Nc0EIMTTBWQYikUvpW4rp7jDDMaE5Ue7JZROBxgNhtUPkprf9QtTtOgaxUgkP42krt8h6sv09361Szk+YhXv/tqXTRM8+ye4T6Ac1sd3CL9CTFyjP46mVmQ1b0ZHo6zOErrNiO5V1biUOaJ18CQtxFeFTWd3032cHuILQiDd9Hljh3/Qzw5BVJ1j8MKZ8wGa9vR4QWcg5/41fME0IQ7lOlwKzCzbjvC16AFcsPyVh3cSFb4SH5wuhEcTJXlfoQBuDmP4QCU40qETZm9qyOWTpdQQX1 fbQ== 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: From: "Hailong.Liu" This reverts commit b7108d66318a ("Multi-gen LRU: skip CMA pages when they are not eligible") commit 5da226dbfce3 ("mm: skip CMA pages when they are not available") skip_cma may cause system not responding. if cma pages is large in lru_list and system is in lowmemory, many tasks would direct reclaim and waste cpu time to isolate_lru_pages and return. Test this patch on android-5.15 8G device reproducer: - cma_declare_contiguous 3G pages - set /proc/sys/vm/swappiness 0 to enable direct_reclaim reclaim file only. - run a memleak process in userspace trace the trace_mm_vmscan_lru_isolate which get [ 1178.059160] 2825 3405 I UsbFfs-worker : isolate_lru_pages:1895 total_scan: 24385 skipped: 24382 [ 1178.059699] 2825 3405 I UsbFfs-worker : isolate_lru_pages:1895 total_scan: 24412 skipped: 24401 [ 1178.061747] 2825 3405 I UsbFfs-worker : isolate_lru_pages:1895 total_scan: 24412 skipped: 24401 From the log, tasks is waste time to scan lru list and call stack as below. Task name: UsbFfs-worker [affinity: 0xff] pid: 3374 cpu: 7 prio: 120 start: ffffff8897a35c80 state: 0x0[R] exit_state: 0x0 stack base: 0xffffffc01eaa0000 Last_enqueued_ts: 0.000000000 Last_sleep_ts: 0.000000000 Stack: [] __switch_to+0x180 [] __schedule+0x4dc [] preempt_schedule+0x5c [] _raw_spin_unlock_irq+0x54 [] shrink_inactive_list+0x1d0 [] shrink_lruvec+0x1bc [] shrink_node_memcgs+0x184 [] shrink_node+0x2d0 [] shrink_zones+0x14c [] do_try_to_free_pages+0xe8 [] try_to_free_pages+0x2e0 [] __alloc_pages_direct_reclaim+0x84 [] __alloc_pages_slowpath+0x4d0 [] __alloc_pages_nodemask[jt]+0x124 [] __vmalloc_area_node+0x188 [] __vmalloc_node+0x148 [] vmalloc+0x4c [] ffs_epfile_io+0x258 [] kretprobe_trampoline[jt]+0x0 [] kretprobe_trampoline[jt]+0x0 [] __io_submit_one+0x1c0 [] io_submit_one+0x88 [] __do_sys_io_submit+0x178 [] __arm64_sys_io_submit+0x20 [] el0_svc_common.llvm.9961749221945255377+0xd0 [] do_el0_svc+0x28 [] el0_svc+0x14 [] el0_sync_handler+0x88 [] el0_sync+0x1b8 Task name: kthreadd [affinity: 0xff] pid: 2 cpu: 7 prio: 120 start: ffffff87808c0000 state: 0x0[R] exit_state: 0x0 stack base: 0xffffffc008078000 Last_enqueued_ts: 0.000000000 Last_sleep_ts: 0.000000000 Stack: [] __switch_to+0x180 [] __schedule+0x4dc [] preempt_schedule+0x5c [] _raw_spin_unlock_irq+0x54 [] shrink_inactive_list+0x2cc [] shrink_lruvec+0x1bc [] shrink_node_memcgs+0x184 [] shrink_node+0x2d0 [] shrink_zones+0x14c [] do_try_to_free_pages+0xe8 [] try_to_free_pages+0x2e0 [] __alloc_pages_direct_reclaim+0x84 [] __alloc_pages_slowpath+0x4d0 [] __alloc_pages_nodemask[jt]+0x124 [] __vmalloc_area_node+0x188 [] __vmalloc_node_range+0x88 [] scs_alloc+0x1b8 [] scs_prepare+0x20 [] dup_task_struct+0xd4 [] copy_process+0x144 [] kernel_clone+0xb4 [] kernel_thread+0x5c [] kthreadd+0x184 Signed-off-by: Hailong.Liu --- mm/vmscan.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) -- Changes in v2: - add reproducer - fix build error on v6.6-rc7 diff --git a/mm/vmscan.c b/mm/vmscan.c index 6f13394b112e..29306c29309f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2261,25 +2261,6 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec, } -#ifdef CONFIG_CMA -/* - * It is waste of effort to scan and reclaim CMA pages if it is not available - * for current allocation context. Kswapd can not be enrolled as it can not - * distinguish this scenario by using sc->gfp_mask = GFP_KERNEL - */ -static bool skip_cma(struct folio *folio, struct scan_control *sc) -{ - return !current_is_kswapd() && - gfp_migratetype(sc->gfp_mask) != MIGRATE_MOVABLE && - get_pageblock_migratetype(&folio->page) == MIGRATE_CMA; -} -#else -static bool skip_cma(struct folio *folio, struct scan_control *sc) -{ - return false; -} -#endif - /* * Isolating page from the lruvec to fill in @dst list by nr_to_scan times. * @@ -2326,8 +2307,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages = folio_nr_pages(folio); total_scan += nr_pages; - if (folio_zonenum(folio) > sc->reclaim_idx || - skip_cma(folio, sc)) { + if (folio_zonenum(folio) > sc->reclaim_idx) { nr_skipped[folio_zonenum(folio)] += nr_pages; move_to = &folios_skipped; goto move; @@ -4945,7 +4925,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c } /* ineligible */ - if (zone > sc->reclaim_idx || skip_cma(folio, sc)) { + if (zone > sc->reclaim_idx) { gen = folio_inc_gen(lruvec, folio, false); list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]); return true;