Skip to contentSkip to conversation

Fallocate Volatile Ranges v2

RFC PATCH In review John Stultz 7 participants 28 messages Jun 1, 2012 – Jun 13, 2012

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

cover Fallocate Volatile Ranges v2

Here's another update to the Fallocate Volatile Range code.

The bigish change is renaming the range-tree code to interval-tree, as Jan Kara pointed out that term is more accurate (although this is a naive implementation).

I also fixed a bad bug in the volatile range management, and added an optimization so we don't run over the lru to determine how many pages are unpurged.

Thanks to everyone for the review so far, please let me know if you have any further thoughts or suggestions.

thanks
-john

CC Andrew Morton <[email protected]>
CC Android Kernel Team <[email protected]>
CC Robert Love <[email protected]>
CC Mel Gorman <[email protected]>
CC Hugh Dickins <[email protected]>
CC Dave Hansen <[email protected]>
CC Rik van Riel <[email protected]>
CC Dmitry Adamushko <[email protected]>
CC Dave Chinner <[email protected]>
CC Neil Brown <[email protected]>
CC Andrea Righi <[email protected]>
CC Aneesh Kumar K.V <[email protected]>
CC Taras Glek <[email protected]>
CC Mike Hommey <[email protected]>
CC Jan Kara <[email protected]>

John Stultz (3):
[RFC] Interval tree implementation
[RFC] Add volatile range management code
[RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

 fs/open.c                    |    3 +-
 include/linux/falloc.h       |    7 +-
 include/linux/intervaltree.h |   55 +++++
 include/linux/volatile.h     |   45 ++++
 lib/Makefile                 |    2 +-
 lib/intervaltree.c           |  119 ++++++++++
 mm/Makefile                  |    2 +-
 mm/shmem.c                   |  107 +++++++++
 mm/volatile.c                |  509 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 843 insertions(+), 6 deletions(-)
 create mode 100644 include/linux/intervaltree.h
 create mode 100644 include/linux/volatile.h
 create mode 100644 lib/intervaltree.c
 create mode 100644 mm/volatile.c
Signature · 1 line
1.7.3.2.146.gca209
#2 lore raw

RFC PATCH 2/3 Add volatile range management code

This patch provides the volatile range management code that filesystems can utilize when implementing FALLOC_FL_MARK_VOLATILE.

It tracks a collection of page ranges against a mapping stored in an interval-tree. This code handles coalescing overlapping and adjacent ranges, as well as splitting ranges when sub-chunks are removed.

The ranges can be marked purged or unpurged. And there is a per-fs lru list that tracks all the unpurged ranges for that fs.

v2:
* Fix bug in volatile_ranges_get_last_used returning bad start,end values
* Rework for intervaltree renaming
* Optimize volatile_range_lru_size to avoid running through lru list each time.

CC Andrew Morton <[email protected]>
CC Android Kernel Team <[email protected]>
CC Robert Love <[email protected]>
CC Mel Gorman <[email protected]>
CC Hugh Dickins <[email protected]>
CC Dave Hansen <[email protected]>
CC Rik van Riel <[email protected]>
CC Dmitry Adamushko <[email protected]>
CC Dave Chinner <[email protected]>
CC Neil Brown <[email protected]>
CC Andrea Righi <[email protected]>
CC Aneesh Kumar K.V <[email protected]>
CC Taras Glek <[email protected]>
CC Mike Hommey <[email protected]>
CC Jan Kara <[email protected]>
---
 include/linux/volatile.h |   45 ++++
 mm/Makefile              |    2 +-
 mm/volatile.c            |  509 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 555 insertions(+), 1 deletions(-)
 create mode 100644 include/linux/volatile.h
 create mode 100644 mm/volatile.c
include/linux/volatile.h new file +45 -0
new file mode 100644
index 0000000..66737a8
@@ -0,0 +1,45 @@
+#ifndef _LINUX_VOLATILE_H
+#define _LINUX_VOLATILE_H
+
+#include <linux/fs.h>
+
+struct volatile_fs_head {
+	struct mutex lock;
+	struct list_head lru_head;
+	s64 unpurged_page_count;
+};
+
+
+#define DEFINE_VOLATILE_FS_HEAD(name) struct volatile_fs_head name = {	\
+	.lock = __MUTEX_INITIALIZER(name.lock),				\
+	.lru_head = LIST_HEAD_INIT(name.lru_head),			\
+	.unpurged_page_count = 0,					\
+}
+
+
+static inline void volatile_range_lock(struct volatile_fs_head *head)
+{
+	mutex_lock(&head->lock);
+}
+
+static inline void volatile_range_unlock(struct volatile_fs_head *head)
+{
+	mutex_unlock(&head->lock);
+}
+
+extern long volatile_range_add(struct volatile_fs_head *head,
+				struct address_space *mapping,
+				pgoff_t start_index, pgoff_t end_index);
+extern long volatile_range_remove(struct volatile_fs_head *head,
+				struct address_space *mapping,
+				pgoff_t start_index, pgoff_t end_index);
+
+extern s64 volatile_range_lru_size(struct volatile_fs_head *head);
+
+extern void volatile_range_clear(struct volatile_fs_head *head,
+					struct address_space *mapping);
+
+extern s64 volatile_ranges_get_last_used(struct volatile_fs_head *head,
+				struct address_space **mapping,
+				loff_t *start, loff_t *end);
+#endif /* _LINUX_VOLATILE_H */
mm/Makefile +1 -1
index a156285..dc79eb8 100644
@@ -16,7 +16,7 @@ obj-y			:= filemap.o mempool.o oom_kill.o fadvise.o \
 			   readahead.o swap.o truncate.o vmscan.o shmem.o \
 			   prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
 			   page_isolation.o mm_init.o mmu_context.o percpu.o \
-			   compaction.o $(mmu-y)
+			   compaction.o volatile.o $(mmu-y)
 obj-y += init-mm.o
 
 ifdef CONFIG_NO_BOOTMEM
mm/volatile.c new file +509 -0

509 lines not on this page · raw message

Signature · 1 line
1.7.3.2.146.gca209
#3 lore raw

RFC PATCH 3/3 tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to John Stultz

This patch enables FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE functionality for tmpfs making use of the volatile range management code.

Conceptually, FALLOC_FL_MARK_VOLATILE is like a delayed FALLOC_FL_PUNCH_HOLE. This allows applications that have data caches that can be re-created to tell the kernel that some memory contains data that is useful in the future, but can be recreated if needed, so if the kernel needs, it can zap the memory without having to swap it out.

In use, applications use FALLOC_FL_MARK_VOLATILE to mark page ranges as volatile when they are not in use. Then later if they wants to reuse the data, they use FALLOC_FL_UNMARK_VOLATILE, which will return an error if the data has been purged.

This is very much influenced by the Android Ashmem interface by Robert Love so credits to him and the Android developers. In many cases the code & logic come directly from the ashmem patch. The intent of this patch is to allow for ashmem-like behavior, but embeds the idea a little deeper into the VM code.

This is a reworked version of the fadvise volatile idea submitted earlier to the list. Thanks to Dave Chinner for suggesting to rework the idea in this fashion. Also thanks to Dmitry Adamushko for continued review and bug reporting, and Dave Hansen for help with the original design and mentoring me in the VM code.

CC Andrew Morton <[email protected]>
CC Android Kernel Team <[email protected]>
CC Robert Love <[email protected]>
CC Mel Gorman <[email protected]>
CC Hugh Dickins <[email protected]>
CC Dave Hansen <[email protected]>
CC Rik van Riel <[email protected]>
CC Dmitry Adamushko <[email protected]>
CC Dave Chinner <[email protected]>
CC Neil Brown <[email protected]>
CC Andrea Righi <[email protected]>
CC Aneesh Kumar K.V <[email protected]>
CC Taras Glek <[email protected]>
CC Mike Hommey <[email protected]>
CC Jan Kara <[email protected]>
---
 fs/open.c              |    3 +-
 include/linux/falloc.h |    7 ++-
 mm/shmem.c             |  107 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 4 deletions(-)
fs/open.c +2 -1
index d543012..448ed5a 100644
@@ -223,7 +223,8 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 		return -EINVAL;
 
 	/* Return error if mode is not supported */
-	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+			FALLOC_FL_MARK_VOLATILE | FALLOC_FL_UNMARK_VOLATILE))
 		return -EOPNOTSUPP;
 
 	/* Punch hole must have keep size set */
include/linux/falloc.h +4 -3
index 73e0b62..3e47ad5 100644
@@ -1,9 +1,10 @@
 #ifndef _FALLOC_H_
 #define _FALLOC_H_
 
