mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-26 06:33:19 -04:00
mm: cma: sleep between retries in cma_alloc
Port support from 3.10 for retrying cma allocations to 3.18 to help resolve cma allocation failures. It was observed that CMA pages are sometimes getting pinned down by BG processes scheduled out in their exit path. Since BG processes have lower priority they end up getting less time slice by scheduler there by consuming more time to free up CMA pages. Also when a process is being forked copy_one_pte may create copy-on-write mappings, when this is done the page _count and page _mapcount are each incremented sequentially. If the process is context switched out after incrementing the _count but before incrementing the _mapcount then the page will appear temporarily pinned. So instead of failing to allocate and directly returning an error on the CMA allocation path we do 2 retries, with sleeps, to give the system an opportunity to unpin any pinned pages. Change-Id: I022a9341f8ee44f281c7cb34769695843e97d684 Signed-off-by: Susheel Khiani <skhiani@codeaurora.org> Signed-off-by: Liam Mark <lmark@codeaurora.org> Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org> Signed-off-by: Charan Teja Reddy <charante@codeaurora.org> [isaacm@codeaurora.org: resolve merge conflicts] Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
This commit is contained in:
parent
89f1fad7ce
commit
8ffd0015dd
1 changed files with 20 additions and 2 deletions
22
mm/cma.c
22
mm/cma.c
|
|
@ -33,6 +33,7 @@
|
|||
#include <linux/highmem.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/kmemleak.h>
|
||||
#include <linux/delay.h>
|
||||
#include <trace/events/cma.h>
|
||||
|
||||
#include "cma.h"
|
||||
|
|
@ -426,6 +427,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
|
|||
size_t i;
|
||||
struct page *page = NULL;
|
||||
int ret = -ENOMEM;
|
||||
int retry_after_sleep = 0;
|
||||
|
||||
if (!cma || !cma->count)
|
||||
return NULL;
|
||||
|
|
@ -450,8 +452,24 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
|
|||
bitmap_maxno, start, bitmap_count, mask,
|
||||
offset);
|
||||
if (bitmap_no >= bitmap_maxno) {
|
||||
mutex_unlock(&cma->lock);
|
||||
break;
|
||||
if (retry_after_sleep < 2) {
|
||||
start = 0;
|
||||
/*
|
||||
* Page may be momentarily pinned by some other
|
||||
* process which has been scheduled out, eg.
|
||||
* in exit path, during unmap call, or process
|
||||
* fork and so cannot be freed there. Sleep
|
||||
* for 100ms and retry twice to see if it has
|
||||
* been freed later.
|
||||
*/
|
||||
mutex_unlock(&cma->lock);
|
||||
msleep(100);
|
||||
retry_after_sleep++;
|
||||
continue;
|
||||
} else {
|
||||
mutex_unlock(&cma->lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bitmap_set(cma->bitmap, bitmap_no, bitmap_count);
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue