diff options
-rw-r--r-- | mm/cma.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -31,6 +31,7 @@ #include <linux/highmem.h> #include <linux/io.h> #include <linux/kmemleak.h> +#include <linux/syscalls.h> #include <trace/events/cma.h> #include "cma.h" @@ -411,6 +412,24 @@ static void cma_debug_show_areas(struct cma *cma) static inline void cma_debug_show_areas(struct cma *cma) { } #endif +static void cma_sync_work(struct work_struct *work) +{ + ksys_sync(); + kfree(work); + pr_debug("%s(): EBUSY Sync complete\n", __func__); +} + +static void cma_ebusy_sync_pinned_pages(void) +{ + struct work_struct *work; + + work = kmalloc(sizeof(*work), GFP_ATOMIC); + if (work) { + INIT_WORK(work, cma_sync_work); + schedule_work(work); + } +} + /** * cma_alloc() - allocate pages from contiguous area * @cma: Contiguous memory region for which the allocation is performed. @@ -431,6 +450,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned long i; struct page *page = NULL; int ret = -ENOMEM; + bool sys_synchronized = false; if (!cma || !cma->count || !cma->bitmap) goto out; @@ -482,6 +502,11 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, if (ret != -EBUSY) break; + if (!sys_synchronized) { + sys_synchronized = true; + cma_ebusy_sync_pinned_pages(); + } + pr_debug("%s(): memory range at %p is busy, retrying\n", __func__, pfn_to_page(pfn)); |