-#define FALLOC_FL_KEEP_SIZE	0x01 /* default is extend size */
-#define FALLOC_FL_PUNCH_HOLE	0x02 /* de-allocates range */
-
+#define FALLOC_FL_KEEP_SIZE		0x01 /* default is extend size */
+#define FALLOC_FL_PUNCH_HOLE		0x02 /* de-allocates range */
+#define FALLOC_FL_MARK_VOLATILE		0x04 /* mark range volatile */
+#define FALLOC_FL_UNMARK_VOLATILE	0x08 /* mark range non-volatile */
 #ifdef __KERNEL__
 
 /*
mm/shmem.c +107 -0

130 lines not on this page · raw message

Signature · 1 line
1.7.3.2.146.gca209
#1 lore raw

RFC PATCH 1/3 Interval tree implementation

In reply to John Stultz

After Andrew suggested something like his mumbletree idea to better store a list of intervals, I worked on a few different approaches, and this is what I've finally managed to get working.

The idea of storing intervals in a tree is nice, but has a number of complications. When adding an interval, its possible that a large interval will consume and merge a number of smaller intervals. When removing a interval, its possible you may end up splitting an existing interval, causing one interval to become two. This makes it very difficult to provide generic list_head like behavior, as the parent structures would need to be duplicated and removed, and that has lots of memory ownership issues.

So, this is a much simplified and more list_head like implementation. You can add a node to a tree, or remove a node to a tree, but the generic implementation doesn't do the merging or splitting for you. But it does provide helpers to find overlapping and adjacent intervals.

Andrew also really wanted this interval-tree implementation to be resuable so we don't duplicate the file locking logic. I'm not totally convinced that the requirements between the volatile intervals and file locking are really equivelent, but this reduced impelementation may make it possible.

Changelog:
v2:
* Reworked code to use an rbtree instead of splaying

v3:
* Added range_tree_next_in_range() to avoid having to start lookups from the root every time.
* Fixed some comments and return NULL instead of 0, as suggested by Aneesh Kumar K.V

v6:
* Fixed range_tree_in_range() so that it finds the earliest range, rather then the first. This allows the next_in_range() function to properly cover all the ranges in the tree.
* Minor clenaups to simplify some of the functions

v7:
* Changed terminology from rangetree to intervaltree as suggested by Jan Kara

CC Andrew Morton <[email protected]>
CC Android Kernel Team <[email protected]>
CC Robert Love <[email protected]>
CC Mel Gorman <[email protected]>
CC Hugh Dickins <[email protected]>
CC Dave Hansen <[email protected]>
CC Rik van Riel <[email protected]>
CC Dmitry Adamushko <[email protected]>
CC Dave Chinner <[email protected]>
CC Neil Brown <[email protected]>
CC Andrea Righi <[email protected]>
CC Aneesh Kumar K.V <[email protected]>
CC Taras Glek <[email protected]>
CC Mike Hommey <[email protected]>
CC Jan Kara <[email protected]>
---
 include/linux/intervaltree.h |   55 +++++++++++++++++++
 lib/Makefile                 |    2 +-
 lib/intervaltree.c           |  119 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+), 1 deletions(-)
 create mode 100644 include/linux/intervaltree.h
 create mode 100644 lib/intervaltree.c
include/linux/intervaltree.h new file +55 -0
new file mode 100644
index 0000000..cfaa174
@@ -0,0 +1,55 @@
+#ifndef _LINUX_INTERVALTREE_H
+#define _LINUX_INTERVALTREE_H
+
+#include <linux/types.h>
+#include <linux/rbtree.h>
+
+struct interval_tree_node {
+	struct rb_node rb;
+	u64 start;
+	u64 end;
+};
+
+struct interval_tree_root {
+	struct rb_root head;
+};
+
+static inline void interval_tree_init(struct interval_tree_root *root)
+{
+	root->head = RB_ROOT;
+}
+
+static inline void interval_tree_node_init(struct interval_tree_node *node)
+{
+	rb_init_node(&node->rb);
+	node->start = 0;
+	node->end = 0;
+}
+
+static inline int interval_tree_empty(struct interval_tree_root *root)
+{
+	return RB_EMPTY_ROOT(&root->head);
+}
+
+static inline
+struct interval_tree_node *interval_tree_root_node(
+						struct interval_tree_root *root)
+{
+	struct interval_tree_node *ret;
+	ret = container_of(root->head.rb_node, struct interval_tree_node, rb);
+	return ret;
+}
+
+extern struct interval_tree_node *interval_tree_in_interval(
+						struct interval_tree_root *root,
+						 u64 start, u64 end);
+extern struct interval_tree_node *interval_tree_next_in_interval(
+						struct interval_tree_node *node,
+						u64 start, u64 end);
+extern void interval_tree_add(struct interval_tree_root *root,
+					struct interval_tree_node *node);
+extern void interval_tree_remove(struct interval_tree_root *root,
+					struct interval_tree_node *node);
+#endif
+
+
lib/Makefile +1 -1
index 8c31a0c..2bbad25 100644
@@ -12,7 +12,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 idr.o int_sqrt.o extable.o prio_tree.o \
 	 sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \
 	 proportions.o prio_heap.o ratelimit.o show_mem.o \
-	 is_single_threaded.o plist.o decompress.o
+	 is_single_threaded.o plist.o decompress.o intervaltree.o
 
 lib-$(CONFIG_MMU) += ioremap.o
 lib-$(CONFIG_SMP) += cpumask.o
lib/intervaltree.c new file +119 -0

119 lines not on this page · raw message

Signature · 1 line
1.7.3.2.146.gca209
#4 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to John Stultz

Hi John,

Quoted 23 lines · John Stultz

This patch enables FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE functionality for tmpfs making use of the volatile range management code.

Conceptually, FALLOC_FL_MARK_VOLATILE is like a delayed FALLOC_FL_PUNCH_HOLE. This allows applications that have data caches that can be re-created to tell the kernel that some memory contains data that is useful in the future, but can be recreated if needed, so if the kernel needs, it can zap the memory without having to swap it out.

In use, applications use FALLOC_FL_MARK_VOLATILE to mark page ranges as volatile when they are not in use. Then later if they wants to reuse the data, they use FALLOC_FL_UNMARK_VOLATILE, which will return an error if the data has been purged.

This is very much influenced by the Android Ashmem interface by Robert Love so credits to him and the Android developers. In many cases the code& logic come directly from the ashmem patch. The intent of this patch is to allow for ashmem-like behavior, but embeds the idea a little deeper into the VM code.

Quoted 5 lines

This is a reworked version of the fadvise volatile idea submitted earlier to the list. Thanks to Dave Chinner for suggesting to rework the idea in this fashion. Also thanks to Dmitry Adamushko for continued review and bug reporting, and Dave Hansen for help with the original design and mentoring me in the VM code.

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

(snip)

Quoted 11 lines
mm/shmem.c +11 -0
+static
+int shmem_volatile_shrink(struct shrinker *ignored, struct shrink_control *sc)
+{
+	s64 nr_to_scan = sc->nr_to_scan;
+	const gfp_t gfp_mask = sc->gfp_mask;
+	struct address_space *mapping;
+	loff_t start, end;
+	int ret;
+	s64 page_count;
+
+	if (nr_to_scan&&  !(gfp_mask&  __GFP_FS))

mm/shmem.c static int shmem_setattr(struct dentry *dentry, struct iattr *attr)

Quoted 10 lines
mm/shmem.c +10 -0
+		return -1;
+
+	volatile_range_lock(&shmem_volatile_head);
+	page_count = volatile_range_lru_size(&shmem_volatile_head);
+	if (!nr_to_scan)
+		goto out;
+
+	do {
+		ret = volatile_ranges_get_last_used(&shmem_volatile_head,
+							&mapping,&start,&end);

Why drop last used region? Not recently used region is better?

Quoted 15 lines
mm/shmem.c +15 -0
+		if (ret) {
+			shmem_truncate_range(mapping->host,
+						start<<PAGE_CACHE_SHIFT,
+						(end<<PAGE_CACHE_SHIFT)-1);
+			nr_to_scan -= end-start;
+			page_count -= end-start;
+		};
+	} while (ret&&  (nr_to_scan>  0));
+
+out:
+	volatile_range_unlock(&shmem_volatile_head);
+
+	return page_count;
+}
+
#5 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 31 lines · KOSAKI Motohiro

Hi John,

Quoted 23 lines · John Stultz

This patch enables FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE functionality for tmpfs making use of the volatile range management code.

Conceptually, FALLOC_FL_MARK_VOLATILE is like a delayed FALLOC_FL_PUNCH_HOLE. This allows applications that have data caches that can be re-created to tell the kernel that some memory contains data that is useful in the future, but can be recreated if needed, so if the kernel needs, it can zap the memory without having to swap it out.

In use, applications use FALLOC_FL_MARK_VOLATILE to mark page ranges as volatile when they are not in use. Then later if they wants to reuse the data, they use FALLOC_FL_UNMARK_VOLATILE, which will return an error if the data has been purged.

This is very much influenced by the Android Ashmem interface by Robert Love so credits to him and the Android developers. In many cases the code& logic come directly from the ashmem patch. The intent of this patch is to allow for ashmem-like behavior, but embeds the idea a little deeper into the VM code.

Quoted 5 lines

This is a reworked version of the fadvise volatile idea submitted earlier to the list. Thanks to Dave Chinner for suggesting to rework the idea in this fashion. Also thanks to Dmitry Adamushko for continued review and bug reporting, and Dave Hansen for help with the original design and mentoring me in the VM code.

Quoted 4 lines

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

Any recommendations for alternative approaches? What should I be hooking into in order to get notified that tmpfs should drop volatile pages?

Quoted 14 lines
Quoted 14 lines
mm/shmem.c +14 -0
+static
+int shmem_volatile_shrink(struct shrinker *ignored, struct shrink_control *sc)
+{
+	s64 nr_to_scan = sc->nr_to_scan;
+	const gfp_t gfp_mask = sc->gfp_mask;
+	struct address_space *mapping;
+	loff_t start, end;
+	int ret;
+	s64 page_count;
+
+	if (nr_to_scan&&  !(gfp_mask&  __GFP_FS))
+		return -1;
+
+	volatile_range_lock(&shmem_volatile_head);
Quoted 9 lines

mm/shmem.c static int shmem_setattr(struct dentry *dentry, struct iattr *attr)

Quoted 7 lines
mm/shmem.c +7 -0
+	page_count = volatile_range_lru_size(&shmem_volatile_head);
+	if (!nr_to_scan)
+		goto out;
+
+	do {
+		ret = volatile_ranges_get_last_used(&shmem_volatile_head,
+							&mapping,&start,&end);

Why drop last used region? Not recently used region is better?

Sorry, that function name isn't very good. It does return the least-recently-used range, or more specifically: the least-recently-marked-volatile-range.

I'll improve that function name, but if I misunderstood you and you have a different suggestion for the purging order, let me know.

thanks
-john

#6 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 32 lines · John Stultz
Quoted 31 lines · KOSAKI Motohiro

Hi John,

Quoted 28 lines · John Stultz

This patch enables FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE functionality for tmpfs making use of the volatile range management code.

Conceptually, FALLOC_FL_MARK_VOLATILE is like a delayed FALLOC_FL_PUNCH_HOLE. This allows applications that have data caches that can be re-created to tell the kernel that some memory contains data that is useful in the future, but can be recreated if needed, so if the kernel needs, it can zap the memory without having to swap it out.

In use, applications use FALLOC_FL_MARK_VOLATILE to mark page ranges as volatile when they are not in use. Then later if they wants to reuse the data, they use FALLOC_FL_UNMARK_VOLATILE, which will return an error if the data has been purged.

This is very much influenced by the Android Ashmem interface by Robert Love so credits to him and the Android developers.
In many cases the code& logic come directly from the ashmem patch.
The intent of this patch is to allow for ashmem-like behavior, but embeds the idea a little deeper into the VM code.

This is a reworked version of the fadvise volatile idea submitted earlier to the list. Thanks to Dave Chinner for suggesting to rework the idea in this fashion. Also thanks to Dmitry Adamushko for continued review and bug reporting, and Dave Hansen for help with the original design and mentoring me in the VM code.

Quoted 6 lines
Quoted 4 lines

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

Any recommendations for alternative approaches? What should I be hooking into in order to get notified that tmpfs should drop volatile pages?

I thought to modify shmem_write_page(). But other way is also ok to me.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
mm/shmem.c +14 -0
+static
+int shmem_volatile_shrink(struct shrinker *ignored, struct shrink_control *sc)
+{
+	s64 nr_to_scan = sc->nr_to_scan;
+	const gfp_t gfp_mask = sc->gfp_mask;
+	struct address_space *mapping;
+	loff_t start, end;
+	int ret;
+	s64 page_count;
+
+	if (nr_to_scan&&   !(gfp_mask&   __GFP_FS))
+		return -1;
+
+	volatile_range_lock(&shmem_volatile_head);
Quoted 9 lines

mm/shmem.c static int shmem_setattr(struct dentry *dentry, struct iattr *attr)

Quoted 7 lines
mm/shmem.c +7 -0
+	page_count = volatile_range_lru_size(&shmem_volatile_head);
+	if (!nr_to_scan)
+		goto out;
+
+	do {
+		ret = volatile_ranges_get_last_used(&shmem_volatile_head,
+							&mapping,&start,&end);

Why drop last used region? Not recently used region is better?

Quoted 3 lines

Sorry, that function name isn't very good. It does return the least-recently-used range, or more specifically: the least-recently-marked-volatile-range.

Ah, I misunderstood. thanks for correction.

Quoted 2 lines

I'll improve that function name, but if I misunderstood you and you have a different suggestion for the purging order, let me know.

No, please just rename.

#7 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 33 lines · KOSAKI Motohiro
Quoted 32 lines · John Stultz
Quoted 31 lines · KOSAKI Motohiro

Hi John,

Quoted 28 lines · John Stultz

This patch enables FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE functionality for tmpfs making use of the volatile range management code.

Conceptually, FALLOC_FL_MARK_VOLATILE is like a delayed FALLOC_FL_PUNCH_HOLE. This allows applications that have data caches that can be re-created to tell the kernel that some memory contains data that is useful in the future, but can be recreated if needed, so if the kernel needs, it can zap the memory without having to swap it out.

In use, applications use FALLOC_FL_MARK_VOLATILE to mark page ranges as volatile when they are not in use. Then later if they wants to reuse the data, they use FALLOC_FL_UNMARK_VOLATILE, which will return an error if the data has been purged.

This is very much influenced by the Android Ashmem interface by Robert Love so credits to him and the Android developers.
In many cases the code& logic come directly from the ashmem patch.
The intent of this patch is to allow for ashmem-like behavior, but embeds the idea a little deeper into the VM code.

This is a reworked version of the fadvise volatile idea submitted earlier to the list. Thanks to Dave Chinner for suggesting to rework the idea in this fashion. Also thanks to Dmitry Adamushko for continued review and bug reporting, and Dave Hansen for help with the original design and mentoring me in the VM code.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

Any recommendations for alternative approaches? What should I be hooking into in order to get notified that tmpfs should drop volatile pages?

I thought to modify shmem_write_page(). But other way is also ok to me.

So initially the patch used shmem_write_page(), purging ranges if a page was to be swapped (and just dropping it instead). The problem there is that if there's a large range that is very active, we might purge the entire range just because it contains one rarely used page. This is why the LRU list for unpurged volatile ranges is useful.

However, Dave Hansen just suggested to me on irc the idea of if we're swapping any pages, we might want to just purge a volatile range instead. This allows us to keep the unpurged LRU range list, but just uses write_page as the flag for needing to free memory.

I'm taking a shot at implementing this now, but let me know if it sounds good to you.

Quoted 26 lines
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
mm/shmem.c +14 -0
+static
+int shmem_volatile_shrink(struct shrinker *ignored, struct shrink_control *sc)
+{
+	s64 nr_to_scan = sc->nr_to_scan;
+	const gfp_t gfp_mask = sc->gfp_mask;
+	struct address_space *mapping;
+	loff_t start, end;
+	int ret;
+	s64 page_count;
+
+	if (nr_to_scan&&   !(gfp_mask&   __GFP_FS))
+		return -1;
+
+	volatile_range_lock(&shmem_volatile_head);
Quoted 9 lines

mm/shmem.c static int shmem_setattr(struct dentry *dentry, struct iattr *attr)

Quoted 7 lines
mm/shmem.c +7 -0
+	page_count = volatile_range_lru_size(&shmem_volatile_head);
+	if (!nr_to_scan)
+		goto out;
+
+	do {
+		ret = volatile_ranges_get_last_used(&shmem_volatile_head,
+							&mapping,&start,&end);

Why drop last used region? Not recently used region is better?

Quoted 3 lines

Sorry, that function name isn't very good. It does return the least-recently-used range, or more specifically: the least-recently-marked-volatile-range.

Quoted 6 lines

Ah, I misunderstood. thanks for correction.

Quoted 2 lines

I'll improve that function name, but if I misunderstood you and you have a different suggestion for the purging order, let me know.

No, please just rename.

Will do.

Thanks for the feedback!
-john

#8 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 38 lines · John Stultz
Quoted 37 lines · KOSAKI Motohiro
Quoted 36 lines · John Stultz
Quoted 35 lines · KOSAKI Motohiro

Hi John,

Quoted 23 lines · John Stultz

This patch enables FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE functionality for tmpfs making use of the volatile range management code.

Conceptually, FALLOC_FL_MARK_VOLATILE is like a delayed FALLOC_FL_PUNCH_HOLE. This allows applications that have data caches that can be re-created to tell the kernel that some memory contains data that is useful in the future, but can be recreated if needed, so if the kernel needs, it can zap the memory without having to swap it out.

In use, applications use FALLOC_FL_MARK_VOLATILE to mark page ranges as volatile when they are not in use. Then later if they wants to reuse the data, they use FALLOC_FL_UNMARK_VOLATILE, which will return an error if the data has been purged.

This is very much influenced by the Android Ashmem interface by Robert Love so credits to him and the Android developers.
In many cases the code& logic come directly from the ashmem patch.
The intent of this patch is to allow for ashmem-like behavior, but embeds the idea a little deeper into the VM code.

Quoted 5 lines

This is a reworked version of the fadvise volatile idea submitted earlier to the list. Thanks to Dave Chinner for suggesting to rework the idea in this fashion. Also thanks to Dmitry Adamushko for continued review and bug reporting, and Dave Hansen for help with the original design and mentoring me in the VM code.

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Any recommendations for alternative approaches? What should I be hooking into in order to get notified that tmpfs should drop volatile pages?

I thought to modify shmem_write_page(). But other way is also ok to me.

So initially the patch used shmem_write_page(), purging ranges if a page was to be swapped (and just dropping it instead). The problem there is that if there's a large range that is very active, we might purge the entire range just because it contains one rarely used page. This is why the LRU list for unpurged volatile ranges is useful.

???
But, volatile marking order is not related to access frequency. Why do you bother more inaccurate one? At least, pageout() should affect lru order of volatile ranges?

Quoted 4 lines

However, Dave Hansen just suggested to me on irc the idea of if we're swapping any pages, we might want to just purge a volatile range instead. This allows us to keep the unpurged LRU range list, but just uses write_page as the flag for needing to free memory.

Can you please elaborate more? I don't understand what's different "just dropping it instead" and "just purge a volatile range instead".

Quoted 2 lines

I'm taking a shot at implementing this now, but let me know if it sounds good to you.

#9 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 10 lines · KOSAKI Motohiro
Quoted 9 lines · John Stultz
Quoted 8 lines · KOSAKI Motohiro
Quoted 7 lines · John Stultz
Quoted 4 lines · KOSAKI Motohiro

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

Any recommendations for alternative approaches? What should I be hooking into in order to get notified that tmpfs should drop volatile pages?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I thought to modify shmem_write_page(). But other way is also ok to me.

So initially the patch used shmem_write_page(), purging ranges if a page was to be swapped (and just dropping it instead). The problem there is that if there's a large range that is very active, we might purge the entire range just because it contains one rarely used page. This is why the LRU list for unpurged volatile ranges is useful.

???
But, volatile marking order is not related to access frequency.

Correct.

Quoted 3 lines

Why do you
bother more inaccurate one? At least, pageout() should affect lru order of volatile ranges?

Not sure I'm following you here.

The key point is we want volatile ranges to be purged in the order they were marked volatile.
If we use the page lru via shmem_writeout to trigger range purging, we wouldn't necessarily get this desired behavior.

That said, Dave's idea is to still use a volatile range LRU, but to free it via shmem_writeout. This allows us to purge volatile pages before swapping out pages. I'll be sending a modified patchset out shortly that does this, hopefully it helps makes this idea clear.

Quoted 6 lines
Quoted 4 lines

However, Dave Hansen just suggested to me on irc the idea of if we're swapping any pages, we might want to just purge a volatile range instead. This allows us to keep the unpurged LRU range list, but just uses write_page as the flag for needing to free memory.

Can you please elaborate more? I don't understand what's different "just dropping it instead" and "just purge a volatile range instead".

So in the first implementation, on writeout we checked if the page was in a volatile range, and if so we dropped the page (just unlocking the page) and marked the range as purged instead of swapping the page out. This was non-optimal since the entire range was marked purged, but other volatile pages in that range would not be dropped until writeout was called on them.

My next implementation purged the entire range (via shmem_truncate_range) if we did a writeout on a page in that range. This was better, but still left us open to purging recently marked volatile ranges if only a single page in that range had not been accessed in awhile.

That's when I added the LRU tracking at the volatile range level (which reverted back to the behavior ashmem has always used), and have been using that model sense.

Hopefully this clarifies things. My apologies if I don't always use the correct terminology, as I'm still a newbie when it comes to VM code.

thanks
-john

#10 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 21 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

I like this patch concept. This is cleaner than userland notification quirk. But I don't like you use shrinker. Because of, after applying this patch, normal page reclaim path can still make swap out. this is undesirable.

Any recommendations for alternative approaches? What should I be hooking into in order to get notified that tmpfs should drop volatile pages?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I thought to modify shmem_write_page(). But other way is also ok to me.

So initially the patch used shmem_write_page(), purging ranges if a page was to be swapped (and just dropping it instead). The problem there is that if there's a large range that is very active, we might purge the entire range just because it contains one rarely used page. This is why the LRU list for unpurged volatile ranges is useful.

???
But, volatile marking order is not related to access frequency.

Correct.

Quoted 3 lines

Why do you
bother more inaccurate one? At least, pageout() should affect lru order of volatile ranges?

Quoted 6 lines

Not sure I'm following you here.

The key point is we want volatile ranges to be purged in the order they were marked volatile.
If we use the page lru via shmem_writeout to trigger range purging, we wouldn't necessarily get this desired behavior.

Ok, so can you please explain your ideal order to reclaim. your last mail described old and new volatiled region. but I'm not sure regular tmpfs pages vs volatile pages vs regular file cache order. That said, when using shrink_slab(), we choose random order to drop against page cache. I'm not sure why you sure it is ideal.

And, now I guess you think nobody touch volatiled page, yes? because otherwise volatile marking order is silly choice. If yes, what's happen if anyone touch a patch which volatiled. no-op? SIGBUS?

Quoted 19 lines

That said, Dave's idea is to still use a volatile range LRU, but to free it via shmem_writeout. This allows us to purge volatile pages before swapping out pages. I'll be sending a modified patchset out shortly that does this, hopefully it helps makes this idea clear.

Quoted 6 lines
Quoted 4 lines

However, Dave Hansen just suggested to me on irc the idea of if we're swapping any pages, we might want to just purge a volatile range instead. This allows us to keep the unpurged LRU range list, but just uses write_page as the flag for needing to free memory.

Can you please elaborate more? I don't understand what's different "just dropping it instead" and "just purge a volatile range instead".

So in the first implementation, on writeout we checked if the page was in a volatile range, and if so we dropped the page (just unlocking the page) and marked the range as purged instead of swapping the page out. This was non-optimal since the entire range was marked purged, but other volatile pages in that range would not be dropped until writeout was called on them.

Quoted 4 lines

My next implementation purged the entire range (via shmem_truncate_range) if we did a writeout on a page in that range. This was better, but still left us open to purging recently marked volatile ranges if only a single page in that range had not been accessed in awhile.

Which worklord didn't work. Usually, anon pages reclaim are only happen when
1) tmpfs streaming io workload or 2) heavy vm pressure. So, this scenario are not so inaccurate to me.

Quoted 6 lines

That's when I added the LRU tracking at the volatile range level (which reverted back to the behavior ashmem has always used), and have been using that model sense.

Hopefully this clarifies things. My apologies if I don't always use the correct terminology, as I'm still a newbie when it comes to VM code.

I think your code is enough clean. But I'm still not sure your background design. Please help me to understand clearly.

btw, Why do you choice fallocate instead of fadvise? As far as I skimmed, fallocate() is an operation of a disk layout, not of a cache. And, why did you choice fadvise() instead of madvise() at initial version. vma hint might be useful than fadvise() because it can be used for anonymous pages too.

#11 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 9 lines · KOSAKI Motohiro
Quoted 4 lines

The key point is we want volatile ranges to be purged in the order they were marked volatile.
If we use the page lru via shmem_writeout to trigger range purging, we wouldn't necessarily get this desired behavior.

Ok, so can you please explain your ideal order to reclaim. your last mail described old and new volatiled region. but I'm not sure regular tmpfs pages vs volatile pages vs regular file cache order. That said, when using shrink_slab(), we choose random order to drop against page cache. I'm not sure why you sure it is ideal.

So I'm not totally sure its ideal, but I can tell you what make sense to me. If there is a more ideal order, I'm open to suggestions.

So volatile ranges should be purged first-in-first-out. So the first range marked volatile should be purged first. Since volatile ranges might have different costs depending on what filesystem the file is backed by, this LRU order is per-filesystem.

It seems that if we have tmpfs volatile ranges, we should purge them before we swap out any regular tmpfs pages. Thus why I'm purging any available ranges on shmem_writepage before swapping, rather then using a shrinker now (I'm hoping you saw the updated patchset I sent out friday).

Does that make sense?

Quoted 3 lines

And, now I guess you think nobody touch volatiled page, yes? because otherwise volatile marking order is silly choice. If yes, what's happen if anyone touch a patch which volatiled. no-op? SIGBUS?

So more of a noop. If you read a page that has been marked volatile, it may return the data that was there, or it may return an empty nulled page.

I guess we could throw a signal to help avoid developers making programming mistakes, but I'm not sure what the extra cost would be to set up and tare that down each time. One important aspect of this is that in order to make it attractive for an application to mark ranges as volatile, it has to be very cheap to mark and unmark ranges.

Quoted 3 lines

Which worklord didn't work. Usually, anon pages reclaim are only happen when 1) tmpfs streaming io workload or 2) heavy vm pressure. So, this scenario are not so inaccurate to me.

So it was more of a theoretical issue in my discussions, but once it was brought up, ashmems' global range lru made more sense.

I think the workload we're mostly concerned with here is heavy vm pressure.

Quoted 8 lines
Quoted 6 lines

That's when I added the LRU tracking at the volatile range level (which reverted back to the behavior ashmem has always used), and have been using that model sense.

Hopefully this clarifies things. My apologies if I don't always use the correct terminology, as I'm still a newbie when it comes to VM code.

I think your code is enough clean. But I'm still not sure your background design. Please help me to understand clearly.

Hopefully the above helps. But let me know where you'd like more clarification.

Quoted 5 lines

btw, Why do you choice fallocate instead of fadvise? As far as I skimmed, fallocate() is an operation of a disk layout, not of a cache. And, why did you choice fadvise() instead of madvise() at initial version. vma hint might be useful than fadvise() because it can be used for anonymous pages too.

I actually started with madvise, but quickly moved to fadvise when feeling that the fd based ranges made more sense. With ashmem, fds are often shared, and coordinating volatile ranges on a shared fd made more sense on a (fd, offset, len) tuple, rather then on an offset and length on an mmapped region.

I moved to fallocate at Dave Chinner's request. In short, it allows non-tmpfs filesystems to implement volatile range semantics allowing them to zap rather then writeout dirty volatile pages. And since the volatile ranges are very similar to a delayed/cancel-able hole-punch, it made sense to use a similar interface to FALLOC_FL_HOLE_PUNCH.

You can read the details of DaveC's suggestion here:
https://lkml.org/lkml/2012/4/30/441

thanks
-john

#12 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

[ ... ]

Quoted 14 lines
Quoted 5 lines

Ok, so can you please explain your ideal order to reclaim. your last mail described old and new volatiled region. but I'm not sure regular tmpfs pages vs volatile pages vs regular file cache order. That said, when using shrink_slab(), we choose random order to drop against page cache. I'm not sure why you sure it is ideal.

So I'm not totally sure its ideal, but I can tell you what make sense to me. If there is a more ideal order, I'm open to suggestions.

So volatile ranges should be purged first-in-first-out. So the first range marked volatile should be purged first. Since volatile ranges might have different costs depending on what filesystem the file is backed by, this LRU order is per-filesystem.

Quoted 5 lines

It seems that if we have tmpfs volatile ranges, we should purge them before we swap out any regular tmpfs pages. Thus why I'm purging any available ranges on shmem_writepage before swapping, rather then using a shrinker now (I'm hoping you saw the updated patchset I sent out friday).

so there are multiple sources of reclaimable memory, each coming with its own cost of (a) giving a memory page back to the kernel and (b) populating a new page with the content (if accessed later). Given that the costs are different, I assume that the kernel tries to balance between different sources with the goal of minimizing the overall cost.

In this light, the placement of a new source (like 'volatile ranges') of reclaimable memory does affect this balance (and hence, the overall cost) one way or another. For instance,

"we should purge them before we swap out any regular tmpfs pages"

but maybe we should also purge them before we swap out some non-tmpfs pages or drop some file-backed pages?

-- Dmitry

#13 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 2 lines · Dmitry Adamushko

but maybe we should also purge them before we swap out some non-tmpfs pages or drop some file-backed pages?

Sure... I guess we could kick that from either direct reclaim or from kswapd. But, then we're basically back to the places where shrink_slab() is called.

I think that means that we think it's preferable to integrate this more directly in the VM instead of sticking it off in the corner of tmpfs only, or pretending it's a slab.

Dunno... The slab shrinker one isn't looking _so_ bad at the moment.

#14 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 8 lines · Dave Hansen
Quoted 2 lines · Dmitry Adamushko

but maybe we should also purge them before we swap out some non-tmpfs pages or drop some file-backed pages?

Sure... I guess we could kick that from either direct reclaim or from kswapd. But, then we're basically back to the places where shrink_slab() is called.

Quoted 5 lines

I think that means that we think it's preferable to integrate this more directly in the VM instead of sticking it off in the corner of tmpfs only, or pretending it's a slab.

Dunno... The slab shrinker one isn't looking _so_ bad at the moment.

Dave also pointed out to me on irc that on a system without swap, shmem_writepage doesn't even get called, which kills the utility of triggering volatile purging from writepage.

So I'm falling back to using a shrinker for now, but I think Dmitry's point is an interesting one, and am interested in finding a better place to trigger purging volatile ranges from the mm code. If anyone has any suggestions, let me know, otherwise I'll go back to trying to better grok the mm code.

thanks
-john

#15 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 13 lines · John Stultz
Quoted 12 lines · Dave Hansen
Quoted 2 lines · Dmitry Adamushko

but maybe we should also purge them before we swap out some non-tmpfs pages or drop some file-backed pages?

Sure... I guess we could kick that from either direct reclaim or from kswapd. But, then we're basically back to the places where shrink_slab() is called.

I think that means that we think it's preferable to integrate this more directly in the VM instead of sticking it off in the corner of tmpfs only, or pretending it's a slab.

Quoted 5 lines
Quoted 1 line

Dunno... The slab shrinker one isn't looking _so_ bad at the moment.

Dave also pointed out to me on irc that on a system without swap, shmem_writepage doesn't even get called, which kills the utility of triggering volatile purging from writepage.

Ah, right you are. swap-less system never try to reclaim anon pages. So, volatile pages is no longer swap backed. swap backed lru is no longer suitable place.

Quoted 4 lines

So I'm falling back to using a shrinker for now, but I think Dmitry's point is an interesting one, and am interested in finding a better
place to trigger purging volatile ranges from the mm code. If anyone has any suggestions, let me know, otherwise I'll go back to trying to better grok the mm code.

I hate vm feature to abuse shrink_slab(). because of, it was not designed generic callback. it was designed for shrinking filesystem metadata. Therefore, vm keeping a balance between page scanning and slab scanning. then, a lot of shrink_slab misuse may lead to break balancing logic. i.e. drop icache/dcache too many and makes perfomance impact.

As far as a code impact is small, I'm prefer to connect w/ vm reclaim code directly.

#27 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to John Stultz
Quoted 30 lines · John Stultz
Quoted 9 lines · KOSAKI Motohiro
Quoted 4 lines

The key point is we want volatile ranges to be purged in the order they were marked volatile.
If we use the page lru via shmem_writeout to trigger range purging, we wouldn't necessarily get this desired behavior.

Ok, so can you please explain your ideal order to reclaim. your last mail described old and new volatiled region. but I'm not sure regular tmpfs pages vs volatile pages vs regular file cache order. That said, when using shrink_slab(), we choose random order to drop against page cache. I'm not sure why you sure it is ideal.

So I'm not totally sure its ideal, but I can tell you what make sense to me. If there is a more ideal order, I'm open to suggestions.

So volatile ranges should be purged first-in-first-out. So the first range marked volatile should be purged first. Since volatile ranges might have different costs depending on what filesystem the file is backed by, this LRU order is per-filesystem.

It seems that if we have tmpfs volatile ranges, we should purge them before we swap out any regular tmpfs pages. Thus why I'm purging any available ranges on shmem_writepage before swapping, rather then using a shrinker now (I'm hoping you saw the updated patchset I sent out friday).

Does that make sense?

Quoted 3 lines

And, now I guess you think nobody touch volatiled page, yes? because otherwise volatile marking order is silly choice. If yes, what's happen if anyone touch a patch which volatiled. no-op? SIGBUS?

Quoted 8 lines

So more of a noop. If you read a page that has been marked volatile, it may return the data that was there, or it may return an empty nulled page.

I guess we could throw a signal to help avoid developers making programming mistakes, but I'm not sure what the extra cost would be to set up and tare that down each time. One important aspect of this is that in order to make it attractive for an application to mark ranges as volatile, it has to be very cheap to mark and unmark ranges.

ok, i agree we don't need to pay any extra cost.

Quoted 6 lines
Quoted 3 lines

Which worklord didn't work. Usually, anon pages reclaim are only happen when 1) tmpfs streaming io workload or 2) heavy vm pressure. So, this scenario are not so inaccurate to me.

So it was more of a theoretical issue in my discussions, but once it was brought up, ashmems' global range lru made more sense.

No. Every global lru is evil. Please don't introduce numa unaware code for a new feature. That's a legacy and poor performance.

Quoted 1 line

I think the workload we're mostly concerned with here is heavy vm pressure.

I don't admit it. but note, when under heavy workload, shrink_slab() behave stupid seriously.

Quoted 23 lines
Quoted 8 lines
Quoted 6 lines

That's when I added the LRU tracking at the volatile range level (which reverted back to the behavior ashmem has always used), and have been using that model sense.

Hopefully this clarifies things. My apologies if I don't always use the correct terminology, as I'm still a newbie when it comes to VM code.

I think your code is enough clean. But I'm still not sure your background design. Please help me to understand clearly.

Hopefully the above helps. But let me know where you'd like more clarification.

Quoted 5 lines

btw, Why do you choice fallocate instead of fadvise? As far as I skimmed, fallocate() is an operation of a disk layout, not of a cache. And, why did you choice fadvise() instead of madvise() at initial version. vma hint might be useful than fadvise() because it can be used for anonymous pages too.

I actually started with madvise, but quickly moved to fadvise when feeling that the fd based ranges made more sense. With ashmem, fds are often shared, and coordinating volatile ranges on a shared fd made more sense on a (fd, offset, len) tuple, rather then on an offset and length on an mmapped region.

Quoted 8 lines

I moved to fallocate at Dave Chinner's request. In short, it allows non-tmpfs filesystems to implement volatile range semantics allowing them to zap rather then writeout dirty volatile pages. And since the volatile ranges are very similar to a delayed/cancel-able hole-punch, it made sense to use a similar interface to FALLOC_FL_HOLE_PUNCH.

You can read the details of DaveC's suggestion here:
https://lkml.org/lkml/2012/4/30/441

Hmmm...

I'm sorry. I can't imagine how to integrate FALLOCATE_VOLATILE into regular file systems. do you have any idea?

#16 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to KOSAKI Motohiro
Quoted 7 lines · KOSAKI Motohiro
Quoted 4 lines · John Stultz

So I'm falling back to using a shrinker for now, but I think Dmitry's point is an interesting one, and am interested in finding a better
place to trigger purging volatile ranges from the mm code. If anyone has any suggestions, let me know, otherwise I'll go back to trying to better grok the mm code.

Quoted 6 lines

I hate vm feature to abuse shrink_slab(). because of, it was not designed generic callback. it was designed for shrinking filesystem metadata. Therefore, vm keeping a balance between page scanning and slab scanning. then, a lot of shrink_slab misuse may lead to break balancing logic. i.e. drop icache/dcache too many and makes perfomance impact.

As far as a code impact is small, I'm prefer to connect w/ vm reclaim code directly.

I can see your concern about mis-using the shrinker code. Also your other email's point about the problem of having LRU range purging behavior on a NUMA system makes some sense too. Unfortunately I'm not yet familiar enough with the reclaim core to sort out how to best track and connect the volatile range purging in the vm's reclaim core yet.

So for now, I've moved the code back to using the shrinker (along with fixing a few bugs along the way). Thus, currently we manage the ranges as so:

    [per fs volatile range lru head] -> [volatile range] -> [volatile 

range] -> [volatile range]
With the per-fs shrinker zaping the volatile ranges from the lru.

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

So maybe the right appraoch give up the per-fs volatile range lru, and try a varient of what DaveC and DaveH have suggested: Letting the page based lru reclamation handle the selection on a physical page basis, but then zapping the entirety of the neighboring range if any one page is reclaimed. In order to try to preserve the range based LRU behavior, activate all the pages in the range together when the range is marked volatile. Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of activating each of the containing pages on mark_volatile.

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec. So it seems we may need to add a new lru_list enum and nr[] entry (maybe LRU_VOLATILE?). So then it may be that when we mark a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Does that sound reasonable? Any other suggested approaches? I'll think some more about it this weekend and try to get a patch scratched out early next week.

thanks
-john

#17 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 11 lines

So maybe the right appraoch give up the per-fs volatile range lru, and try a varient of what DaveC and DaveH have suggested: Letting the page based lru reclamation handle the selection on a physical page basis, but then zapping the entirety of the neighboring range if any one page is reclaimed.  In order to try to preserve the range based LRU behavior, activate all the pages in the range together when the range is marked volatile.  Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

Quoted 3 lines

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of activating each of the containing pages on mark_volatile.

(for my education) just to be sure that I got it right. So what you suggest is

(1) to 'deactivate-page' for all the pages in the range upon mark_volatile. Hence, the pages from the same volatile range are placed in clusters within their original LRU lists [a] and so

(1.1) the standard per-page reclaim mechanism is more likely to discard them together;
(1.2) they are also (LRU-style) ordered wrt other volatile ranges (clusters)

[a] it's LRU_INACTIVE_FILE for tmpfs, right? also, the pages can be from different zones (otoh, at least on x86 HIGH_MEM is likely).

or

(2) somehow remove all the pages from the standard LRU lists (or do something else) to make sure that that the normal per-page reclaim procedure can't see them. Then we introduce LRU_VOLATILE (where we keep whole volatile ranges, not pages) and find the appropriate place to process it in the reclaim code.

Also, I had another idea (it looks quite hacky though). For (1) above, we don't necessarily need to touch all the pages... what we can do is as follows:
- take the first page of the range (or even create a (hacky-hacky) virtual one);
- we need to mark it somehow as belonging to the volatile-reclaim (modifying page->mapping ?);
- we place it at the beginning of the corresponding LRU_INACTIVE_* list (hm, more complex if different zones);
the idea here, is that the standard per-page reclaim code should see
this page before seeing any other page from its range
- once the per-page reclaim code encounters such a page (heh, should be a low cost check though) - we call into volatile-reclaim...

now, this volatile-reclaim can even purge another volatile range, because by placing "the page at the beginning of the corresponding LRU_INACTIVE_* list)" we broke LRU-like behavior for volatile ranges.

Quoted 10 lines

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec.  So it seems we may need to add a new lru_list enum and nr[] entry (maybe LRU_VOLATILE?).   So then it may be that when we mark a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Kind of what I meant with (2) above?

[ I was in a bit of hurry while writing this, so I apologize for possible confusion... I can elaborate on it more in details later on ]

Thanks,

-- Dmitry

#18 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to John Stultz
Quoted 3 lines · John Stultz

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces

Easier to mark them dirty.

Quoted 4 lines

a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

Then the volatile ->writepage function can zap the whole object.

Signature · 1 line
All rights reversed
#19 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 8 lines · Rik van Riel
Quoted 3 lines · John Stultz

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces

Easier to mark them dirty.

Quoted 8 lines
Quoted 4 lines

a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

Then the volatile ->writepage function can zap the whole object.

What about the concern that if we don't have swap, we'll not call writepage on tmpfs files?

thanks
-john

#20 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 14 lines · John Stultz
Quoted 13 lines · Rik van Riel
Quoted 3 lines · John Stultz

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces

Easier to mark them dirty.

Quoted 4 lines

a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

Quoted 5 lines
Quoted 3 lines

Then the volatile ->writepage function can zap the whole object.

What about the concern that if we don't have swap, we'll not call writepage on tmpfs files?

So actually, a more concrete question might be: What is the value of the active/inactive split of anonymous memory on a system without swap?

Basically I'm looking at trying to allow the writepage function to zap the range as you suggest, but also changing the behavior when there is no swap so that all anonymous pages stay active, unless they are volatile. Then, in both cases with swap and without, we would still shrink the inactive list, call writepage and zap the volatile ranges. Its just without swap, the only anonymous pages on the inactive list would be volatile.

Does that make any sense?

Hopefully will have a hackish patch to demonstrate what I'm describing tomorrow.

thanks
-john

#21 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to John Stultz

Please, Cced linux-mm.

Quoted 42 lines · John Stultz
Quoted 17 lines · KOSAKI Motohiro
Quoted 6 lines · John Stultz

So I'm falling back to using a shrinker for now, but I think Dmitry's point is an interesting one, and am interested in finding a better place to trigger purging volatile ranges from the mm code. If anyone has any
suggestions, let me know, otherwise I'll go back to trying to better grok the mm code.

I hate vm feature to abuse shrink_slab(). because of, it was not designed generic callback.
it was designed for shrinking filesystem metadata. Therefore, vm keeping a balance between
page scanning and slab scanning. then, a lot of shrink_slab misuse may lead to break balancing
logic. i.e. drop icache/dcache too many and makes perfomance impact.

Quoted 2 lines

As far as a code impact is small, I'm prefer to connect w/ vm reclaim code directly.

I can see your concern about mis-using the shrinker code. Also your other email's point about the problem of having LRU range purging behavior on a NUMA system makes some sense too. Unfortunately I'm not yet familiar enough with the reclaim core to sort out how to best track and connect the volatile range purging in the vm's reclaim core yet.

So for now, I've moved the code back to using the shrinker (along with fixing a few bugs along the way).
Thus, currently we manage the ranges as so:

    [per fs volatile range lru head] -> [volatile range] -> [volatile

range] -> [volatile range]
With the per-fs shrinker zaping the volatile ranges from the lru.

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

Quoted 6 lines

So maybe the right appraoch give up the per-fs volatile range lru, and try a varient of what DaveC and DaveH have suggested: Letting the page based lru reclamation handle the selection on a physical page basis, but then zapping the entirety of the neighboring range if any one page is reclaimed. In order to try to preserve the range based LRU behavior, activate all the pages in the range together when the range is marked

You mean deactivation for fast reclaiming, not activation when memory pressure happen?

Quoted 7 lines

volatile. Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of activating each of the containing pages on mark_volatile.

Yes. it could be a problem if range is very large and populated already. Why can't we make new hooks?

Just concept for showing my intention..

+int shrink_volatile_pages(struct zone *zone)
+{
+ int ret = 0;
+ if (zone_page_state(zone, NR_ZONE_VOLATILE))
+ ret = shmem_purge_one_volatile_range();
+ return ret;
+}
+
static void shrink_zone(struct zone *zone, struct scan_control *sc)

 {
        struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -1827,6 +1835,18 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc)
                .priority = sc->priority,
        };
        struct mem_cgroup *memcg;
+       int ret;
+
+       /*
+        * Before we dive into trouble maker, let's look at easy-
+        * reclaimable pages and avoid costly-reclaim if possible.
+        */

