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: 101198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2609694vqr; Tue, 30 May 2023 20:20:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GPhIDXfJiJD5MAUR3dlKlr3pn5OpHYrCqF7Bof4s7a6e2ZgbgRXqAbize7oSZP4ENeYGO X-Received: by 2002:a05:620a:2cc5:b0:75b:23a0:de8d with SMTP id tc5-20020a05620a2cc500b0075b23a0de8dmr4140534qkn.11.1685503202839; Tue, 30 May 2023 20:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685503202; cv=none; d=google.com; s=arc-20160816; b=WtuaCRu94+rPEslHIyCb+Qb0AF/pHUIigsL2+G/jqx0U2TitDP3gFnJWwB8A9K63v+ hKisjsLyuMqjZzIOyLPNXV2aVR9h9HBSZv6qwzMCLyBoXT0gqTgLKNU49bicMLvolYiV JTLpflmQzqUonk/6yhUKuG37ccVkIMhS29g5dAqya6E5RrrB2UBN4HVIMCVxBkCEl8Uo YjdeFUjzsAhEumBdp+3uw73sojhqHUnbaelSnIELoAyFPhgIHgXwlawau8WKioqn+deZ 6jcoF2HerIJ+zHLIERak/N8qXQRhs5UTkv+lBeae6OIaVmhOCkHAx8okg1oJ/nTKO7iZ /LCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=Pkowbzu515VH0pmVZMYvL4Jy01BG+dEuKfpwmWV/5/A=; b=g0m+EGMm70PqneB3GGOVjw/txYrpKb/ayFC/GyZUFqTeiNgW9J3RPFX6KpSoke4OAS cLvoHVytoN+OuKUssLZiejxhGzei4X0PKNXFCaud1jb3AN8AVJiOL8ANw0bVj9DhwgsI 8vYKtqwbb2wypAk7qHZR6yRead4DksFXVv35sVn6A/LG6tN3mDCy3T7mzlGGShiPMeYY T2IYGR12pqObwdVosiqzVUcHmMEPkfhk0JU0dYJ4u+dnJecpXWmd8WNmwc570Ro1IM36 lXYOcQKdi/Wn5MIhLHJnOg/QIVl4FuEssypRxCM2HMIRJPixHRIHWz1up/DIi3ztmCb8 KZ0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z19-20020a63e113000000b0051b749eb332si223125pgh.248.2023.05.30.20.19.48; Tue, 30 May 2023 20:20:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233945AbjEaCwf (ORCPT + 99 others); Tue, 30 May 2023 22:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbjEaCwe (ORCPT ); Tue, 30 May 2023 22:52:34 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62A67D9 for ; Tue, 30 May 2023 19:52:30 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767378206129944087?= X-GMAIL-MSGID: =?utf-8?q?1767378206129944087?= 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;