From mboxrd@z Thu Jan 1 00:00:00 1970 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 1676AC02198 for ; Sat, 8 Feb 2025 08:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A670280001; Sat, 8 Feb 2025 03:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 756396B008C; Sat, 8 Feb 2025 03:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64575280001; Sat, 8 Feb 2025 03:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 47E1A6B008A for ; Sat, 8 Feb 2025 03:50:55 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E3DE8B4E7D for ; Sat, 8 Feb 2025 08:50:54 +0000 (UTC) X-FDA: 83096157228.18.B170FB6 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.6]) by imf16.hostedemail.com (Postfix) with ESMTP id DF6F8180006 for ; Sat, 8 Feb 2025 08:50:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=b2xwJPoO; spf=pass (imf16.hostedemail.com: domain of yangge1116@126.com designates 220.197.31.6 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739004653; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wp52D9fpjdxEowIxQTuIVRiH+cfHPxfJV9jwR5WSAfM=; b=tavJ9i0215m4yh8g6fvz46rxGcGvfsptVlJL6XPbRbYdy3bhkmzpcss6Ii3ksM7VbBisu7 E4B1dEUvNTOD/C1wEo73h8PDJUs2SIWR2zoBenzUIyFfENdxYN33DJXhKL79K4vQLPke7l mvIwOiHgEgEUx6fXoyn8D3cTQEURyLw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=b2xwJPoO; spf=pass (imf16.hostedemail.com: domain of yangge1116@126.com designates 220.197.31.6 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739004653; a=rsa-sha256; cv=none; b=Wdp0SbVu9jx4WDDOjurVKCWBWSVImIgXOulSWcg7X/yCUA5RvzGfkq/eFXFBbEx5tVItTd HOWXpPJncVVaI9F2J0YibD01UxO6nIjoaUD0g/WMGvAbAiooGrZh3pz0yiYhNzpHmdl+YP opcuk8YiqrW2BkHDEwoTHb9DJWoME0g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=Wp52D9fpjdxEowIxQTuIVRiH+cfHPxfJV9jwR5WSAfM=; b=b2xwJPoOQBDC2eqY8yzPGC4e5KHs0I4LoGjLCbe18y8xdNlJAWhr9ulXCaNxWs S4gjDWE8sh/xJuECf5wVSq1bbbD5jna11J7tvgARUdmI/tqdw/MlXbrKvcYNLfeu xUXMsKYa/WRm7+dsnRPZ6O7d/jf4oBS+jJN4AftnJpLCM= Received: from [172.19.20.199] (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wD35zHmGqdnQ8XpAg--.51012S2; Sat, 08 Feb 2025 16:50:46 +0800 (CST) Message-ID: <28edc5df-eed5-45b8-ab6d-76e63ef635a9@126.com> Date: Sat, 8 Feb 2025 16:50:46 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/cma: add an API to enable/disable concurrent memory allocation for the CMA To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, david@redhat.com, baolin.wang@linux.alibaba.com, aisheng.dong@nxp.com, liuzixing@hygon.cn References: <1737717687-16744-1-git-send-email-yangge1116@126.com> From: Ge Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD35zHmGqdnQ8XpAg--.51012S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF4kJr18ZFWkCw47Zw1DJrb_yoWrWryDpF W8G3WYk345XrnrZ392qw4093ZIg397CF4UGFyagas7ZF9xtr12gr1UKw15ur98ArWkWF1I vF4jq34a93WUZa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jbPEfUUUUU= X-Originating-IP: [112.64.138.194] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbifhntG2enCquwowAAsj X-Rspam-User: X-Rspamd-Queue-Id: DF6F8180006 X-Stat-Signature: u7eeftgz8acj4o868x7adz4meuqbgu36 X-Rspamd-Server: rspam03 X-HE-Tag: 1739004651-342927 X-HE-Meta: U2FsdGVkX1/dlFGzaNYpTKaiXGtqXQs4KgvcKqtO/BmDynXSPtnhr3aLUn4mgSobnK/PKDZ03wQGSRY+1K0ORLB/eBGmeA9ZML/giE4AcG98S05J5+qdh08qg+uefUITN/igGFpBRvFRSpImeIzCkf8lSieDiBmJK3AIQmWjn6ERvanM1ZFGVQkRXr8YL5qiB7B/l6ySEgacSUtfRbVLD+Oqx1olv9CwN1D4K0ePPe57ebDCd3dKWTEhAGscE6Bzk54qUQFL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f+iiPzx2lvLoeUa6ImzcjIvmhTLBh+rMkm8pSF4PTPGDbmN5JoR11ZoDeZmq65UM2xZs7nP7 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: List-Subscribe: List-Unsubscribe: 在 2025/1/28 17:58, Barry Song 写道: > On Sat, Jan 25, 2025 at 12:21 AM wrote: >> >> From: yangge >> >> Commit 60a60e32cf91 ("Revert "mm/cma.c: remove redundant cma_mutex lock"") >> simply reverts to the original method of using the cma_mutex to ensure >> that alloc_contig_range() runs sequentially. This change was made to avoid >> concurrency allocation failures. However, it can negatively impact >> performance when concurrent allocation of CMA memory is required. > > Do we have some data? Yes, I will add it in the next version, thanks. > >> >> To address this issue, we could introduce an API for concurrency settings, >> allowing users to decide whether their CMA can perform concurrent memory >> allocations or not. > > Who is the intended user of cma_set_concurrency? We have some drivers that use cma_set_concurrency(), but they have not yet been merged into the mainline. The cma_alloc_mem() function in the mainline also supports concurrent allocation of CMA memory. By applying this patch, we can also achieve significant performance improvements in certain scenarios. I will provide performance data in the next version. I also feel it is somewhat > unsafe since cma->concurr_alloc is not protected by any locks. Ok, thanks. > > Will a user setting cma->concurr_alloc = 1 encounter the original issue that > commit 60a60e32cf91 was attempting to fix? > Yes, if a user encounters the issue described in commit 60a60e32cf91, they will not be able to set cma->concurr_alloc to 1. >> >> Fixes: 60a60e32cf91 ("Revert "mm/cma.c: remove redundant cma_mutex lock"") >> Signed-off-by: yangge >> Cc: >> --- >> include/linux/cma.h | 2 ++ >> mm/cma.c | 22 ++++++++++++++++++++-- >> mm/cma.h | 1 + >> 3 files changed, 23 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/cma.h b/include/linux/cma.h >> index d15b64f..2384624 100644 >> --- a/include/linux/cma.h >> +++ b/include/linux/cma.h >> @@ -53,6 +53,8 @@ extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data) >> >> extern void cma_reserve_pages_on_error(struct cma *cma); >> >> +extern bool cma_set_concurrency(struct cma *cma, bool concurrency); >> + >> #ifdef CONFIG_CMA >> struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp); >> bool cma_free_folio(struct cma *cma, const struct folio *folio); >> diff --git a/mm/cma.c b/mm/cma.c >> index de5bc0c..49a7186 100644 >> --- a/mm/cma.c >> +++ b/mm/cma.c >> @@ -460,9 +460,17 @@ static struct page *__cma_alloc(struct cma *cma, unsigned long count, >> spin_unlock_irq(&cma->lock); >> >> pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); >> - mutex_lock(&cma_mutex); >> + >> + /* >> + * If the user sets the concurr_alloc of CMA to true, concurrent >> + * memory allocation is allowed. If the user sets it to false or >> + * does not set it, concurrent memory allocation is not allowed. >> + */ >> + if (!cma->concurr_alloc) >> + mutex_lock(&cma_mutex); >> ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, gfp); >> - mutex_unlock(&cma_mutex); >> + if (!cma->concurr_alloc) >> + mutex_unlock(&cma_mutex); >> if (ret == 0) { >> page = pfn_to_page(pfn); >> break; >> @@ -610,3 +618,13 @@ int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data) >> >> return 0; >> } >> + >> +bool cma_set_concurrency(struct cma *cma, bool concurrency) >> +{ >> + if (!cma) >> + return false; >> + >> + cma->concurr_alloc = concurrency; >> + >> + return true; >> +} >> diff --git a/mm/cma.h b/mm/cma.h >> index 8485ef8..30f489d 100644 >> --- a/mm/cma.h >> +++ b/mm/cma.h >> @@ -16,6 +16,7 @@ struct cma { >> unsigned long *bitmap; >> unsigned int order_per_bit; /* Order of pages represented by one bit */ >> spinlock_t lock; >> + bool concurr_alloc; >> #ifdef CONFIG_CMA_DEBUGFS >> struct hlist_head mem_head; >> spinlock_t mem_head_lock; >> -- >> 2.7.4 >> >> > > Thanks > Barry