Skip to content

Commit 83138d4

Browse files
Xin JiangAvenger-285714
authored andcommitted
mm/cma: add API to enable concurrent allocation from the CMA
hygon inclusion category: feature CVE: NA --------------------------- The mutex prevents allocating CMA memory concurently, and it's removed and reverted back and forth, refer to commit 60a60e3 ("Revert "mm/cma.c: remove redundant cma_mutex lock"") and commit a4efc17 ("mm/cma.c: remove redundant cma_mutex lock") in the upstream. 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 <[email protected]> Signed-off-by: Xin Jiang <[email protected]> Signed-off-by: hanliyang <[email protected]>
1 parent 089c8e1 commit 83138d4

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

include/linux/cma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data)
5858
extern void cma_reserve_pages_on_error(struct cma *cma);
5959

6060
extern int __init cma_alloc_areas(unsigned int max_cma_size);
61+
extern void cma_enable_concurrency(struct cma *cma);
6162
#endif

mm/cma.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,12 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
492492
spin_unlock_irq(&cma->lock);
493493

494494
pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
495-
mutex_lock(&cma_mutex);
495+
if (!cma->no_mutex)
496+
mutex_lock(&cma_mutex);
496497
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
497498
GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0));
498-
mutex_unlock(&cma_mutex);
499+
if (!cma->no_mutex)
500+
mutex_unlock(&cma_mutex);
499501
if (ret == 0) {
500502
page = pfn_to_page(pfn);
501503
break;
@@ -609,3 +611,11 @@ int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data)
609611

610612
return 0;
611613
}
614+
615+
void cma_enable_concurrency(struct cma *cma)
616+
{
617+
if (!cma)
618+
return;
619+
620+
cma->no_mutex = true;
621+
}

mm/cma.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct cma {
1616
unsigned long *bitmap;
1717
unsigned int order_per_bit; /* Order of pages represented by one bit */
1818
spinlock_t lock;
19+
bool no_mutex;
1920
#ifdef CONFIG_CMA_DEBUGFS
2021
struct hlist_head mem_head;
2122
spinlock_t mem_head_lock;

0 commit comments

Comments
 (0)