Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp76689rdb; Sun, 21 Jan 2024 18:23:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmxZakWf2Z6i+071YCX2I2CdDBAmvVnhV5bDJU4YGXlUpizdg0hbtKKqJXebA3vf/3idUp X-Received: by 2002:a05:6830:329a:b0:6dd:de9c:98e3 with SMTP id m26-20020a056830329a00b006ddde9c98e3mr1211171ott.19.1705890224805; Sun, 21 Jan 2024 18:23:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705890224; cv=pass; d=google.com; s=arc-20160816; b=SVO5h89mXg03TvllZOzqK0NnJpa841pWbdC8t9HP54YqetsIE9BPBFSiXdo+KLNzMN LHwjXhMUIesOA/Qk4KlIVCuJ+KBg5aO4yfzv1D4m33LxFw3ErPjvOx63rM3F/8hO/sbo NNEM+Y1midlQvzNcZ8ngwC69p5BUoa0xM9hlGBH7oxrD/Dj82HqVRm0siiJTlgujVWHu eWBGliGiiRaMUx+nFVwwZ0vLGTglMPiQV2ka1SwE1Ryu+5TIqRSguFEvXZK8v1qFvfD3 GKSKyJVUZAPYExJTQqHcxFZDJZBr/7prcZe3FtVbexegTJrBvd9CjReo1BCm/mTah3mJ 6lTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=bRxKAlBcxk+wjGn9fgIoumEgOFMc9m85oqcebArTOQs=; fh=4IUdWNFckj+g3aFcQO9eAn6t/FYPHUITNMlq5vMVJCg=; b=mzy1ulPLJT4p2PokxKUqIQiJ2SWOjBOTpGHavYJmKQAH+p4WuJiD7sSTHMf2puW19F /VIk4aZZITg2p5cJvEqyeG8NdLTA3ze7RZ6h0nMcrLtY2udp5jt99nXI9aSIr6hZGZam wVYiT2AOtdgfeHioO2AHFZzBw0bNjYHrRKi9GYEBGn1WycbzOxnjTwrWDR1Xrq9+c4EF XAm/6vAYf76Od4DkOzuLTO95RmdpSJNrcEWRsVSn8NqaAO+CoG+FVXnlm5PdF5OLEtej Yh8kHZo4jg/tgGIu0tIqnSrp1jldrVTyz5QNZ6by3QAgxDoI0SJ15C3aGnkaQVEIZ5zO qjCg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="Ogz9f/Wn"; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-32276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m13-20020a633f0d000000b005cfbedffb54si3461548pga.128.2024.01.21.18.23.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 18:23:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="Ogz9f/Wn"; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-32276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7004E282444 for ; Mon, 22 Jan 2024 02:23:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E4F04C9A; Mon, 22 Jan 2024 02:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Ogz9f/Wn" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAE664C87 for ; Mon, 22 Jan 2024 02:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705890218; cv=none; b=m+ejXRxbnQZhUglMocSYvfnL0urIg8UxMJrXbesHfodVWAJy80X5UMPa4Ha/jAJfjvuY9EeWJfLp/T83FmY62hr/vp/W/jWUR0ifY3PiFcQ5tMVCeW9chUNDRLGCVugqvX26ud1uGkYKnuX+1PD9JR+v96JAakTk/BaoL2/uc+E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705890218; c=relaxed/simple; bh=SrjGkBt4ws/L7TjHduCftjvbL8f6eEJFzr2T3hjmFk0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=MCYTYSDUkog4pezyQQ8q/eV7TZnl9ZTucw3WDxQEyOmnlvfpjo09c2JeCWId3pjTTuy8FL+gOXpK1AzpnMnGImef/d4XDaMm1fR2CdRBQct9vz/Mr5dzp+9rF8XIKeFKA2HNqQvDEkiD0uDk6W9WKrah5OqmgqetBnn+2mfVwJk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=Ogz9f/Wn; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 3723d14eb8cd11ee9e680517dc993faa-20240122 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=bRxKAlBcxk+wjGn9fgIoumEgOFMc9m85oqcebArTOQs=; b=Ogz9f/WnjJkKND+iWq8RxdlEuTaMO/8DZT2p/bxdhTQawN9iZUfIPI7Rtl+KO1Ea+oyyJzZ1liRc0J35skL0Fm0ewaq6T5bqpdWGO6vNXO/7VaxA+1m3qPOci+Fo8pwhYZr8FIf1tkYunr8Uj9oPF+iwbaZK9OI1X9pO3x0D/1A=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:ccd3e91b-b6a8-44eb-a738-2a7388ec1eae,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:6e16cf4,CLOUDID:6af17f8e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES :1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: 3723d14eb8cd11ee9e680517dc993faa-20240122 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1256969273; Mon, 22 Jan 2024 10:23:22 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Mon, 22 Jan 2024 10:23:21 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Mon, 22 Jan 2024 10:23:20 +0800 From: Haiqiang Gong To: CC: , , Andrew Morton , Matthias Brugger , AngeloGioacchino Del Regno , , , , Haiqiang Gong Subject: [PATCH] mm/compaction: add check mechanism to avoid cma alloc fail Date: Mon, 22 Jan 2024 10:23:17 +0800 Message-ID: <20240122022317.30091-1-Haiqiang.Gong@mediatek.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--8.251100-8.000000 X-TMASE-MatchedRID: riRbj5ZX+8qJ+w2BcN2shkZakoam9+aeKFFZAe4nyZ6M2ehTV+imi/+i UQ058Mu6pSxgXQCmVD5G77nj4gxZpFXkr5xNB8EcyeVujmXuYYUzTWEsGiZW/N9RlPzeVuQQMSu S6JxBG64Cym2hDB78TgykqSdZGSoeZMLMXtQ7bzGJLx4p0P/u5AYX4TqbN42omyiLZetSf8mfop 0ytGwvXiq2rl3dzGQ1ropAi/FV10xvOMKV9GJxgt1zlJ6cDFtyq0Ik/XvnkHxi4XnZ0i355d/T4 9kdKys+ X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--8.251100-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: AC853335170166E5CE942A0222C21DE05826A344C137900CD90F48576EEBCC162000:8 cma alloc may fail when we doing cma alloc/free test on kernel 5.10/5.15. We found that the next memory cannot be migrated because of the alloc of fs as next backtrace: __alloc_pages_nodemask pagecache_get_page grow_dev_page __getblk_gfp ext4_sb_breadahead_unmovable __ext4_get_inode_loc __ext4_iget ext4_lookup __lookup_slow walk_component path_lookupat filename_lookup vfs_statx This kind of unmovable memory is not placed in the cma buffer when kernel memory alloc but is migrated in by kcompactd when the kernel migration. It will cause memory can't be migrate when cma alloc. Add check mechanism in the compaction_alloc() where kcompaced alloc for memory. Will return NULL and give up this memory migration if the allocated memory is in the cma buffer and the memory is unmovable. Signed-off-by: Haiqiang Gong --- mm/compaction.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 27ada42924d5..29c0661adc22 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -25,6 +25,11 @@ #include #include "internal.h" +#ifdef CONFIG_CMA +#include +#include "cma.h" +#endif + #ifdef CONFIG_COMPACTION /* * Fragmentation score check interval for proactive compaction purposes. @@ -1758,6 +1763,33 @@ static void isolate_freepages(struct compact_control *cc) split_map_pages(freelist); } +#ifdef CONFIG_CMA +static bool is_in_cma_range(struct folio *folio) +{ + int i; + unsigned long pfn = 0; + struct page *page = folio_page(folio, 0); + + pfn = page_to_pfn(page); + for (i = 0; i < cma_area_count; i++) { + struct cma *cma = &cma_areas[i]; + + if (cma->base_pfn <= pfn && (cma->base_pfn + cma->count) > pfn) + return true; + } + + return false; +} + +static bool forbid_move_to_cma_range(struct folio *src, struct folio *dst) +{ + if (folio_mapping(src) && is_in_cma_range(dst)) + return true; + + return false; +} +#endif + /* * This is a migrate-callback that "allocates" freepages by taking pages * from the isolated freelists in the block we are migrating to. @@ -1775,6 +1807,12 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) } dst = list_entry(cc->freepages.next, struct folio, lru); +#ifdef CONFIG_CMA + if (forbid_move_to_cma_range(src, dst)) { + pr_notice("kcompactd: could not move non-cma memory to cma buffer\n"); + return NULL; + } +#endif list_del(&dst->lru); cc->nr_freepages--; -- 2.25.1