+ do {
+ ret = shrink_volatile_pages();
+ if (ret)
+ zone_watermark_ok(zone, sc->order, xxx);
+ return;
+ } while(ret)

Off-topic:

I want to drive low memory notification level-triggering instead of raw vmstat trigger. (It's rather long thread https://lkml.org/lkml/2012/5/1/97)

level 1: out-of-easy reclaimable pages (NR_VOLATILE + NR_UNMAPPED_CLEAN_PAGE) level 2 (more sever VM pressure than level 1): level2 + reclaimable dirty pages

When it is out of easy-reclaimable pages, it might be good indication for low memory notification.

Quoted 9 lines

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec. So it seems we may need to add a new lru_list enum and
nr[] entry (maybe LRU_VOLATILE?). So then it may be that when we mark
a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Adding new LRU idea might make very slow fallocate(VOLATILE) so I hope we can avoid that if possible.

Off-topic:
But I'm not sure because I might try to make new easy-reclaimable LRU list for low memory notification. That LRU list would contain non-mapped clean cache page and volatile pages if I decide adding it. Both pages has a common characteristic that recreating page is less costly.
It's true for eMMC/SSD like device, at least.

Quoted 20 lines

Does that sound reasonable? Any other suggested approaches? I'll think some more about it this weekend and try to get a patch scratched out early next week.

thanks
-john

Signature · 8 lines
Kind regards,
Minchan Kim

--
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>
#22 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 5 lines

Off-topic:
But I'm not sure because I might try to make new easy-reclaimable LRU list for low memory notification. That LRU list would contain non-mapped clean cache page and volatile pages if I decide adding it. Both pages has a common characteristic that recreating page is less costly.
It's true for eMMC/SSD like device, at least.

+1.

I like L2 inactive list.

--
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>

#23 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

In reply to Minchan Kim
Quoted 44 lines · Minchan Kim

Please, Cced linux-mm.

Quoted 40 lines · John Stultz
Quoted 16 lines · KOSAKI Motohiro
Quoted 6 lines · John Stultz

So I'm falling back to using a shrinker for now, but I think Dmitry's point is an interesting one, and am interested in finding a better place to trigger purging volatile ranges from the mm code. If anyone has any
suggestions, let me know, otherwise I'll go back to trying to better grok the mm code.

I hate vm feature to abuse shrink_slab(). because of, it was not designed generic callback.
it was designed for shrinking filesystem metadata. Therefore, vm keeping a balance between
page scanning and slab scanning. then, a lot of shrink_slab misuse may lead to break balancing
logic. i.e. drop icache/dcache too many and makes perfomance impact.

Quoted 2 lines

As far as a code impact is small, I'm prefer to connect w/ vm reclaim code directly.

I can see your concern about mis-using the shrinker code. Also your other email's point about the problem of having LRU range purging behavior on a NUMA system makes some sense too. Unfortunately I'm not yet familiar enough with the reclaim core to sort out how to best track and connect the volatile range purging in the vm's reclaim core yet.

So for now, I've moved the code back to using the shrinker (along with fixing a few bugs along the way).
Thus, currently we manage the ranges as so:

     [per fs volatile range lru head] ->  [volatile range] ->  [volatile

range] -> [volatile range]
With the per-fs shrinker zaping the volatile ranges from the lru.

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

Quoted 8 lines
Quoted 6 lines

So maybe the right appraoch give up the per-fs volatile range lru, and try a varient of what DaveC and DaveH have suggested: Letting the page based lru reclamation handle the selection on a physical page basis, but then zapping the entirety of the neighboring range if any one page is reclaimed. In order to try to preserve the range based LRU behavior, activate all the pages in the range together when the range is marked

You mean deactivation for fast reclaiming, not activation when memory pressure happen?

Yes. Sorry for mixing up terms here. The point is moving all the pages together to the inactive list to preserve relative LRU behavior for purging ranges.

Quoted 30 lines
Quoted 7 lines

volatile. Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of activating each of the containing pages on mark_volatile.

Yes. it could be a problem if range is very large and populated already. Why can't we make new hooks?

Just concept for showing my intention..

(quoted diff) +10 -0
+int shrink_volatile_pages(struct zone *zone)
+{
+       int ret = 0;
+       if (zone_page_state(zone, NR_ZONE_VOLATILE))
+               ret = shmem_purge_one_volatile_range();
+       return ret;
+}
+
  static void shrink_zone(struct zone *zone, struct scan_control *sc)
  {
         struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -1827,6 +1835,18 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc)
                 .priority = sc->priority,
         };
         struct mem_cgroup *memcg;
