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: 12711383 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8CDCC433FE for ; Wed, 12 Jan 2022 13:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ywAyHhSsZ03u0aBZN8DIT0NhJDvkCghLqV0dliC0rt4=; b=R3lH5g7zmGaTw9 0BGIDZJ8fG4UzfcCOW3Q/McXrcs+PwFSeVS6l7iuLH0AjpUf5vQpbfHXvr7k0TC5DevWc6SiIlUMj GDLbADXMYcqG2zAHe5cauImOjvd1PyDym92RWk6s/3aeKVolBbXtLwP/U1IEbKZplmzTceihNhx0t O59hJ5dbbhbCVLpqHoMwrzw2x+OIpyTa4nuoWnTS/L9VGcZu5rQ7QLsQJg4Wv0YcWNo7Qzo6R5Ptl P3SYH35Ib2Na+MpYf51VWDIx0a7jfaj20rgUx4a0uGWhtPsc1kGx9ygCv/t6bqaHG2hxRKPGGgEYT tRxLVlEEiBJrLrLmryRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7dVg-002YqE-Np; Wed, 12 Jan 2022 13:17:52 +0000 Received: from mail-db8eur05on2064.outbound.protection.outlook.com ([40.107.20.64] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7dVP-002Yn6-QX for linux-arm-kernel@lists.infradead.org; Wed, 12 Jan 2022 13:17:37 +0000 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+Yms5wISqP4uBETB9wj7C6sYqbIy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q6/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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220112_051735_946149_440DC702 X-CRM114-Status: GOOD ( 17.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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);