Skip to contentSkip to conversation

introduce gcma

RFC In review SeongJae Park 2 participants 10 messages Feb 23, 2015 – Feb 25, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover introduce gcma

This RFC patchset is based on linux v3.18 and available on git:
git://github.com/sjp38/linux.gcma -b gcma/rfc/v2

Abstract
========

Current cma(contiguous memory allocator) could not guarantee success and fast latency of contiguous allocation.
This coverletter explains about the problem in detail and proposes new contiguous memory allocator, gcma(guaranteed contiguous allocator).

CMA: Contiguous Memory Allocator
================================

Basic idea of cma
-----------------

Basic idea of cma is as follows. It focuses on memory efficiency while keeping contiguous allocation could be done without serious penalty.

- Reserves large contiguous memory area during boot and let the area could be used by contiguous allocation.
- Because system memory could be inefficient if the reserved memory is not fully utilized by contiguous allocation, let the area could be allocated for 2nd-class clients.
- If pages being allocated for 2nd-class clients are necessary for contiguous allocation(doubtless 1st class client), migrates or discard the page and use them for contiguous allocation.

In cma, _2nd-class client_ is movable page. The reserved area could be allocated for movable pages and the movable pages be migrated or discarded if contiguous allocation needs them.

Problem of cma
--------------

The cma mechanism imposes following weaknesses.

1. Allocation failure
CMA could fail to allocate contiguous memory due to following reasons. 1-1. Direct pinning
Any kernel thread could pin any movable pages for a long time. If a movable page which needs to be migrated for a contiguous memory allocation is already pinned by someone, migration could not be completed. In consequence, contiguous allocation could be fail if the page is not be unpinned longtime. 1-2. Indirect pin
If a movable page have dependency with an object, the object would increase reference count of the movable page to assert it is safe to use the page. If a movable page which is needs to be migrated for a contiguous memory allocation is in the case, the page could not be free to be used by contiguous allocation. In consequence, contiguous allocation could be failed.

2. High cost
Contiguous memory allocation of CMA could be expensive by following reasons. 2-1. Function overhead
Most of all, migration itself is not so simple. It should manipulate rmap and copy content of the pages into another pages. It could require relatively long time.
After migration, migrated pages be inserted in head of LRU page list again though it was not be used, just migrated. In that case, the pages on LRU list is not ordered in LRU degree. In consequence, system performance could be degraded because working set pages could be swapped-out by the abnormal LRU list.
2-2. Writeback cost
If the page which needs to be discarded for contiguous memory allocation was dirty, it should be written-back to mapped file. Latency of write-back is usually not predictably high because it depends on not only memory management, but also block layer, file system and block device h/w characteristic.

In short, cma doesn't guarantee success and fast latency of contiguous memory allocation. And, the main reason is the fact that cma chosen 2nd-class client(movable pages) was not nice(hard to migrate / discard) enough.

The problem was discussed in detail from [1] and [2].

GCMA: Guaranteed contiguous memory allocator
============================================

Goal of gcma is to solve those two weaknesses of cma discussed above. In other words, gcma aims to guarantee success and fast latency of contiguous memory allocation.

Basic idea
----------

Basic idea of gcma is as same as cma's. It reserves large contiguous memory area during boot and use it for contiguous memory allocator while let it be allocated for 2nd-class clients to keep memory efficiency. If the pages allocated for 2nd-class clients are need for contiguous allocation(doubtless 1st-class client), discard or migrate them.

Difference with cma is choice and operation of 2nd-class client. In gcma, 2nd-class client should allocate pages from the reserved area only if the allocated pages mets following conditions.

1. Out of Kernel
If a page is out of kernel scope, the page could be handled by the 2nd-class client only and no others could see, touch or hold it. Those pages could be discarded anytime. In consequence, contiguous allocation could not be fail if 2nd-class client cooperates well.
2. Quickly discardable or migratable
The pages being used by 2nd-class client should be Quickly discardable of migratable. If so, the contiguous allocation could guarantee fast latency.

With above conditions, we picked 2 candidates for gcma 2nd-class clients. Cleancache and Frontswap are them.

Cleancache
----------

1. Out of Kernel
Pages inside clean cache is clean pages evicted from page cache, which means out of kernel.

2. Quickly discardable or migratable
Because pages inside clean cache is clean, it could be free immediately without any additional operation.

Frontswap backend
-----------------

1. Out of Kernel
Pages inside frontswap backend is swapped-out pages, which are out of kernel.