+       int ret;
+

Review static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1849

Quoted 10 lines
(quoted diff) +10 -0
+       /*
+        * Before we dive into trouble maker, let's look at easy-
+        * reclaimable pages and avoid costly-reclaim if possible.
+        */
+       do {
+               ret = shrink_volatile_pages();
+               if (ret)
+                       zone_watermark_ok(zone, sc->order, xxx);
+                               return;
+       } while(ret)

Hmm. I'm confused.
This doesn't seem that different from the shrinker approach.
How does this resolve the numa-unawareness issue that Kosaki-san brought up?

Quoted 9 lines
Quoted 8 lines

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec. So it seems we may need to add a new lru_list enum and
nr[] entry (maybe LRU_VOLATILE?). So then it may be that when we mark
a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Adding new LRU idea might make very slow fallocate(VOLATILE) so I hope we can avoid that if possible.

Indeed. This is a major concern. I'm currently prototyping it out so I have a concrete sense of the performance cost.

thanks
-john

#24 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 52 lines · John Stultz
Quoted 51 lines · Minchan Kim

Please, Cced linux-mm.

Quoted 46 lines · John Stultz
Quoted 16 lines · KOSAKI Motohiro
Quoted 6 lines · John Stultz

So I'm falling back to using a shrinker for now, but I think Dmitry's point is an interesting one, and am interested in finding a better place to trigger purging volatile ranges from the mm code. If anyone has any
suggestions, let me know, otherwise I'll go back to trying to better grok the mm code.

