Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30f491c9 authored by Susheel Khiani's avatar Susheel Khiani Committed by Ian Maund
Browse files

cma: Add 100ms delay before retrying for CMA allocation



CMA allocation sometimes fail because page is
momentarily pinned by some other process, i.e.
reference count page->_count > 1, as a
result of which we are not able to migrate
the page out of CMA area. When such situation
occurs, instead of failing to allocate and directly
returning error,sleep for 100ms and re-scan the
CMA area to see if the page which was pinned down
has been freed.

Change-Id: Ie9b92002f38fd44cf28aee32a184c57c26e59437
Signed-off-by: default avatarSusheel Khiani <skhiani@codeaurora.org>
parent 527b9a94
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <linux/mm_types.h>
#include <linux/dma-contiguous.h>
#include <linux/dma-removed.h>
#include <linux/delay.h>
#include <trace/events/kmem.h>

struct cma {
@@ -595,6 +596,7 @@ unsigned long dma_alloc_from_contiguous(struct device *dev, int count,
	struct cma *cma = dev_get_cma_area(dev);
	int ret = 0;
	int tries = 0;
	int retry_after_sleep = 0;

	if (!cma || !cma->count)
		return 0;
@@ -616,10 +618,26 @@ unsigned long dma_alloc_from_contiguous(struct device *dev, int count,
		pageno = bitmap_find_next_zero_area(cma->bitmap, cma->count,
						    start, count, mask);
		if (pageno >= cma->count) {
			if (retry_after_sleep == 0) {
				pfn = 0;
				start = 0;
				pr_debug("%s: Memory range busy,"
					"retry after sleep\n", __func__);
				/*
				* Page momentarily pinned by some other process
				* and so cannot be migrated. Wait for 100ms and
				* then retry to see if it has been freed.
				*/
				msleep(100);
				retry_after_sleep = 1;
				mutex_unlock(&cma->lock);
				continue;
			} else {
				pfn = 0;
				mutex_unlock(&cma->lock);
				break;
			}
		}
		bitmap_set(cma->bitmap, pageno, count);
		/*
		 * It's safe to drop the lock here. We've marked this region for