Fallocate Volatile Ranges v6
Subsystems (10)
RFC PATCH 1/5 Add volatile range management code
In reply to John StultzThis 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.
v3:
* Improve function name to make it clear what the volatile_ranges_pluck_lru() code does.
* Drop volatile_range_lru_size and unpurged_page_count mangement as its now unused
v4:
* Re-add volatile_range_lru_size and unpruged_page_count
* Fix bug in range_remove when we split ranges, we add an overlapping range before resizing the existing range.
v5:
* Drop intervaltree for prio_tree usage per Michel & Dmitry's suggestions.
* Cleanups
--- include/linux/volatile.h | 45 ++++ mm/Makefile | 2 +- mm/volatile.c | 509 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 555 insertions(+), 1 deletion(-) create mode 100644 include/linux/volatile.h create mode 100644 mm/volatile.c
include/linux/volatile.h new file +45 -0
@@ -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_pluck_lru (struct volatile_fs_head *head, +struct address_space **mapping, +pgoff_t *start,pgoff_t *end); +#endif /* _LINUX_VOLATILE_H */
mm/Makefile +1 -1
@@ -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.9.5
RFC PATCH 4/5 Add LRU_VOLATILE support to the VM
In reply to John StultzIn an attempt to push the volatile range managment even deeper into the VM code, this is my first attempt at implementing Minchan's idea of a LRU_VOLATILE list in the mm core.
This list sits along side the LRU_ACTIVE_ANON, _INACTIVE_ANON, _ACTIVE_FILE, _INACTIVE_FILE and _UNEVICTABLE lru lists.
When a range is marked volatile, the pages in that range are moved to the LRU_VOLATILE list. Since volatile pages can be quickly purged, this list is the first list we shrink when we need to free memory.
When a page is marked non-volatile, it is moved from the LRU_VOLATILE list to the appropriate LRU_ACTIVE_ list.
This patch introduces the LRU_VOLATILE list, an isvolatile page flag, functions to mark and unmark a single page as volatile, and shrinker functions to purge volatile pages.
This is a very raw first pass, and is neither performant or likely bugfree. It works in my trivial testing, but I've not pushed it very hard yet.
I wanted to send it out just to get some inital thoughts on the approach and any suggestions should I be going too far in the wrong direction.
--- include/linux/fs.h | 1 + include/linux/mm_inline.h | 2 ++ include/linux/mmzone.h | 1 + include/linux/page-flags.h | 3 ++ include/linux/swap.h | 3 ++ mm/memcontrol.c | 1 + mm/page_alloc.c | 1 + mm/swap.c | 71 +++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 76 +++++++++++++++++++++++++++++++++++++++++--- 9 files changed, 155 insertions(+), 4 deletions(-)
include/linux/fs.h +1 -0
@@ -636,6 +636,7 @@ struct address_space_operations {int (*is_partially_uptodate) (struct page *,read_descriptor_t *,unsigned long );int (*error_remove_page)(struct address_space *,struct page *); +int (*purgepage)(struct page *page,struct writeback_control *wbc); };extern const struct address_space_operations empty_aops;
include/linux/mm_inline.h +2 -0
@@ -91,6 +91,8 @@ static __always_inline enum lru_list page_lru(struct page *page)if (PageUnevictable (page)) lru =LRU_UNEVICTABLE ; +else if (PageIsVolatile (page)) + lru =LRU_VOLATILE ;else { lru =page_lru_base_type (page);if (PageActive (page))
include/linux/mmzone.h +1 -0
@@ -162,6 +162,7 @@ enum lru_list {LRU_ACTIVE_ANON =LRU_BASE +LRU_ACTIVE ,LRU_INACTIVE_FILE =LRU_BASE +LRU_FILE ,LRU_ACTIVE_FILE =LRU_BASE +LRU_FILE +LRU_ACTIVE , +LRU_VOLATILE ,LRU_UNEVICTABLE , NR_LRU_LISTS };
include/linux/page-flags.h +3 -0
@@ -108,6 +108,7 @@ enum pageflags {#ifdef CONFIG_TRANSPARENT_HUGEPAGE PG_compound_lock, #endif + PG_isvolatile, __NR_PAGEFLAGS,/* Filesystems */
@@ -201,6 +202,8 @@ PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty, dirty) PAGEFLAG(LRU, lru) __CLEARPAGEFLAG(LRU, lru) PAGEFLAG(Active, active) __CLEARPAGEFLAG(Active, active) TESTCLEARFLAG(Active, active) +PAGEFLAG(IsVolatile, isvolatile) __CLEARPAGEFLAG(IsVolatile, isvolatile) + TESTCLEARFLAG(IsVolatile, isvolatile) __PAGEFLAG(Slab, slab) PAGEFLAG(Checked, checked) /* Used by some filesystems */ PAGEFLAG(Pinned, pinned) TESTSCFLAG(Pinned, pinned) /* Xen */
include/linux/swap.h +3 -0
@@ -236,6 +236,9 @@ extern void rotate_reclaimable_page(struct page *page);extern void deactivate_page (struct page *page);extern void swap_setup (void ); +extern void mark_volatile_page (struct page *page); +extern void mark_nonvolatile_page (struct page *page); +extern void add_page_to_unevictable_list (struct page *page);/**
mm/memcontrol.c +1 -0
@@ -4066,6 +4066,7 @@ static const char * const mem_cgroup_lru_names[] = {"active_anon" ,"inactive_file" ,"active_file" , +"volatile" , "unevictable", };
mm/page_alloc.c +1 -0
@@ -5975,6 +5975,7 @@ static const struct trace_print_flags pageflag_names[] = { #ifdef CONFIG_TRANSPARENT_HUGEPAGE {1UL << PG_compound_lock, "compound_lock" }, #endif + {1UL << PG_isvolatile, "volatile" }, }; static void dump_page_flags(unsigned long flags)
mm/swap.c +71 -0
77 lines not on this page · raw message
mm/vmscan.c +72 -4
112 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC PATCH 3/5 ashmem: Convert ashmem to use volatile ranges
In reply to John StultzRework of my first pass attempt at getting ashmem to utilize the volatile range code, now using the fallocate interface.
In this implementaiton GET_PIN_STATUS is unimplemented, due to the fact that adding a ISVOLATILE check wasn't considered terribly useful in earlier reviews. It would be trivial to re-add that functionality, but I wanted to check w/ the Android developers to see how often GET_PIN_STATUS is actually used?
Similarly the ashmem PURGE_ALL_CACHES ioctl does not function, as the volatile range purging is no longer directly under its control.
--- drivers/staging/android/ashmem.c | 331 ++------------------------------------ 1 file changed, 10 insertions(+), 321 deletions(-)
drivers/staging/android/ashmem.c +10 -321
@@ -52,26 +52,6 @@ struct ashmem_area { };/* -* ashmem_range - represents an interval of unpinned (evictable) pages -* Lifecycle: From unpin to pin -* Locking: Protected by `ashmem_mutex' -*/ -struct ashmem_range { -struct list_head lru;/* entry in LRU list */ -struct list_head unpinned;/* entry in its area's unpinned list */ -struct ashmem_area *asma;/* associated area */ -size_t pgstart;/* starting page, inclusive */ -size_t pgend;/* ending page, inclusive */ -unsigned int purged;/* ASHMEM_NOT or ASHMEM_WAS_PURGED */ -}; - -/* LRU list of unpinned pages, protected by ashmem_mutex */ -static LIST_HEAD (ashmem_lru_list); - -/* Count of pages on our LRU list, protected by ashmem_mutex */ -static unsigned long lru_count; - -/* * ashmem_mutex - protects the list of and each individual ashmem_area * * Lock Ordering: ashmex_mutex -> i_mutex -> i_alloc_sem
@@ -79,102 +59,9 @@ static unsigned long lru_count;static DEFINE_MUTEX (ashmem_mutex);static struct kmem_cache *ashmem_area_cachep__read_mostly ; -static struct kmem_cache *ashmem_range_cachep__read_mostly ; - -#define range_size (range) \ - ((range)->pgend - (range)->pgstart + 1) - -#define range_on_lru (range) \ - ((range)->purged == ASHMEM_NOT_PURGED) - -#define page_range_subsumes_range (range, start, end) \ - (((range)->pgstart >= (start)) && ((range)->pgend <= (end))) - -#define page_range_subsumed_by_range (range, start, end) \ - (((range)->pgstart <= (start)) && ((range)->pgend >= (end))) - -#define page_in_range (range, page) \ - (((range)->pgstart <= (page)) && ((range)->pgend >= (page))) - -#define page_range_in_range (range, start, end) \ - (page_in_range(range, start) || page_in_range(range, end) || \ - page_range_subsumes_range(range, start, end)) - -#define range_before_page (range, page) \ - ((range)->pgend < (page))#define PROT_MASK (PROT_EXEC | PROT_READ | PROT_WRITE) -static inline void lru_add (struct ashmem_range *range) -{ -list_add_tail (&range->lru, &ashmem_lru_list); - lru_count +=range_size (range); -} - -static inline void lru_del (struct ashmem_range *range) -{ -list_del (&range->lru); - lru_count -=range_size (range); -} - -/* -* range_alloc - allocate and initialize a new ashmem_range structure -* -* 'asma' - associated ashmem_area -* 'prev_range' - the previous ashmem_range in the sorted asma->unpinned list -* 'purged' - initial purge value (ASMEM_NOT_PURGED or ASHMEM_WAS_PURGED) -* 'start' - starting page, inclusive -* 'end' - ending page, inclusive -* -* Caller must hold ashmem_mutex. -*/ -static int range_alloc (struct ashmem_area *asma, -struct ashmem_range *prev_range,unsigned int purged, -size_t start,size_t end) -{ -struct ashmem_range *range; - - range =kmem_cache_zalloc (ashmem_range_cachep,GFP_KERNEL ); -if (unlikely (!range)) -return -ENOMEM ; - - range->asma = asma; - range->pgstart = start; - range->pgend = end; - range->purged = purged; - -list_add_tail (&range->unpinned, &prev_range->unpinned); - -if (range_on_lru (range)) -lru_add (range); - -return 0 ; -} - -static void range_del (struct ashmem_range *range) -{ -list_del (&range->unpinned); -if (range_on_lru (range)) -lru_del (range); -kmem_cache_free (ashmem_range_cachep, range); -} - -/* -* range_shrink - shrinks a range -* -* Caller must hold ashmem_mutex. -*/ -static inline void range_shrink (struct ashmem_range *range, -size_t start,size_t end) -{ -size_t pre =range_size (range); - - range->pgstart = start; - range->pgend = end; - -if (range_on_lru (range)) - lru_count -= pre -range_size (range); -}static int ashmem_open (struct inode *inode,struct file *file) {
@@ -200,12 +87,6 @@ static int ashmem_open(struct inode *inode, struct file *file)static int ashmem_release (struct inode *ignored,struct file *file) {struct ashmem_area *asma = file->private_data; -struct ashmem_range *range, *next; - -mutex_lock (&ashmem_mutex); -list_for_each_entry_safe (range, next, &asma->unpinned_list, unpinned) -range_del (range); -mutex_unlock (&ashmem_mutex);if (asma->file)fput (asma->file);
@@ -339,56 +220,6 @@ out:return ret; } -/* -* ashmem_shrink - our cache shrinker, called from mm/vmscan.c :: shrink_slab -* -* 'nr_to_scan' is the number of objects (pages) to prune, or 0 to query how -* many objects (pages) we have in total. -* -* 'gfp_mask' is the mask of the allocation that got us into this mess. -* -* Return value is the number of objects (pages) remaining, or -1 if we cannot -* proceed without risk of deadlock (due to gfp_mask). -* -* We approximate LRU via least-recently-unpinned, jettisoning unpinned partial -* chunks of ashmem regions LRU-wise one-at-a-time until we hit 'nr_to_scan' -* pages freed. -*/ -static int ashmem_shrink (struct shrinker *s,struct shrink_control *sc) -{ -struct ashmem_range *range, *next; - -/* We might recurse into filesystem code, so bail out if necessary */ -if (sc->nr_to_scan && !(sc->gfp_mask & __GFP_FS)) -return -1 ; -if (!sc->nr_to_scan) -return lru_count; - -mutex_lock (&ashmem_mutex); -list_for_each_entry_safe (range, next, &ashmem_lru_list, lru) { -loff_t start = range->pgstart *PAGE_SIZE ; -loff_t end = (range->pgend +1 ) *PAGE_SIZE ; - -do_fallocate (range->asma->file, -FALLOC_FL_PUNCH_HOLE |FALLOC_FL_KEEP_SIZE , - start, end - start); - range->purged =ASHMEM_WAS_PURGED ; -lru_del (range); - - sc->nr_to_scan -=range_size (range); -if (sc->nr_to_scan <=0 ) -break ; - } -mutex_unlock (&ashmem_mutex); - -return lru_count; -} - -static struct shrinker ashmem_shrinker = { - .shrink = ashmem_shrink, - .seeks =DEFAULT_SEEKS *4 , -}; -static int set_prot_mask (struct ashmem_area *asma,unsigned long prot) {int ret =0 ;
@@ -461,136 +292,10 @@ static int get_name(struct ashmem_area *asma, void __user *name)return ret; } -/* -* ashmem_pin - pin the given ashmem region, returning whether it was -* previously purged (ASHMEM_WAS_PURGED) or not (ASHMEM_NOT_PURGED). -* -* Caller must hold ashmem_mutex. -*/ -static int ashmem_pin (struct ashmem_area *asma,size_t pgstart,size_t pgend) -{ -struct ashmem_range *range, *next; -int ret =ASHMEM_NOT_PURGED ; - -list_for_each_entry_safe (range, next, &asma->unpinned_list, unpinned) { -/* moved past last applicable page; we can short circuit */ -if (range_before_page (range, pgstart)) -break ; - -/* -* The user can ask us to pin pages that span multiple ranges, -* or to pin pages that aren't even unpinned, so this is messy. -* -* Four cases: -* 1. The requested range subsumes an existing range, so we -* just remove the entire matching range. -* 2. The requested range overlaps the start of an existing -* range, so we just update that range. -* 3. The requested range overlaps the end of an existing -* range, so we just update that range. -* 4. The requested range punches a hole in an existing range, -* so we have to update one side of the range and then -* create a new range for the other side. -*/ -if (page_range_in_range (range, pgstart, pgend)) { - ret |= range->purged; - -/* Case #1: Easy. Just nuke the whole thing. */ -if (page_range_subsumes_range (range, pgstart, pgend)) { -range_del (range); -continue ; - } - -/* Case #2: We overlap from the start, so adjust it */ -if (range->pgstart >= pgstart) { -range_shrink (range, pgend +1 , range->pgend); -continue ; - } - -/* Case #3: We overlap from the rear, so adjust it */ -if (range->pgend <= pgend) { -range_shrink (range, range->pgstart, pgstart-1 ); -continue ; - } - -/* -* Case #4: We eat a chunk out of the middle. A bit -* more complicated, we allocate a new range for the -* second half and adjust the first chunk's endpoint. -*/ -range_alloc (asma, range, range->purged, - pgend +1 , range->pgend); -range_shrink (range, range->pgstart, pgstart -1 ); -break ; - } - } - -return ret; -} - -/* -* ashmem_unpin - unpin the given range of pages. Returns zero on success. -* -* Caller must hold ashmem_mutex. -*/ -static int ashmem_unpin (struct ashmem_area *asma,size_t pgstart,size_t pgend) -{ -struct ashmem_range *range, *next; -unsigned int purged =ASHMEM_NOT_PURGED ; - -restart: -list_for_each_entry_safe (range, next, &asma->unpinned_list, unpinned) { -/* short circuit: this is our insertion point */ -if (range_before_page (range, pgstart)) -break ; - -/* -* The user can ask us to unpin pages that are already entirely -* or partially pinned. We handle those two cases here. -*/ -if (page_range_subsumed_by_range (range, pgstart, pgend)) -return 0 ; -if (page_range_in_range (range, pgstart, pgend)) { - pgstart =min_t (size_t, range->pgstart, pgstart), - pgend =max_t (size_t, range->pgend, pgend); - purged |= range->purged; -range_del (range); - goto restart; - } - } - -return range_alloc (asma, range, purged, pgstart, pgend); -} - -/* -* ashmem_get_pin_status - Returns ASHMEM_IS_UNPINNED if _any_ pages in the -* given interval are unpinned and ASHMEM_IS_PINNED otherwise. -* -* Caller must hold ashmem_mutex. -*/ -static int ashmem_get_pin_status (struct ashmem_area *asma,size_t pgstart, -size_t pgend) -{ -struct ashmem_range *range; -int ret =ASHMEM_IS_PINNED ; - -list_for_each_entry (range, &asma->unpinned_list, unpinned) { -if (range_before_page (range, pgstart)) -break ; -if (page_range_in_range (range, pgstart, pgend)) { - ret =ASHMEM_IS_UNPINNED ; -break ; - } - } - -return ret; -} -static int ashmem_pin_unpin (struct ashmem_area *asma,unsigned long cmd,void __user *p) {struct ashmem_pin pin; -size_t pgstart, pgend;int ret = -EINVAL ;if (unlikely (!asma->file))
@@ -612,20 +317,24 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,if (unlikely (PAGE_ALIGN (asma->size) < pin.offset + pin.len))return -EINVAL ; - pgstart = pin.offset /PAGE_SIZE ; - pgend = pgstart + (pin.len /PAGE_SIZE ) -1 ;mutex_lock (&ashmem_mutex);switch (cmd) {case ASHMEM_PIN : - ret =ashmem_pin (asma, pgstart, pgend); + ret =do_fallocate (asma->file,FALLOC_FL_MARK_VOLATILE , + pin.offset, pin.len);break ;case ASHMEM_UNPIN : - ret =ashmem_unpin (asma, pgstart, pgend); + ret =do_fallocate (asma->file,FALLOC_FL_UNMARK_VOLATILE , + pin.offset, pin.len);break ;case ASHMEM_GET_PIN_STATUS : - ret =ashmem_get_pin_status (asma, pgstart, pgend); +/* +* XXX - volatile ranges currently don't provide status, +* due to questionable utility +*/ + ret = -EINVAL ;break ; }
@@ -669,15 +378,6 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)break ;case ASHMEM_PURGE_ALL_CACHES : ret = -EPERM ; -if (capable (CAP_SYS_ADMIN )) { -struct shrink_control sc = { - .gfp_mask =GFP_KERNEL , - .nr_to_scan =0 , - }; - ret =ashmem_shrink (&ashmem_shrinker, &sc); - sc.nr_to_scan = ret; -ashmem_shrink (&ashmem_shrinker, &sc); - }break ; }
@@ -713,21 +413,13 @@ static int __init ashmem_init(void)return -ENOMEM ; } - ashmem_range_cachep =kmem_cache_create ("ashmem_range_cache" , -sizeof (struct ashmem_range ), -0 ,0 ,NULL ); -if (unlikely (!ashmem_range_cachep)) { -pr_err ("failed to create slab cache\n" ); -return -ENOMEM ; - } - ret =misc_register (&ashmem_misc);if (unlikely (ret)) {pr_err ("failed to register misc device!\n" );return ret; } -register_shrinker (&ashmem_shrinker); +pr_info ("initialized\n" );
@@ -738,13 +430,10 @@ static void __exit ashmem_exit(void) {int ret; -unregister_shrinker (&ashmem_shrinker); - ret =misc_deregister (&ashmem_misc);if (unlikely (ret))pr_err ("failed to unregister misc device!\n" ); -kmem_cache_destroy (ashmem_range_cachep);kmem_cache_destroy (ashmem_area_cachep);pr_info ("unloaded\n" );
Signature · 7 lines
1.7.9.5 -- 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>
RFC PATCH 2/5 tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers
In reply to John StultzThis 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.
v3:
* Fix off by one issue when truncating page ranges
* Use Dave Hansesn's suggestion to use shmem_writepage to trigger range purging instead of using a shrinker.
v4:
* Revert the shrinker removal, since writepage won't get called if we don't have swap.
v5:
* Cleanups
--- fs/open.c | 3 +- include/linux/falloc.h | 7 +-- mm/shmem.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 4 deletions(-)
fs/open.c +2 -1
@@ -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
@@ -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 +113 -0
143 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 -- 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>
RFC PATCH 5/5 Switch volatile/shmem over to LRU_VOLATILE
In reply to John StultzThis changes the earlier shrinker based volatile range management over to using the LRU_VOLATILE list in mm core.
Again, this is likely has performance issues, as well as other problems I'm not aware of, so I'd greatly appreciate any additional feedback or suggestions.
--- include/linux/volatile.h | 12 ++---- mm/shmem.c | 103 ++++++++++++++++++++++++---------------------- mm/volatile.c | 86 ++++++++------------------------------ 3 files changed, 75 insertions(+), 126 deletions(-)
include/linux/volatile.h +3 -9
@@ -5,15 +5,11 @@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, \ }
@@ -34,12 +30,10 @@ 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_pluck_lru (struct volatile_fs_head *head, -struct address_space **mapping, -pgoff_t *start,pgoff_t *end); +int volatile_page_mark_range_purged (struct volatile_fs_head *head, +struct page *page); +#endif /* _LINUX_VOLATILE_H */
mm/shmem.c +54 -49
140 lines not on this page · raw message
mm/volatile.c +18 -68
127 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 -- 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>
cover Fallocate Volatile Ranges v6
So after not getting too much positive feedback on my last attempt at trying to use a non-shrinker method for managing & purging volatile ranges, I decided I'd go ahead and try to implement something along Minchan's ERECLAIM LRU list idea.
Again this patchset has two parts:
The first 3 patches add generic volatile range management code, as well as tmpfs support for FALLOC_FL_MARK_VOLATILE, which uses a shrinker to purge ranges, and converts ashmem to use FALLOC_FL_MARK_VOLATILE, almost reducing the driver in half.
Since Kosaki-san objected to using the shrinker, as its not numa aware, and is only called after we shrink normal lru lists. The second half of this patch set provides a different method that is not shrinker based.
The last two patches introduce a new lru list, LRU_VOLATILE. When pages are marked volatile, they are moved to this lru list, which we will shrink first when trying to free up memory.
The reason why I'm keeping this in two parts is that I want to be able to easily do performance comparisons between the more lightweight, but numa-unaware, shrinker method vs the more correct, but slower (due to the page-by-page management) method of handling it deeper in the VM.
I know the way this is currently implemented is really bad for performance, since we add/remove pages to the LRU_VOLATILE list page by page instead of batching. So I know this needs more work, but I wanted to get just some initial reactions to this approach versus the earlier ones.
Also, I know this isn't exactly the same as the ERECLAIM lru list that Minchan suggested, since that might also contain inactive clean file pages as well, but I wanted to stick to just volatile pages for now as I learn more about how the core vm works. I'll be fine to rename LRU_VOLATILE later if its appropriate.
What's new in this iteration:
* Dropped the writepage style purging instead for the LRU_VOLATILE
John Stultz (5):
[RFC] Add volatile range management code
[RFC] tmpfs: Add FALLOC_FL_MARK_VOLATILE/UNMARK_VOLATILE handlers [RFC] ashmem: Convert ashmem to use volatile ranges [RFC][HACK] Add LRU_VOLATILE support to the VM [RFC][HACK] Switch volatile/shmem over to LRU_VOLATILE
drivers/staging/android/ashmem.c | 331 +-------------------------- fs/open.c | 3 +- include/linux/falloc.h | 7 +- include/linux/fs.h | 1 + include/linux/mm_inline.h | 2 + include/linux/mmzone.h | 1 + include/linux/page-flags.h | 3 + include/linux/swap.h | 3 + include/linux/volatile.h | 39 ++++ mm/Makefile | 2 +- mm/memcontrol.c | 1 + mm/page_alloc.c | 1 + mm/shmem.c | 118 ++++++++++ mm/swap.c | 71 ++++++ mm/vmscan.c | 76 ++++++- mm/volatile.c | 459 ++++++++++++++++++++++++++++++++++++++ 16 files changed, 788 insertions(+), 330 deletions(-) create mode 100644 include/linux/volatile.h create mode 100644 mm/volatile.c
Signature · 7 lines
1.7.9.5 -- 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>
Re: [PATCH 4/5] [RFC][HACK] Add LRU_VOLATILE support to the VM
In reply to John StultzHi John,
Quoted 8 lines · John Stultz
In an attempt to push the volatile range managment even deeper into the VM code, this is my first attempt at implementing Minchan's idea of a
LRU_VOLATILElist in the mm core.This list sits along side the
LRU_ACTIVE_ANON,_INACTIVE_ANON,_ACTIVE_FILE,_INACTIVE_FILEand_UNEVICTABLElru lists.
Quoted 7 lines
When a range is marked volatile, the pages in that range are moved to the
LRU_VOLATILElist. Since volatile pages can be quickly purged, this list is the first list we shrink when we need to free memory.When a page is marked non-volatile, it is moved from the
LRU_VOLATILElist to the appropriateLRU_ACTIVE_list.
I think active list promotion is not good.
It should go to the inactive list and they get a chance to activate from inactive to active sooner or later if it is really touched.
Quoted 6 lines
This patch introduces the
LRU_VOLATILElist, an isvolatile page flag, functions to mark and unmark a single page as volatile, and shrinker functions to purge volatile pages.
Quoted 7 lines
This is a very raw first pass, and is neither performant or likely bugfree. It works in my trivial testing, but I've not pushed it very hard yet.
I wanted to send it out just to get some inital thoughts on the approach and any suggestions should I be going too far in the wrong direction.
I look at this series and found several nitpicks about implemenataion but I think it's not a good stage about concerning it.
Although naming is rather differet with I suggested, I think it's good idea. So let's talk about it firstly.
I will call VOLATILE list as EReclaimale LRU list.
The purpose of it is that prevent unnecessary LRU churning and reclaim unnecessary pages fastly so that latency-sensitive system don't have a big latency when memory pressure happens.
Targets for the LRU list could be following as in future
1. volatile pages in this patchset.
2. ephemeral pages of tmem
3. madivse(DONTNEED)
4. fadvise(NOREUSE)
5. PG_reclaimed pages
6. clean pages if we write CFLRU(clean first LRU)
So if any guys have objection, please raise your hands before further progress.
Quoted 32 lines
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 Mike Hommey <[email protected]>CC Jan Kara <[email protected]>CC KOSAKI Motohiro <[email protected]>CC Michel Lespinasse <[email protected]>CC Minchan Kim <[email protected]>Signed-off-by John Stultz <[email protected]>--- include/linux/fs.h | 1 + include/linux/mm_inline.h | 2 ++ include/linux/mmzone.h | 1 + include/linux/page-flags.h | 3 ++ include/linux/swap.h | 3 ++ mm/memcontrol.c | 1 + mm/page_alloc.c | 1 + mm/swap.c | 71 +++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 76 +++++++++++++++++++++++++++++++++++++++++--- 9 files changed, 155 insertions(+), 4 deletions(-)
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>
RE: [PATCH 4/5] [RFC][HACK] Add LRU_VOLATILE support to the VM
Quoted 3 lines
From: Minchan Kim [mailto:[email protected]]
To: John Stultz
Subject: Re: [PATCH 4/5] [RFC][HACK] AddLRU_VOLATILEsupport to the VM
Hi Minchan --
Thanks for cc'ing me on this!
Quoted 11 lines
Targets for the LRU list could be following as in future
1. volatile pages in this patchset.
2. ephemeral pages of tmem
3. madivse(DONTNEED)
4. fadvise(NOREUSE)
5.PG_reclaimedpages
6. clean pages if we write CFLRU(clean first LRU)So if any guys have objection, please raise your hands before further progress.
I agree that the existing shrinker mechanism is too primitive and the kernel needs to take into account more factors in deciding how to quickly reclaim pages from a broader set of sources. However, I think it is important to ensure that both the "demand" side and the "supply" side are studied. There has to be some kind of prioritization policy among all the RAM consumers so that a lower-priority alloc_page doesn't cause a higher-priority "volatile" page to be consumed. I suspect this policy will be VERY hard to define and maintain.
Related, ephemeral pages in tmem are not truly volatile as there is always at least one tmem data structure pointing to it. I haven't followed this thread previously so my apologies if it already has this, but the LRU_VOLATILE list might need to support a per-page "garbage collection" callback.
Dan
--
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>
Re: [PATCH 4/5] [RFC][HACK] Add LRU_VOLATILE support to the VM
In reply to Minchan KimQuoted 16 lines · Minchan Kim
Hi John,
Quoted 13 lines · John Stultz
In an attempt to push the volatile range managment even deeper into the VM code, this is my first attempt at implementing Minchan's idea of a
LRU_VOLATILElist in the mm core.This list sits along side the
LRU_ACTIVE_ANON,_INACTIVE_ANON,_ACTIVE_FILE,_INACTIVE_FILEand_UNEVICTABLElru lists.When a range is marked volatile, the pages in that range are moved to the
LRU_VOLATILElist. Since volatile pages can be quickly purged, this list is the first list we shrink when we need to free memory.
Quoted 6 lines
Quoted 2 lines
When a page is marked non-volatile, it is moved from the
LRU_VOLATILElist to the appropriateLRU_ACTIVE_list.I think active list promotion is not good.
It should go to the inactive list and they get a chance to activate from inactive to active sooner or later if it is really touched.
Ok. Thanks, I'll change it so we move to the inactive list then.
Quoted 9 lines
Quoted 9 lines
This patch introduces the
LRU_VOLATILElist, an isvolatile page flag, functions to mark and unmark a single page as volatile, and shrinker functions to purge volatile pages.This is a very raw first pass, and is neither performant or likely bugfree. It works in my trivial testing, but I've not pushed it very hard yet.
Quoted 5 lines
Quoted 3 lines
I wanted to send it out just to get some inital thoughts on the approach and any suggestions should I be going too far in the wrong direction.
I look at this series and found several nitpicks about implemenataion but I think it's not a good stage about concerning it.
Although while I know the design may still need significant change, I'd still appreciate nitpicks, as they might help me better understand the mm code and any mistakes I'm making.
Quoted 3 lines
Although naming is rather differet with I suggested, I think it's good idea. So let's talk about it firstly.
I will call VOLATILE list as EReclaimale LRU list.
Yea, I didn't want to call it ERECLAIMABLE since for this iteration I was limiting the scope just to volatile pages. I'm totally fine renaming it as the scope widens.
thanks
-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>
Re: [PATCH 4/5] [RFC][HACK] Add LRU_VOLATILE support to the VM
In reply to Dan MagenheimerQuoted 20 lines · Dan Magenheimer
Quoted 3 lines
From: Minchan Kim [mailto:[email protected]]
To: John Stultz
Subject: Re: [PATCH 4/5] [RFC][HACK] AddLRU_VOLATILEsupport to the VMHi Minchan --
Thanks for cc'ing me on this!
Quoted 11 lines
Targets for the LRU list could be following as in future
1. volatile pages in this patchset.
2. ephemeral pages of tmem
3. madivse(DONTNEED)
4. fadvise(NOREUSE)
5.PG_reclaimedpages
6. clean pages if we write CFLRU(clean first LRU)So if any guys have objection, please raise your hands before further progress.
Quoted 10 lines
I agree that the existing shrinker mechanism is too primitive and the kernel needs to take into account more factors in deciding how to quickly reclaim pages from a broader set of sources. However, I think it is important to ensure that both the "demand" side and the "supply" side are studied. There has to be some kind of prioritization policy among all the RAM consumers so that a lower-priority
alloc_pagedoesn't cause a higher-priority "volatile" page to be consumed. I suspect this policy will be VERY hard to define and maintain.
Yes. It's another story.
At the moment, VM doesn't consider such priority-inversion problem excpet giving the more memory to privileged processes. It's so simple but works well till now.
Quoted 2 lines
Related, ephemeral pages in tmem are not truly volatile
"volatile" term is used by John for only his special patch so I like Ereclaim(Easy Reclaim) rather than volatile.
Quoted 4 lines
as there is always at least one tmem data structure pointing to it. I haven't followed this thread previously so my apologies if it already has this, but the
LRU_VOLATILElist might need to support a per-page "garbage collection" callback.
Right. That's why this patch provides purgepage in address_space_operations. I think zcache could attach own address_space_operations to the page which is allocated by zbud for instance, zcache_purgepage which is called by VM when the page is reclaimed. So zcache don't need custom LRU policy(but still need linked list for managing zbuddy) and pass the decision to the VM.
Quoted 8 lines
Dan
--
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>
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>
RE: [PATCH 4/5] [RFC][HACK] Add LRU_VOLATILE support to the VM
Quoted 35 lines
From: Minchan Kim [mailto:[email protected]]
Subject: Re: [PATCH 4/5] [RFC][HACK] AddLRU_VOLATILEsupport to the VMQuoted 20 lines · Dan Magenheimer
Quoted 3 lines
From: Minchan Kim [mailto:[email protected]]
To: John Stultz
Subject: Re: [PATCH 4/5] [RFC][HACK] AddLRU_VOLATILEsupport to the VMHi Minchan --
Thanks for cc'ing me on this!
Quoted 11 lines
Targets for the LRU list could be following as in future
1. volatile pages in this patchset.
2. ephemeral pages of tmem
3. madivse(DONTNEED)
4. fadvise(NOREUSE)
5.PG_reclaimedpages
6. clean pages if we write CFLRU(clean first LRU)So if any guys have objection, please raise your hands before further progress.
Quoted 10 lines
I agree that the existing shrinker mechanism is too primitive and the kernel needs to take into account more factors in deciding how to quickly reclaim pages from a broader set of sources. However, I think it is important to ensure that both the "demand" side and the "supply" side are studied. There has to be some kind of prioritization policy among all the RAM consumers so that a lower-priority
alloc_pagedoesn't cause a higher-priority "volatile" page to be consumed. I suspect this policy will be VERY hard to define and maintain.
Quoted 4 lines
Yes. It's another story.
At the moment, VM doesn't consider such priority-inversion problem excpet giving the more memory to privileged processes. It's so simple but works well till now.
I think it is very important that both stories must be solved together. See below...
Quoted 4 lines
Quoted 1 line
Related, ephemeral pages in tmem are not truly volatile
"volatile" term is used by John for only his special patch so I like Ereclaim(Easy Reclaim) rather than volatile.
If others agree, that's fine. However, the "E" prefix is currently used differently in common English (for example, for e-books). Maybe "ezreclaim"?
Quoted 10 lines
Quoted 4 lines
as there is always at least one tmem data structure pointing to it. I haven't followed this thread previously so my apologies if it already has this, but the
LRU_VOLATILElist might need to support a per-page "garbage collection" callback.Right. That's why this patch provides purgepage in
address_space_operations. I think zcache could attach ownaddress_space_operationsto the page which is allocated by zbud for instance,zcache_purgepagewhich is called by VM when the page is reclaimed. So zcache don't need custom LRU policy(but still need linked list for managing zbuddy) and pass the decision to the VM.
The simple VM decisions are going to need a lot more intelligence (and data?) to drive which page to reclaim. For example, is it better to reclaim a pageframe that contains two compressed pages of ephemeral data or a pageframe that has one active (or inactive) file page? Such a policy is not "Easy". ;-)
(Also, BTW, zcache pages aren't in any address space so don't have an address_space_operations... because it is not possible to directly address the data in a compressed page.)
--
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>
Re: [PATCH 4/5] [RFC][HACK] Add LRU_VOLATILE support to the VM
Quoted 43 lines · Dan Magenheimer
Quoted 35 lines
From: Minchan Kim [mailto:[email protected]]
Subject: Re: [PATCH 4/5] [RFC][HACK] AddLRU_VOLATILEsupport to the VMQuoted 20 lines · Dan Magenheimer
Quoted 3 lines
From: Minchan Kim [mailto:[email protected]]
To: John Stultz
Subject: Re: [PATCH 4/5] [RFC][HACK] AddLRU_VOLATILEsupport to the VMHi Minchan --
Thanks for cc'ing me on this!
Quoted 11 lines
Targets for the LRU list could be following as in future
1. volatile pages in this patchset.
2. ephemeral pages of tmem
3. madivse(DONTNEED)
4. fadvise(NOREUSE)
5.PG_reclaimedpages
6. clean pages if we write CFLRU(clean first LRU)So if any guys have objection, please raise your hands before further progress.
Quoted 10 lines
I agree that the existing shrinker mechanism is too primitive and the kernel needs to take into account more factors in deciding how to quickly reclaim pages from a broader set of sources. However, I think it is important to ensure that both the "demand" side and the "supply" side are studied. There has to be some kind of prioritization policy among all the RAM consumers so that a lower-priority
alloc_pagedoesn't cause a higher-priority "volatile" page to be consumed. I suspect this policy will be VERY hard to define and maintain.Quoted 4 lines
Yes. It's another story.
At the moment, VM doesn't consider such priority-inversion problem excpet giving the more memory to privileged processes. It's so simple but works well till now.I think it is very important that both stories must be solved together. See below...
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Related, ephemeral pages in tmem are not truly volatile
"volatile" term is used by John for only his special patch so I like Ereclaim(Easy Reclaim) rather than volatile.
If others agree, that's fine. However, the "E" prefix is currently used differently in common English (for example, for e-books). Maybe "ezreclaim"?
Looks better. I will use that term from now on.
Thanks!
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
as there is always at least one tmem data structure pointing to it. I haven't followed this thread previously so my apologies if it already has this, but the
LRU_VOLATILElist might need to support a per-page "garbage collection" callback.Right. That's why this patch provides purgepage in
address_space_operations. I think zcache could attach ownaddress_space_operationsto the page which is allocated by zbud for instance,zcache_purgepagewhich is called by VM when the page is reclaimed. So zcache don't need custom LRU policy(but still need linked list for managing zbuddy) and pass the decision to the VM.
Quoted 5 lines
The simple VM decisions are going to need a lot more intelligence (and data?) to drive which page to reclaim. For example, is it better to reclaim a pageframe that contains two compressed pages of ephemeral data or a pageframe that has one active (or inactive) file page? Such a policy is not "Easy". ;-)
I should have said more cleary.
VM just pick a page in tail of ezreclaim list and and then just reclaim. So rotation of the active page or two compresssed pages should be implemented by smart zcache which can do anyting.
Quoted 4 lines
(Also, BTW, zcache pages aren't in any address space so don't have an
address_space_operations... because it is not possible to directly address the data in a compressed page.)
I mean we can make just fake address_space_operations like this.
static struct address_space_operations zcache_aop = {
.purgepage = zcache_purge_page,
};
static struct address_space zcache_address_space = {
.a_ops = &zcache_aop,
}; struct page *page = alloc_page();
page->mapping = &zcache_address_space;Quoted 6 lines
--
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>
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>
Hi John,
Quoted 5 lines · John Stultz
So after not getting too much positive feedback on my last attempt at trying to use a non-shrinker method for managing & purging volatile ranges, I decided I'd go ahead and try to implement something along Minchan's ERECLAIM LRU list idea.
Agree that there hasn't been much feedback from MM folks yet - sorry about that :/
I think one issue might be that most people don't have a good background on how the feature is intended to be used, and it is very difficult to comment meaningfully without that.
As for myself, I have been wondering:
- Why the feature needs to be on a per-range basis, rather than per-file. Is this simply to make it easier to transition the android use case from whatever they are doing right now, or is it that the object boundaries within a file can't be known in advance, and thus one wouldn't know how to split objects accross different files ? Or could it be that some of the objects would be small (less than a page) so space use would be inefficient if they were placed in different files ? Or just that there would be too many files for efficient management ?
- What are the desired semantics for the volatile objects. Can the objects be accessed while they are marked as volatile, or do they have to get unmarked first ? Is it really the case that we always want to reclaim from volatile objects first, before any other kind of caches we might have ? This sounds like a very strong hint, and I think I would be more comfortable with something more subtle if that's possible. Also, if we have several volatile objects to reclaim from, is it desirable to reclaim from the one that's been marked volatile the longest or does it make no difference ? When an object is marked volatile, would it be sufficient to ensure it gets placed on the inactive list (maybe with the referenced bit cleared) and let the normal reclaim algorithm get to it, or is that an insufficiently strong hint somehow ?
Basically, having some background information of how android would be using the feature would help us better understand the design decision here, I think.
Signature · 8 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. -- 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>
Re: [PATCH 1/5] [RFC] Add volatile range management code
In reply to John StultzQuoted 3 lines · John Stultz
v5:
* Drop intervaltree forprio_treeusage per Michel & Dmitry's suggestions.
Actually, I believe the ranges you need to track are non-overlapping, correct ?
If that is the case, a simple rbtree, sorted by start-of-range address, would work best.
(I am trying to remove prio_tree users... :)
mm/volatile.c line 268
Quoted 2 lines
mm/volatile.c new file +2
-0+/* First, find any existing intervals that overlap */ +prio_tree_iter_init (&iter, root, start, end);
Note that prio tree iterations take intervals as [start; last] not [start; end[ So if you want to stick with prio trees, you would have to use end-1 here.
mm/volatile.c line 296
Quoted 2 lines
mm/volatile.c new file +2
-0+/* Coalesce left-adjacent ranges */ +prio_tree_iter_init (&iter, root, start-1 , start);
Same here; you probably want to use start-1 on both ends
Review
Quoted 2 lines
(quoted diff) +2
-0+ node = prio_tree_next(&iter); + while (node) {
I'm confused, I don't think you ever expect more than one range to match, do you ???
mm/volatile.c line 312
Quoted 2 lines
mm/volatile.c new file +2
-0+/* Coalesce right-adjacent ranges */ +prio_tree_iter_init (&iter, root, end, end+1 );
Same again, here you probably want end on both ends
This is far from a complete code review, but I just wanted to point out a couple details that jumped to me first. I am afraid I am missing some of the background about how the feature is to be used to really dig into the rest of the changes at this point :/
Signature · 8 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. -- 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>
Re: [PATCH 1/5] [RFC] Add volatile range management code
Quoted 11 lines · Michel Lespinasse
Quoted 3 lines · John Stultz
v5:
* Drop intervaltree forprio_treeusage per Michel & Dmitry's suggestions.Actually, I believe the ranges you need to track are non-overlapping, correct ?
If that is the case, a simple rbtree, sorted by start-of-range address, would work best.
(I am trying to removeprio_treeusers... :)
John,
JFYI, if you want to try a possible rbtree-based implementation, as suggested by Michel you could try this one:
https://github.com/arighi/kinterval
This implementation supports insertion, deletion and transparent merging of adjacent ranges, as well as splitting ranges when chunks removed or different chunk types are added in the middle of an existing range; so if I'm not wrong probably you should be able to use this code as is, without any modification.
If you decide to go this way and/or need help to use it in your patch set just let me know.
-Andrea
--
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>
Quoted 17 lines · Michel Lespinasse
Hi John,
Quoted 5 lines · John Stultz
So after not getting too much positive feedback on my last attempt at trying to use a non-shrinker method for managing & purging volatile ranges, I decided I'd go ahead and try to implement something along Minchan's ERECLAIM LRU list idea.
Agree that there hasn't been much feedback from MM folks yet - sorry about that :/
I think one issue might be that most people don't have a good background on how the feature is intended to be used, and it is very difficult to comment meaningfully without that.
As for myself, I have been wondering:
Quoted 9 lines
- Why the feature needs to be on a per-range basis, rather than per-file. Is this simply to make it easier to transition the android use case from whatever they are doing right now, or is it that the object boundaries within a file can't be known in advance, and thus one wouldn't know how to split objects accross different files ? Or could it be that some of the objects would be small (less than a page) so space use would be inefficient if they were placed in different files ? Or just that there would be too many files for efficient management ?
For me, keeping the feature per-range instead of something like per-file is in order to be able to support Android's existing use case.
As to why Android uses per-range instead of per file, Arve or someone from the Android team could probably better answer, but I can theorize. In discussions with the Android guys, they've mentioned ashmem's primary goal was to basically provide atomically unlinked tmpfs fds for sharing memory, and memory unpinning was a follow on feature. So I suspect that ranges fit better into their existing model of using a mmapped fd to share data between two processes. Instead of creating a new tmpfs file and sharing the fd for each object, they're able to create a one shared mapping, which can be effectively resized w/ unpinning, for multiple objects.
Another use case where ranges would be beneficial might be for where there's a large single object that might not all be in use at one time. For example, a very large web page, where you have a limited view onto it. Having the rest of the page rendered so you can quickly scroll without re-rendering would be nice, but under memory pressure it could effectively throw out the non-visible portions.
Further, one additional reason I have for not having the volatile attribute be per-file, is that I have my eye on allowing volatile ranges to be set on anonymous heap memory via something like madvise() in the future, which would be an easier api to use if you're not sharing data via mmapped tmpfs files, but wouldn't be possible if this was a file attribute rather then a range of pages.
Quoted 3 lines
- What are the desired semantics for the volatile objects. Can the objects be accessed while they are marked as volatile, or do they have to get unmarked first ?
So accessing a volatile page before marking it non-volatile can produce undefined behavior. You could get the data that was there, or you could get empty pages. The expectation is that pages are unmarked before being accessed, so one can know if the data was lost or not. I'm open to other suggestions here, if folks think we should SIGSEGV on accesses to volatile pages. However, I don't know how setting that up and tearing it down on each mark_volatile/unmark_volatile might affect performance.
Quoted 5 lines
Is it really the case that we always want to
reclaim from volatile objects first, before any other kind of caches we might have ? This sounds like a very strong hint, and I think I would be more comfortable with something more subtle if that's possible.
So the current Android ashmem implementation uses a shrinker, which isn't necessarily called before any other caches are freed. So, I don't think its a strong hint, but it just seems somewhat intuitive to me that we should free effectively "user-donated" pages before freeing other system caches. But that's not something the interface necessarily defines or requires.
Quoted 3 lines
Also, if we have several volatile objects to reclaim from, is it desirable to reclaim from the one that's been marked volatile the longest or does it make no difference ?
While I don't think its strictly necessary, I do think LRU order purging is important from the least-surprise angle. Since ranges marked volatile should not be touched until they are marked non-volatile, it follows normal expectations that recently touched data is likely to be faster then data that has not been accessed for some time. Reasonable exceptions would be situations like NUMA systems where pressure on one node forces purging volatile pages in a non-global-lru order. So probably not critical, but I think useful to try to preserve.
Quoted 5 lines
When an object is marked
volatile, would it be sufficient to ensure it gets placed on the inactive list (maybe with the referenced bit cleared) and let the normal reclaim algorithm get to it, or is that an insufficiently strong hint somehow ?
The problem is that on machines without swap, there wouldn't be any reclaim for inactive anonymous pages.
An earlier iteration of this implementation (v4 I think?) used writepage to decide if to purge or writeout a page, and made it so in non-swap cases the anonymous inactive list was in effect the "volatile" list. However, folks didn't seem to like this approach.
Quoted 3 lines
Basically, having some background information of how android would be using the feature would help us better understand the design decision here, I think.
Hopefully the details above help, and I'll try to get some more concrete examples from the Android code base.
thanks
-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>
Re: [PATCH 1/5] [RFC] Add volatile range management code
In reply to Michel LespinasseQuoted 5 lines · Michel Lespinasse
Quoted 3 lines · John Stultz
v5:
* Drop intervaltree forprio_treeusage per Michel & Dmitry's suggestions.Actually, I believe the ranges you need to track are non-overlapping, correct ?
Correct. Any overlapping range is coalesced.
Quoted 3 lines
If that is the case, a simple rbtree, sorted by start-of-range address, would work best.
(I am trying to removeprio_treeusers... :)
Sigh. Sure. Although I've blown with the wind on a number of different approaches for storing the ranges. I'm not particularly passionate about it, but the continual conflicting suggestions are a slight frustration. :)
Quoted 4 lines
mm/volatile.c line 268
Quoted 2 lines
mm/volatile.c new file +2
-0+/* First, find any existing intervals that overlap */ +prio_tree_iter_init (&iter, root, start, end);Note that prio tree iterations take intervals as [start; last] not [start; end[ So if you want to stick with prio trees, you would have to use end-1 here.
Thanks! I think I hit this off-by-one issue in my testing, but fixed it on the backend w/ :
modify_range(&inode->i_data, start, end-1, &mark_nonvolatile_page);
Clearly fixing it at the start instead of papering over it is better.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ node = prio_tree_next(&iter); + while (node) {I'm confused, I don't think you ever expect more than one range to match, do you ???
So yea. If you already have two ranges (0-5),(10-15) and then add range (0-20) we need to coalesce the two existing ranges into the new one.
Quoted 4 lines
This is far from a complete code review, but I just wanted to point out a couple details that jumped to me first. I am afraid I am missing some of the background about how the feature is to be used to really dig into the rest of the changes at this point :/
Well, I really appreciate any feedback here.
thanks
-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>
Re: [PATCH 1/5] [RFC] Add volatile range management code
In reply to Andrea RighiQuoted 17 lines · Andrea Righi
Quoted 10 lines · Michel Lespinasse
Quoted 3 lines · John Stultz
v5:
* Drop intervaltree forprio_treeusage per Michel & Dmitry's suggestions.Actually, I believe the ranges you need to track are non-overlapping, correct ?
If that is the case, a simple rbtree, sorted by start-of-range address, would work best.
(I am trying to removeprio_treeusers... :)John,
JFYI, if you want to try a possible rbtree-based implementation, as suggested by Michel you could try this one:
https://github.com/arighi/kinterval
Quoted 5 lines
This implementation supports insertion, deletion and transparent merging of adjacent ranges, as well as splitting ranges when chunks removed or different chunk types are added in the middle of an existing range; so if I'm not wrong probably you should be able to use this code as is, without any modification.
I do appreciate the suggestion, and considered this earlier when you posted this before.
Unfotunately the transparent merging/splitting/etc is actually not useful for me, since I manage other data per-range. The earlier generic rangetree/intervaltree implementations I tried limiting the interface to basically add(), remove(), search(), and search_next(), since when we coalesce intervals, we need to free the data in the structure referencing the interval being deleted (and similarly create new structures to reference new intervals created when we remove an interval). So the coalescing/splitting logic can't be pushed into the interval management code cleanly.
So while I might be able to make use of your kinterval in a fairly simple manner (only using add/del/lookup), I'm not sure it wins anything over just using an rbtree. Especially since I'd have to do my own coalesce/splitting logic anyway, it would actually be more expensive as on add() it would still scan to check for overlapping ranges to merge.
I ended up dropping my generic intervaltree implementation because folks objected that it was so trivial (basically just wrapping an rbtree) and didn't handle some of the more complex intervaltree use cases (ie: allowing for overlapping intervals). The priotree seemed to match fairly closely the interface I was using, but apparently its on its way out as well, so unless anyone further objects, I think I'll just fall back to a simple rbtree implementation.
thanks
-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>
Re: [PATCH 1/5] [RFC] Add volatile range management code
Quoted 43 lines · John Stultz
Quoted 17 lines · Andrea Righi
Quoted 10 lines · Michel Lespinasse
Quoted 3 lines · John Stultz
v5:
* Drop intervaltree forprio_treeusage per Michel & Dmitry's suggestions.Actually, I believe the ranges you need to track are non-overlapping, correct ?
If that is the case, a simple rbtree, sorted by start-of-range address, would work best.
(I am trying to removeprio_treeusers... :)John,
JFYI, if you want to try a possible rbtree-based implementation, as suggested by Michel you could try this one:
https://github.com/arighi/kintervalQuoted 5 lines
This implementation supports insertion, deletion and transparent merging of adjacent ranges, as well as splitting ranges when chunks removed or different chunk types are added in the middle of an existing range; so if I'm not wrong probably you should be able to use this code as is, without any modification.
I do appreciate the suggestion, and considered this earlier when you posted this before.
Unfotunately the transparent merging/splitting/etc is actually not useful for me, since I manage other data per-range. The earlier generic rangetree/intervaltree implementations I tried limiting the interface to basically
add(),remove(),search(), andsearch_next(), since when we coalesce intervals, we need to free the data in the structure referencing the interval being deleted (and similarly create new structures to reference new intervals created when we remove an interval). So the coalescing/splitting logic can't be pushed into the interval management code cleanly.So while I might be able to make use of your kinterval in a fairly simple manner (only using add/del/lookup), I'm not sure it wins anything over just using an rbtree. Especially since I'd have to do my own coalesce/splitting logic anyway, it would actually be more expensive as on
add()it would still scan to check for overlapping ranges to merge.
Quoted 7 lines
I ended up dropping my generic intervaltree implementation because folks objected that it was so trivial (basically just wrapping an rbtree) and didn't handle some of the more complex intervaltree use cases (ie: allowing for overlapping intervals). The priotree seemed to match fairly closely the interface I was using, but apparently its on its way out as well, so unless anyone further objects, I think I'll just fall back to a simple rbtree implementation.
OK, everything makes sense now, thanks for the clarifications, and sorry for suggesting yet another range/interval tree implementation. :)
I'll look at your patch set more in details and try to test/review it closely.
-Andrea
--
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>