I hate vm feature to abuse shrink_slab(). because of, it was not designed generic callback.
it was designed for shrinking filesystem metadata. Therefore, vm keeping a balance between
page scanning and slab scanning. then, a lot of shrink_slab misuse may lead to break balancing
logic. i.e. drop icache/dcache too many and makes perfomance impact.

Quoted 2 lines

As far as a code impact is small, I'm prefer to connect w/ vm reclaim code directly.

I can see your concern about mis-using the shrinker code. Also your other email's point about the problem of having LRU range purging behavior on a NUMA system makes some sense too. Unfortunately I'm not yet familiar enough with the reclaim core to sort out how to best track and connect the volatile range purging in the vm's reclaim core yet.

So for now, I've moved the code back to using the shrinker (along with fixing a few bugs along the way).
Thus, currently we manage the ranges as so:

     [per fs volatile range lru head] ->  [volatile range] ->  [volatile

range] -> [volatile range]
With the per-fs shrinker zaping the volatile ranges from the lru.

I *think* ideally, the pages in a volatile range should be similar to non-dirty file-backed pages. There is a cost to restore them, but freeing them is very cheap. The trick is that volatile ranges introduces a new relationship between pages. Since the neighboring virtual pages in a volatile range are in effect tied together, purging one effectively ruins the value of keeping the others, regardless of which zone they are physically.

