anolis: mm/cma: add API to enable concurrent allocation from the CMA

ANBZ: #7046

The mutex prevents allocating CMA memory concurently, and it's
removed and reverted back and forth, refer to patch 60a60e32cf
and 60a60e32cf from mainline.

To solve the awkward dilemma, an API to enable concurrency is added,
it's up to user to decide whether their CMA can handle concurrent
allocations.

Signed-off-by: Yangwencheng <yangwencheng@hygon.cn>
Signed-off-by: Xin Jiang <jiangxin@hygon.cn>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/2350
This commit is contained in:
Yangwencheng 2023-08-29 02:13:19 -04:00 committed by 小龙
parent 1b4d4cce1b
commit 9fecbc8830
3 changed files with 14 additions and 2 deletions

View File

@ -50,4 +50,5 @@ extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int
extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data);
extern int __init cma_alloc_areas(unsigned int max_cma_size);
extern void cma_enable_concurrency(struct cma *cma);
#endif

View File

@ -476,10 +476,12 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
spin_unlock_irq(&cma->lock);
pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
mutex_lock(&cma_mutex);
if (!cma->no_mutex)
mutex_lock(&cma_mutex);
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0));
mutex_unlock(&cma_mutex);
if (!cma->no_mutex)
mutex_unlock(&cma_mutex);
if (ret == 0) {
page = pfn_to_page(pfn);
break;
@ -563,3 +565,11 @@ int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data)
return 0;
}
void cma_enable_concurrency(struct cma *cma)
{
if (!cma)
return;
cma->no_mutex = true;
}

View File

@ -10,6 +10,7 @@ struct cma {
unsigned long *bitmap;
unsigned int order_per_bit; /* Order of pages represented by one bit */
spinlock_t lock;
bool no_mutex;
#ifdef CONFIG_CMA_DEBUGFS
struct hlist_head mem_head;
spinlock_t mem_head_lock;