2. Quickly discardable or migratable
Pages inside frontswap backend could be discarded using following policies. 2.1. Write-back
After the pages written-back containing data to backed real swap device, the page could be free without any interference.
In this policy, latency of write-back operation could be bounded to swap device write speed.
2.2. Write-through
Frontswap could be run with write-through mode. In this case, any pages in frontswap backend could be free immediately because the data is already in swap device.
This policy could show very fast speed but could make whole system slow due to frequent write-through. In flash storage based system, it could cause the storage system failure unless it do wear-leveling on swap device. 2.3. Put-back
When pages inside frontswap backend need to be discarded, gcma could allocates pages from system memroy(not reserved memory) and copy content of discarding pages into newly allocated page. After that, put those newly-allocated, data copied pages inside swap cache to let them in frontswap backend again. After that, the discarding pages are free.
Because it do only memory-operation, speed would not be too slow. We call the operation as _put-back_.

Current RFC implementation
==========================

Though we suggested various policies for frontswap pages discarding, current RFC implementation uses only write-through policy frontswap naively because this is a prototype for various comments from reviewers.

At the moment, current naive implementation is as follows:
1) Reserves large amount of memory during boot.
2) Allow the memory to cleancache, write-through mode frontswap and contiguous memory allocation.
3) Drain pages being used for the cleancache, frontswap if contiguous memroy allocation needs.

As discussed above, this implementation could introduces clear trade-off:
1) System performance could be degraded due to write-through mode
2) Flash storage using system should worry about wear-leveling

Configuring swap device using zram could be helpful to alleviate those problems though the trade-off still exists.

Basic concept, implementation, and performance evaluation result were presented in detail at [2].

Disclaimer
==========

Because cma and gcma has clear merits and demerits, gcma aims to be coexists with cma rather than alternates it. Users could operate cma and gcma on a system concurrently and could use them as they need.

Performance Evaluation
======================

Machine Setting
---------------

CuBox i4 Pro
- ARM v7, 4 * 1 GHz cores
- 800 MiB DDR3 RAM (Originally 2 GiB equipped.)
- Class 10 SanDisk 16 GiB microSD card

Evaluation Variants
-------------------

- Baseline: Linux v3.17, 128 MiB swap
- cma: Baseline + 256 MiB CMA area
- gcma: Baseline + 256 MiB GCMA area
- gcma.zram: GCMA + 128 MiB zram swap device

Workloads
---------

- Background workload: make defconfig && time make -j 16 with Linux v3.12.6
- Foreground workload: Request 1-32000 contiguous page allocation 32 times

Evaluation Result
-----------------

[ Latency (u-seconds) ]
Results below shows gcma's latency is significantly lower than cma's. Note that cma max latency reaches more than 4 seconds easily.

		cma			gcma			gcma.zram

nr_pages min max avg min max avg min max avg
1 381 2853 684 13 279 26 14 274 101
512 818 2382 1162 512 10140 2002 510 648 600
1024 3113 184703 12303 1016 17426 3495 1014 1284 1192
2048 2545 790727 33084 2029 27027 5983 2142 3781 2829
4096 2899 2768349 298640 4087 86887 13091 4101 6046 4780
8192 4476 3496211 407076 8254 75976 17519 9888 11386 10580
16384 7266 4132546 657603 16398 98087 30474 21079 23641 22491
32000 8612 3910423 641340 32328 92502 44675 44859 654966 249453

[ System performance ]
Background workload(kernel build) result measured to evaluate system performance degradation cma / gcma affects.
original means background workload result on CMA configuration without foreground(contiguous allocation) workload.

Ran workload 5 times and measured average of user / system / elapsed time and cpu utilization percentage. Result are as below:

user system elapsed cpu
original 1675.388 167.702 507.738 362.4
cma 1707.902 172.184 523.738 358.4
gcma 1677.492 170.016 515.042 358.2
gcma.zram 1678.104 166.992 513.622 358.6

cma and gcma degraded system performance due to page migration / write-through and affected kernel build workload performance while gcma with zram swap device shows alleviated performance degradation.

[ Evaluation result summary ]
With performance evaluation results above, we can say,
1. latency of gcma is significantly lower then cma's.
2. gcma degrade system performance though zram swap device configuration can abbreviate the effect a little.

Acknowledgement
===============

Really appreciate Minchan who suggested main idea and have helped a lot during development with code fix/review.

[1] https://lkml.org/lkml/2013/10/30/16
[2] http://sched.co/1qZcBAO

Changes in v2:
- Discardable memory abstraction
- Cleancache implementation