So maybe the right appraoch give up the per-fs volatile range lru, and try a varient of what DaveC and DaveH have suggested: Letting the page based lru reclamation handle the selection on a physical page basis, but then zapping the entirety of the neighboring range if any one page is reclaimed. In order to try to preserve the range based LRU behavior, activate all the pages in the range together when the range is marked

Quoted 5 lines
Quoted 2 lines

You mean deactivation for fast reclaiming, not activation when memory pressure happen?

Yes. Sorry for mixing up terms here. The point is moving all the pages together to the inactive list to preserve relative LRU behavior for purging ranges.

No problem :)

Quoted 39 lines
Quoted 39 lines
Quoted 10 lines

volatile. Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of activating each of the containing pages on mark_volatile.

Yes. it could be a problem if range is very large and populated already. Why can't we make new hooks?

Just concept for showing my intention..

(quoted diff) +15 -0
+int shrink_volatile_pages(struct zone *zone)
+{
+       int ret = 0;
+       if (zone_page_state(zone, NR_ZONE_VOLATILE))
+               ret = shmem_purge_one_volatile_range();
+       return ret;
+}
+
  static void shrink_zone(struct zone *zone, struct scan_control *sc)
  {
         struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -1827,6 +1835,18 @@ static void shrink_zone(struct zone *zone,
 struct scan_control *sc)
                 .priority = sc->priority,
         };
         struct mem_cgroup *memcg;
