Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1407398 > unrolled thread
| Started by | js1304@gmail.com |
|---|---|
| First post | 2016-05-26 08:30 +0200 |
| Last post | 2016-05-30 07:50 +0200 |
| Articles | 13 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH v3 0/6] Introduce ZONE_CMA js1304@gmail.com - 2016-05-26 08:30 +0200
[PATCH v3 3/6] mm/cma: populate ZONE_CMA js1304@gmail.com - 2016-05-26 08:30 +0200
[PATCH v3 1/6] mm/page_alloc: recalculate some of zone threshold when on/offline memory js1304@gmail.com - 2016-05-26 08:30 +0200
[PATCH v3 5/6] mm/cma: remove MIGRATE_CMA js1304@gmail.com - 2016-05-26 08:30 +0200
Re: [PATCH v3 5/6] mm/cma: remove MIGRATE_CMA Chen Feng <puck.chen@hisilicon.com> - 2016-05-27 03:50 +0200
Re: [PATCH v3 5/6] mm/cma: remove MIGRATE_CMA Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2016-05-27 07:40 +0200
[PATCH v3 6/6] mm/cma: remove per zone CMA stat js1304@gmail.com - 2016-05-26 08:30 +0200
Re: [PATCH v3 0/6] Introduce ZONE_CMA Feng Tang <feng.tang@intel.com> - 2016-05-26 10:10 +0200
Re: [PATCH v3 0/6] Introduce ZONE_CMA Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2016-05-27 07:30 +0200
Re: [PATCH v3 0/6] Introduce ZONE_CMA Feng Tang <feng.tang@intel.com> - 2016-05-27 08:30 +0200
Re: [PATCH v3 0/6] Introduce ZONE_CMA Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2016-05-27 08:50 +0200
Re: [PATCH v3 0/6] Introduce ZONE_CMA Feng Tang <feng.tang@intel.com> - 2016-05-27 09:30 +0200
Re: [PATCH v3 0/6] Introduce ZONE_CMA Joonsoo Kim <iamjoonsoo.kim@lge.com> - 2016-05-30 07:50 +0200
| From | js1304@gmail.com |
|---|---|
| Date | 2016-05-26 08:30 +0200 |
| Subject | [PATCH v3 0/6] Introduce ZONE_CMA |
| Message-ID | <rCWXT-2Qp-5@gated-at.bofh.it> |
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Hello,
Changes from v2
o Rebase on next-20160525
o No other changes except following description
There was a discussion with Mel [1] after LSF/MM 2016. I could summarise
it to help merge decision but it's better to read by yourself since
if I summarise it, it would be biased for me. But, if anyone hope
the summary, I will do it. :)
Anyway, Mel's position on this patchset seems to be neutral. He said:
"I'm not going to outright NAK your series but I won't ACK it either"
We can fix the problems with any approach but I hope to go a new zone
approach because it is less error-prone. It reduces some corner case
handling for now and remove need for potential corner case handling to fix
problems.
Note that our company is already using ZONE_CMA for a years and
there is no problem.
If anyone has a different opinion, please let me know and let's discuss
together.
Andrew, if there is something to do for merge, please let me know.
[1] https://lkml.kernel.org/r/20160425053653.GA25662@js1304-P5Q-DELUXE
Changes from v1
o Separate some patches which deserve to submit independently
o Modify description to reflect current kernel state
(e.g. high-order watermark problem disappeared by Mel's work)
o Don't increase SECTION_SIZE_BITS to make a room in page flags
(detailed reason is on the patch that adds ZONE_CMA)
o Adjust ZONE_CMA population code
This series try to solve problems of current CMA implementation.
CMA is introduced to provide physically contiguous pages at runtime
without exclusive reserved memory area. But, current implementation
works like as previous reserved memory approach, because freepages
on CMA region are used only if there is no movable freepage. In other
words, freepages on CMA region are only used as fallback. In that
situation where freepages on CMA region are used as fallback, kswapd
would be woken up easily since there is no unmovable and reclaimable
freepage, too. If kswapd starts to reclaim memory, fallback allocation
to MIGRATE_CMA doesn't occur any more since movable freepages are
already refilled by kswapd and then most of freepage on CMA are left
to be in free. This situation looks like exclusive reserved memory case.
In my experiment, I found that if system memory has 1024 MB memory and
512 MB is reserved for CMA, kswapd is mostly woken up when roughly 512 MB
free memory is left. Detailed reason is that for keeping enough free
memory for unmovable and reclaimable allocation, kswapd uses below
equation when calculating free memory and it easily go under the watermark.
Free memory for unmovable and reclaimable = Free total - Free CMA pages
This is derivated from the property of CMA freepage that CMA freepage
can't be used for unmovable and reclaimable allocation.
Anyway, in this case, kswapd are woken up when (FreeTotal - FreeCMA)
is lower than low watermark and tries to make free memory until
(FreeTotal - FreeCMA) is higher than high watermark. That results
in that FreeTotal is moving around 512MB boundary consistently. It
then means that we can't utilize full memory capacity.
To fix this problem, I submitted some patches [1] about 10 months ago,
but, found some more problems to be fixed before solving this problem.
It requires many hooks in allocator hotpath so some developers doesn't
like it. Instead, some of them suggest different approach [2] to fix
all the problems related to CMA, that is, introducing a new zone to deal
with free CMA pages. I agree that it is the best way to go so implement
here. Although properties of ZONE_MOVABLE and ZONE_CMA is similar, I
decide to add a new zone rather than piggyback on ZONE_MOVABLE since
they have some differences. First, reserved CMA pages should not be
offlined. If freepage for CMA is managed by ZONE_MOVABLE, we need to keep
MIGRATE_CMA migratetype and insert many hooks on memory hotplug code
to distiguish hotpluggable memory and reserved memory for CMA in the same
zone. It would make memory hotplug code which is already complicated
more complicated. Second, cma_alloc() can be called more frequently
than memory hotplug operation and possibly we need to control
allocation rate of ZONE_CMA to optimize latency in the future.
In this case, separate zone approach is easy to modify. Third, I'd
like to see statistics for CMA, separately. Sometimes, we need to debug
why cma_alloc() is failed and separate statistics would be more helpful
in this situtaion.
Anyway, this patchset solves four problems related to CMA implementation.
1) Utilization problem
As mentioned above, we can't utilize full memory capacity due to the
limitation of CMA freepage and fallback policy. This patchset implements
a new zone for CMA and uses it for GFP_HIGHUSER_MOVABLE request. This
typed allocation is used for page cache and anonymous pages which
occupies most of memory usage in normal case so we can utilize full
memory capacity. Below is the experiment result about this problem.
8 CPUs, 1024 MB, VIRTUAL MACHINE
make -j16
<Before this series>
CMA reserve: 0 MB 512 MB
Elapsed-time: 92.4 186.5
pswpin: 82 18647
pswpout: 160 69839
<After this series>
CMA reserve: 0 MB 512 MB
Elapsed-time: 93.1 93.4
pswpin: 84 46
pswpout: 183 92
FYI, there is another attempt [3] trying to solve this problem in lkml.
And, as far as I know, Qualcomm also has out-of-tree solution for this
problem.
2) Reclaim problem
Currently, there is no logic to distinguish CMA pages in reclaim path.
If reclaim is initiated for unmovable and reclaimable allocation,
reclaiming CMA pages doesn't help to satisfy the request and reclaiming
CMA page is just waste. By managing CMA pages in the new zone, we can
skip to reclaim ZONE_CMA completely if it is unnecessary.
3) Atomic allocation failure problem
Kswapd isn't started to reclaim pages when allocation request is movable
type and there is enough free page in the CMA region. After bunch of
consecutive movable allocation requests, free pages in ordinary region
(not CMA region) would be exhausted without waking up kswapd. At that time,
if atomic unmovable allocation comes, it can't be successful since there
is not enough page in ordinary region. This problem is reported
by Aneesh [4] and can be solved by this patchset.
4) Inefficiently work of compaction
Usual high-order allocation request is unmovable type and it cannot
be serviced from CMA area. In compaction, migration scanner doesn't
distinguish migratable pages on the CMA area and do migration.
In this case, even if we make high-order page on that region, it
cannot be used due to type mismatch. This patch will solve this problem
by separating CMA pages from ordinary zones.
I passed boot test on x86_64, x86_32, arm and arm64. I did some stress
tests on x86_64 and x86_32 and there is no problem. Feel free to enjoy
and please give me a feedback. :)
This patchset is based on linux-next-20160330.
Thanks.
[1] https://lkml.org/lkml/2014/5/28/64
[2] https://lkml.org/lkml/2014/11/4/55
[3] https://lkml.org/lkml/2014/10/15/623
[4] http://www.spinics.net/lists/linux-mm/msg100562.html
Joonsoo Kim (6):
mm/page_alloc: recalculate some of zone threshold when on/offline
memory
mm/cma: introduce new zone, ZONE_CMA
mm/cma: populate ZONE_CMA
mm/cma: remove ALLOC_CMA
mm/cma: remove MIGRATE_CMA
mm/cma: remove per zone CMA stat
arch/x86/mm/highmem_32.c | 8 ++
fs/proc/meminfo.c | 2 +-
include/linux/cma.h | 6 +
include/linux/gfp.h | 32 +++--
include/linux/memory_hotplug.h | 3 -
include/linux/mempolicy.h | 2 +-
include/linux/mmzone.h | 54 +++++----
include/linux/vm_event_item.h | 10 +-
include/linux/vmstat.h | 8 --
include/trace/events/compaction.h | 10 +-
kernel/power/snapshot.c | 8 ++
mm/cma.c | 58 ++++++++-
mm/compaction.c | 10 +-
mm/hugetlb.c | 2 +-
mm/internal.h | 6 +-
mm/memory_hotplug.c | 3 +
mm/page_alloc.c | 242 +++++++++++++++++++++-----------------
mm/page_isolation.c | 5 +-
mm/vmstat.c | 15 ++-
19 files changed, 303 insertions(+), 181 deletions(-)
--
1.9.1
[toc] | [next] | [standalone]
| From | js1304@gmail.com |
|---|---|
| Date | 2016-05-26 08:30 +0200 |
| Subject | [PATCH v3 3/6] mm/cma: populate ZONE_CMA |
| Message-ID | <rCWXT-2Qp-11@gated-at.bofh.it> |
| In reply to | #1407398 |
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Until now, reserved pages for CMA are managed in the ordinary zones
where page's pfn are belong to. This approach has numorous problems
and fixing them isn't easy. (It is mentioned on previous patch.)
To fix this situation, ZONE_CMA is introduced in previous patch, but,
not yet populated. This patch implement population of ZONE_CMA
by stealing reserved pages from the ordinary zones.
Unlike previous implementation that kernel allocation request with
__GFP_MOVABLE could be serviced from CMA region, allocation request only
with GFP_HIGHUSER_MOVABLE can be serviced from CMA region in the new
approach. This is an inevitable design decision to use the zone
implementation because ZONE_CMA could contain highmem. Due to this
decision, ZONE_CMA will work like as ZONE_HIGHMEM or ZONE_MOVABLE.
I don't think it would be a problem because most of file cache pages
and anonymous pages are requested with GFP_HIGHUSER_MOVABLE. It could
be proved by the fact that there are many systems with ZONE_HIGHMEM and
they work fine. Notable disadvantage is that we cannot use these pages
for blockdev file cache page, because it usually has __GFP_MOVABLE but
not __GFP_HIGHMEM and __GFP_USER. But, in this case, there is pros and
cons. In my experience, blockdev file cache pages are one of the top
reason that causes cma_alloc() to fail temporarily. So, we can get more
guarantee of cma_alloc() success by discarding that case.
Implementation itself is very easy to understand. Steal when cma area is
initialized and recalculate various per zone stat/threshold.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
include/linux/memory_hotplug.h | 3 ---
mm/cma.c | 41 +++++++++++++++++++++++++++++++++++++++++
mm/internal.h | 3 +++
mm/page_alloc.c | 26 ++++++++++++++++++++++++--
4 files changed, 68 insertions(+), 5 deletions(-)
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index a864d79..6fde69b 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -198,9 +198,6 @@ void put_online_mems(void);
void mem_hotplug_begin(void);
void mem_hotplug_done(void);
-extern void set_zone_contiguous(struct zone *zone);
-extern void clear_zone_contiguous(struct zone *zone);
-
#else /* ! CONFIG_MEMORY_HOTPLUG */
/*
* Stub functions for when hotplug is off
diff --git a/mm/cma.c b/mm/cma.c
index ea506eb..8684f50 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -38,6 +38,7 @@
#include <trace/events/cma.h>
#include "cma.h"
+#include "internal.h"
struct cma cma_areas[MAX_CMA_AREAS];
unsigned cma_area_count;
@@ -145,6 +146,11 @@ err:
static int __init cma_init_reserved_areas(void)
{
int i;
+ struct zone *zone;
+ unsigned long start_pfn = UINT_MAX, end_pfn = 0;
+
+ if (!cma_area_count)
+ return 0;
for (i = 0; i < cma_area_count; i++) {
int ret = cma_activate_area(&cma_areas[i]);
@@ -153,6 +159,41 @@ static int __init cma_init_reserved_areas(void)
return ret;
}
+ for (i = 0; i < cma_area_count; i++) {
+ if (start_pfn > cma_areas[i].base_pfn)
+ start_pfn = cma_areas[i].base_pfn;
+ if (end_pfn < cma_areas[i].base_pfn + cma_areas[i].count)
+ end_pfn = cma_areas[i].base_pfn + cma_areas[i].count;
+ }
+
+ for_each_populated_zone(zone) {
+ if (!is_zone_cma(zone))
+ continue;
+
+ /* ZONE_CMA doesn't need to exceed CMA region */
+ zone->zone_start_pfn = max(zone->zone_start_pfn, start_pfn);
+ zone->spanned_pages = min(zone_end_pfn(zone), end_pfn) -
+ zone->zone_start_pfn;
+ }
+
+ /*
+ * Reserved pages for ZONE_CMA are now activated and this would change
+ * ZONE_CMA's managed page counter and other zone's present counter.
+ * We need to re-calculate various zone information that depends on
+ * this initialization.
+ */
+ build_all_zonelists(NULL, NULL);
+ for_each_populated_zone(zone) {
+ zone_pcp_update(zone);
+ set_zone_contiguous(zone);
+ }
+
+ /*
+ * We need to re-init per zone wmark by calling
+ * init_per_zone_wmark_min() but doesn't call here because it is
+ * registered on module_init and it will be called later than us.
+ */
+
return 0;
}
core_initcall(cma_init_reserved_areas);
diff --git a/mm/internal.h b/mm/internal.h
index b6ead95..4c37234 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -155,6 +155,9 @@ extern void __free_pages_bootmem(struct page *page, unsigned long pfn,
extern void prep_compound_page(struct page *page, unsigned int order);
extern int user_min_free_kbytes;
+extern void set_zone_contiguous(struct zone *zone);
+extern void clear_zone_contiguous(struct zone *zone);
+
#if defined CONFIG_COMPACTION || defined CONFIG_CMA
/*
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0197d5d..796b271 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1572,16 +1572,38 @@ void __init page_alloc_init_late(void)
}
#ifdef CONFIG_CMA
+static void __init adjust_present_page_count(struct page *page, long count)
+{
+ struct zone *zone = page_zone(page);
+
+ /* We don't need to hold a lock since it is boot-up process */
+ zone->present_pages += count;
+}
+
/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
void __init init_cma_reserved_pageblock(struct page *page)
{
unsigned i = pageblock_nr_pages;
+ unsigned long pfn = page_to_pfn(page);
struct page *p = page;
+ int nid = page_to_nid(page);
+
+ /*
+ * ZONE_CMA will steal present pages from other zones by changing
+ * page links so page_zone() is changed. Before that,
+ * we need to adjust previous zone's page count first.
+ */
+ adjust_present_page_count(page, -pageblock_nr_pages);
do {
__ClearPageReserved(p);
set_page_count(p, 0);
- } while (++p, --i);
+
+ /* Steal pages from other zones */
+ set_page_links(p, ZONE_CMA, nid, pfn);
+ } while (++p, ++pfn, --i);
+
+ adjust_present_page_count(page, pageblock_nr_pages);
set_pageblock_migratetype(page, MIGRATE_CMA);
@@ -7545,7 +7567,7 @@ void free_contig_range(unsigned long pfn, unsigned nr_pages)
}
#endif
-#ifdef CONFIG_MEMORY_HOTPLUG
+#if defined CONFIG_MEMORY_HOTPLUG || defined CONFIG_CMA
/*
* The zone indicated has a new number of managed_pages; batch sizes and percpu
* page high values need to be recalulated.
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | js1304@gmail.com |
|---|---|
| Date | 2016-05-26 08:30 +0200 |
| Subject | [PATCH v3 1/6] mm/page_alloc: recalculate some of zone threshold when on/offline memory |
| Message-ID | <rCWXU-2Qp-21@gated-at.bofh.it> |
| In reply to | #1407398 |
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Some of zone threshold depends on number of managed pages in the zone.
When memory is going on/offline, it can be changed and we need to
adjust them.
This patch add recalculation to appropriate places and clean-up
related function for better maintanance.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
mm/page_alloc.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d27e8b9..90e5a82 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4874,6 +4874,8 @@ int local_memory_node(int node)
}
#endif
+static void setup_min_unmapped_ratio(struct zone *zone);
+static void setup_min_slab_ratio(struct zone *zone);
#else /* CONFIG_NUMA */
static void set_zonelist_order(void)
@@ -5988,9 +5990,8 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
zone->managed_pages = is_highmem_idx(j) ? realsize : freesize;
#ifdef CONFIG_NUMA
zone->node = nid;
- zone->min_unmapped_pages = (freesize*sysctl_min_unmapped_ratio)
- / 100;
- zone->min_slab_pages = (freesize * sysctl_min_slab_ratio) / 100;
+ setup_min_unmapped_ratio(zone);
+ setup_min_slab_ratio(zone);
#endif
zone->name = zone_names[j];
spin_lock_init(&zone->lock);
@@ -6896,6 +6897,7 @@ int __meminit init_per_zone_wmark_min(void)
{
unsigned long lowmem_kbytes;
int new_min_free_kbytes;
+ struct zone *zone;
lowmem_kbytes = nr_free_buffer_pages() * (PAGE_SIZE >> 10);
new_min_free_kbytes = int_sqrt(lowmem_kbytes * 16);
@@ -6913,6 +6915,14 @@ int __meminit init_per_zone_wmark_min(void)
setup_per_zone_wmarks();
refresh_zone_stat_thresholds();
setup_per_zone_lowmem_reserve();
+
+ for_each_zone(zone) {
+#ifdef CONFIG_NUMA
+ setup_min_unmapped_ratio(zone);
+ setup_min_slab_ratio(zone);
+#endif
+ }
+
return 0;
}
core_initcall(init_per_zone_wmark_min)
@@ -6954,6 +6964,12 @@ int watermark_scale_factor_sysctl_handler(struct ctl_table *table, int write,
}
#ifdef CONFIG_NUMA
+static void setup_min_unmapped_ratio(struct zone *zone)
+{
+ zone->min_unmapped_pages = (zone->managed_pages *
+ sysctl_min_unmapped_ratio) / 100;
+}
+
int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *length, loff_t *ppos)
{
@@ -6965,11 +6981,17 @@ int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write,
return rc;
for_each_zone(zone)
- zone->min_unmapped_pages = (zone->managed_pages *
- sysctl_min_unmapped_ratio) / 100;
+ setup_min_unmapped_ratio(zone);
+
return 0;
}
+static void setup_min_slab_ratio(struct zone *zone)
+{
+ zone->min_slab_pages = (zone->managed_pages *
+ sysctl_min_slab_ratio) / 100;
+}
+
int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *length, loff_t *ppos)
{
@@ -6981,8 +7003,8 @@ int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write,
return rc;
for_each_zone(zone)
- zone->min_slab_pages = (zone->managed_pages *
- sysctl_min_slab_ratio) / 100;
+ setup_min_slab_ratio(zone);
+
return 0;
}
#endif
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | js1304@gmail.com |
|---|---|
| Date | 2016-05-26 08:30 +0200 |
| Subject | [PATCH v3 5/6] mm/cma: remove MIGRATE_CMA |
| Message-ID | <rCWXT-2Qp-17@gated-at.bofh.it> |
| In reply to | #1407398 |
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Now, all reserved pages for CMA region are belong to the ZONE_CMA
and there is no other type of pages. Therefore, we don't need to
use MIGRATE_CMA to distinguish and handle differently for CMA pages
and ordinary pages. Remove MIGRATE_CMA.
Unfortunately, this patch make free CMA counter incorrect because
we count it when pages are on the MIGRATE_CMA. It will be fixed
by next patch. I can squash next patch here but it makes changes
complicated and hard to review so I separate that.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
include/linux/gfp.h | 3 +-
include/linux/mmzone.h | 22 -------------
include/linux/vmstat.h | 8 -----
mm/cma.c | 2 +-
mm/compaction.c | 10 ++----
mm/hugetlb.c | 2 +-
mm/page_alloc.c | 87 +++++++++++++-------------------------------------
mm/page_isolation.c | 5 ++-
mm/vmstat.c | 5 +--
9 files changed, 31 insertions(+), 113 deletions(-)
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 4d6c008..1a3b869 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -559,8 +559,7 @@ static inline bool pm_suspended_storage(void)
#if (defined(CONFIG_MEMORY_ISOLATION) && defined(CONFIG_COMPACTION)) || defined(CONFIG_CMA)
/* The below functions must be run on a range from a single zone. */
-extern int alloc_contig_range(unsigned long start, unsigned long end,
- unsigned migratetype);
+extern int alloc_contig_range(unsigned long start, unsigned long end);
extern void free_contig_range(unsigned long pfn, unsigned nr_pages);
#endif
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 54c92a6..236d0bd 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -41,22 +41,6 @@ enum {
MIGRATE_RECLAIMABLE,
MIGRATE_PCPTYPES, /* the number of types on the pcp lists */
MIGRATE_HIGHATOMIC = MIGRATE_PCPTYPES,
-#ifdef CONFIG_CMA
- /*
- * MIGRATE_CMA migration type is designed to mimic the way
- * ZONE_MOVABLE works. Only movable pages can be allocated
- * from MIGRATE_CMA pageblocks and page allocator never
- * implicitly change migration type of MIGRATE_CMA pageblock.
- *
- * The way to use it is to change migratetype of a range of
- * pageblocks to MIGRATE_CMA which can be done by
- * __free_pageblock_cma() function. What is important though
- * is that a range of pageblocks must be aligned to
- * MAX_ORDER_NR_PAGES should biggest page be bigger then
- * a single pageblock.
- */
- MIGRATE_CMA,
-#endif
#ifdef CONFIG_MEMORY_ISOLATION
MIGRATE_ISOLATE, /* can't allocate from here */
#endif
@@ -66,12 +50,6 @@ enum {
/* In mm/page_alloc.c; keep in sync also with show_migration_types() there */
extern char * const migratetype_names[MIGRATE_TYPES];
-#ifdef CONFIG_CMA
-# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
-#else
-# define is_migrate_cma(migratetype) false
-#endif
-
#define for_each_migratetype_order(order, type) \
for (order = 0; order < MAX_ORDER; order++) \
for (type = 0; type < MIGRATE_TYPES; type++)
diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index 0aa613d..e0eb3e5 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -264,14 +264,6 @@ static inline void drain_zonestat(struct zone *zone,
struct per_cpu_pageset *pset) { }
#endif /* CONFIG_SMP */
-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_migrate_cma(migratetype))
- __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages);
-}
-
extern const char * const vmstat_text[];
#endif /* _LINUX_VMSTAT_H */
diff --git a/mm/cma.c b/mm/cma.c
index 8684f50..bd436e4 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -444,7 +444,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align)
pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
mutex_lock(&cma_mutex);
- ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
+ ret = alloc_contig_range(pfn, pfn + count);
mutex_unlock(&cma_mutex);
if (ret == 0) {
page = pfn_to_page(pfn);
diff --git a/mm/compaction.c b/mm/compaction.c
index 1427366..acb1d1a 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -76,7 +76,7 @@ static void map_pages(struct list_head *list)
static inline bool migrate_async_suitable(int migratetype)
{
- return is_migrate_cma(migratetype) || migratetype == MIGRATE_MOVABLE;
+ return migratetype == MIGRATE_MOVABLE;
}
#ifdef CONFIG_COMPACTION
@@ -953,7 +953,7 @@ static bool suitable_migration_target(struct page *page)
return false;
}
- /* If the block is MIGRATE_MOVABLE or MIGRATE_CMA, allow migration */
+ /* If the block is MIGRATE_MOVABLE, allow migration */
if (migrate_async_suitable(get_pageblock_migratetype(page)))
return true;
@@ -1277,12 +1277,6 @@ static enum compact_result __compact_finished(struct zone *zone, struct compact_
if (!list_empty(&area->free_list[migratetype]))
return COMPACT_PARTIAL;
-#ifdef CONFIG_CMA
- /* MIGRATE_MOVABLE can fallback on MIGRATE_CMA */
- if (migratetype == MIGRATE_MOVABLE &&
- !list_empty(&area->free_list[MIGRATE_CMA]))
- return COMPACT_PARTIAL;
-#endif
/*
* Job done if allocation would steal freepages from
* other migratetype buddy lists.
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index d26162e..a081f15 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1029,7 +1029,7 @@ static int __alloc_gigantic_page(unsigned long start_pfn,
unsigned long nr_pages)
{
unsigned long end_pfn = start_pfn + nr_pages;
- return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
+ return alloc_contig_range(start_pfn, end_pfn);
}
static bool pfn_range_valid_gigantic(struct zone *z,
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index bab3698..e1c17d15 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -124,8 +124,8 @@ gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
* put on a pcplist. Used to avoid the pageblock migratetype lookup when
* freeing from pcplists in most cases, at the cost of possibly becoming stale.
* Also the migratetype set in the page does not necessarily match the pcplist
- * index, e.g. page might have MIGRATE_CMA set but be on a pcplist with any
- * other index - this ensures that it will be put on the correct CMA freelist.
+ * index, e.g. page might have MIGRATE_MOVABLE set but be on a pcplist with any
+ * other index - this ensures that it will be put on the correct freelist.
*/
static inline int get_pcppage_migratetype(struct page *page)
{
@@ -234,9 +234,6 @@ char * const migratetype_names[MIGRATE_TYPES] = {
"Movable",
"Reclaimable",
"HighAtomic",
-#ifdef CONFIG_CMA
- "CMA",
-#endif
#ifdef CONFIG_MEMORY_ISOLATION
"Isolate",
#endif
@@ -670,7 +667,7 @@ static inline void set_page_guard(struct zone *zone, struct page *page,
INIT_LIST_HEAD(&page->lru);
set_page_private(page, order);
/* Guard pages are not available for any usage */
- __mod_zone_freepage_state(zone, -(1 << order), migratetype);
+ __mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
}
static inline void clear_page_guard(struct zone *zone, struct page *page,
@@ -689,7 +686,7 @@ static inline void clear_page_guard(struct zone *zone, struct page *page,
set_page_private(page, 0);
if (!is_migrate_isolate(migratetype))
- __mod_zone_freepage_state(zone, (1 << order), migratetype);
+ __mod_zone_page_state(zone, NR_FREE_PAGES, (1 << order));
}
#else
struct page_ext_operations debug_guardpage_ops = { NULL, };
@@ -800,7 +797,7 @@ static inline void __free_one_page(struct page *page,
VM_BUG_ON(migratetype == -1);
if (likely(!is_migrate_isolate(migratetype)))
- __mod_zone_freepage_state(zone, 1 << order, migratetype);
+ __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
page_idx = pfn & ((1 << MAX_ORDER) - 1);
@@ -1580,7 +1577,7 @@ static void __init adjust_present_page_count(struct page *page, long count)
zone->present_pages += count;
}
-/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
+/* Free whole pageblock and set its migration type to MIGRATE_MOVABLE. */
void __init init_cma_reserved_pageblock(struct page *page)
{
unsigned i = pageblock_nr_pages;
@@ -1605,7 +1602,7 @@ void __init init_cma_reserved_pageblock(struct page *page)
adjust_present_page_count(page, pageblock_nr_pages);
- set_pageblock_migratetype(page, MIGRATE_CMA);
+ set_pageblock_migratetype(page, MIGRATE_MOVABLE);
if (pageblock_order >= MAX_ORDER) {
i = pageblock_nr_pages;
@@ -1830,25 +1827,11 @@ static int fallbacks[MIGRATE_TYPES][4] = {
[MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_TYPES },
[MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_TYPES },
[MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_TYPES },
-#ifdef CONFIG_CMA
- [MIGRATE_CMA] = { MIGRATE_TYPES }, /* Never used */
-#endif
#ifdef CONFIG_MEMORY_ISOLATION
[MIGRATE_ISOLATE] = { MIGRATE_TYPES }, /* Never used */
#endif
};
-#ifdef CONFIG_CMA
-static struct page *__rmqueue_cma_fallback(struct zone *zone,
- unsigned int order)
-{
- return __rmqueue_smallest(zone, order, MIGRATE_CMA);
-}
-#else
-static inline struct page *__rmqueue_cma_fallback(struct zone *zone,
- unsigned int order) { return NULL; }
-#endif
-
/*
* Move the free pages in a range to the free lists of the requested type.
* Note that start_page and end_pages are not aligned on a pageblock
@@ -2053,7 +2036,7 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone,
/* Yoink! */
mt = get_pageblock_migratetype(page);
if (mt != MIGRATE_HIGHATOMIC &&
- !is_migrate_isolate(mt) && !is_migrate_cma(mt)) {
+ !is_migrate_isolate(mt)) {
zone->nr_reserved_highatomic += pageblock_nr_pages;
set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC);
move_freepages_block(zone, page, MIGRATE_HIGHATOMIC);
@@ -2156,9 +2139,7 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype)
/*
* The pcppage_migratetype may differ from pageblock's
* migratetype depending on the decisions in
- * find_suitable_fallback(). This is OK as long as it does not
- * differ for MIGRATE_CMA pageblocks. Those can be used as
- * fallback only via special __rmqueue_cma_fallback() function
+ * find_suitable_fallback(). This is OK.
*/
set_pcppage_migratetype(page, start_migratetype);
@@ -2181,13 +2162,8 @@ static struct page *__rmqueue(struct zone *zone, unsigned int order,
struct page *page;
page = __rmqueue_smallest(zone, order, migratetype);
- if (unlikely(!page)) {
- if (migratetype == MIGRATE_MOVABLE)
- page = __rmqueue_cma_fallback(zone, order);
-
- if (!page)
- page = __rmqueue_fallback(zone, order, migratetype);
- }
+ if (unlikely(!page))
+ page = __rmqueue_fallback(zone, order, migratetype);
trace_mm_page_alloc_zone_locked(page, order, migratetype);
return page;
@@ -2227,9 +2203,6 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
else
list_add_tail(&page->lru, list);
list = &page->lru;
- if (is_migrate_cma(get_pcppage_migratetype(page)))
- __mod_zone_page_state(zone, NR_FREE_CMA_PAGES,
- -(1 << order));
}
__mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
spin_unlock(&zone->lock);
@@ -2527,7 +2500,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
if (!zone_watermark_ok(zone, 0, watermark, 0, 0))
return 0;
- __mod_zone_freepage_state(zone, -(1UL << order), mt);
+ __mod_zone_page_state(zone, NR_FREE_PAGES, -(1UL << order));
}
/* Remove page from free list */
@@ -2542,7 +2515,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
struct page *endpage = page + (1 << order) - 1;
for (; page < endpage; page += pageblock_nr_pages) {
int mt = get_pageblock_migratetype(page);
- if (!is_migrate_isolate(mt) && !is_migrate_cma(mt))
+ if (!is_migrate_isolate(mt))
set_pageblock_migratetype(page,
MIGRATE_MOVABLE);
}
@@ -2670,8 +2643,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
if (!page)
goto failed;
__mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
- __mod_zone_freepage_state(zone, -(1 << order),
- get_pcppage_migratetype(page));
+ __mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
}
if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
@@ -2825,11 +2797,6 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
if (!list_empty(&area->free_list[mt]))
return true;
}
-
-#ifdef CONFIG_CMA
- if (!list_empty(&area->free_list[MIGRATE_CMA]))
- return true;
-#endif
}
return false;
}
@@ -4320,9 +4287,6 @@ static void show_migration_types(unsigned char type)
[MIGRATE_MOVABLE] = 'M',
[MIGRATE_RECLAIMABLE] = 'E',
[MIGRATE_HIGHATOMIC] = 'H',
-#ifdef CONFIG_CMA
- [MIGRATE_CMA] = 'C',
-#endif
#ifdef CONFIG_MEMORY_ISOLATION
[MIGRATE_ISOLATE] = 'I',
#endif
@@ -7244,7 +7208,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
return false;
mt = get_pageblock_migratetype(page);
- if (mt == MIGRATE_MOVABLE || is_migrate_cma(mt))
+ if (mt == MIGRATE_MOVABLE)
return false;
pfn = page_to_pfn(page);
@@ -7392,15 +7356,11 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
* alloc_contig_range() -- tries to allocate given range of pages
* @start: start PFN to allocate
* @end: one-past-the-last PFN to allocate
- * @migratetype: migratetype of the underlaying pageblocks (either
- * #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks
- * in range must have the same migratetype and it must
- * be either of the two.
*
* The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
* aligned, however it's the caller's responsibility to guarantee that
* we are the only thread that changes migrate type of pageblocks the
- * pages fall in.
+ * pages fall in and it should be MIGRATE_MOVABLE.
*
* The PFN range must belong to a single zone.
*
@@ -7408,8 +7368,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
* pages which PFN is in [start, end) are allocated for the caller and
* need to be freed with free_contig_range().
*/
-int alloc_contig_range(unsigned long start, unsigned long end,
- unsigned migratetype)
+int alloc_contig_range(unsigned long start, unsigned long end)
{
unsigned long outer_start, outer_end;
unsigned int order;
@@ -7442,14 +7401,14 @@ int alloc_contig_range(unsigned long start, unsigned long end,
* allocator removing them from the buddy system. This way
* page allocator will never consider using them.
*
- * This lets us mark the pageblocks back as
- * MIGRATE_CMA/MIGRATE_MOVABLE so that free pages in the
- * aligned range but not in the unaligned, original range are
- * put back to page allocator so that buddy can use them.
+ * This lets us mark the pageblocks back as MIGRATE_MOVABLE
+ * so that free pages in the aligned range but not in the
+ * unaligned, original range are put back to page allocator
+ * so that buddy can use them.
*/
ret = start_isolate_page_range(pfn_max_align_down(start),
- pfn_max_align_up(end), migratetype,
+ pfn_max_align_up(end), MIGRATE_MOVABLE,
false);
if (ret)
return ret;
@@ -7528,7 +7487,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);
+ pfn_max_align_up(end), MIGRATE_MOVABLE);
return ret;
}
diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index 612122b..5708649 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -61,13 +61,12 @@ static int set_migratetype_isolate(struct page *page,
out:
if (!ret) {
unsigned long nr_pages;
- int migratetype = get_pageblock_migratetype(page);
set_pageblock_migratetype(page, MIGRATE_ISOLATE);
zone->nr_isolate_pageblock++;
nr_pages = move_freepages_block(zone, page, MIGRATE_ISOLATE);
- __mod_zone_freepage_state(zone, -nr_pages, migratetype);
+ __mod_zone_page_state(zone, NR_FREE_PAGES, -nr_pages);
}
spin_unlock_irqrestore(&zone->lock, flags);
@@ -122,7 +121,7 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
*/
if (!isolated_page) {
nr_pages = move_freepages_block(zone, page, migratetype);
- __mod_zone_freepage_state(zone, nr_pages, migratetype);
+ __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
}
set_pageblock_migratetype(page, migratetype);
zone->nr_isolate_pageblock--;
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 48c4942..8d18d1e 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1088,10 +1088,7 @@ static void pagetypeinfo_showmixedcount_print(struct seq_file *m,
page_mt = gfpflags_to_migratetype(page_ext->gfp_mask);
if (pageblock_mt != page_mt) {
- if (is_migrate_cma(pageblock_mt))
- count[MIGRATE_MOVABLE]++;
- else
- count[pageblock_mt]++;
+ count[pageblock_mt]++;
pfn = block_end_pfn;
break;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Chen Feng <puck.chen@hisilicon.com> |
|---|---|
| Date | 2016-05-27 03:50 +0200 |
| Subject | Re: [PATCH v3 5/6] mm/cma: remove MIGRATE_CMA |
| Message-ID | <rDf4t-5pr-7@gated-at.bofh.it> |
| In reply to | #1407403 |
Hi Joonsoo,
On 2016/5/26 14:22, js1304@gmail.com wrote:
> From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
>
> Now, all reserved pages for CMA region are belong to the ZONE_CMA
> and there is no other type of pages. Therefore, we don't need to
> use MIGRATE_CMA to distinguish and handle differently for CMA pages
> and ordinary pages. Remove MIGRATE_CMA.
>
> Unfortunately, this patch make free CMA counter incorrect because
> we count it when pages are on the MIGRATE_CMA. It will be fixed
> by next patch. I can squash next patch here but it makes changes
> complicated and hard to review so I separate that.
>
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> ---
> include/linux/gfp.h | 3 +-
> include/linux/mmzone.h | 22 -------------
> include/linux/vmstat.h | 8 -----
> mm/cma.c | 2 +-
> mm/compaction.c | 10 ++----
> mm/hugetlb.c | 2 +-
> mm/page_alloc.c | 87 +++++++++++++-------------------------------------
> mm/page_isolation.c | 5 ++-
> mm/vmstat.c | 5 +--
> 9 files changed, 31 insertions(+), 113 deletions(-)
>
> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> index 4d6c008..1a3b869 100644
> --- a/include/linux/gfp.h
> +++ b/include/linux/gfp.h
> @@ -559,8 +559,7 @@ static inline bool pm_suspended_storage(void)
>
> #if (defined(CONFIG_MEMORY_ISOLATION) && defined(CONFIG_COMPACTION)) || defined(CONFIG_CMA)
> /* The below functions must be run on a range from a single zone. */
> -extern int alloc_contig_range(unsigned long start, unsigned long end,
> - unsigned migratetype);
> +extern int alloc_contig_range(unsigned long start, unsigned long end);
> extern void free_contig_range(unsigned long pfn, unsigned nr_pages);
> #endif
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 54c92a6..236d0bd 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -41,22 +41,6 @@ enum {
> MIGRATE_RECLAIMABLE,
> MIGRATE_PCPTYPES, /* the number of types on the pcp lists */
> MIGRATE_HIGHATOMIC = MIGRATE_PCPTYPES,
> -#ifdef CONFIG_CMA
> - /*
> - * MIGRATE_CMA migration type is designed to mimic the way
> - * ZONE_MOVABLE works. Only movable pages can be allocated
> - * from MIGRATE_CMA pageblocks and page allocator never
> - * implicitly change migration type of MIGRATE_CMA pageblock.
> - *
> - * The way to use it is to change migratetype of a range of
> - * pageblocks to MIGRATE_CMA which can be done by
> - * __free_pageblock_cma() function. What is important though
> - * is that a range of pageblocks must be aligned to
> - * MAX_ORDER_NR_PAGES should biggest page be bigger then
> - * a single pageblock.
> - */
> - MIGRATE_CMA,
> -#endif
> #ifdef CONFIG_MEMORY_ISOLATION
> MIGRATE_ISOLATE, /* can't allocate from here */
> #endif
> @@ -66,12 +50,6 @@ enum {
> /* In mm/page_alloc.c; keep in sync also with show_migration_types() there */
> extern char * const migratetype_names[MIGRATE_TYPES];
>
> -#ifdef CONFIG_CMA
> -# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
> -#else
> -# define is_migrate_cma(migratetype) false
> -#endif
> -
> #define for_each_migratetype_order(order, type) \
> for (order = 0; order < MAX_ORDER; order++) \
> for (type = 0; type < MIGRATE_TYPES; type++)
> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> index 0aa613d..e0eb3e5 100644
> --- a/include/linux/vmstat.h
> +++ b/include/linux/vmstat.h
> @@ -264,14 +264,6 @@ static inline void drain_zonestat(struct zone *zone,
> struct per_cpu_pageset *pset) { }
> #endif /* CONFIG_SMP */
>
> -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_migrate_cma(migratetype))
> - __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages);
> -}
> -
> extern const char * const vmstat_text[];
>
> #endif /* _LINUX_VMSTAT_H */
> diff --git a/mm/cma.c b/mm/cma.c
> index 8684f50..bd436e4 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -444,7 +444,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align)
>
> pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
> mutex_lock(&cma_mutex);
> - ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
> + ret = alloc_contig_range(pfn, pfn + count);
> mutex_unlock(&cma_mutex);
> if (ret == 0) {
> page = pfn_to_page(pfn);
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 1427366..acb1d1a 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -76,7 +76,7 @@ static void map_pages(struct list_head *list)
>
> static inline bool migrate_async_suitable(int migratetype)
> {
> - return is_migrate_cma(migratetype) || migratetype == MIGRATE_MOVABLE;
> + return migratetype == MIGRATE_MOVABLE;
> }
>
> #ifdef CONFIG_COMPACTION
> @@ -953,7 +953,7 @@ static bool suitable_migration_target(struct page *page)
> return false;
> }
>
> - /* If the block is MIGRATE_MOVABLE or MIGRATE_CMA, allow migration */
> + /* If the block is MIGRATE_MOVABLE, allow migration */
> if (migrate_async_suitable(get_pageblock_migratetype(page)))
> return true;
>
> @@ -1277,12 +1277,6 @@ static enum compact_result __compact_finished(struct zone *zone, struct compact_
> if (!list_empty(&area->free_list[migratetype]))
> return COMPACT_PARTIAL;
>
> -#ifdef CONFIG_CMA
> - /* MIGRATE_MOVABLE can fallback on MIGRATE_CMA */
> - if (migratetype == MIGRATE_MOVABLE &&
> - !list_empty(&area->free_list[MIGRATE_CMA]))
> - return COMPACT_PARTIAL;
> -#endif
> /*
> * Job done if allocation would steal freepages from
> * other migratetype buddy lists.
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index d26162e..a081f15 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1029,7 +1029,7 @@ static int __alloc_gigantic_page(unsigned long start_pfn,
> unsigned long nr_pages)
> {
> unsigned long end_pfn = start_pfn + nr_pages;
> - return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
> + return alloc_contig_range(start_pfn, end_pfn);
> }
>
> static bool pfn_range_valid_gigantic(struct zone *z,
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index bab3698..e1c17d15 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -124,8 +124,8 @@ gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
> * put on a pcplist. Used to avoid the pageblock migratetype lookup when
> * freeing from pcplists in most cases, at the cost of possibly becoming stale.
> * Also the migratetype set in the page does not necessarily match the pcplist
> - * index, e.g. page might have MIGRATE_CMA set but be on a pcplist with any
> - * other index - this ensures that it will be put on the correct CMA freelist.
> + * index, e.g. page might have MIGRATE_MOVABLE set but be on a pcplist with any
> + * other index - this ensures that it will be put on the correct freelist.
> */
> static inline int get_pcppage_migratetype(struct page *page)
> {
> @@ -234,9 +234,6 @@ char * const migratetype_names[MIGRATE_TYPES] = {
> "Movable",
> "Reclaimable",
> "HighAtomic",
> -#ifdef CONFIG_CMA
> - "CMA",
> -#endif
> #ifdef CONFIG_MEMORY_ISOLATION
> "Isolate",
> #endif
> @@ -670,7 +667,7 @@ static inline void set_page_guard(struct zone *zone, struct page *page,
> INIT_LIST_HEAD(&page->lru);
> set_page_private(page, order);
> /* Guard pages are not available for any usage */
> - __mod_zone_freepage_state(zone, -(1 << order), migratetype);
> + __mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
> }
>
> static inline void clear_page_guard(struct zone *zone, struct page *page,
> @@ -689,7 +686,7 @@ static inline void clear_page_guard(struct zone *zone, struct page *page,
>
> set_page_private(page, 0);
> if (!is_migrate_isolate(migratetype))
> - __mod_zone_freepage_state(zone, (1 << order), migratetype);
> + __mod_zone_page_state(zone, NR_FREE_PAGES, (1 << order));
> }
> #else
> struct page_ext_operations debug_guardpage_ops = { NULL, };
> @@ -800,7 +797,7 @@ static inline void __free_one_page(struct page *page,
>
> VM_BUG_ON(migratetype == -1);
> if (likely(!is_migrate_isolate(migratetype)))
> - __mod_zone_freepage_state(zone, 1 << order, migratetype);
> + __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
>
> page_idx = pfn & ((1 << MAX_ORDER) - 1);
>
> @@ -1580,7 +1577,7 @@ static void __init adjust_present_page_count(struct page *page, long count)
> zone->present_pages += count;
> }
>
> -/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
> +/* Free whole pageblock and set its migration type to MIGRATE_MOVABLE. */
> void __init init_cma_reserved_pageblock(struct page *page)
> {
> unsigned i = pageblock_nr_pages;
> @@ -1605,7 +1602,7 @@ void __init init_cma_reserved_pageblock(struct page *page)
>
> adjust_present_page_count(page, pageblock_nr_pages);
>
> - set_pageblock_migratetype(page, MIGRATE_CMA);
> + set_pageblock_migratetype(page, MIGRATE_MOVABLE);
I have a question here, if the ZONE_CMA pages are all movable.
Then the unmovable alloc will also use CMA memory. Is this right?
How can the cma memory be migrate?
>
> if (pageblock_order >= MAX_ORDER) {
> i = pageblock_nr_pages;
> @@ -1830,25 +1827,11 @@ static int fallbacks[MIGRATE_TYPES][4] = {
> [MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_TYPES },
> [MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_TYPES },
> [MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_TYPES },
> -#ifdef CONFIG_CMA
> - [MIGRATE_CMA] = { MIGRATE_TYPES }, /* Never used */
> -#endif
> #ifdef CONFIG_MEMORY_ISOLATION
> [MIGRATE_ISOLATE] = { MIGRATE_TYPES }, /* Never used */
> #endif
> };
>
> -#ifdef CONFIG_CMA
> -static struct page *__rmqueue_cma_fallback(struct zone *zone,
> - unsigned int order)
> -{
> - return __rmqueue_smallest(zone, order, MIGRATE_CMA);
> -}
> -#else
> -static inline struct page *__rmqueue_cma_fallback(struct zone *zone,
> - unsigned int order) { return NULL; }
> -#endif
> -
> /*
> * Move the free pages in a range to the free lists of the requested type.
> * Note that start_page and end_pages are not aligned on a pageblock
> @@ -2053,7 +2036,7 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone,
> /* Yoink! */
> mt = get_pageblock_migratetype(page);
> if (mt != MIGRATE_HIGHATOMIC &&
> - !is_migrate_isolate(mt) && !is_migrate_cma(mt)) {
> + !is_migrate_isolate(mt)) {
> zone->nr_reserved_highatomic += pageblock_nr_pages;
> set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC);
> move_freepages_block(zone, page, MIGRATE_HIGHATOMIC);
> @@ -2156,9 +2139,7 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype)
> /*
> * The pcppage_migratetype may differ from pageblock's
> * migratetype depending on the decisions in
> - * find_suitable_fallback(). This is OK as long as it does not
> - * differ for MIGRATE_CMA pageblocks. Those can be used as
> - * fallback only via special __rmqueue_cma_fallback() function
> + * find_suitable_fallback(). This is OK.
> */
> set_pcppage_migratetype(page, start_migratetype);
>
> @@ -2181,13 +2162,8 @@ static struct page *__rmqueue(struct zone *zone, unsigned int order,
> struct page *page;
>
> page = __rmqueue_smallest(zone, order, migratetype);
> - if (unlikely(!page)) {
> - if (migratetype == MIGRATE_MOVABLE)
> - page = __rmqueue_cma_fallback(zone, order);
> -
> - if (!page)
> - page = __rmqueue_fallback(zone, order, migratetype);
> - }
> + if (unlikely(!page))
> + page = __rmqueue_fallback(zone, order, migratetype);
>
> trace_mm_page_alloc_zone_locked(page, order, migratetype);
> return page;
> @@ -2227,9 +2203,6 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
> else
> list_add_tail(&page->lru, list);
> list = &page->lru;
> - if (is_migrate_cma(get_pcppage_migratetype(page)))
> - __mod_zone_page_state(zone, NR_FREE_CMA_PAGES,
> - -(1 << order));
> }
> __mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
> spin_unlock(&zone->lock);
> @@ -2527,7 +2500,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
> if (!zone_watermark_ok(zone, 0, watermark, 0, 0))
> return 0;
>
> - __mod_zone_freepage_state(zone, -(1UL << order), mt);
> + __mod_zone_page_state(zone, NR_FREE_PAGES, -(1UL << order));
> }
>
> /* Remove page from free list */
> @@ -2542,7 +2515,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
> struct page *endpage = page + (1 << order) - 1;
> for (; page < endpage; page += pageblock_nr_pages) {
> int mt = get_pageblock_migratetype(page);
> - if (!is_migrate_isolate(mt) && !is_migrate_cma(mt))
> + if (!is_migrate_isolate(mt))
> set_pageblock_migratetype(page,
> MIGRATE_MOVABLE);
> }
> @@ -2670,8 +2643,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
> if (!page)
> goto failed;
> __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
> - __mod_zone_freepage_state(zone, -(1 << order),
> - get_pcppage_migratetype(page));
> + __mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
> }
>
> if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
> @@ -2825,11 +2797,6 @@ bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
> if (!list_empty(&area->free_list[mt]))
> return true;
> }
> -
> -#ifdef CONFIG_CMA
> - if (!list_empty(&area->free_list[MIGRATE_CMA]))
> - return true;
> -#endif
> }
> return false;
> }
> @@ -4320,9 +4287,6 @@ static void show_migration_types(unsigned char type)
> [MIGRATE_MOVABLE] = 'M',
> [MIGRATE_RECLAIMABLE] = 'E',
> [MIGRATE_HIGHATOMIC] = 'H',
> -#ifdef CONFIG_CMA
> - [MIGRATE_CMA] = 'C',
> -#endif
> #ifdef CONFIG_MEMORY_ISOLATION
> [MIGRATE_ISOLATE] = 'I',
> #endif
> @@ -7244,7 +7208,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
> return false;
>
> mt = get_pageblock_migratetype(page);
> - if (mt == MIGRATE_MOVABLE || is_migrate_cma(mt))
> + if (mt == MIGRATE_MOVABLE)
> return false;
>
> pfn = page_to_pfn(page);
> @@ -7392,15 +7356,11 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
> * alloc_contig_range() -- tries to allocate given range of pages
> * @start: start PFN to allocate
> * @end: one-past-the-last PFN to allocate
> - * @migratetype: migratetype of the underlaying pageblocks (either
> - * #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks
> - * in range must have the same migratetype and it must
> - * be either of the two.
> *
> * The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
> * aligned, however it's the caller's responsibility to guarantee that
> * we are the only thread that changes migrate type of pageblocks the
> - * pages fall in.
> + * pages fall in and it should be MIGRATE_MOVABLE.
> *
> * The PFN range must belong to a single zone.
> *
> @@ -7408,8 +7368,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
> * pages which PFN is in [start, end) are allocated for the caller and
> * need to be freed with free_contig_range().
> */
> -int alloc_contig_range(unsigned long start, unsigned long end,
> - unsigned migratetype)
> +int alloc_contig_range(unsigned long start, unsigned long end)
> {
> unsigned long outer_start, outer_end;
> unsigned int order;
> @@ -7442,14 +7401,14 @@ int alloc_contig_range(unsigned long start, unsigned long end,
> * allocator removing them from the buddy system. This way
> * page allocator will never consider using them.
> *
> - * This lets us mark the pageblocks back as
> - * MIGRATE_CMA/MIGRATE_MOVABLE so that free pages in the
> - * aligned range but not in the unaligned, original range are
> - * put back to page allocator so that buddy can use them.
> + * This lets us mark the pageblocks back as MIGRATE_MOVABLE
> + * so that free pages in the aligned range but not in the
> + * unaligned, original range are put back to page allocator
> + * so that buddy can use them.
> */
>
> ret = start_isolate_page_range(pfn_max_align_down(start),
> - pfn_max_align_up(end), migratetype,
> + pfn_max_align_up(end), MIGRATE_MOVABLE,
> false);
> if (ret)
> return ret;
> @@ -7528,7 +7487,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);
> + pfn_max_align_up(end), MIGRATE_MOVABLE);
> return ret;
> }
>
> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
> index 612122b..5708649 100644
> --- a/mm/page_isolation.c
> +++ b/mm/page_isolation.c
> @@ -61,13 +61,12 @@ static int set_migratetype_isolate(struct page *page,
> out:
> if (!ret) {
> unsigned long nr_pages;
> - int migratetype = get_pageblock_migratetype(page);
>
> set_pageblock_migratetype(page, MIGRATE_ISOLATE);
> zone->nr_isolate_pageblock++;
> nr_pages = move_freepages_block(zone, page, MIGRATE_ISOLATE);
>
> - __mod_zone_freepage_state(zone, -nr_pages, migratetype);
> + __mod_zone_page_state(zone, NR_FREE_PAGES, -nr_pages);
> }
>
> spin_unlock_irqrestore(&zone->lock, flags);
> @@ -122,7 +121,7 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
> */
> if (!isolated_page) {
> nr_pages = move_freepages_block(zone, page, migratetype);
> - __mod_zone_freepage_state(zone, nr_pages, migratetype);
> + __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
> }
> set_pageblock_migratetype(page, migratetype);
> zone->nr_isolate_pageblock--;
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 48c4942..8d18d1e 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1088,10 +1088,7 @@ static void pagetypeinfo_showmixedcount_print(struct seq_file *m,
>
> page_mt = gfpflags_to_migratetype(page_ext->gfp_mask);
> if (pageblock_mt != page_mt) {
> - if (is_migrate_cma(pageblock_mt))
> - count[MIGRATE_MOVABLE]++;
> - else
> - count[pageblock_mt]++;
> + count[pageblock_mt]++;
>
> pfn = block_end_pfn;
> break;
>
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <iamjoonsoo.kim@lge.com> |
|---|---|
| Date | 2016-05-27 07:40 +0200 |
| Subject | Re: [PATCH v3 5/6] mm/cma: remove MIGRATE_CMA |
| Message-ID | <rDiF3-7NW-1@gated-at.bofh.it> |
| In reply to | #1407773 |
On Fri, May 27, 2016 at 09:42:24AM +0800, Chen Feng wrote:
> Hi Joonsoo,
> > -/* Free whole pageblock and set its migration type to MIGRATE_CMA. */
> > +/* Free whole pageblock and set its migration type to MIGRATE_MOVABLE. */
> > void __init init_cma_reserved_pageblock(struct page *page)
> > {
> > unsigned i = pageblock_nr_pages;
> > @@ -1605,7 +1602,7 @@ void __init init_cma_reserved_pageblock(struct page *page)
> >
> > adjust_present_page_count(page, pageblock_nr_pages);
> >
> > - set_pageblock_migratetype(page, MIGRATE_CMA);
> > + set_pageblock_migratetype(page, MIGRATE_MOVABLE);
>
> I have a question here, if the ZONE_CMA pages are all movable.
>
> Then the unmovable alloc will also use CMA memory. Is this right?
No, previous patch changes that the CMA memory is on separate zone,
ZONE_CMA. We allow that zone when gfp is GFP_HIGHUSER_MOVABLE so
unmovable allocation cannot happen on CMA memory.
Thanks.
[toc] | [prev] | [next] | [standalone]
| From | js1304@gmail.com |
|---|---|
| Date | 2016-05-26 08:30 +0200 |
| Subject | [PATCH v3 6/6] mm/cma: remove per zone CMA stat |
| Message-ID | <rCWXU-2Qp-23@gated-at.bofh.it> |
| In reply to | #1407398 |
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Now, all reserved pages for CMA region are belong to the ZONE_CMA
so we don't need to maintain CMA stat in other zones. Remove it.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
fs/proc/meminfo.c | 2 +-
include/linux/cma.h | 6 ++++++
include/linux/mmzone.h | 1 -
mm/cma.c | 15 +++++++++++++++
mm/page_alloc.c | 5 ++---
mm/vmstat.c | 1 -
6 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 8372046..bd853725c 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -167,7 +167,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
#endif
#ifdef CONFIG_CMA
, K(totalcma_pages)
- , K(global_page_state(NR_FREE_CMA_PAGES))
+ , K(cma_get_free())
#endif
);
diff --git a/include/linux/cma.h b/include/linux/cma.h
index 29f9e77..816290c 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -28,4 +28,10 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
struct cma **res_cma);
extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align);
extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count);
+
+#ifdef CONFIG_CMA
+extern unsigned long cma_get_free(void);
+#else
+static inline unsigned long cma_get_free(void) { return 0; }
+#endif
#endif
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 236d0bd..59f2181 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -130,7 +130,6 @@ enum zone_stat_item {
WORKINGSET_ACTIVATE,
WORKINGSET_NODERECLAIM,
NR_ANON_TRANSPARENT_HUGEPAGES,
- NR_FREE_CMA_PAGES,
NR_VM_ZONE_STAT_ITEMS };
/*
diff --git a/mm/cma.c b/mm/cma.c
index bd436e4..6dbddf2 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -54,6 +54,21 @@ unsigned long cma_get_size(const struct cma *cma)
return cma->count << PAGE_SHIFT;
}
+unsigned long cma_get_free(void)
+{
+ struct zone *zone;
+ unsigned long freecma = 0;
+
+ for_each_populated_zone(zone) {
+ if (!is_zone_cma(zone))
+ continue;
+
+ freecma += zone_page_state(zone, NR_FREE_PAGES);
+ }
+
+ return freecma;
+}
+
static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
int align_order)
{
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e1c17d15..da6e6cf 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -63,6 +63,7 @@
#include <linux/sched/rt.h>
#include <linux/page_owner.h>
#include <linux/kthread.h>
+#include <linux/cma.h>
#include <asm/sections.h>
#include <asm/tlbflush.h>
@@ -4351,7 +4352,7 @@ void show_free_areas(unsigned int filter)
global_page_state(NR_BOUNCE),
global_page_state(NR_FREE_PAGES),
free_pcp,
- global_page_state(NR_FREE_CMA_PAGES));
+ cma_get_free());
for_each_populated_zone(zone) {
int i;
@@ -4391,7 +4392,6 @@ void show_free_areas(unsigned int filter)
" bounce:%lukB"
" free_pcp:%lukB"
" local_pcp:%ukB"
- " free_cma:%lukB"
" writeback_tmp:%lukB"
" pages_scanned:%lu"
" all_unreclaimable? %s"
@@ -4424,7 +4424,6 @@ void show_free_areas(unsigned int filter)
K(zone_page_state(zone, NR_BOUNCE)),
K(free_pcp),
K(this_cpu_read(zone->pageset->pcp.count)),
- K(zone_page_state(zone, NR_FREE_CMA_PAGES)),
K(zone_page_state(zone, NR_WRITEBACK_TEMP)),
K(zone_page_state(zone, NR_PAGES_SCANNED)),
(!zone_reclaimable(zone) ? "yes" : "no")
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 8d18d1e..9607f99 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -750,7 +750,6 @@ const char * const vmstat_text[] = {
"workingset_activate",
"workingset_nodereclaim",
"nr_anon_transparent_hugepages",
- "nr_free_cma",
/* enum writeback_stat_item counters */
"nr_dirty_threshold",
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Feng Tang <feng.tang@intel.com> |
|---|---|
| Date | 2016-05-26 10:10 +0200 |
| Message-ID | <rCYwG-3W0-11@gated-at.bofh.it> |
| In reply to | #1407398 |
On Thu, May 26, 2016 at 02:22:22PM +0800, js1304@gmail.com wrote: > From: Joonsoo Kim <iamjoonsoo.kim@lge.com> Hi Joonsoo, Nice work! > > Hello, > > Changes from v2 > o Rebase on next-20160525 > o No other changes except following description > > There was a discussion with Mel [1] after LSF/MM 2016. I could summarise > it to help merge decision but it's better to read by yourself since > if I summarise it, it would be biased for me. But, if anyone hope > the summary, I will do it. :) > > Anyway, Mel's position on this patchset seems to be neutral. He said: > "I'm not going to outright NAK your series but I won't ACK it either" > > We can fix the problems with any approach but I hope to go a new zone > approach because it is less error-prone. It reduces some corner case > handling for now and remove need for potential corner case handling to fix > problems. > > Note that our company is already using ZONE_CMA for a years and > there is no problem. > > If anyone has a different opinion, please let me know and let's discuss > together. > > Andrew, if there is something to do for merge, please let me know. > > [1] https://lkml.kernel.org/r/20160425053653.GA25662@js1304-P5Q-DELUXE > > Changes from v1 > o Separate some patches which deserve to submit independently > o Modify description to reflect current kernel state > (e.g. high-order watermark problem disappeared by Mel's work) > o Don't increase SECTION_SIZE_BITS to make a room in page flags > (detailed reason is on the patch that adds ZONE_CMA) > o Adjust ZONE_CMA population code > > This series try to solve problems of current CMA implementation. > > CMA is introduced to provide physically contiguous pages at runtime > without exclusive reserved memory area. But, current implementation > works like as previous reserved memory approach, because freepages > on CMA region are used only if there is no movable freepage. In other > words, freepages on CMA region are only used as fallback. In that > situation where freepages on CMA region are used as fallback, kswapd > would be woken up easily since there is no unmovable and reclaimable > freepage, too. If kswapd starts to reclaim memory, fallback allocation > to MIGRATE_CMA doesn't occur any more since movable freepages are > already refilled by kswapd and then most of freepage on CMA are left > to be in free. This situation looks like exclusive reserved memory case. > > In my experiment, I found that if system memory has 1024 MB memory and > 512 MB is reserved for CMA, kswapd is mostly woken up when roughly 512 MB > free memory is left. Detailed reason is that for keeping enough free > memory for unmovable and reclaimable allocation, kswapd uses below > equation when calculating free memory and it easily go under the watermark. > > Free memory for unmovable and reclaimable = Free total - Free CMA pages > > This is derivated from the property of CMA freepage that CMA freepage > can't be used for unmovable and reclaimable allocation. > > Anyway, in this case, kswapd are woken up when (FreeTotal - FreeCMA) > is lower than low watermark and tries to make free memory until > (FreeTotal - FreeCMA) is higher than high watermark. That results > in that FreeTotal is moving around 512MB boundary consistently. It > then means that we can't utilize full memory capacity. > > To fix this problem, I submitted some patches [1] about 10 months ago, > but, found some more problems to be fixed before solving this problem. > It requires many hooks in allocator hotpath so some developers doesn't > like it. Instead, some of them suggest different approach [2] to fix > all the problems related to CMA, that is, introducing a new zone to deal > with free CMA pages. I agree that it is the best way to go so implement > here. Although properties of ZONE_MOVABLE and ZONE_CMA is similar, I > decide to add a new zone rather than piggyback on ZONE_MOVABLE since > they have some differences. First, reserved CMA pages should not be > offlined. If freepage for CMA is managed by ZONE_MOVABLE, we need to keep > MIGRATE_CMA migratetype and insert many hooks on memory hotplug code > to distiguish hotpluggable memory and reserved memory for CMA in the same > zone. It would make memory hotplug code which is already complicated > more complicated. Second, cma_alloc() can be called more frequently > than memory hotplug operation and possibly we need to control > allocation rate of ZONE_CMA to optimize latency in the future. > In this case, separate zone approach is easy to modify. Third, I'd > like to see statistics for CMA, separately. Sometimes, we need to debug > why cma_alloc() is failed and separate statistics would be more helpful > in this situtaion. > > Anyway, this patchset solves four problems related to CMA implementation. > > 1) Utilization problem > As mentioned above, we can't utilize full memory capacity due to the > limitation of CMA freepage and fallback policy. This patchset implements > a new zone for CMA and uses it for GFP_HIGHUSER_MOVABLE request. This > typed allocation is used for page cache and anonymous pages which > occupies most of memory usage in normal case so we can utilize full > memory capacity. Below is the experiment result about this problem. > > 8 CPUs, 1024 MB, VIRTUAL MACHINE > make -j16 > > <Before this series> > CMA reserve: 0 MB 512 MB > Elapsed-time: 92.4 186.5 > pswpin: 82 18647 > pswpout: 160 69839 > > <After this series> > CMA reserve: 0 MB 512 MB > Elapsed-time: 93.1 93.4 > pswpin: 84 46 > pswpout: 183 92 > > FYI, there is another attempt [3] trying to solve this problem in lkml. > And, as far as I know, Qualcomm also has out-of-tree solution for this > problem. This may be a little off-topic :) Actually, we have used another way in our products, that we disable the fallback from MIGRATETYE_MOVABLE to MIGRATETYPE_CMA completely, and only allow free CMA memory to be used by file page cache (which is easy to be reclaimed by its nature). We did it by adding a GFP_PAGE_CACHE to every allocation request for page cache, and the MM will try to pick up an available free CMA page first, and goes to normal path when fail. It works fine on our products, though we still see some cases that some page can't be reclaimed. Our product has a special user case of CMA, that sometimes it will need to use the whole CMA memory (say 256MB on a phone), then all share out CMA pages need to be reclaimed all at once. Don't know if this new ZONE_CMA approach could meet this request? (our page cache solution can't ganrantee to meet this request all the time). Thanks, Feng
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <iamjoonsoo.kim@lge.com> |
|---|---|
| Date | 2016-05-27 07:30 +0200 |
| Message-ID | <rDivn-7KL-3@gated-at.bofh.it> |
| In reply to | #1407443 |
On Thu, May 26, 2016 at 04:04:54PM +0800, Feng Tang wrote: > On Thu, May 26, 2016 at 02:22:22PM +0800, js1304@gmail.com wrote: > > From: Joonsoo Kim <iamjoonsoo.kim@lge.com> > > Hi Joonsoo, > > Nice work! Thanks! > > FYI, there is another attempt [3] trying to solve this problem in lkml. > > And, as far as I know, Qualcomm also has out-of-tree solution for this > > problem. > > This may be a little off-topic :) Actually, we have used another way in > our products, that we disable the fallback from MIGRATETYE_MOVABLE to > MIGRATETYPE_CMA completely, and only allow free CMA memory to be used > by file page cache (which is easy to be reclaimed by its nature). > We did it by adding a GFP_PAGE_CACHE to every allocation request for > page cache, and the MM will try to pick up an available free CMA page > first, and goes to normal path when fail. Just wonder, why do you allow CMA memory to file page cache rather than anonymous page? I guess that anonymous pages would be more easily migrated/reclaimed than file page cache. In fact, some of our product uses anonymous page adaptation to satisfy similar requirement by introducing GFP_CMA. AFAIK, some of chip vendor also uses "anonymous page first adaptation" to get better success rate. > It works fine on our products, though we still see some cases that > some page can't be reclaimed. > > Our product has a special user case of CMA, that sometimes it will > need to use the whole CMA memory (say 256MB on a phone), then all I don't think this usecase is so special. Our product also has similar usecase. And, I already knows one another. > share out CMA pages need to be reclaimed all at once. Don't know if > this new ZONE_CMA approach could meet this request? (our page cache > solution can't ganrantee to meet this request all the time). This ZONE_CMA approach would be better than before, since CMA memory is not be used for blockdev page cache. Blockdev page cache is one of the frequent failure points in my experience. I'm not sure that ZONE_CMA works better than your GFP_PAGE_CACHE adaptation for your system. In ZONE_CMA, CMA memory is used for file page cache or anonymous pages. If my assumption that anonymous pages are easier to be migrated/reclaimed is correct, ZONE_CMA would work better than your adaptation since there is less file page cache pages in CMA memory. Anyway, it also doesn't guarantee to succeed all the time. There is different kind of problem that prevents CMA allocation success and we need to solve it. I will try it after problems that this patchset try to fix is solved. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Feng Tang <feng.tang@intel.com> |
|---|---|
| Date | 2016-05-27 08:30 +0200 |
| Message-ID | <rDjrr-8iY-7@gated-at.bofh.it> |
| In reply to | #1407819 |
On Fri, May 27, 2016 at 01:28:20PM +0800, Joonsoo Kim wrote: > On Thu, May 26, 2016 at 04:04:54PM +0800, Feng Tang wrote: > > On Thu, May 26, 2016 at 02:22:22PM +0800, js1304@gmail.com wrote: > > > From: Joonsoo Kim <iamjoonsoo.kim@lge.com> > > > > > FYI, there is another attempt [3] trying to solve this problem in lkml. > > > And, as far as I know, Qualcomm also has out-of-tree solution for this > > > problem. > > > > This may be a little off-topic :) Actually, we have used another way in > > our products, that we disable the fallback from MIGRATETYE_MOVABLE to > > MIGRATETYPE_CMA completely, and only allow free CMA memory to be used > > by file page cache (which is easy to be reclaimed by its nature). > > We did it by adding a GFP_PAGE_CACHE to every allocation request for > > page cache, and the MM will try to pick up an available free CMA page > > first, and goes to normal path when fail. > > Just wonder, why do you allow CMA memory to file page cache rather > than anonymous page? I guess that anonymous pages would be more easily > migrated/reclaimed than file page cache. In fact, some of our product > uses anonymous page adaptation to satisfy similar requirement by > introducing GFP_CMA. AFAIK, some of chip vendor also uses "anonymous > page first adaptation" to get better success rate. The biggest problem we faced is to allocate big chunk of CMA memory, say 256MB in a whole, or 9 pieces of 20MB buffers, so the speed is not the biggest concern, but whether all the cma pages be reclaimed. With the MOVABLE fallback, there may be many types of bad guys from device drivers/kernel or different subsystems, who refuse to return the borrowed cma pages, so I took a lazy way by only allowing page cache to use free cma pages, and we see good results which could pass most of the test for allocating big chunks. One of the customer used to use a CMA sharing patch from another vendor on our Socs, which can't pass these tests and finally took our page cache approach. > > > It works fine on our products, though we still see some cases that > > some page can't be reclaimed. > > > > Our product has a special user case of CMA, that sometimes it will > > need to use the whole CMA memory (say 256MB on a phone), then all > > I don't think this usecase is so special. Our product also has similar > usecase. And, I already knows one another. :) I first touch CMA in 2014 and have only worked on Sofia platforms. > > > share out CMA pages need to be reclaimed all at once. Don't know if > > this new ZONE_CMA approach could meet this request? (our page cache > > solution can't ganrantee to meet this request all the time). > > This ZONE_CMA approach would be better than before, since CMA memory > is not be used for blockdev page cache. Blockdev page cache is one of > the frequent failure points in my experience. Indeed! I also explicitely disabled cma sharing for blkdev FS page cache. > > I'm not sure that ZONE_CMA works better than your GFP_PAGE_CACHE > adaptation for your system. In ZONE_CMA, CMA memory is used for file > page cache or anonymous pages. If my assumption that anonymous pages > are easier to be migrated/reclaimed is correct, ZONE_CMA would work > better than your adaptation since there is less file page cache pages > in CMA memory. > > Anyway, it also doesn't guarantee to succeed all the time. There is > different kind of problem that prevents CMA allocation success and we > need to solve it. I will try it after problems that this patchset try > to fix is solved. ZONE_CMA should be cleaner, while our page cache solution needs to adjust some policy for lowmemorykiller and page scan/reclaim code. Thanks, Feng
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <iamjoonsoo.kim@lge.com> |
|---|---|
| Date | 2016-05-27 08:50 +0200 |
| Message-ID | <rDjKN-8ri-1@gated-at.bofh.it> |
| In reply to | #1407839 |
On Fri, May 27, 2016 at 02:25:27PM +0800, Feng Tang wrote: > On Fri, May 27, 2016 at 01:28:20PM +0800, Joonsoo Kim wrote: > > On Thu, May 26, 2016 at 04:04:54PM +0800, Feng Tang wrote: > > > On Thu, May 26, 2016 at 02:22:22PM +0800, js1304@gmail.com wrote: > > > > From: Joonsoo Kim <iamjoonsoo.kim@lge.com> > > > > > > > > FYI, there is another attempt [3] trying to solve this problem in lkml. > > > > And, as far as I know, Qualcomm also has out-of-tree solution for this > > > > problem. > > > > > > This may be a little off-topic :) Actually, we have used another way in > > > our products, that we disable the fallback from MIGRATETYE_MOVABLE to > > > MIGRATETYPE_CMA completely, and only allow free CMA memory to be used > > > by file page cache (which is easy to be reclaimed by its nature). > > > We did it by adding a GFP_PAGE_CACHE to every allocation request for > > > page cache, and the MM will try to pick up an available free CMA page > > > first, and goes to normal path when fail. > > > > Just wonder, why do you allow CMA memory to file page cache rather > > than anonymous page? I guess that anonymous pages would be more easily > > migrated/reclaimed than file page cache. In fact, some of our product > > uses anonymous page adaptation to satisfy similar requirement by > > introducing GFP_CMA. AFAIK, some of chip vendor also uses "anonymous > > page first adaptation" to get better success rate. > > The biggest problem we faced is to allocate big chunk of CMA memory, > say 256MB in a whole, or 9 pieces of 20MB buffers, so the speed > is not the biggest concern, but whether all the cma pages be reclaimed. Okay. Our product have similar workload. > With the MOVABLE fallback, there may be many types of bad guys from device > drivers/kernel or different subsystems, who refuse to return the borrowed > cma pages, so I took a lazy way by only allowing page cache to use free > cma pages, and we see good results which could pass most of the test for > allocating big chunks. Could you explain more about why file page cache rather than anonymous page? If there is a reason, I'd like to test it by myself. > One of the customer used to use a CMA sharing patch from another vendor > on our Socs, which can't pass these tests and finally took our page cache > approach. CMA has too many problems so each vendor uses their own adaptation. I'd like to solve this code fragmentation by fixing problems on upstream kernel and this ZONE_CMA is one of that effort. If you can share the pointer for your adaptation, it would be very helpful to me. Thanks. > > > > > It works fine on our products, though we still see some cases that > > > some page can't be reclaimed. > > > > > > Our product has a special user case of CMA, that sometimes it will > > > need to use the whole CMA memory (say 256MB on a phone), then all > > > > I don't think this usecase is so special. Our product also has similar > > usecase. And, I already knows one another. > > :) I first touch CMA in 2014 and have only worked on Sofia platforms. > > > > > > share out CMA pages need to be reclaimed all at once. Don't know if > > > this new ZONE_CMA approach could meet this request? (our page cache > > > solution can't ganrantee to meet this request all the time). > > > > This ZONE_CMA approach would be better than before, since CMA memory > > is not be used for blockdev page cache. Blockdev page cache is one of > > the frequent failure points in my experience. > > Indeed! I also explicitely disabled cma sharing for blkdev FS page cache. > > > > > I'm not sure that ZONE_CMA works better than your GFP_PAGE_CACHE > > adaptation for your system. In ZONE_CMA, CMA memory is used for file > > page cache or anonymous pages. If my assumption that anonymous pages > > are easier to be migrated/reclaimed is correct, ZONE_CMA would work > > better than your adaptation since there is less file page cache pages > > in CMA memory. > > > > Anyway, it also doesn't guarantee to succeed all the time. There is > > different kind of problem that prevents CMA allocation success and we > > need to solve it. I will try it after problems that this patchset try > > to fix is solved. > > ZONE_CMA should be cleaner, while our page cache solution needs to > adjust some policy for lowmemorykiller and page scan/reclaim code. > > Thanks, > Feng > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
[toc] | [prev] | [next] | [standalone]
| From | Feng Tang <feng.tang@intel.com> |
|---|---|
| Date | 2016-05-27 09:30 +0200 |
| Message-ID | <rDknw-rU-1@gated-at.bofh.it> |
| In reply to | #1407845 |
On Fri, May 27, 2016 at 02:42:18PM +0800, Joonsoo Kim wrote:
> On Fri, May 27, 2016 at 02:25:27PM +0800, Feng Tang wrote:
> > On Fri, May 27, 2016 at 01:28:20PM +0800, Joonsoo Kim wrote:
> > > On Thu, May 26, 2016 at 04:04:54PM +0800, Feng Tang wrote:
> > > > On Thu, May 26, 2016 at 02:22:22PM +0800, js1304@gmail.com wrote:
> > > > > From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> > > >
> >
> > > > > FYI, there is another attempt [3] trying to solve this problem in lkml.
> > > > > And, as far as I know, Qualcomm also has out-of-tree solution for this
> > > > > problem.
> > > >
> > > > This may be a little off-topic :) Actually, we have used another way in
> > > > our products, that we disable the fallback from MIGRATETYE_MOVABLE to
> > > > MIGRATETYPE_CMA completely, and only allow free CMA memory to be used
> > > > by file page cache (which is easy to be reclaimed by its nature).
> > > > We did it by adding a GFP_PAGE_CACHE to every allocation request for
> > > > page cache, and the MM will try to pick up an available free CMA page
> > > > first, and goes to normal path when fail.
> > >
> > > Just wonder, why do you allow CMA memory to file page cache rather
> > > than anonymous page? I guess that anonymous pages would be more easily
> > > migrated/reclaimed than file page cache. In fact, some of our product
> > > uses anonymous page adaptation to satisfy similar requirement by
> > > introducing GFP_CMA. AFAIK, some of chip vendor also uses "anonymous
> > > page first adaptation" to get better success rate.
> >
> > The biggest problem we faced is to allocate big chunk of CMA memory,
> > say 256MB in a whole, or 9 pieces of 20MB buffers, so the speed
> > is not the biggest concern, but whether all the cma pages be reclaimed.
>
> Okay. Our product have similar workload.
>
> > With the MOVABLE fallback, there may be many types of bad guys from device
> > drivers/kernel or different subsystems, who refuse to return the borrowed
> > cma pages, so I took a lazy way by only allowing page cache to use free
> > cma pages, and we see good results which could pass most of the test for
> > allocating big chunks.
>
> Could you explain more about why file page cache rather than anonymous page?
> If there is a reason, I'd like to test it by myself.
I didn't make it clear. This is not for anonymous page, but for MIGRATETYPE_MOVABLE.
following is the patch to disable the kernel default sharing (kernel 3.14)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 1b5f20e..a5e698f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -974,7 +974,11 @@ static int fallbacks[MIGRATE_TYPES][4] = {
[MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE },
[MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE },
#ifdef CONFIG_CMA
- [MIGRATE_MOVABLE] = { MIGRATE_CMA, MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_RESERVE },
+ [MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_RESERVE },
[MIGRATE_CMA] = { MIGRATE_RESERVE }, /* Never used */
[MIGRATE_CMA_ISOLATE] = { MIGRATE_RESERVE }, /* Never used */
#else
@@ -1414,6 +1418,18 @@ void free_hot_cold_page(struct page *page, int cold)
local_irq_save(flags);
__count_vm_event(PGFREE);
+#ifndef CONFIG_USE_CMA_FALLBACK
+ if (migratetype == MIGRATE_CMA) {
+ free_one_page(zone, page, 0, MIGRATE_CMA);
+ local_irq_restore(flags);
+ return;
+ }
+#endif
+
>
> > One of the customer used to use a CMA sharing patch from another vendor
> > on our Socs, which can't pass these tests and finally took our page cache
> > approach.
>
> CMA has too many problems so each vendor uses their own adaptation. I'd
> like to solve this code fragmentation by fixing problems on upstream
> kernel and this ZONE_CMA is one of that effort. If you can share the
> pointer for your adaptation, it would be very helpful to me.
As I said, I started to work on CMA problem back in 2014, and faced many
of these failure in reclamation problems. I didn't have time and capability
to track/analyze each and every failure, but decided to go another way by
only allowing the page cache to use CMA. And frankly speaking, I don't have
detailed data for performance measurement, but some rough one, that it
did improve the cma page reclaiming and the usage rate.
Our patches was based on 3.14 (the Android Mashmallow kenrel). Earlier this
year I finally got some free time, and worked on cleaning them for submission
to LKML, and found your cma improving patches merged in 4.1 or 4.2, so I gave
up as my patches is more hacky :)
The sharing patch is here FYI:
------
commit fb28d4db6278df42ab2ef4996bdfd44e613ace99
Author: Feng Tang <feng.tang@intel.com>
Date: Wed Jul 15 13:39:50 2015 +0800
cma, page-cache: use cma as page cache
This will free a lot of cma memory for system to use them
as page cache. Previously, cma memory is mostly preserved
and difficult to be shared by others, thus a big waste.
Using them as page cache will improve the meory usage, while
keeping the flexibility of fast reclaiming when big cma memory
request comes.
And some of the threshold values should be adjustable for
different platforms with different cma reserved memory, common
cma usage scenario and CTS test should be carefully verified
for those adjustment.
Signed-off-by: Feng Tang <feng.tang@intel.com>
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 5dc12b7..3c3ab2b 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -36,6 +36,7 @@ struct vm_area_struct;
#define ___GFP_NO_KSWAPD 0x400000u
#define ___GFP_OTHER_NODE 0x800000u
#define ___GFP_WRITE 0x1000000u
+#define ___GFP_CMA_PAGE_CACHE 0x2000000u
/* If the above are modified, __GFP_BITS_SHIFT may need updating */
/*
@@ -123,6 +124,9 @@ struct vm_area_struct;
__GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
__GFP_NO_KSWAPD)
+/* Allocat for page cache use */
+#define GFP_PAGE_CACHE ((__force gfp_t)___GFP_CMA_PAGE_CACHE)
+
/*
* GFP_THISNODE does not perform any reclaim, you most likely want to
* use __GFP_THISNODE to allocate from a given node without fallback!
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 1710d1b..a2452f6 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -221,7 +221,7 @@ extern struct page *__page_cache_alloc(gfp_t gfp);
#else
static inline struct page *__page_cache_alloc(gfp_t gfp)
{
- return alloc_pages(gfp, 0);
+ return alloc_pages(gfp | GFP_PAGE_CACHE, 0);
}
#endif
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 532ee0d..1b5f20e 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1568,7 +1568,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
int cold = !!(gfp_flags & __GFP_COLD);
again:
- if (likely(order == 0)) {
+ if (likely(order == 0) && !(gfp_flags & GFP_PAGE_CACHE)) {
struct per_cpu_pages *pcp;
struct list_head *list;
@@ -2744,6 +2744,8 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
int alloc_flags = ALLOC_WMARK_LOW|ALLOC_CPUSET;
struct mem_cgroup *memcg = NULL;
+ gfp_allowed_mask |= GFP_PAGE_CACHE;
+
gfp_mask &= gfp_allowed_mask;
lockdep_trace_alloc(gfp_mask);
@@ -2753,6 +2755,25 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
if (should_fail_alloc_page(gfp_mask, order))
return NULL;
+#ifdef CONFIG_CMA
+ if (gfp_mask & GFP_PAGE_CACHE) {
+ int nr_free = global_page_state(NR_FREE_PAGES)
+ - totalreserve_pages;
+ int free_cma = global_page_state(NR_FREE_CMA_PAGES);
+
+ /*
+ * Use CMA memory as page cache iff system is under memory
+ * pressure and free cma is big enough (>= 48M). And these
+ * value should be adjustable for different platforms with
+ * different cma reserved memory
+ */
+ if ((nr_free - free_cma) <= (48 * 1024 * 1024 / PAGE_SIZE)
+ && free_cma >= (48 * 1024 * 1024 / PAGE_SIZE)) {
+ migratetype = MIGRATE_CMA;
+ }
+ }
+#endif
+
/*
* Check the zones suitable for the gfp_mask contain at least one
* valid zone. It's possible to have an empty zonelist as a result
[toc] | [prev] | [next] | [standalone]
| From | Joonsoo Kim <iamjoonsoo.kim@lge.com> |
|---|---|
| Date | 2016-05-30 07:50 +0200 |
| Message-ID | <rEofn-8rU-1@gated-at.bofh.it> |
| In reply to | #1407867 |
On Fri, May 27, 2016 at 03:27:02PM +0800, Feng Tang wrote:
> On Fri, May 27, 2016 at 02:42:18PM +0800, Joonsoo Kim wrote:
> > On Fri, May 27, 2016 at 02:25:27PM +0800, Feng Tang wrote:
> > > On Fri, May 27, 2016 at 01:28:20PM +0800, Joonsoo Kim wrote:
> > > > On Thu, May 26, 2016 at 04:04:54PM +0800, Feng Tang wrote:
> > > > > On Thu, May 26, 2016 at 02:22:22PM +0800, js1304@gmail.com wrote:
> > > > > > From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> > > > >
> > >
> > > > > > FYI, there is another attempt [3] trying to solve this problem in lkml.
> > > > > > And, as far as I know, Qualcomm also has out-of-tree solution for this
> > > > > > problem.
> > > > >
> > > > > This may be a little off-topic :) Actually, we have used another way in
> > > > > our products, that we disable the fallback from MIGRATETYE_MOVABLE to
> > > > > MIGRATETYPE_CMA completely, and only allow free CMA memory to be used
> > > > > by file page cache (which is easy to be reclaimed by its nature).
> > > > > We did it by adding a GFP_PAGE_CACHE to every allocation request for
> > > > > page cache, and the MM will try to pick up an available free CMA page
> > > > > first, and goes to normal path when fail.
> > > >
> > > > Just wonder, why do you allow CMA memory to file page cache rather
> > > > than anonymous page? I guess that anonymous pages would be more easily
> > > > migrated/reclaimed than file page cache. In fact, some of our product
> > > > uses anonymous page adaptation to satisfy similar requirement by
> > > > introducing GFP_CMA. AFAIK, some of chip vendor also uses "anonymous
> > > > page first adaptation" to get better success rate.
> > >
> > > The biggest problem we faced is to allocate big chunk of CMA memory,
> > > say 256MB in a whole, or 9 pieces of 20MB buffers, so the speed
> > > is not the biggest concern, but whether all the cma pages be reclaimed.
> >
> > Okay. Our product have similar workload.
> >
> > > With the MOVABLE fallback, there may be many types of bad guys from device
> > > drivers/kernel or different subsystems, who refuse to return the borrowed
> > > cma pages, so I took a lazy way by only allowing page cache to use free
> > > cma pages, and we see good results which could pass most of the test for
> > > allocating big chunks.
> >
> > Could you explain more about why file page cache rather than anonymous page?
> > If there is a reason, I'd like to test it by myself.
>
> I didn't make it clear. This is not for anonymous page, but for MIGRATETYPE_MOVABLE.
Anonymous page is one of the pages with MIGRATETYPE_MOVABLE. So, you
can also restrict CMA memory only for anonymous page like as you did
for file page cache. Some of our product used this work around so I'd
like to know if there is a reason.
>
> following is the patch to disable the kernel default sharing (kernel 3.14)
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 1b5f20e..a5e698f 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -974,7 +974,11 @@ static int fallbacks[MIGRATE_TYPES][4] = {
> [MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE },
> [MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE },
> #ifdef CONFIG_CMA
> - [MIGRATE_MOVABLE] = { MIGRATE_CMA, MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_RESERVE },
> + [MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_RESERVE },
> [MIGRATE_CMA] = { MIGRATE_RESERVE }, /* Never used */
> [MIGRATE_CMA_ISOLATE] = { MIGRATE_RESERVE }, /* Never used */
> #else
> @@ -1414,6 +1418,18 @@ void free_hot_cold_page(struct page *page, int cold)
> local_irq_save(flags);
> __count_vm_event(PGFREE);
>
> +#ifndef CONFIG_USE_CMA_FALLBACK
> + if (migratetype == MIGRATE_CMA) {
> + free_one_page(zone, page, 0, MIGRATE_CMA);
> + local_irq_restore(flags);
> + return;
> + }
> +#endif
> +
>
> >
> > > One of the customer used to use a CMA sharing patch from another vendor
> > > on our Socs, which can't pass these tests and finally took our page cache
> > > approach.
> >
> > CMA has too many problems so each vendor uses their own adaptation. I'd
> > like to solve this code fragmentation by fixing problems on upstream
> > kernel and this ZONE_CMA is one of that effort. If you can share the
> > pointer for your adaptation, it would be very helpful to me.
>
> As I said, I started to work on CMA problem back in 2014, and faced many
> of these failure in reclamation problems. I didn't have time and capability
> to track/analyze each and every failure, but decided to go another way by
> only allowing the page cache to use CMA. And frankly speaking, I don't have
> detailed data for performance measurement, but some rough one, that it
> did improve the cma page reclaiming and the usage rate.
Okay!
> Our patches was based on 3.14 (the Android Mashmallow kenrel). Earlier this
> year I finally got some free time, and worked on cleaning them for submission
> to LKML, and found your cma improving patches merged in 4.1 or 4.2, so I gave
> up as my patches is more hacky :)
>
> The sharing patch is here FYI:
Thanks for sharing!! It will be helpful.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web