SeongJae Park (5):
gcma: introduce contiguous memory allocator
gcma: utilize reserved memory as discardable memory
gcma: adopt cleancache and frontswap as second-class clients
gcma: export statistical data on debugfs
gcma: integrate gcma under cma interface

 include/linux/cma.h  |    4 +
 include/linux/gcma.h |   64 +++
 mm/Kconfig           |   24 +
 mm/Makefile          |    1 +
 mm/cma.c             |  113 ++++-
 mm/gcma.c            | 1321 ++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1508 insertions(+), 19 deletions(-)
 create mode 100644 include/linux/gcma.h
 create mode 100644 mm/gcma.c
Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

RFC v2 1/5 gcma: introduce contiguous memory allocator

Currently, cma reserves large contiguous memory area during early boot and let the area could be used by others for movable pages only. Then, if those movable pages are necessary for contiguous memory allocation, cma migrates and / or discards them out.

This mechanism have two weakness.
1) Because any one in kernel could pin any movable pages, migration of movable pages could be fail. It could lead to contiguous memory allocation failure.
2) Because of migration / reclaim overhead, the latency could be extremely high.
In short, cma doesn't guarantee success and fast latency of contiguous memory allocation. The problem was discussed in detail from [1] and [2].

This patch introduces a simple contiguous memory allocator, namely, GCMA(Guaranteed Contiguous Memory Allocator). It aims to guarantee success and fast latency by reserving memory during early boot time. However, this simple mechanism could degrade system memory space efficiency seriously; following commits will settle the problem.

[1] https://lkml.org/lkml/2013/10/30/16
[2] http://sched.co/1qZcBAO

---
 include/linux/gcma.h |  26 ++++++++
 mm/gcma.c            | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 199 insertions(+)
 create mode 100644 include/linux/gcma.h
 create mode 100644 mm/gcma.c
include/linux/gcma.h new file +26 -0
new file mode 100644
index 0000000..cda481f
@@ -0,0 +1,26 @@
+/*
+ * gcma.h - Guaranteed Contiguous Memory Allocator
+ *
+ * GCMA aims for contiguous memory allocation with success and fast
+ * latency guarantee.
+ * It reserves large amount of memory and let it be allocated to
+ * contiguous memory requests.
+ *
+ * Copyright (C) 2014  LG Electronics Inc.,
+ * Copyright (C) 2014  Minchan Kim <[email protected]>
+ * Copyright (C) 2014-2015  SeongJae Park <[email protected]>
+ */
+
+#ifndef _LINUX_GCMA_H
+#define _LINUX_GCMA_H
+
+struct gcma;
+
+int gcma_init(unsigned long start_pfn, unsigned long size,
+	      struct gcma **res_gcma);
+int gcma_alloc_contig(struct gcma *gcma,
+		      unsigned long start_pfn, unsigned long size);
+void gcma_free_contig(struct gcma *gcma,
+		      unsigned long start_pfn, unsigned long size);
+
+#endif /* _LINUX_GCMA_H */
mm/gcma.c new file +173 -0

173 lines not on this page · raw message

Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

RFC v2 2/5 gcma: utilize reserved memory as discardable memory

In reply to SeongJae Park

Because gcma reserves large amount of memory during early boot and let it be used for contiguous memory requests only, system memory space efficiency could be degraded if the reserved area being idle. The problem could be settled by lending the reserved area to other clients. In this context, we could call contiguous memory requests as first-class clients and other clients as second-class clients. CMA also shares this idea using movable pages as second-class clients.

Key point of this idea is, niceness of second-class clients. If second-class clients does not pay borrowed pages back soon while first-class clients waiting them, first-class clients could suffer from slow latency or failure.

For that, gcma restricts second-class clients to use the reserved area as only easily discardable memory. With the restriction, gcma guarantees success and fast latency by discarding pages of second-class clients whenever first-class client needs them.

This commit implements interface and backend of discardable memory inside gcma. Any subsystem satisfying with discardable memory could be second-class clients of gcma by using the interface.

---
 include/linux/gcma.h |  16 +-
 mm/gcma.c            | 751 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 754 insertions(+), 13 deletions(-)
include/linux/gcma.h +15 -1
index cda481f..005bf77 100644
@@ -4,7 +4,21 @@
  * GCMA aims for contiguous memory allocation with success and fast
  * latency guarantee.
  * It reserves large amount of memory and let it be allocated to
- * contiguous memory requests.
+ * contiguous memory requests. Because system memory space efficiency could be
+ * degraded if reserved area being idle, GCMA let the reserved area could be
+ * used by other clients with lower priority.
+ * We call those lower priority clients as second-class clients. In this
+ * context, contiguous memory requests are first-class clients, of course.
+ *
+ * With this idea, gcma withdraw pages being used for second-class clients and
+ * gives them to first-class clients if they required. Because latency
+ * and success of first-class clients depend on speed and availability of
+ * withdrawing, GCMA restricts only easily discardable memory could be used for
+ * second-class clients.
+ *
+ * To support various second-class clients, GCMA provides interface and
+ * backend of discardable memory. Any candiates satisfying with discardable
+ * memory could be second-class client of GCMA using the interface.
  *
  * Copyright (C) 2014  LG Electronics Inc.,
  * Copyright (C) 2014  Minchan Kim <[email protected]>
