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

Commit 483242bd authored by Heesub Shin's avatar Heesub Shin Committed by Vinayak Menon
Browse files

cma: redirect page allocation to CMA



CMA pages are designed to be used as fallback for movable allocations
and cannot be used for non-movable allocations. If CMA pages are
utilized poorly, non-movable allocations may end up getting starved if
all regular movable pages are allocated and the only pages left are
CMA. Always using CMA pages first creates unacceptable performance
problems. As a midway alternative, use CMA pages for certain
userspace allocations. The userspace pages can be migrated or dropped
quickly which giving decent utilization.

Change-Id: I6165dda01b705309eebabc6dfa67146b7a95c174
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarHeesub Shin <heesub.shin@samsung.com>
[lauraa@codeaurora.org: Missing CONFIG_CMA guards, add commit text]
Signed-off-by: default avatarLaura Abbott <lauraa@codeaurora.org>
[lmark@codeaurora.org: resolve conflicts relating to
 MIGRATE_HIGHATOMIC and some other trivial merge conflicts]
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
Signed-off-by: default avatarVinayak Menon <vinmenon@codeaurora.org>
parent cd89bafd
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ struct vm_area_struct;
#define ___GFP_OTHER_NODE	0x800000u
#define ___GFP_WRITE		0x1000000u
#define ___GFP_KSWAPD_RECLAIM	0x2000000u
#define ___GFP_CMA		0x4000000u
/* If the above are modified, __GFP_BITS_SHIFT may need updating */

/*
@@ -54,8 +55,9 @@ struct vm_area_struct;
#define __GFP_HIGHMEM	((__force gfp_t)___GFP_HIGHMEM)
#define __GFP_DMA32	((__force gfp_t)___GFP_DMA32)
#define __GFP_MOVABLE	((__force gfp_t)___GFP_MOVABLE)  /* ZONE_MOVABLE allowed */
#define GFP_ZONEMASK	(__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE)

#define __GFP_CMA	((__force gfp_t)___GFP_CMA)
#define GFP_ZONEMASK	(__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE| \
			__GFP_CMA)
/*
 * Page mobility and placement hints
 *
@@ -274,7 +276,12 @@ static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
		return MIGRATE_UNMOVABLE;

	/* Group based on mobility */
#ifndef CONFIG_CMA
	return (gfp_flags & GFP_MOVABLE_MASK) >> GFP_MOVABLE_SHIFT;
#else
	return ((gfp_flags & GFP_MOVABLE_MASK) >> GFP_MOVABLE_SHIFT) |
	       ((gfp_flags & __GFP_CMA) != 0);
#endif
}
#undef GFP_MOVABLE_MASK
#undef GFP_MOVABLE_SHIFT
+15 −0
Original line number Diff line number Diff line
@@ -187,8 +187,23 @@ static inline struct page *
alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma,
					unsigned long vaddr)
{
#ifndef CONFIG_CMA
	return __alloc_zeroed_user_highpage(__GFP_MOVABLE, vma, vaddr);
#else
	return __alloc_zeroed_user_highpage(__GFP_MOVABLE|__GFP_CMA, vma,
						vaddr);
#endif
}

#ifdef CONFIG_CMA
static inline struct page *
alloc_zeroed_user_highpage_movable_cma(struct vm_area_struct *vma,
						unsigned long vaddr)
{
	return __alloc_zeroed_user_highpage(__GFP_MOVABLE|__GFP_CMA, vma,
						vaddr);
}
#endif

static inline void clear_highpage(struct page *page)
{
+4 −0
Original line number Diff line number Diff line
@@ -368,6 +368,10 @@ struct zone {
	struct pglist_data	*zone_pgdat;
	struct per_cpu_pageset __percpu *pageset;

#ifdef CONFIG_CMA
	bool			cma_alloc;
#endif

#ifndef CONFIG_SPARSEMEM
	/*
	 * Flags for a pageblock_nr_pages block. See pageblock-flags.h.
+35 −9
Original line number Diff line number Diff line
@@ -2209,10 +2209,25 @@ static struct page *__rmqueue(struct zone *zone, unsigned int order,

	page = __rmqueue_smallest(zone, order, migratetype);
	if (unlikely(!page)) {
		if (migratetype == MIGRATE_MOVABLE)
		page = __rmqueue_fallback(zone, order, migratetype);
	}

	trace_mm_page_alloc_zone_locked(page, order, migratetype);
	return page;
}

static struct page *__rmqueue_cma(struct zone *zone, unsigned int order,
					int migratetype)
{
	struct page *page = 0;
#ifdef CONFIG_CMA
	if (migratetype == MIGRATE_MOVABLE && !zone->cma_alloc)
		page = __rmqueue_cma_fallback(zone, order);
	else
#endif
		page = __rmqueue_smallest(zone, order, migratetype);

		if (!page)
	if (unlikely(!page)) {
		page = __rmqueue_fallback(zone, order, migratetype);
	}

@@ -2227,13 +2242,17 @@ static struct page *__rmqueue(struct zone *zone, unsigned int order,
 */
static int rmqueue_bulk(struct zone *zone, unsigned int order,
			unsigned long count, struct list_head *list,
			int migratetype, bool cold)
			int migratetype, bool cold, int cma)
{
	int i, alloced = 0;

	spin_lock(&zone->lock);
	for (i = 0; i < count; ++i) {
		struct page *page = __rmqueue(zone, order, migratetype);
		struct page *page;
		if (cma)
			page = __rmqueue_cma(zone, order, migratetype);
		else
			page = __rmqueue(zone, order, migratetype);
		if (unlikely(page == NULL))
			break;

@@ -2645,7 +2664,8 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
			if (list_empty(list)) {
				pcp->count += rmqueue_bulk(zone, 0,
						pcp->batch, list,
						migratetype, cold);
						migratetype, cold,
						gfp_flags & __GFP_CMA);
				if (unlikely(list_empty(list)))
					goto failed;
			}
@@ -2674,8 +2694,12 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
				if (page)
					trace_mm_page_alloc_zone_locked(page, order, migratetype);
			}
			if (!page)
			if (!page) {
				if (gfp_flags & __GFP_CMA)
					page = __rmqueue_cma(zone, order, migratetype);
				else
					page = __rmqueue(zone, order, migratetype);
			}
		} while (page && check_new_pages(page, order));
		spin_unlock(&zone->lock);
		if (!page)
@@ -7311,6 +7335,7 @@ int alloc_contig_range(unsigned long start, unsigned long end,
	if (ret)
		return ret;

	cc.zone->cma_alloc = 1;
	/*
	 * In case of -EBUSY, we'd like to know which page causes problem.
	 * So, just fall through. We will check it in test_pages_isolated().
@@ -7386,6 +7411,7 @@ int alloc_contig_range(unsigned long start, unsigned long end,
done:
	undo_isolate_page_range(pfn_max_align_down(start),
				pfn_max_align_up(end), migratetype);
	cc.zone->cma_alloc = 0;
	return ret;
}