From patchwork Wed May 31 02:51:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13261376 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 937F8C7EE23 for ; Wed, 31 May 2023 02:52:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED9E66B0072; Tue, 30 May 2023 22:52:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8ADC6B0074; Tue, 30 May 2023 22:52:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D791B900002; Tue, 30 May 2023 22:52:25 -0400 (EDT) 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 C5B076B0072 for ; Tue, 30 May 2023 22:52:25 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9CAB5C0119 for ; Wed, 31 May 2023 02:52:25 +0000 (UTC) X-FDA: 80849026650.22.24C270A Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf19.hostedemail.com (Postfix) with ESMTP id E903E1A0010 for ; Wed, 31 May 2023 02:52:22 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.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=1685501544; 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=Pkowbzu515VH0pmVZMYvL4Jy01BG+dEuKfpwmWV/5/A=; b=61vXnr8TT4nzTZ5wrCm9uBxmXuwqP5hTrx06OVmjJalnzkVe9hOLrh0xj5WmydyiqiHqiQ tyo2sCEzqu90F3rUOj2xbX3+2QOo+JJHMcLB/pPNy6MJFiF2EHGi2qNt6McOfaFk4wK7vL BLju916jigrAHwJJqNUGba8rpq1aqyg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.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=1685501544; a=rsa-sha256; cv=none; b=0EWAmqEdIU+kP6yu3BhfSjK0D9V+ds52k5bGrwvg0n4zxk8rK/0NBX4YJ7y3s//iOuYFH5 30ocPp0NROLKDF3tS18Fm2TZNekVof0wqHwDBu+14/bPy1R2uHChcmYgxrJAcSXMrYcbat KZn6Hyak7stUJ+Ua+TxrqMSVKe06p/c= Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 34V2pM9k099530; Wed, 31 May 2023 10:51:22 +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; Wed, 31 May 2023 10:51:17 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Suren Baghdasaryan , Minchan Kim , , , Zhaoyang Huang , Subject: [PATCHv5] mm: skip CMA pages when they are not available Date: Wed, 31 May 2023 10:51:01 +0800 Message-ID: <1685501461-19290-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 34V2pM9k099530 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E903E1A0010 X-Stat-Signature: mhhbdhmd4nt19bndnr5zkcufcarqezt8 X-Rspam-User: X-HE-Tag: 1685501542-788105 X-HE-Meta: U2FsdGVkX19afQGkxM+k/Rc9w9yiDh4glO6lOL0Lr2CbfRm5qjQNb708zwZSaQSaufTSwVnIQSVLfF0xEM3fh59OlKfe9ACsZlY2RuZXcKfG3J73xPPJkZbjGCXj4TMdDOumQ8aWg2j0fk7j3SJxOMCadHZ4oP7l1B0wjY7ExmtDOW/JyOzG7Bl9xw2QuYNp4zydHWnnTyhKyPuU81SmyopQnC8MD7se3ApSddm3TTF8DpXqxuGttyrGhKFBQtGncx4P2orxNee5MZ5PeuN8Ko2wf8tM5Str70mSfrGGR1838erMiQuj4ahFy4CRFsFtNwCA1PU0CTFazXJbhCj80qa+fn/U1nNdIeNxT15YPPhTmeSWSClV6gip6BTr3ELk0WH2UnzbBL0d0Cl9rtJMZBHNc0uOt59+s6PDjMds/8kM13ENhMvRzWlFI9TKHB31n8TTnWYFK/S0caapiqbvmXzSCEmomUoLsORvF1hXJ7wrEtYG7vNvob6A1kVJ3W6QBaFNOb/o95QQTPEhFjeDk8kwUYlzbr73SwADhnm1Ikww2fAmj9HbgRqD8OjDuRKvYaMLebCuaXt4cWQixQWkm4y4BhI9UMexZwsp6HbpvyEJF+MVoTT2O19pdGLh63cJCuHwbsqmh6SUVHUOdrA/6oqrCSxEnUUYFv7n3MAaxDS2CZXndQeWgxYebDFS7GZJbfcad+CdHlXvS/xICDm+OcL0UvxGjinEdLUBKelu2K9BONjOS38bO2V2aRJGbJtcPfrA5vBWB1P20LoksPLYOUCYCD8iEqgCczw4jfAzO/AtmLf4JAdEk3V88G18HYuJTBYrJvIdHbUW3I2rwggt1y+3tID23N80jvfHMQu5VpISTmRT/3ciGdad9MEZZeMEkvfMeoSkObRPW7WIkua8nK3Yd4cS+vGtDkRDwSnrLNpKj/h+9gL8ZN9p786lzRcE0fTxc36rYQdd+aYHUln j1mB42p2 9hSsOd2neBp+vr++kBE6Q5Db46bmAlQCz+yfmKn7STDTCxJeUXo4YhdALHUY8pEPI6voD3Uu2PZUY9iT4ePRAowZbsVQSheHVV9RpXNltTzMk0gAZsCieWHnzGDgOqU1Mu9FqM/TdOyWoUA8VMiyU5J14+roQVr+VmJHv/BbbyVZ84n/Rd+kJ8LjGDDZ+bXZtQ9GIBjkaBwhrMbpsN5IaYm8w6eMXEBlXt1K2X0vi57wWKR0HmhvUBHijZZ5y8o8H+iFUERweYOTr0FRhIeWPNmVWNowAJ/3DCVAlgrHLG7Nk6ROvKrF89S/Eng== 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 Acked-by: David Hildenbrand --- v2: update commit message and fix build error when CONFIG_CMA is not set v3,v4,v5: update code and comments --- --- mm/vmscan.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index bd6637f..972a54d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2193,6 +2193,25 @@ 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. * @@ -2239,7 +2258,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;