mm/gcma.c +739 -12

811 lines not on this page · raw message

Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

RFC v2 3/5 gcma: adopt cleancache and frontswap as second-class clients

In reply to SeongJae Park

Because pages in cleancache is clean and out of kernel scope, they could be free immediately whenever it required to be with no additional task. Similarly, because frontswap pages are out of kernel scope, they could be free easily after written back to backing swap device. Moreover, the writing back task could be avoided if frontswap run as write-through mode. It means cleancache and write-through mode frontswap pages are best candidates for second-class clients of gcma.

By the consequence, this commit implements cleancache and write-through mode frontswap backend inside gcma area using discardable memory interface.

---
 include/linux/gcma.h |   3 +
 mm/gcma.c            | 312 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 314 insertions(+), 1 deletion(-)
include/linux/gcma.h +3 -0
index 005bf77..12e4431 100644
@@ -20,6 +20,9 @@
  * backend of discardable memory. Any candiates satisfying with discardable
  * memory could be second-class client of GCMA using the interface.
  *
+ * Currently, GCMA uses cleancache and write-through mode frontswap as
+ * second-class clients.
+ *
  * Copyright (C) 2014  LG Electronics Inc.,
  * Copyright (C) 2014  Minchan Kim <[email protected]>
  * Copyright (C) 2014-2015  SeongJae Park <[email protected]>
mm/gcma.c +311 -1

483 lines not on this page · raw message

Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

RFC v2 4/5 gcma: export statistical data on debugfs

In reply to SeongJae Park

Export statistical data of second-class clients of gcma on debugfs to let users know how gcma is working internally.

---
 mm/gcma.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 119 insertions(+), 8 deletions(-)
mm/gcma.c +119 -8
index 924e3f6..57203b4 100644
@@ -130,6 +130,26 @@ module_param_named(fs_disabled, fs_disabled, bool, 0444);
 static bool cc_disabled __read_mostly;
 module_param_named(cc_disabled, cc_disabled, bool, 0444);
 
+/* For statistics */
+static atomic_t gcma_fs_inits = ATOMIC_INIT(0);
+static atomic_t gcma_fs_stored_pages = ATOMIC_INIT(0);
+static atomic_t gcma_fs_loaded_pages = ATOMIC_INIT(0);
+static atomic_t gcma_fs_evicted_pages = ATOMIC_INIT(0);
+static atomic_t gcma_fs_reclaimed_pages = ATOMIC_INIT(0);
+static atomic_t gcma_fs_invalidated_pages = ATOMIC_INIT(0);
+static atomic_t gcma_fs_invalidated_areas = ATOMIC_INIT(0);
+
+static atomic_t gcma_cc_inits = ATOMIC_INIT(0);
+static atomic_t gcma_cc_stored_pages = ATOMIC_INIT(0);
+static atomic_t gcma_cc_loaded_pages = ATOMIC_INIT(0);
+static atomic_t gcma_cc_load_failed_pages = ATOMIC_INIT(0);
+static atomic_t gcma_cc_evicted_pages = ATOMIC_INIT(0);
+static atomic_t gcma_cc_reclaimed_pages = ATOMIC_INIT(0);
+static atomic_t gcma_cc_invalidated_pages = ATOMIC_INIT(0);
+static atomic_t gcma_cc_invalidated_inodes = ATOMIC_INIT(0);
+static atomic_t gcma_cc_invalidated_fses = ATOMIC_INIT(0);
+static atomic_t gcma_cc_invalidate_failed_fses = ATOMIC_INIT(0);
+
 static unsigned long dmem_evict_lru(struct dmem *dmem, unsigned long nr_pages);
 
 static struct dmem_hashbucket *dmem_hashbuck(struct page *page)
@@ -475,6 +495,10 @@ static unsigned long dmem_evict_lru(struct dmem *dmem, unsigned long nr_pages)
 		spin_unlock(&buck->lock);
 	}
 
+	if (dmem == &fs_dmem)
+		atomic_add(evicted, &gcma_fs_evicted_pages);
+	else
+		atomic_add(evicted, &gcma_cc_evicted_pages);
 	return evicted;
 }
 
