From patchwork Mon May 22 03:08:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13249702 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 E71E9C77B73 for ; Mon, 22 May 2023 03:09:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DD486B0078; Sun, 21 May 2023 23:09:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78D376B007B; Sun, 21 May 2023 23:09:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6555E6B007D; Sun, 21 May 2023 23:09:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 51D566B0078 for ; Sun, 21 May 2023 23:09:29 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 24FDC1C7285 for ; Mon, 22 May 2023 03:09:29 +0000 (UTC) X-FDA: 80816410458.24.2984C81 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf25.hostedemail.com (Postfix) with ESMTP id AD636A000C for ; Mon, 22 May 2023 03:09:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684724967; 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=9ef8IWbsTzQd6iJLYMSHvl0dWoT/0VDQMvMcty640j4=; b=msm5a8mVv9bxjLkD8JFDO2gKEw++/bq7gDbb6dR96RxuvXdVzkvA7XbAM7fioSL7QJaPwC gBPRxAY6uVEH0CSFpuQXanAotO8DKPRtX5eUBpIO+cMzzM5sBvXoYgLNhEqjV55pgYIRCy sbVy90iTGR2ghvPmEUH/w6OF8MIkZL8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684724967; a=rsa-sha256; cv=none; b=dA/KeLuvoNmP5Dm6M9djh5N6GM5Mexm+N7nsAz/2T1A3MIrOWi1To0nWBSwYdTBK1O24UM YRQW2wyv8SQKRdNqlxemkbFMy+G6QD+SPeTTzRoqFt1H6CzfeyDBSmzZ897QGZKkehP8LV SuO61tLTi8Lj2FDWwbVip4gWPwRXlak= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 34M38SV7079848; Mon, 22 May 2023 11:08:28 +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 11:08:23 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Minchan Kim , Joonsoo Kim , , , Zhaoyang Huang , Subject: [PATCHv3] mm: skip CMA pages when they are not available Date: Mon, 22 May 2023 11:08:02 +0800 Message-ID: <1684724882-22266-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: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 34M38SV7079848 X-Rspamd-Queue-Id: AD636A000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: a8n8yhzkx1df3oc7igka5gr4hfpuabtt X-HE-Tag: 1684724966-502681 X-HE-Meta: U2FsdGVkX18TK7+MdSMkSsRu4/IUGH3UnP/qCGV223o3/DRSC1xALdK2SO3pU7QIav+u4K/N51KIJ5CBGs2u7Q03UajgfXJP0mKtgxK/uO2XvDH7a+fo0er2cgY9frzY4ViFD7zRSKEkQXXDSgaoOFmwP6zxedxswdQXBOl13jIW+0aFNvoD7hcZNqd2JwU12W89mqj0F0tsV9qAAmKVfQIpra+FeQdM+VV90qy7roeAL4npE0qW2jicEoNKs+9ywi+x9XUssc3Lu8eTkHas4ICog2rjsSx4K447ff/YcH2MhOVMFVEw/v+Ohx2lQ/fviiZWm4Ut3kmBO2dX+T/KGWb2wp2RC2ZVGJO11RtoNYEBE9W8xdsMXFmhvrySYd7lXwt+rvESJsWlBtetfpPfLpY8DDUuSAax+EohyZN3ZtW/2gR+OxzsrNFp6M0wfC5QKkvqbNksxKhF0bqsoVSrkrlrOyIFyt+bQ4I/EIIFVFbrsFhcqtKFzJxuOPcL+12m/NbnzRtxvfohYJ4UVCKzpFuajDes2O28CcEvo5WppxGb2hJe5mVgi+7gLzJCgNMsodbLAu0klxnowJDIpnrIx7bAjfCl9ayD0ppb6Ganbvwcm0C3RgexBp49cQwEmTK6gx34MHkc85S31HBPUCk7pbWGtL5lxWYb53s9C1B0hqVqM/yGafHhdzJuoEQiKG505RKgjWozA5OTNDo6Sq+NfXX7w9YeCP9GhSOSouf9PHlKBaWsew3pb5DqnxLr/zT9msTerJP8UkSkhKG73U6mRhuQ2W+rJxQEyifYL1DBt4UKYHRbP2XavDlRsdT4Sf58sDDp7swNH0LlZ5N9LFfvNP+8h9ejGeW/g7sfmaQk+0AC0ZVtxZLNLuqG0C3BkZXVEsg0C3Zq3W/XDp5c+/6daGW3h1Lp8V8lIViW+1a8uvCej993mL9rsaHBJ3+Si3QL6x/YGWFZQMccLvCx8fC E1+WFdTG BETH9bgRg1NfyeQx4Xfm/cqOBalDwJlGVZ62s6V3rNFNwD+TUcRp+Ls3N2l2Ui3Z0p6UKyHE+7Arrct8Jt2XTVCcw45orOc+pf4M1sKk1+yZmTVSn3ikYh8O+ws+d4FTnNdp8p21IMZ8dPWuV4RkiU13JPO/kZ/wcjVwD8/M/5VmU9v8WceXIXNMoGu+oqVmFPyQNCFB9pcj0K7XEQbaGON0bvsmVv12K/P6f6xgAOPxgjHry1fzW2bXcA3J0iseXYnMwP0lUXhxj+p0tbNT7O3F4mChCPu7e7vI4zsKlIxSxoGI6rSlRelzOIg== 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: update code and comments --- --- mm/vmscan.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index bd6637f..17cd246 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2192,7 +2192,24 @@ 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 page *page, struct scan_control *sc) +{ + if (!current_is_kswapd() && gfp_migratetype(sc->gfp_mask) != MIGRATE_MOVABLE + && get_pageblock_migratetype(page) == MIGRATE_CMA) + return true; + return false; +} +#else +static bool skip_cma(struct page *page, struct scan_control *sc) +{ + return false; +} +#endif /* * Isolating page from the lruvec to fill in @dst list by nr_to_scan times. * @@ -2225,10 +2242,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, unsigned long nr_skipped[MAX_NR_ZONES] = { 0, }; unsigned long skipped = 0; unsigned long scan, total_scan, nr_pages; + struct page *page; LIST_HEAD(folios_skipped); total_scan = 0; scan = 0; + while (scan < nr_to_scan && !list_empty(src)) { struct list_head *move_to = src; struct folio *folio; @@ -2239,12 +2258,14 @@ 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) { + page = &folio->page; + + if (folio_zonenum(folio) > sc->reclaim_idx + || skip_cma(page, sc)) { nr_skipped[folio_zonenum(folio)] += nr_pages; move_to = &folios_skipped; goto move; } - /* * Do not count skipped folios because that makes the function * return with no isolated folios if the LRU mostly contains