static inline void __mod_zone_freepage_state(struct zone *zone, int nr_pages,
int migratetype)
{
- __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
+ if (IS_ENABLED(CONFIG_CMA_EXCLUDE)) {
+ if (!is_migrate_cma(migratetype))
+ __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
+ } else
+ __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
if (is_migrate_cma(migratetype))
__mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages);
}
If unsure, leave the default value "7".
+config CMA_EXCLUDE
+ bool "Exclude CMA from free memory"
+ depends on CMA
+ help
+ This excludes CMA free memory from system free memory states
+ to give exact memory information for user-level.
+ If this option is enabled, allocation for movable pages cannot
+ steal CMA free pages.
+
+
config MEM_SOFT_DIRTY
bool "Track memory changes"
depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY && PROC_FS
retry:
page = __rmqueue_smallest(zone, order, migratetype);
if (unlikely(!page)) {
- if (migratetype == MIGRATE_MOVABLE)
+ if (!IS_ENABLED(CONFIG_CMA_EXCLUDE) && migratetype == MIGRATE_MOVABLE)
page = __rmqueue_cma_fallback(zone, order);
if (!page && __rmqueue_fallback(zone, order, migratetype,
int migratetype, unsigned int alloc_flags)
{
int i, alloced = 0;
+#ifdef CONFIG_CMA_EXCLUDE
+ int cma_alloc = 0;
+#endif
spin_lock(&zone->lock);
for (i = 0; i < count; ++i) {
*/
list_add_tail(&page->lru, list);
alloced++;
+#ifdef CONFIG_CMA_EXCLUDE
+ if (is_migrate_cma(get_pcppage_migratetype(page))) {
+ __mod_zone_page_state(zone, NR_FREE_CMA_PAGES,
+ -(1 << order));
+ cma_alloc++;
+ }
+#else
if (is_migrate_cma(get_pcppage_migratetype(page)))
__mod_zone_page_state(zone, NR_FREE_CMA_PAGES,
-(1 << order));
+#endif
}
/*
* on i. Do not confuse with 'alloced' which is the number of
* pages added to the pcp list.
*/
+#ifdef CONFIG_CMA_EXCLUDE
+ __mod_zone_page_state(zone, NR_FREE_PAGES, -((i - cma_alloc) << order));
+#else
__mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
+#endif
spin_unlock(&zone->lock);
return alloced;
}
#ifdef CONFIG_CMA
/* If allocation can't use CMA areas don't use free CMA pages */
- if (!(alloc_flags & ALLOC_CMA))
+ if (!IS_ENABLED(CONFIG_CMA_EXCLUDE) && !(alloc_flags & ALLOC_CMA))
free_pages -= zone_page_state(z, NR_FREE_CMA_PAGES);
#endif
#ifdef CONFIG_CMA
/* If allocation can't use CMA areas don't use free CMA pages */
- if (!(alloc_flags & ALLOC_CMA))
+ if (!IS_ENABLED(CONFIG_CMA_EXCLUDE) && !(alloc_flags & ALLOC_CMA))
cma_pages = zone_page_state(z, NR_FREE_CMA_PAGES);
#endif
alloc_flags |= ALLOC_KSWAPD;
#ifdef CONFIG_CMA
+#ifndef CONFIG_CMA_EXCLUDE
if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE)
alloc_flags |= ALLOC_CMA;
#endif
+#endif
return alloc_flags;
}
if (should_fail_alloc_page(gfp_mask, order))
return false;
- if (IS_ENABLED(CONFIG_CMA) && ac->migratetype == MIGRATE_MOVABLE)
+ if (IS_ENABLED(CONFIG_CMA) && !IS_ENABLED(CONFIG_CMA_EXCLUDE) &&
+ ac->migratetype == MIGRATE_MOVABLE)
*alloc_flags |= ALLOC_CMA;
return true;