@@ -791,12 +815,18 @@ static unsigned frontswap_hash_key(void *key)
 void gcma_frontswap_init(unsigned type)
 {
 	dmem_init_pool(&fs_dmem, type);
+	atomic_inc(&gcma_fs_inits);
 }
 
 int gcma_frontswap_store(unsigned type, pgoff_t offset,
 				struct page *page)
 {
-	return dmem_store_page(&fs_dmem, type, (void *)&offset, page);
+	int ret;
+
+	ret = dmem_store_page(&fs_dmem, type, (void *)&offset, page);
+	if (ret == 0)
+		atomic_inc(&gcma_fs_stored_pages);
+	return ret;
 }
 
 /*
@@ -806,17 +836,24 @@ int gcma_frontswap_store(unsigned type, pgoff_t offset,
 int gcma_frontswap_load(unsigned type, pgoff_t offset,
 			       struct page *page)
 {
-	return dmem_load_page(&fs_dmem, type, (void *)&offset, page);
+	int ret;
+
+	ret = dmem_load_page(&fs_dmem, type, (void *)&offset, page);
+	if (ret == 0)
+		atomic_inc(&gcma_fs_loaded_pages);
+	return ret;
 }
 
 void gcma_frontswap_invalidate_page(unsigned type, pgoff_t offset)
 {
-	dmem_invalidate_entry(&fs_dmem, type, (void *)&offset);
+	if (dmem_invalidate_entry(&fs_dmem, type, (void *)&offset) == 0)
+		atomic_inc(&gcma_fs_invalidated_pages);
 }
 
 void gcma_frontswap_invalidate_area(unsigned type)
 {
-	dmem_invalidate_pool(&fs_dmem, type);
+	if (dmem_invalidate_pool(&fs_dmem, type) == 0)
+		atomic_inc(&gcma_fs_invalidated_areas);
 }
 
 static struct frontswap_ops gcma_frontswap_ops = {
@@ -865,6 +902,8 @@ int gcma_cleancache_init_fs(size_t pagesize)
 	err = dmem_init_pool(&cc_dmem, pool_id);
 	if (err != 0)
 		return err;
+
+	atomic_inc(&gcma_cc_inits);
 	return pool_id;
 }
 
@@ -885,6 +924,10 @@ int gcma_cleancache_get_page(int pool_id, struct cleancache_filekey fkey,
 	local_irq_save(flags);
 	ret = dmem_load_page(&cc_dmem, pool_id, &key, page);
 	local_irq_restore(flags);
+	if (ret == 0)
+		atomic_inc(&gcma_cc_loaded_pages);
+	else
+		atomic_inc(&gcma_cc_load_failed_pages);
 	return ret;
 }
 
@@ -897,7 +940,8 @@ void gcma_cleancache_put_page(int pool_id, struct cleancache_filekey fkey,
 	cleancache_set_key(&fkey, &offset, &key);
 
 	local_irq_save(flags);
-	dmem_store_page(&cc_dmem, pool_id, &key, page);
+	if (dmem_store_page(&cc_dmem, pool_id, &key, page) == 0)
+		atomic_inc(&gcma_cc_stored_pages);
 	local_irq_restore(flags);
 }
 
@@ -911,7 +955,8 @@ void gcma_cleancache_invalidate_page(int pool_id,
 	cleancache_set_key(&fkey, &offset, &key);
 
 	local_irq_save(flags);
-	dmem_invalidate_entry(&cc_dmem, pool_id, &key);
+	if (dmem_invalidate_entry(&cc_dmem, pool_id, &key) == 0)
+		atomic_inc(&gcma_cc_invalidated_pages);
 	local_irq_restore(flags);
 }
 
@@ -933,10 +978,12 @@ void gcma_cleancache_invalidate_fs(int pool_id)
 	if (pool_id < 0 || pool_id >= atomic_read(&nr_cleancache_fses)) {
 		pr_warn("%s received wrong pool id %d\n",
 				__func__, pool_id);
+		atomic_inc(&gcma_cc_invalidate_failed_fses);
 		return;
 	}
 	local_irq_save(flags);
-	dmem_invalidate_pool(&cc_dmem, pool_id);
+	if (dmem_invalidate_pool(&cc_dmem, pool_id) == 0)
+		atomic_inc(&gcma_cc_invalidated_fses);
 	local_irq_restore(flags);
 }
 
@@ -1102,8 +1149,12 @@ next_page:
 			dmem_put(buck, entry);
 		spin_unlock(lru_lock);
 		spin_unlock(&buck->lock);
-		if (lru_lock == &cc_dmem.lru_lock)
+		if (lru_lock == &cc_dmem.lru_lock) {
 			local_irq_restore(flags);
+			atomic_inc(&gcma_cc_reclaimed_pages);
+		} else {
+			atomic_inc(&gcma_fs_reclaimed_pages);
+		}
 	}
 
 	start_pfn = isolate_interrupted(gcma, orig_start, orig_start + size);
@@ -1133,6 +1184,66 @@ void gcma_free_contig(struct gcma *gcma,
 	local_irq_restore(flags);
 }
 
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+
+static struct dentry *gcma_debugfs_root;
+
+static int __init gcma_debugfs_init(void)
+{
+	if (!debugfs_initialized())
+		return -ENODEV;
+
+	gcma_debugfs_root = debugfs_create_dir("gcma", NULL);
+	if (!gcma_debugfs_root)
+		return -ENOMEM;
+
+	debugfs_create_atomic_t("fs_inits", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_inits);
+	debugfs_create_atomic_t("fs_stored_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_stored_pages);
+	debugfs_create_atomic_t("fs_loaded_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_loaded_pages);
+	debugfs_create_atomic_t("fs_evicted_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_evicted_pages);
+	debugfs_create_atomic_t("fs_reclaimed_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_reclaimed_pages);
+	debugfs_create_atomic_t("fs_invalidated_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_invalidated_pages);
+	debugfs_create_atomic_t("fs_invalidated_areas", S_IRUGO,
+			gcma_debugfs_root, &gcma_fs_invalidated_areas);
+
+	debugfs_create_atomic_t("cc_inits", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_inits);
+	debugfs_create_atomic_t("cc_stored_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_stored_pages);
+	debugfs_create_atomic_t("cc_loaded_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_loaded_pages);
+	debugfs_create_atomic_t("cc_load_failed_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_load_failed_pages);
+	debugfs_create_atomic_t("cc_evicted_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_evicted_pages);
+	debugfs_create_atomic_t("cc_reclaimed_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_reclaimed_pages);
+	debugfs_create_atomic_t("cc_invalidated_pages", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_invalidated_pages);
+	debugfs_create_atomic_t("cc_invalidated_inodes", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_invalidated_inodes);
+	debugfs_create_atomic_t("cc_invalidated_fses", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_invalidated_fses);
+	debugfs_create_atomic_t("cc_invalidate_failed_fses", S_IRUGO,
+			gcma_debugfs_root, &gcma_cc_invalidate_failed_fses);
+
+	pr_info("gcma debufs init\n");
+	return 0;
+}
+#else
+static int __init gcma_debugfs_init(void)
+{
+	return 0;
+}
+#endif
+
 static int __init init_gcma(void)
 {
 	pr_info("loading gcma\n");
Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

RFC v2 5/5 gcma: integrate gcma under cma interface

In reply to SeongJae Park

This commit let cma clients to be able to use gcma easily using familiar cma interface by integrating gcma under cma interface.

With this commit, clients can decalre a contiguous memory area to be managed in gcma way instead of cma way internally by using gcma_declare_contiguous() function call. After declaration, clients can use the area using familiar cma interface while it works in gcma way.

For example, you can use following code snippet to make two contiguous
regions: one region will work as cma and the other will work as gcma.

```
struct cma *cma, *gcma;

cma_declare_contiguous(base, size, limit, 0, 0, fixed, &cma);
gcma_declare_contiguous(gcma_base, size, gcma_limit, 0, 0, fixed,
&gcma);

cma_alloc(cma, 1024, 0);	/* alloc in cma way */
cma_alloc(gcma, 1024, 0);	/* alloc in gcma way */
```
---
 include/linux/cma.h  |   4 ++
 include/linux/gcma.h |  21 ++++++++++
 mm/Kconfig           |  24 +++++++++++
 mm/Makefile          |   1 +
 mm/cma.c             | 113 ++++++++++++++++++++++++++++++++++++++++++---------
 5 files changed, 144 insertions(+), 19 deletions(-)
include/linux/cma.h +4 -0
index a93438b..6173cff 100644
@@ -22,6 +22,10 @@ extern int __init cma_declare_contiguous(phys_addr_t base,
 			phys_addr_t size, phys_addr_t limit,
 			phys_addr_t alignment, unsigned int order_per_bit,
 			bool fixed, struct cma **res_cma);
+extern int __init gcma_declare_contiguous(phys_addr_t base,
+			phys_addr_t size, phys_addr_t limit,
+			phys_addr_t alignment, unsigned int order_per_bit,
+			bool fixed, struct cma **res_cma);
 extern int cma_init_reserved_mem(phys_addr_t base,
 					phys_addr_t size, int order_per_bit,
 					struct cma **res_cma);
include/linux/gcma.h +21 -0
index 12e4431..c8f8c32 100644
@@ -33,6 +33,25 @@
 
 struct gcma;
 
+#ifndef CONFIG_GCMA
+
+inline int gcma_init(unsigned long start_pfn, unsigned long size,
+		     struct gcma **res_gcma)
+{
+	return 0;
+}
+
+inline int gcma_alloc_contig(struct gcma *gcma,
+			     unsigned long start, unsigned long end)
+{
+	return 0;
+}
+
+void gcma_free_contig(struct gcma *gcma,
+		      unsigned long pfn, unsigned long nr_pages) { }
+
+#else
+
 int gcma_init(unsigned long start_pfn, unsigned long size,
 	      struct gcma **res_gcma);
 int gcma_alloc_contig(struct gcma *gcma,
@@ -40,4 +59,6 @@ int gcma_alloc_contig(struct gcma *gcma,
 void gcma_free_contig(struct gcma *gcma,
 		      unsigned long start_pfn, unsigned long size);
 
+#endif
+
 #endif /* _LINUX_GCMA_H */
mm/Kconfig +24 -0
index 1d1ae6b..cceef9a 100644
@@ -527,6 +527,30 @@ config CMA_AREAS
 
 	  If unsure, leave the default value "7".
 
+config GCMA
+	bool "Guaranteed Contiguous Memory Allocator (EXPERIMENTAL)"
+	default n
+	select FRONTSWAP
+	select CLEANCACHE
+	select CMA
+	help
+	  A contiguous memory allocator which guarantees success and
+	  predictable latency for allocation request.
+	  It carves out large amount of memory and let them be allocated
+	  to the contiguous memory request while it can be used as backend
+	  for frontswap.
+
+	  This is marked experimental because it is a new feature that
+	  interacts heavily with memory reclaim.
+
+config GCMA_DEFAULT
+	bool "Set GCMA as default CMA facility (EXPERIMENTA)"
+	default n
+	depends on GCMA
+	help
+	  Set older CMA interfaces to work as GCMA rather than CMA without any
+	  client code change.
+
 config MEM_SOFT_DIRTY
 	bool "Track memory changes"
 	depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY && PROC_FS
mm/Makefile +1 -0
index 8405eb0..e79cb70 100644
@@ -68,4 +68,5 @@ obj-$(CONFIG_ZBUD)	+= zbud.o
 obj-$(CONFIG_ZSMALLOC)	+= zsmalloc.o
 obj-$(CONFIG_GENERIC_EARLY_IOREMAP) += early_ioremap.o
 obj-$(CONFIG_CMA)	+= cma.o
+obj-$(CONFIG_GCMA)	+= gcma.o
 obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
mm/cma.c +94 -19

180 lines not on this page · raw message

Signature · 7 lines
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to SeongJae Park

On Tue 24-02-15 04:54:18, SeongJae Park wrote:
[...]

Quoted 9 lines
 include/linux/cma.h  |    4 +
 include/linux/gcma.h |   64 +++
 mm/Kconfig           |   24 +
 mm/Makefile          |    1 +
 mm/cma.c             |  113 ++++-
 mm/gcma.c            | 1321 ++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1508 insertions(+), 19 deletions(-)
 create mode 100644 include/linux/gcma.h
 create mode 100644 mm/gcma.c

Wow this is huge! And I do not see reason for it to be so big. Why cannot you simply define (per-cma area) 2-class users policy? Either via kernel command line or export areas to userspace and allow to set policy there.

For starter something like the following policies should suffice AFAIU your description.
- NONE - exclusive pool for CMA allocations only
- DROPABLE - only allocations which might be dropped without any additional actions - e.g. cleancache and frontswap with write-through policy
- RECLAIMABLE - only movable allocations which can be migrated or dropped after writeback.

Has such an approach been considered?

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Hello Michal,

Thanks for your comment :)

Quoted 12 lines · Michal Hocko

On Tue 24-02-15 04:54:18, SeongJae Park wrote:
[...]

Quoted 9 lines
 include/linux/cma.h  |    4 +
 include/linux/gcma.h |   64 +++
 mm/Kconfig           |   24 +
 mm/Makefile          |    1 +
 mm/cma.c             |  113 ++++-
 mm/gcma.c            | 1321 ++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1508 insertions(+), 19 deletions(-)
 create mode 100644 include/linux/gcma.h
 create mode 100644 mm/gcma.c
Quoted 4 lines

Wow this is huge! And I do not see reason for it to be so big. Why cannot you simply define (per-cma area) 2-class users policy? Either via kernel command line or export areas to userspace and allow to set policy there.

For implementation of the idea, we should develop not only policy selection, but also backend for discardable memory. Most part of this patch were made for the backend.

Current implementation gives selection of policy per cma area to users. Only about 120 lines of code were changed for that though it's most ugly part of this patch. The part remains as ugly in this RFC because this is just prototype. The part will be changed in next version patchset.

Quoted 11 lines

For starter something like the following policies should suffice AFAIU your description.
- NONE - exclusive pool for CMA allocations only
- DROPABLE - only allocations which might be dropped without any additional actions - e.g. cleancache and frontswap with write-through policy
- RECLAIMABLE - only movable allocations which can be migrated or dropped after writeback.

Has such an approach been considered?

Similarly, but not in same way. In summary, GCMA gives DROPABLE and RECLAIMABLE policy selection per cma area and NONE policy to entire cma area declared using GCMA interface.

In detail, user could set policy of cma area as gcma way(DROPABLE) or cma way(RECLAIMABLE). Also, user could set gcma to utilize their cma area with Cleancache and/or Frontswap or not(NONE policy).

Your suggestion looks simple and better to understand. Next version of gcma will let users to be able to select policy as those per cma area.

Thanks,
SeongJae Park

Quoted 4 lines
Signature · 2 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 18 lines · SeongJae Park

Hello Michal,

Thanks for your comment :)

Quoted 12 lines · Michal Hocko

On Tue 24-02-15 04:54:18, SeongJae Park wrote:
[...]

Quoted 9 lines
include/linux/cma.h  |    4 +
include/linux/gcma.h |   64 +++
mm/Kconfig           |   24 +
mm/Makefile          |    1 +
mm/cma.c             |  113 ++++-
mm/gcma.c            | 1321 ++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 1508 insertions(+), 19 deletions(-)

create mode 100644 include/linux/gcma.h
create mode 100644 mm/gcma.c

Quoted 8 lines
Quoted 4 lines

Wow this is huge! And I do not see reason for it to be so big. Why cannot you simply define (per-cma area) 2-class users policy? Either via kernel command line or export areas to userspace and allow to set policy there.

For implementation of the idea, we should develop not only policy selection, but also backend for discardable memory. Most part of this patch were made for the backend.

What is the backend and why is it needed? I thought the discardable will go back to the CMA pool. I mean the cover email explained why the current CMA allocation policy might lead to lower success rate or stalls. So I would expect a new policy would be a relatively small change in the CMA allocation path to serve 2-class users as per policy. It is not clear to my why we need to pull a whole gcma layer in. I might be missing something obvious because I haven't looked at the patches yet but this should better be explained in the cover letter.

Thanks!

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
Quoted 28 lines · Michal Hocko
Quoted 18 lines · SeongJae Park

Hello Michal,

Thanks for your comment :)

Quoted 12 lines · Michal Hocko

On Tue 24-02-15 04:54:18, SeongJae Park wrote:
[...]

Quoted 9 lines
include/linux/cma.h  |    4 +
include/linux/gcma.h |   64 +++
mm/Kconfig           |   24 +
mm/Makefile          |    1 +
mm/cma.c             |  113 ++++-
mm/gcma.c            | 1321 ++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 1508 insertions(+), 19 deletions(-)

create mode 100644 include/linux/gcma.h
create mode 100644 mm/gcma.c

Quoted 8 lines
Quoted 4 lines

Wow this is huge! And I do not see reason for it to be so big. Why cannot you simply define (per-cma area) 2-class users policy? Either via kernel command line or export areas to userspace and allow to set policy there.

For implementation of the idea, we should develop not only policy selection, but also backend for discardable memory. Most part of this patch were made for the backend.

Quoted 8 lines

What is the backend and why is it needed? I thought the discardable will go back to the CMA pool. I mean the cover email explained why the current CMA allocation policy might lead to lower success rate or stalls. So I would expect a new policy would be a relatively small change in the CMA allocation path to serve 2-class users as per policy. It is not clear to my why we need to pull a whole gcma layer in. I might be missing something obvious because I haven't looked at the patches yet but this should better be explained in the cover letter.

I meant backend for 2nd-class clients like cleancache and frontswap. Because implementing backend for cleancache or frontswap is subsystem's responsibility, gcma was needed to implement those backend. I believe second ("gcma: utilize reserved memory as discardable memory") and third ("gcma: adopt cleancache and frontswap as second-class clients") could be helpful to understand about that.

And yes, I agree the explanation was not enough. My fault, sorry. My explanation was too concentrated on policy itself. I should explained about how the policy could be implemented and how gcma did. I will explain about that in coverletter with next version.

Thanks for your helpful and nice comment.

Thanks,
SeongJae Park

Quoted 6 lines

Thanks!

Signature · 2 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>