+       int ret;
+
+       /*
+        * Before we dive into trouble maker, let's look at easy-
+        * reclaimable pages and avoid costly-reclaim if possible.
+        */
+       do {
Quoted 8 lines

Review static void shrink_zone(struct zone *zone, · line 1850

Quoted 5 lines
(quoted diff) +5 -0
+               ret = shrink_volatile_pages();
+               if (ret)
+                       zone_watermark_ok(zone, sc->order, xxx);
+                               return;
+       } while(ret)

Hmm. I'm confused.
This doesn't seem that different from the shrinker approach.

Shrinker is called after shrink_list so it means normal pages can be reclaimed before we reclaim volatile pages. We shouldn't do that.

Quoted 2 lines

How does this resolve the numa-unawareness issue that Kosaki-san brought up?

Basically, I think your shrink function should be more smart.

when fallocate is called, we can get mem_policy from shmem_inode_info and pass it to volatile_range so that volatile_range can keep the information of NUMA.

When shmem_purge_one_volatile_range is called, it receives zone information. So shmem_purge_one_volatile_range should find a range matched with NUMA policy and passed zone.

Assumption:
A range may include same node/zone pages if possible.

I am not familiar with NUMA handling code so KOSAKI/Rik can point out if I am wrong.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec. So it seems we may need to add a new lru_list enum and
nr[] entry (maybe LRU_VOLATILE?). So then it may be that when we mark
a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Quoted 5 lines
Quoted 2 lines

Adding new LRU idea might make very slow fallocate(VOLATILE) so I hope we can avoid that if possible.

Indeed. This is a major concern. I'm currently prototyping it out so I have a concrete sense of the performance cost.

If performance loss isn't big, that would be a approach!

Quoted 4 lines

thanks
-john

Signature · 8 lines
Kind regards,
Minchan Kim

--
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>
#25 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 51 lines · Minchan Kim
Quoted 40 lines · John Stultz
Quoted 39 lines · Minchan Kim

Please, Cced linux-mm.

Quoted 7 lines · John Stultz

volatile. Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of activating each of the containing pages on mark_volatile.

Yes. it could be a problem if range is very large and populated already. Why can't we make new hooks?

Just concept for showing my intention..

(quoted diff) +14 -0
+int shrink_volatile_pages(struct zone *zone)
+{
+       int ret = 0;
+       if (zone_page_state(zone, NR_ZONE_VOLATILE))
+               ret = shmem_purge_one_volatile_range();
+       return ret;
+}
+
   static void shrink_zone(struct zone *zone, struct scan_control *sc)
   {
          struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -1827,6 +1835,18 @@ static void shrink_zone(struct zone *zone,
 struct scan_control *sc)
                  .priority = sc->priority,
          };
          struct mem_cgroup *memcg;
+       int ret;
+
+       /*
+        * Before we dive into trouble maker, let's look at easy-
+        * reclaimable pages and avoid costly-reclaim if possible.
+        */
Quoted 8 lines

Review static void shrink_zone(struct zone *zone, · line 1850

Quoted 6 lines
(quoted diff) +6 -0
+       do {
+               ret = shrink_volatile_pages();
+               if (ret)
+                       zone_watermark_ok(zone, sc->order, xxx);
+                               return;
+       } while(ret)

Hmm. I'm confused.
This doesn't seem that different from the shrinker approach.

Quoted 2 lines

Shrinker is called after shrink_list so it means normal pages can be reclaimed before we reclaim volatile pages. We shouldn't do that.

Ah. Ok. Maybe that's a reasonable compromise between the shrinker approach and the more complex approach I just posted to lkml? (Forgive me for forgetting to CC you and linux-mm with my latest post!)

Quoted 6 lines
Quoted 2 lines

How does this resolve the numa-unawareness issue that Kosaki-san brought up?

Basically, I think your shrink function should be more smart.

when fallocate is called, we can get mem_policy from shmem_inode_info and pass it to volatile_range so that volatile_range can keep the information of NUMA.

Hrm.. That sounds reasonable. I'll look into the mem_policy bits and try to learn more.

Quoted 8 lines

When shmem_purge_one_volatile_range is called, it receives zone information. So shmem_purge_one_volatile_range should find a range matched with NUMA policy and passed zone.

Assumption:
A range may include same node/zone pages if possible.

I am not familiar with NUMA handling code so KOSAKI/Rik can point out if I am wrong.

Right, the range may cross nodes/zones but maybe that's not a huge deal? The only bit I'd worry about is the lru scanning being non-constant as we searched for a range that matched the node we want to free from. I guess we could have per-node/zone lrus.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec. So it seems we may need to add a new lru_list enum and
nr[] entry (maybe LRU_VOLATILE?). So then it may be that when we mark
a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Adding new LRU idea might make very slow fallocate(VOLATILE) so I hope we can avoid that if possible.

Indeed. This is a major concern. I'm currently prototyping it out so I have a concrete sense of the performance cost.

If performance loss isn't big, that would be a approach!

I've not had a chance yet to measure it, as I wanted to get my very rough patches out for discussion first. But if folks don't nack it outright I'll be providing some data there. The hard part is that range creation would have a linear cost with the number of pages in the range, which at some point will be a pain.

Thanks again for your input!
-john

--
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>

#26 lore raw

Re: [PATCH 3/3] [RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers

Quoted 54 lines · John Stultz
Quoted 53 lines · Minchan Kim
Quoted 50 lines · John Stultz
Quoted 37 lines · Minchan Kim

Please, Cced linux-mm.

Quoted 8 lines · John Stultz

volatile. Since we assume ranges are un-touched when volatile, that should preserve LRU purging behavior on single node systems and on multi-node systems it will approximate fairly closely.

My main concern with this approach is marking and unmarking volatile ranges needs to be fast, so I'm worried about the additional overhead of
activating each of the containing pages on mark_volatile.

Yes. it could be a problem if range is very large and populated already.
Why can't we make new hooks?

Just concept for showing my intention..

(quoted diff) +10 -0
+int shrink_volatile_pages(struct zone *zone)
+{
+       int ret = 0;
+       if (zone_page_state(zone, NR_ZONE_VOLATILE))
+               ret = shmem_purge_one_volatile_range();
+       return ret;
+}
+
   static void shrink_zone(struct zone *zone, struct scan_control *sc)
   {
          struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -1827,6 +1835,18 @@ static void shrink_zone(struct zone *zone,
 struct scan_control *sc)
                  .priority = sc->priority,
          };
          struct mem_cgroup *memcg;
+       int ret;
+

Review static void shrink_zone(struct zone *zone, · line 1850

Quoted 10 lines
(quoted diff) +10 -0
+       /*
+        * Before we dive into trouble maker, let's look at easy-
+        * reclaimable pages and avoid costly-reclaim if possible.
+        */
+       do {
+               ret = shrink_volatile_pages();
+               if (ret)
+                       zone_watermark_ok(zone, sc->order, xxx);
+                               return;
+       } while(ret)

Hmm. I'm confused.
This doesn't seem that different from the shrinker approach.

Quoted 8 lines
Quoted 3 lines

Shrinker is called after shrink_list so it means normal pages can be reclaimed
before we reclaim volatile pages. We shouldn't do that.

Ah. Ok. Maybe that's a reasonable compromise between the shrinker approach and the more complex approach I just posted to lkml? (Forgive me for forgetting to CC you and linux-mm with my latest post!)

NP.

Quoted 20 lines
Quoted 8 lines
Quoted 3 lines

How does this resolve the numa-unawareness issue that Kosaki-san brought up?

Basically, I think your shrink function should be more smart.

when fallocate is called, we can get mem_policy from shmem_inode_info and pass it to
volatile_range so that volatile_range can keep the information of NUMA.

Hrm.. That sounds reasonable. I'll look into the mem_policy bits and try to learn more.

Quoted 9 lines

When shmem_purge_one_volatile_range is called, it receives zone information.
So shmem_purge_one_volatile_range should find a range matched with NUMA policy and
passed zone.

Assumption:
A range may include same node/zone pages if possible.

Quoted 6 lines
Quoted 2 lines

I am not familiar with NUMA handling code so KOSAKI/Rik can point out if I am wrong.

Right, the range may cross nodes/zones but maybe that's not a huge deal? The only bit I'd worry about is the lru scanning being non-constant as we searched for a range that matched the node we want to free from. I guess we could have per-node/zone lrus.

Good.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines

The other question I have with this approach is if we're on a system that doesn't have swap, it *seems* (not totally sure I understand it yet) the tmpfs file pages will be skipped over when we call shrink_lruvec. So it seems we may need to add a new lru_list enum and
nr[] entry (maybe LRU_VOLATILE?). So then it may be that when we
mark
a range as volatile, instead of just activating it, we move it to the volatile lru, and then when we shrink from that list, we call back to the filesystem to trigger the entire range purging.

Adding new LRU idea might make very slow fallocate(VOLATILE) so I hope we can avoid that if possible.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Indeed. This is a major concern. I'm currently prototyping it out so I have a concrete sense of the performance cost.

If performance loss isn't big, that would be a approach!

I've not had a chance yet to measure it, as I wanted to get my very rough patches out for discussion first. But if folks don't nack it outright I'll be providing some data there. The hard part is that range creation would have a linear cost with the number of pages in the range, which at some point will be a pain.

That's right. So IMHO, my suggestion could be a solution.
I looked through your new patchset[5/6]. I know your intention but code still have problems. But I didn't commented out. Before the detail review, I would like to hear opinions from others and am curious about that whether you decide turning the approach or not.
It can save our precious time. :)

Quoted 3 lines

Thanks again for your input!
-john

Thanks for your effort!

Signature · 8 lines
Kind regards,
Minchan Kim

--
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>