From patchwork Mon May 22 06:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13249814 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 03BF3C7EE23 for ; Mon, 22 May 2023 06:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AAD4900003; Mon, 22 May 2023 02:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 631F8900002; Mon, 22 May 2023 02:37:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FA67900003; Mon, 22 May 2023 02:37:11 -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 3D1A4900002 for ; Mon, 22 May 2023 02:37:11 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 089281A0C85 for ; Mon, 22 May 2023 06:37:11 +0000 (UTC) X-FDA: 80816933862.08.D80E525 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf08.hostedemail.com (Postfix) with ESMTP id 8437C160015 for ; Mon, 22 May 2023 06:37:08 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684737429; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=e7R5jz/aRvqKC7RiwV479vXV806WYI8sbWwI9oXOUJI=; b=1ObYG1S8+zt97D+FJKOkZozv5bZIDEkgE3F0cMLIjVkQgR5n4vN3MapyxRpSKCOp4il/wn Cxf63RONd9Bww8BkOe0l5VZNBTrQAKcYhj+xCetu8sVeIfM01neCHGfjXU4sP88f3AeWaX OdSddYgtouu2NAENrW2RugaBufj9vPE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684737429; a=rsa-sha256; cv=none; b=KzmxOZAAiPbKaEigUD9+0gchdvBPtI25zNRpfGlIq4kjUIeLnJVKqhl2tITUeuI8Dto2ml 4O1QrlpgZ+Tpaz0epWNV4QKnrN1+Ia6allGBD/B8pPeAJDJ1H8F/aQF8I0KqHWsHNYlxnY CEbrEWzMJyOBkSyFXC0ErBgkhZkvcR0= Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 34M6aJ7n021937; Mon, 22 May 2023 14:36:19 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.73.76) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 22 May 2023 14:36:18 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Minchan Kim , Joonsoo Kim , , , Zhaoyang Huang , Subject: [PATCHv4] mm: skip CMA pages when they are not available Date: Mon, 22 May 2023 14:36:03 +0800 Message-ID: <1684737363-31554-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.76] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 34M6aJ7n021937 X-Rspamd-Queue-Id: 8437C160015 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: io3yup94ysj1pp8aooaumk8o9tjtnh67 X-HE-Tag: 1684737428-768236 X-HE-Meta: U2FsdGVkX1/OwR7ODNzIdQ8t9DwJADIQUdrcjaJeBtOXCUOQAFw1sEIXFwqfZClJ5v3zQBG9aERIKRGlYvE2Yavrgq/3q62KJahUN3CNSLP2E//7qzenK0NC6EtfVLdEhKqWniP9qT5RYLHDbPqk/Mkr9P8RRZO38bvcYuqeYV9P9lb3lwZgHKrmt3n1cLJ4x8tMW+ezt4srGxxJQ8JnuJwygO3sov6spzfQjkZp75buE+zG5jchXRCjbolVc9/6YZALgryukdkabReB04/HUONtvMULmMeluEQXT8ZfxxL5vN+zzLVWYEwukcgr5ZwZ11ty7V9Om5fcFXsMg03QjWc4xCiEbLRiIBmWF+8OOQO6lEiayknWgHhu2i/vssuSIQ7T1REVEOs9ECNkCh5HdHPUy2eROpmWOHDxCRJOVaz+uDRrZj7RSuOBVFez1HY/mfUqnUI4QsLWVLTz86dmQkA479Ss6rcM6pLdPNzTV5fEi7wq6LEdmvRAKnKT0+QJMTgH9yVlkXFZP66MvvetGb3DpkMWkpgz1ANo4R1i/ndR3r/zogY4Fnc5vtLfp/jRtYPcgNUZ9tYlE6Ikw1fJ5m+RDQghcsQ5QZVKSMaJNykqV7n+2ZT7YWB2qROs1NOndaAheboBPSM6HAwPsFF3PXixHO29Zv/oBpDmbJP0f9p+2pvLWXCir/MKJcIsOQ+cDL1jK9bhRt6SIZqR41gWYs1NsVr/MxjVG18MPbR0uIc3ODd5aSl8JKdKiVeWeZcPqYc/wn5W/wCZGtRTDZRSpp99WENTYfatJDZqgFbgdUNdmLfeUYsl4z0bZZAfx7FDbVy9Omqj8lTzhfmT/DDvz3zVB1JgT6elxLsQMKkGra2LKaTVjXx5lh+8hlycogkZbtNty4Uu86Guz1DIXKJozpDaif2h9mSo/nxp7l7IWTEGsHdF6dJg3NkSRoQ7zcISD9kV/F5nLCq5wxmzqD0 z1qy92bC 5S4DN67XQPuIrsKEZov29JlvPmp/8qht4fyeIjO0f3mkSo/LplAKSfNNQV4uXAUt/OW66I+ujZYWdvD7Qq2gKIGIJpZrIunaHlpW2a2otjmWZxVL+oL6ifaz1FPLWABFD0r1+eicjpMFUR8BscN8zHrOU2dNdhf5sh8v6NUauymqhjuH1wQVngJrb/bQ90RxhqIL666D7EHsq+N3wuK09fNVkqifjIHtNUbfZpTSoFc+NFp8T2XF5pgRmknfYh5epyXRA 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: From: Zhaoyang Huang This patch fixes unproductive reclaiming of CMA pages by skipping them when they are not available for current context. It is arise from bellowing OOM issue, which caused by large proportion of MIGRATE_CMA pages among free pages. [ 36.172486] [03-19 10:05:52.172] ActivityManager: page allocation failure: order:0, mode:0xc00(GFP_NOIO), nodemask=(null),cpuset=foreground,mems_allowed=0 [ 36.189447] [03-19 10:05:52.189] DMA32: 0*4kB 447*8kB (C) 217*16kB (C) 124*32kB (C) 136*64kB (C) 70*128kB (C) 22*256kB (C) 3*512kB (C) 0*1024kB 0*2048kB 0*4096kB = 35848kB [ 36.193125] [03-19 10:05:52.193] Normal: 231*4kB (UMEH) 49*8kB (MEH) 14*16kB (H) 13*32kB (H) 8*64kB (H) 2*128kB (H) 0*256kB 1*512kB (H) 0*1024kB 0*2048kB 0*4096kB = 3236kB ... [ 36.234447] [03-19 10:05:52.234] SLUB: Unable to allocate memory on node -1, gfp=0xa20(GFP_ATOMIC) [ 36.234455] [03-19 10:05:52.234] cache: ext4_io_end, object size: 64, buffer size: 64, default order: 0, min order: 0 [ 36.234459] [03-19 10:05:52.234] node 0: slabs: 53,objs: 3392, free: 0 Signed-off-by: Zhaoyang Huang --- v2: update commit message and fix build error when CONFIG_CMA is not set v3,v4: update code and comments --- --- mm/vmscan.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index bd6637f..20facec 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2193,6 +2193,26 @@ 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 + */ +static bool skip_cma(struct folio *folio, struct scan_control *sc) +{ + if (!current_is_kswapd() && + gfp_migratetype(sc->gfp_mask) != MIGRATE_MOVABLE && + get_pageblock_migratetype(&folio->page) == MIGRATE_CMA) + return true; + return false; +} +#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. * @@ -2239,7 +2259,8 @@ 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) { + if (folio_zonenum(folio) > sc->reclaim_idx || + skip_cma(folio, sc)) { nr_skipped[folio_zonenum(folio)] += nr_pages; move_to = &folios_skipped; goto move;