From patchwork Wed Jan 12 13:15:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 532646 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0971BC4332F for ; Wed, 12 Jan 2022 13:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353468AbiALNRb (ORCPT ); Wed, 12 Jan 2022 08:17:31 -0500 Received: from mail-eopbgr30042.outbound.protection.outlook.com ([40.107.3.42]:1344 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353461AbiALNR3 (ORCPT ); Wed, 12 Jan 2022 08:17:29 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YYWWC2YRWo+kkKTptcmalqZo07vBMbbklssOQ4uxJNL8MiZ+tH7XsCEMm3HlKUBu2kc5tAy5WdJTvNVRvs1/KWYldeSwsw3iwL8Lz2B6xt7ITuTI2KhOp+rfmhKE78V7ZFT9D8te3e1GsCT2SuGSzCJuYrf4SyCtWb5RPKdxsKkXBVvX7j0v3neTOOI1uURGYZAPJfgE07sh5iocbLaGd3OwbfZnEisPoGth+hBiq7EBmNekkOADGVg9uBBvfjaz6AOiKZc2H3TK1GMTq5ECCvuWfBEhvmznINkvqq2z7fb/w6b2uujbGARLqx/ejUdrvzw1HR3unbneCaZE4CVctQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/propddTSYB2GVpDx93GkLZkuiZGv/WwMQEuQU5iXz0=; b=WXEeIn/ZqL3Z8ROFt0g5owdo/HLPpw1M4RHn+WARF1jak1TdIUK5m6EVdxonmkk9pyxcutnvvrsCVitiCuinxNBtuQP/tTxqJQ8vW2qMntduNb808K3CJnXQm6jmwClhXZwDx9+BHST8o1YoiK0XSiSDMJ3sjq1cXuRgx9/fPXfN4t92wzCfwffMVHPSjRguZkVlEN6UJgZhc7/ynY8AE0Y44pVo3gdmiuorLKeRXZ/yil0BHlwn8W8RuzE+6asErlqpFSoKJvYqVvEnsHuG68ViQkjSLs7xeC2WtIImV2vxsZEh6Y228bfenxx8cJ1wLjlGHodoY6mppvLQT9ZqfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/propddTSYB2GVpDx93GkLZkuiZGv/WwMQEuQU5iXz0=; b=Ejbq9ULa5BbnmCL54BfRCHjpZvgP4kC1EEzRWeZbVjN0YHfTThp3AvhRE51MfL1ptTA2iVvLFvu3QKtJQ3Xjl2lxXR4DcCXSp3Z1nh7Y+Xey5X8tOxvFeSA0KQEtCC5TzUAwylTaw1PlzEBsowIzpsMKBjdRRELR8Y4H1LrzAuM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8466.eurprd04.prod.outlook.com (2603:10a6:20b:349::7) by VE1PR04MB6383.eurprd04.prod.outlook.com (2603:10a6:803:11b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.10; Wed, 12 Jan 2022 13:17:27 +0000 Received: from AS8PR04MB8466.eurprd04.prod.outlook.com ([fe80::5c1a:a024:4c5c:9f10]) by AS8PR04MB8466.eurprd04.prod.outlook.com ([fe80::5c1a:a024:4c5c:9f10%8]) with mapi id 15.20.4888.010; Wed, 12 Jan 2022 13:17:27 +0000 From: Dong Aisheng To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dongas86@gmail.com, jason.hui.liu@nxp.com, leoyang.li@nxp.com, abel.vesa@nxp.com, shawnguo@kernel.org, linux-imx@nxp.com, akpm@linux-foundation.org, m.szyprowski@samsung.com, lecopzer.chen@mediatek.com, david@redhat.com, vbabka@suse.cz, stable@vger.kernel.org, shijie.qin@nxp.com, Dong Aisheng Subject: [PATCH v2 1/2] mm: cma: fix allocation may fail sometimes Date: Wed, 12 Jan 2022 21:15:51 +0800 Message-Id: <20220112131552.3329380-2-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112131552.3329380-1-aisheng.dong@nxp.com> References: <20220112131552.3329380-1-aisheng.dong@nxp.com> X-ClientProxiedBy: SGXP274CA0021.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::33) To AS8PR04MB8466.eurprd04.prod.outlook.com (2603:10a6:20b:349::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 368ad0ee-8bc6-4fb7-b125-08d9d5cde0e5 X-MS-TrafficTypeDiagnostic: VE1PR04MB6383:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1227; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JidDj4N2lxYbJzdnpQkXqvamXztB0IArZgy82HRKLjsyAJCaBpYfYoJcvn1BrE6mvfSBCTj1PdwLgsvHCkNxgAzFPx2bcu18qwsxSwyIckTUqzcIUcccrR5szmDXj5E7UfhEeY4+dTT+KxLZ/RAAnaqYKZeNS/iAFfowkeyPQ9ciH2jVMZMJrnPlPMcL5Cvr2z1K3Dh8P2T9agzildAjng8tfMXa2IbBpEDFHIuuLL2skquVf9Y66pONh3tyKhIBWt3sxUfWzoOuFM5ryNqW9EF2d5/evV5jpMu2uEJT0MmmvzlO3Azb48kDnmIjjTV2XctwGt3yF3SlVeYWuBEK184rOn7EC0OyJaS2ittZAbI0sNL1aiKZbg+kNoIS9YWfgbfH8UipmFcYuibAidlAHCILvxapPiOG9EvXCMj2wyUdDCRGXrhAkmN1pYTqP1kMwtr7GUiIL6ytTCUN8X7RBEhWCf5FvSYeUwEoRzsP80ffWY6AvkyjZV7xKuGDMtVRS41tVFwwM062VjsoOrej+q5n0oiUhnR0eP3RZJ7lY4zWvF4aBpYc95z+Gn11q6m+a1+k7L1SHOaF8IaBuBH35H73FJg/asguh6ZedbUZEYVEezUr0w82MRwfsz6iPIBN1dxZUdcpKVjrTNpnXvlC+PD9GMiUhJFXaufg6qtwXiMzQxG12vJ0FXklPnOU0RsVYr8PNPcRc289OvqpPL83DQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8466.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(38350700002)(38100700002)(83380400001)(316002)(1076003)(52116002)(508600001)(66946007)(66556008)(66476007)(6512007)(186003)(4326008)(26005)(6506007)(5660300002)(6916009)(8936002)(2616005)(2906002)(8676002)(6666004)(6486002)(86362001)(7416002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rewOFXvIOvOfnfBc39wjyBfrCus/cKCx9SHTSBqAMBg/99O2uQrngWDSS1fmgHfsWp2IlzaHilvbEhuPRCMQlHj4ERg4fs2i3HCnF2ebjcOOhKqg8Cp7kH6rfKVyc9dHQr9C71Dz1mOqYgQJ1XkzKZVSyFtyz4Bz5ONSqrFK1bygI9osnt4wwZwuRAyFG6p9oNt4rUpYfxH++q+4P+vOT42Znk6mQCQ0N+aAeO1jPu1tnIwAoxVChqm3BGo9NaaMeeFBkss3azQpAAe6Xkt1vmaRLc3vMIWH1Mrz42aUgiLE5yRpGey4HtYMgbYxkLssMPcN50ROhUnd5DZqT1wXQB4u4UFEE4FEeG0syfAG6dv1lqY8W7lqNOaIMepwMjKCpCKQmz4zi61rYnRE4b0nevIlrwY/DG/miBD5k0wxsOVWM5CykUUPIY0q7LQwA8nO0hLg04ra4yNqhN60tq61zGLvshe5jTHnTwTAtonegCFCCz3jgSujRRNgBhKpQLE7UhfIi2rE4piorRNyLzeYNowbsnSEXbxTQH8b2opcubLlHVKqqsl7XySNVK+U0fcpeetXAcpG965IFWLh6iJO+nxktw1t/bTHM6eec2MPx+fu3aSJpQmtxovCr+qKu+MwKO0riB/3DWsM5RKwcDhe7GAkFo9dmEqq2m1vdcwjGADq3GAwqtdbAgU7BSkmE5fm4fgwk+Y3BFxWKVkT1//WuynHJ1lO9J/I3rd1L7PDYFTm1OJXh442nNWBUokbAjJPBFO01msL8N1s+RGnnu5uySSpqt+Z5XwakBdVpqqEqQgiJwz6B5dAUFlMudYMlkLWTqhNZgj/16iUSlrCtKXxciNirQPbpU58fYxsuD3FGTUXbo8Smj/VFLUdeLizVGusg+OjpzaXv4uP48ClvOcrzoAPRRl7Jbafdv9Cr7kbwsnSUkXTS0uAtHwhvoer+ewonNOz2zFUw+HwDiVN323KG/AaQCJiEwcxdMlUa1hZtP5vewHv9L/pD1pWNzGqMW2r75eMvhg8W/kkkuzdKxCW8HAEOhK6HdG6MY2HFk4W/z8+DC2LlSzFMVKvvqDSMNE+hHPY9xNKH6F+X+KKIEjqFHTtgFDGYET2v5jc4NO2Hkfomuj9gioDPzl5tmvu+56q4VxtmQvFL7kSlolkvOA0q89jpQ7tKyYpKR1MiVefsG0n/3amUjVfNbXZPk4GvBqXHeZ44hrpvGv1BO2wWU9OvCkPhUrZ3RagIPf4fi3Jmc80SOw2xKkJSOIZci6nfSGEPZ4oAL+/5oHv+t5EEs1Wc3w7tFxYbaHVEXq236WH8c+1RVZAA5BStYB+2bKWNUq2nLA3Ya0Ge6AaZ0fR9ka2CTlybksdpklxFTx7/Qthh9h6uv3F8GaqTBXtMfTJXuZC3Yi3Z1Sr+VNN1CGmtvlSKPjX8yimohE40z4Y3dFsMh890XCRLDxdIyUyoSGc5n3mWCMZmg5cUDgZZ2BG0TqAbvMdrULfKJotgccGfuWqCxFiBeVkatcFD4p7IyAOlxjOVwEv//nX2vQOyewl47cVjF6UocJbUWwqkzJL6mPQ4FLodBHPxQkLP2RhaEz5Y0+nbtXWWgup9IWa9epLuZFXO12OW+W9eW8QYIR5+nW9raY= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 368ad0ee-8bc6-4fb7-b125-08d9d5cde0e5 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8466.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2022 13:17:27.2327 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: I3oCdZLPh1YQ4lcrjB+Il1HaMAFxIFSHWCf2d1fs3uuY3eXQUJo4XfUTIW242U1awkg+uMTEGDcJvw1/dMCPtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6383 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org We met dma_alloc_coherent() fail sometimes when doing 8 VPU decoder test in parallel on a MX6Q SDB board. Error log: cma: cma_alloc: linux,cma: alloc failed, req-size: 148 pages, ret: -16 cma: number of available pages: 3@125+20@172+12@236+4@380+32@736+17@2287+23@2473+20@36076+99@40477+108@40852+44@41108+20@41196+108@41364+108@41620+ 108@42900+108@43156+483@44061+1763@45341+1440@47712+20@49324+20@49388+5076@49452+2304@55040+35@58141+20@58220+20@58284+ 7188@58348+84@66220+7276@66452+227@74525+6371@75549=> 33161 free of 81920 total pages When issue happened, we saw there were still 33161 pages (129M) free CMA memory and a lot available free slots for 148 pages in CMA bitmap that we want to allocate. If dumping memory info, we found that there was also ~342M normal memory, but only 1352K CMA memory left in buddy system while a lot of pageblocks were isolated. Memory info log: Normal free:351096kB min:30000kB low:37500kB high:45000kB reserved_highatomic:0KB active_anon:98060kB inactive_anon:98948kB active_file:60864kB inactive_file:31776kB unevictable:0kB writepending:0kB present:1048576kB managed:1018328kB mlocked:0kB bounce:0kB free_pcp:220kB local_pcp:192kB free_cma:1352kB lowmem_reserve[]: 0 0 0 Normal: 78*4kB (UECI) 1772*8kB (UMECI) 1335*16kB (UMECI) 360*32kB (UMECI) 65*64kB (UMCI) 36*128kB (UMECI) 16*256kB (UMCI) 6*512kB (EI) 8*1024kB (UEI) 4*2048kB (MI) 8*4096kB (EI) 8*8192kB (UI) 3*16384kB (EI) 8*32768kB (M) = 489288kB The root cause of this issue is that since commit a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock"), CMA supports concurrent memory allocation. It's possible that the pageblock process A try to alloc has already been isolated by the allocation of process B during memory migration. When there're multi process allocating CMA memory in parallel, it's likely that other the remain pageblocks may have also been isolated, then CMA alloc fail finally during the first round of scanning of the whole available CMA bitmap. This patch introduces a retry mechanism to rescan CMA bitmap for -EBUSY error in case the target pageblock may has been temporarily isolated by others and released later. Theoretically, this issue can be easily reproduced on ARMv7 platforms with big MAX_ORDER/pageblock e.g. 1G RAM(320M reserved CMA) and 32M pageblock ARM platform: Page block order: 13 Pages per block: 8192 Cc: Andrew Morton Cc: Marek Szyprowski Cc: Lecopzer Chen Cc: David Hildenbrand Cc: Vlastimil Babka CC: stable@vger.kernel.org # 5.11+ Fixes: a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock") Signed-off-by: Dong Aisheng --- ChangeLog: * v1->v2: no changes --- mm/cma.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index bc9ca8f3c487..1c13a729d274 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -433,6 +433,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned long i; struct page *page = NULL; int ret = -ENOMEM; + int loop = 0; if (!cma || !cma->count || !cma->bitmap) goto out; @@ -460,6 +461,16 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, offset); if (bitmap_no >= bitmap_maxno) { spin_unlock_irq(&cma->lock); + pr_debug("%s(): alloc fail, retry loop %d\n", __func__, loop++); + /* + * rescan as others may finish the memory migration + * and quit if no available CMA memory found finally + */ + if (start) { + schedule(); + start = 0; + continue; + } break; } bitmap_set(cma->bitmap, bitmap_no, bitmap_count); From patchwork Wed Jan 12 13:15:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 531779 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D31CBC433EF for ; Wed, 12 Jan 2022 13:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353484AbiALNRi (ORCPT ); Wed, 12 Jan 2022 08:17:38 -0500 Received: from mail-db8eur05on2062.outbound.protection.outlook.com ([40.107.20.62]:36705 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353489AbiALNRf (ORCPT ); Wed, 12 Jan 2022 08:17:35 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fEGVcu5j+qaS5m+wAeuW8/OBUHO65BCK+EQihFMD1puOHqsg5jSStoKD/Zfd5hWI09ExfMpCyDRT07MdqEHbW7Swp8/WBHJVc2NaSYjoh72kFGwck8bxP21Gl3CDp0hqj2U7fAwxdUdBoiS/7ZNaTrZHzZHxETX0AntNQ4x4Az1eQO0FOovxTqMzxntT9U81eO83zUlrXemEXGt0BlNrXyOrMaA5Q0BNWrZmLnwIB16Q1lUB1Uwsjx9yNdDDMQzqtLZgR4htlqX6cnNAD9/YDnTrmFIZFeux+WNHEhIiP7uYttmYwnvLlkdfqZczlk1KeY5JIukJCrVo6ARUqZ1/qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Flj59rK4Hz6g8apMzUcbQv8leW0I9ut242J9Usox/Dc=; b=LtEfVX9S34QReU1LtCq3kWtvhUri6FLNkysCVpSKKY0zMBJtO2phZCt0QRDuVz3dnrtTL5BaDDxMP41e5/4fiHp95d0GPBGtnwm/aNAF2R5AzzGWMGurwp+RoKucS3fRlvCMkk7yyoiQ3+V6YpW/6AuFfnA5wKsBrZEO5ixisEq91ujR2UT9x9VS2AtdUS40BftmY2mYW824JdE4tfkGIQ/rIYXygvRFkD4pcZanPCWjECeE8X+KFJvn4JX4TO8zosux7nzC8mhAJAMpIWMZGwEDuFi/4bcps9SOC4dkvEATGsGVHyMolVp7sGY56kUBvRXtY1E6Z/QYg9wYXaksEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Flj59rK4Hz6g8apMzUcbQv8leW0I9ut242J9Usox/Dc=; b=Cb2em2tiONmU3ZjpCqmGr7hOiB+C6D45fpYJ2aE+IYECFuEohkj9CfCvwtBI/yjPcfdGf72fKZXGB/9k3ygRJY5sapmPlK/EVgmfvRNY+zwTZRgA1jQJOnLkcF8vlJYSiNMNvF2I5jeOfa829CvHpz93JXfdh6+tobQb8+CIv5Q= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8466.eurprd04.prod.outlook.com (2603:10a6:20b:349::7) by VE1PR04MB6383.eurprd04.prod.outlook.com (2603:10a6:803:11b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.10; Wed, 12 Jan 2022 13:17:32 +0000 Received: from AS8PR04MB8466.eurprd04.prod.outlook.com ([fe80::5c1a:a024:4c5c:9f10]) by AS8PR04MB8466.eurprd04.prod.outlook.com ([fe80::5c1a:a024:4c5c:9f10%8]) with mapi id 15.20.4888.010; Wed, 12 Jan 2022 13:17:32 +0000 From: Dong Aisheng To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dongas86@gmail.com, jason.hui.liu@nxp.com, leoyang.li@nxp.com, abel.vesa@nxp.com, shawnguo@kernel.org, linux-imx@nxp.com, akpm@linux-foundation.org, m.szyprowski@samsung.com, lecopzer.chen@mediatek.com, david@redhat.com, vbabka@suse.cz, stable@vger.kernel.org, shijie.qin@nxp.com, Dong Aisheng Subject: [PATCH v2 2/2] mm: cma: try next MAX_ORDER_NR_PAGES during retry Date: Wed, 12 Jan 2022 21:15:52 +0800 Message-Id: <20220112131552.3329380-3-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220112131552.3329380-1-aisheng.dong@nxp.com> References: <20220112131552.3329380-1-aisheng.dong@nxp.com> X-ClientProxiedBy: SGXP274CA0021.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::33) To AS8PR04MB8466.eurprd04.prod.outlook.com (2603:10a6:20b:349::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f5d4a31-f7dd-48d0-0019-08d9d5cde42d X-MS-TrafficTypeDiagnostic: VE1PR04MB6383:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dPqd4XIdiYB0TexTQBW6OaB40g7pPcG+Bz03kFv7Uwm147nE/Z/rt/R9Aptp9HDqxUMZUSRjhPVZwDl0qcK1iRDjWlgMav5DEvfb3AK8cqCZ+5cxwWAu8x8OjvJJmGz+J7MKywrZprdW+gFF9QzwxdSUoNXyqt4+TN1ILg4VTVIE/068Etx5p8UktE0Ngi6G89AuTB7jq4iU9wYMSVaTMVyBVUHu0d5Wmiboolnt+5ZOOU0iZnMKza5OCbDkEJce2yFYn6aLOkhToG8KvQRU74Kuc7Rghi0tZPPTwkON9PjBtwT1uG8q5iD5U7L0wAgzhQzupRkBkvBlORJpQFZM5U8CsU77apvRE7FstoKR4czL3NChA+lRhV24Xbow74T2gRr3VOPFwK2wAitjq+9+ZjJuZrHLDB9SWjAOOoL2D34ZtwVsE+U95iRlFhLbq92BLa6Gun1w1E8bRVskGqAl0Z6oesKBpEFGVRNGu1AlVTd8Z4uoJhZ5T+VhKOJpRYcSE9ioqUMJjHpQOmcMDt1XXeRuI3TgtLtwBs6n6Pg6iLzL9XHtfqwQ0r7R8q8cUr2qz8oXowi9WdSsEwvjeY/wTKbp3immIIX3kUTB8SPGG8s8Yi7D9l2ZT9okq7j78x9AzAaEyl7FYSqLvbQszDBudy1hn0kyUtfTZVO4VCLXdjkUx9obawGmHKb4RQAvnyI42aTtWcTqdcEUkg4TH/j0uQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8466.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(38350700002)(38100700002)(83380400001)(316002)(1076003)(52116002)(508600001)(66946007)(66556008)(66476007)(6512007)(186003)(4326008)(26005)(6506007)(5660300002)(6916009)(8936002)(2616005)(2906002)(8676002)(6666004)(6486002)(86362001)(7416002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D5O9ABib1jxXDXN/c9p+x/wSwdVEEwztfVxpJL9n+OywhfYOvF7A5Ts4a6th/ET5Q1RR+OSBn+cKP7Msonzo68OrhU8rYdB3vETY8K4jJUvomy1jTdasah78/Wk+JBEfUBalxvkwf9ZTLFBnx28HMRjw7UPprj4Xs9crFngeY9dv6u9kuf6eY13lbdGQvUyuppLAtKwvEB9AQEuVKCQ4WchEFJSD1XAt61wBwgEBAcAzAKnKGZ6qvCVSXjUTbUyYHPuKq0D2GhDWNLo6QEei9Z/gRk5e0UB3s/g8hc6wsl3P7AFRht1gWuV3w7k0a6+5WPWIIyfy5OfyRVoi+2dCS2cFYW1irQwCCkBb2nn3Nxk85BEltnh+0sFyqM/P4OrWE8/a+SMpOpm1vnUqdR/Fsj3DKxusA/V3pHFRUNUV+i+Yms5wISqP4uBETB9wj7C6sYqbIy7ayuq13Iyit7UgPKh2mAGeThU6SVSMu8jCqy6TT/eqe5sP9YvfotxnetJJSvfe/ZWKDY3CxbrqNKO4NIdtohdZciOrH3Fu5iNe+tL9a3ZKnSAg3vFKN8+pTd0sChBCD9LdmFY3pOThCN8tspIs7tvepWgBsDZy/wQ53CMu85qmvr53E3CKmJPzKF12Qwm44LuyHHXTuqG2FO0J6zW0fX3+GX31DQtolXCYrpZE+e4Kw02GXghqNHDpU5e/engeJM2bFMX3a/+QzoCtWJMyP2J7Ps/xkhYeGyPCGeYAAL6pz7F3ulhbjiUQ4Az1QX9BeogJEF9nt9Z6EJE68Vdbwr6m1PGVWhAFmw1spSFOKJOS1GhZkXvyrGKsiwM+3Ni264KFhTedhHeu8JMkkb+5ODiTwmr7o2O2COLWbITGDZTAkfme9vSs2S1cU/DlGi5V8juqooaVMs9o4ZNl7QKhkhBNhufGZUXLkWtqqSFKTbE25tg/CFiIv45lHZqpggWKWPrXxolrAFpor/cwq8+OZmnwrgHpsLKQYl6Fmkoi+VjrjKzmqFl//qx03H0w0xEsJrGjxEmpcpdO4OypmS0RCG2HPUlSY5EpaFJ0gCmlAhnDGRZO+a7Fe7q/eHjwhzGXKbFsPYzIc0Fi4KV/msB2MK/CRqVguu7AuDhjrit19zYP+ULeFRmiJi34Lvc74VLwQBu8LvyFXvWkc1mBEoatj7931zMkBEv8BzcX2/KbcPBCyL8fzVDdi48HASRbNMmAapem4DEpVMxzhSAIE+UjxnhY0q6x/uUTDzvfCPgVAlwZKD+TXP2jhgn8VJ1NHutJXnhDdbODlrUbFiRrbbfMf4mvZdEM2eo1995twfao/aNxfnNZhfQMr7iWorwfvBT+NsjuvPzBsCz0rKvulWpQ4Zru9OAjHMf4SBIavQhjO8byonWdUyCMkdaQaov1uGVGZF984ISBa9zbx77n6vcJZ1CqtK/G+szwKAI6jWJLyDg6CVqoSlJrN4aY7zZVH6uXd7R7/fWHRvMgCMkqGSL5o6bhMvlXzjpNTHNFeRb3KL+BZywpolI6Nq6/aVlC0FcEtfLDLbfF3He3jyxKWLrYgVjvcxJ+ZITH3pXdqg6+Nq1COj8dBeT7+2vteMULQjQs/9YdlTCiXi5irnDFTz1lXnH3Jyy1cRTO92Xcp2A= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f5d4a31-f7dd-48d0-0019-08d9d5cde42d X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8466.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2022 13:17:32.6094 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7NPwfUKVeDZMO6gbjil7OVW1QJd++hnexD9c3OdJNLSElhJ43Ym/9HDmvj3DLhYFuJC3XvBOIHvkA2c0a2nhKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6383 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On an ARMv7 platform with 32M pageblock(MAX_ORDER 14), we observed a huge number of repeat retries of CMA allocation (1k+) during booting when allocating one page for each of 3 mmc instance probe. This is caused by CMA now supports cocurrent allocation since commit a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock"). The pageblock or (MAX_ORDER -1) from which we are trying to allocate memory may have already been acquired and isolated by others. Current cma_alloc() will then retry the next area by the step of bitmap_no + mask + 1 which are very likely within the same isolated range and fail again. So when the pageblock or MAX_ORDER is big (e.g. 8192), keep retrying in a small step become meaningless because it will be known to fail at a huge number of times due to the pageblock has been isolated by others, especially when allocating only one or two pages. Instread of looping in the same pageblock and wasting CPU mips a lot, especially for big pageblock system (e.g. 16M or 32M), we try the next MAX_ORDER_NR_PAGES directly. Doing this way can greatly mitigate the situtation. Below is the original error log during booting: [ 2.004804] cma: cma_alloc(cma (ptrval), count 1, align 0) [ 2.010318] cma: cma_alloc(cma (ptrval), count 1, align 0) [ 2.010776] cma: cma_alloc(): memory range at (ptrval) is busy, retrying [ 2.010785] cma: cma_alloc(): memory range at (ptrval) is busy, retrying [ 2.010793] cma: cma_alloc(): memory range at (ptrval) is busy, retrying [ 2.010800] cma: cma_alloc(): memory range at (ptrval) is busy, retrying [ 2.010807] cma: cma_alloc(): memory range at (ptrval) is busy, retrying [ 2.010814] cma: cma_alloc(): memory range at (ptrval) is busy, retrying .... (+1K retries) After fix, the 1200+ reties can be reduced to 0. Another test running 8 VPU decoder in parallel shows that 1500+ retries dropped to ~145. IOW this patch can improve the CMA allocation speed a lot when there're enough CMA memory by reducing retries significantly. Cc: Andrew Morton Cc: Marek Szyprowski Cc: Lecopzer Chen Cc: David Hildenbrand Cc: Vlastimil Babka CC: stable@vger.kernel.org # 5.11+ Fixes: a4efc174b382 ("mm/cma.c: remove redundant cma_mutex lock") Signed-off-by: Dong Aisheng --- v1->v2: * change to align with MAX_ORDER_NR_PAGES instead of pageblock_nr_pages --- mm/cma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/cma.c b/mm/cma.c index 1c13a729d274..1251f65e2364 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -500,7 +500,9 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, trace_cma_alloc_busy_retry(cma->name, pfn, pfn_to_page(pfn), count, align); /* try again with a bit different memory target */ - start = bitmap_no + mask + 1; + start = ALIGN(bitmap_no + mask + 1, + MAX_ORDER_NR_PAGES >> cma->order_per_bit); + } trace_cma_alloc_finish(cma->name, pfn, page, count, align);