Skip to contentSkip to conversation

Fallocate Volatile Ranges v4

RFC PATCH In review John Stultz 3 participants 9 messages Jun 13, 2012 – Jun 22, 2012

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

cover Fallocate Volatile Ranges v4

So after sending out the v3 iteration of this patch set, I noticed that the approach taken there of using writepage to trigger the volatile range purging would not be functional, as writepage isn't called on systems without swap.

Given this, for this iteration I've reverted the patch set back to using a shrinker. I've also included a patch to convert ashmem to use volatile ranges, which almost cuts the size of the ashmem driver in half.

Now, I've also gotten feedback from Kosaki-san that the shrinker interface along with tracking volatile ranges via an lru is a poor choice, as it is not NUMA aware. I've spent some time trying to learn more about the VM internals, and I've included two HACK patches that try to propose a way to address these concerns.

The basic idea is to remove the the volatile range lru management. Instead leveraging the VM's page lru management, by deactivating the entire range when marking it volatile. Then in the writepage code we check if a page is part of a volatile range, and if so we purge it. This provides LRU-like behavior for purging volatile ranges (so we purge old volatile ranges before new ones), while allowing the kernel to free memory first on a numa node that is under pressure.

Of course, the issue I had w/ the v3 patchset still applies. We never call shmem_writepage on a system without swap! So to address this, I've create a quite hackish patch that tries to manage the anonymous active and inactive lrus slightly differently.

The idea with this is on systems without swap, there's not much use to keeping inactive and active anonymous lrus separately, since we can't swap out any of the anonymous memory (at least this is my assumption, and I may be wrong). So when we don't have swap, keep all anonymous pages active. Thus, only pages that are deactivated will be moved to the inactive lru. Then we change shrink_lruvec() to try to writeout inactive anonymous pages. Of course, writepage won't write anything out if there's no swap, but it will now check if the page is volatile and purge it if appropriate.

So... does that sound reasonable or terrible?

Are there other approaches I should be trying?

Maybe the original shrinker approach isn't so bad after all? :)

Many thanks again to Dave Hansen who's been fending off my numerous questions on irc for the last few days.

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]>
CC KOSAKI Motohiro <[email protected]>

John Stultz (6):
[RFC] Interval tree implementation
[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] tmpfs: Purge volatile ranges on writepage instead of
using shrinker
[RFC][HACK] mm: Change memory management of anonymous pages on
swapless systems

 drivers/staging/android/ashmem.c |  331 +--------------------------
 fs/open.c                        |    3 +-
 include/linux/falloc.h           |    7 +-
 include/linux/intervaltree.h     |   55 +++++
 include/linux/pagevec.h          |    5 +-
 include/linux/swap.h             |   23 ++-
 include/linux/volatile.h         |   40 ++++
 lib/Makefile                     |    2 +-
 lib/intervaltree.c               |  119 ++++++++++
 mm/Makefile                      |    2 +-
 mm/shmem.c                       |  102 +++++++++
 mm/swap.c                        |   13 +-
 mm/vmscan.c                      |    9 -
 mm/volatile.c                    |  467 ++++++++++++++++++++++++++++++++++++++
 14 files changed, 828 insertions(+), 350 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
#1 lore raw

RFC PATCH 1/6 Interval tree implementation

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]>
CC KOSAKI Motohiro <[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
#2 lore raw

Re: [PATCH 1/6] [RFC] Interval tree implementation

Quoted 19 lines · 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.

Quoted 5 lines

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.

Well, we already have several implementations of interval trees:

* lib/prio_tree.c seems to do what you want. It's often used with VMAs, but there is also a 'raw' node structure, as used in mm/kmemleak.c, which supports all the operations you are proposing.

* lib/rb_tree.c has some support for the "augmented tree" structure, with which you can implement interval trees as is done in arch/x86/mm/pat_rbtree.c

I don't think it makes sense to have two implementations already, and I am looking into possibly collapsing these into one. Please don't add a third one :)

Also, the name "interval tree" typically implies a data structure that is capable of representing overlapping intervals. Since your implementation does not support that (it requires its callers to make sure the intervals are non-overlapping), I think calling it "interval tree" could cause confusion.

Signature · 2 lines
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
#3 lore raw

RFC PATCH 2/6 Add volatile range management code

In reply to John Stultz

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.

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.

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]>
CC KOSAKI Motohiro <[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..51f3d6e
@@ -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,
+				loff_t *start, loff_t *end);
+#endif /* _LINUX_VOLATILE_H */
mm/Makefile +1 -1
index 2e2fbbe..3e3cd6f 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
#4 lore raw

RFC PATCH 3/6 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.

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.

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]>
CC KOSAKI Motohiro <[email protected]>
---
 fs/open.c              |    3 +-
 include/linux/falloc.h |    7 ++-
 mm/shmem.c             |  112 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 4 deletions(-)
fs/open.c +2 -1
index d6c79a0..c0531c0 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 +112 -0

142 lines not on this page · raw message

Signature · 1 line
1.7.3.2.146.gca209
#5 lore raw

RFC PATCH 4/6 ashmem: Convert ashmem to use volatile ranges

In reply to John Stultz

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

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]>
CC KOSAKI Motohiro <[email protected]>
---
 drivers/staging/android/ashmem.c |  331 +------------------------------------
 1 files changed, 9 insertions(+), 322 deletions(-)
drivers/staging/android/ashmem.c +9 -322
index e84dbec..9e8fe37 100644
@@ -50,26 +50,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
@@ -77,102 +57,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)
 {
@@ -198,12 +85,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);
@@ -337,56 +218,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;
@@ -459,136 +290,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))
@@ -610,20 +315,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;
 	}
 
@@ -667,15 +376,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;
 	}
 
@@ -711,22 +411,12 @@ 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)) {
-		printk(KERN_ERR "ashmem: failed to create slab cache\n");
-		return -ENOMEM;
-	}
-
 	ret = misc_register(&ashmem_misc);
 	if (unlikely(ret)) {
 		printk(KERN_ERR "ashmem: failed to register misc device!\n");
 		return ret;
 	}
 
-	register_shrinker(&ashmem_shrinker);
-
 	printk(KERN_INFO "ashmem: initialized\n");
 
 	return 0;
@@ -736,13 +426,10 @@ static void __exit ashmem_exit(void)
 {
 	int ret;
 
-	unregister_shrinker(&ashmem_shrinker);
-
 	ret = misc_deregister(&ashmem_misc);
 	if (unlikely(ret))
 		printk(KERN_ERR "ashmem: failed to unregister misc device!\n");
 
-	kmem_cache_destroy(ashmem_range_cachep);
 	kmem_cache_destroy(ashmem_area_cachep);
 
 	printk(KERN_INFO "ashmem: unloaded\n");
Signature · 1 line
1.7.3.2.146.gca209
#6 lore raw

RFC PATCH 5/6 tmpfs: Purge volatile ranges on writepage instead of using shrinker

In reply to John Stultz

In order to avoid using a shrinker, purge volatile ranges on writepage. This requires deactivating/activating the page ranges together to ensure relative LRU behavior in purging the volatile ranges.

This no longer requires the volatile range lru so remove that code. Also add volatile range infrastructure to find a range that contains a given page.

NOTE: On systems without swap, the VM won't shrink anonymous memory, so writepage is never called and volatile ranges won't be purged. This issue will be addressed in a following patch.

I've only been able to do minimal testing, so there's probably much still wrong with this patch. But hopefully it will provide a concrete approach for discussion.

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]>
CC KOSAKI Motohiro <[email protected]>
---
 include/linux/volatile.h |   11 ++----
 mm/shmem.c               |   90 ++++++++++++++++++++-------------------------
 mm/volatile.c            |   84 +++++++++++--------------------------------
 3 files changed, 64 insertions(+), 121 deletions(-)
include/linux/volatile.h +3 -8
index 51f3d6e..8edb5c1 100644
@@ -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,11 @@ 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,
+int volatile_page_in_range(struct volatile_fs_head *head,
+				struct page *page,
 				loff_t *start, loff_t *end);
+
 #endif /* _LINUX_VOLATILE_H */
mm/shmem.c +40 -50

134 lines not on this page · raw message

mm/volatile.c +21 -63

127 lines not on this page · raw message

Signature · 1 line
1.7.3.2.146.gca209
#7 lore raw

RFC PATCH 6/6 mm: Change memory management of anonymous pages on swapless systems

In reply to John Stultz

Due to my newbie-ness, the following may not be precise, but I think it conveys the intent of what I'm trying to do here.

Anonymous memory is tracked on two LRU lists: LRU_INACTIVE_ANON and LRU_ACTIVE_ANON. This split is useful when we need to free up pages and are trying to decide what to swap out.

However, on systems that do no have swap, this partition is less clear. In many cases the code avoids aging active anonymous pages onto the inactive list. However in some cases pages do get moved to the inactive list, but we never call writepage, as there isn't anything to swap out.

This patch changes some of the active/inactive list management of anonymous memory when there is no swap. In that case pages are always added to the active lru. The intent is that since anonymous pages cannot be swapped out, they all shoudld be active.

The one exception is volatile pages, which can be moved to the inactive lru by calling deactivate_page().

In addition, I've changed the logic so we also do try to shrink the inactive anonymous lru, and call writepage. This should only be done if there are volatile pages on the inactive lru.

This allows us to purge volatile pages in writepage when the system does not have swap.

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]>
CC KOSAKI Motohiro <[email protected]>
---
 include/linux/pagevec.h |    5 +----
 include/linux/swap.h    |   23 +++++++++++++++--------
 mm/swap.c               |   13 ++++++++++++-
 mm/vmscan.c             |    9 ---------
 4 files changed, 28 insertions(+), 22 deletions(-)
include/linux/pagevec.h +1 -4
index 2aa12b8..e1312a5 100644
@@ -22,6 +22,7 @@ struct pagevec {
 
 void __pagevec_release(struct pagevec *pvec);
 void __pagevec_lru_add(struct pagevec *pvec, enum lru_list lru);
+void __pagevec_lru_add_anon(struct pagevec *pvec);
 unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
 		pgoff_t start, unsigned nr_pages);
 unsigned pagevec_lookup_tag(struct pagevec *pvec,
@@ -64,10 +65,6 @@ static inline void pagevec_release(struct pagevec *pvec)
 		__pagevec_release(pvec);
 }
 
-static inline void __pagevec_lru_add_anon(struct pagevec *pvec)
-{
-	__pagevec_lru_add(pvec, LRU_INACTIVE_ANON);
-}
 
 static inline void __pagevec_lru_add_active_anon(struct pagevec *pvec)
 {
include/linux/swap.h +15 -8
index c84ec68..639936f 100644
@@ -238,14 +238,6 @@ extern void swap_setup(void);
 
 extern void add_page_to_unevictable_list(struct page *page);
 
-/**
- * lru_cache_add: add a page to the page lists
- * @page: the page to add
- */
-static inline void lru_cache_add_anon(struct page *page)
-{
-	__lru_cache_add(page, LRU_INACTIVE_ANON);
-}
 
 static inline void lru_cache_add_file(struct page *page)
 {
@@ -474,5 +466,20 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent)
 }
 
 #endif /* CONFIG_SWAP */
+
+/**
+ * lru_cache_add: add a page to the page lists
+ * @page: the page to add
+ */
+static inline void lru_cache_add_anon(struct page *page)
+{
+	int lru = LRU_INACTIVE_ANON;
+	if (!total_swap_pages)
+		lru = LRU_ACTIVE_ANON;
+
+	__lru_cache_add(page, lru);
+}
+
+
 #endif /* __KERNEL__*/
 #endif /* _LINUX_SWAP_H */
mm/swap.c +12 -1
index 4e7e2ec..f35df46 100644
@@ -691,7 +691,7 @@ void lru_add_page_tail(struct page *page, struct page *page_tail,
 	SetPageLRU(page_tail);
 
 	if (page_evictable(page_tail, NULL)) {
-		if (PageActive(page)) {
+		if (PageActive(page) || !total_swap_pages) {
 			SetPageActive(page_tail);
 			active = 1;
 			lru = LRU_ACTIVE_ANON;
@@ -755,6 +755,17 @@ void __pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
 }
 EXPORT_SYMBOL(__pagevec_lru_add);
 
+
+void __pagevec_lru_add_anon(struct pagevec *pvec)
+{
+	if (!total_swap_pages)
+		__pagevec_lru_add(pvec, LRU_ACTIVE_ANON);
+	else
+		__pagevec_lru_add(pvec, LRU_INACTIVE_ANON);
+}
+EXPORT_SYMBOL(__pagevec_lru_add_anon);
+
+
 /**
  * pagevec_lookup - gang pagecache lookup
  * @pvec:	Where the resulting pages are placed
mm/vmscan.c +0 -9
index eeb3bc9..52d8ad9 100644
@@ -1597,15 +1597,6 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
 	if (!global_reclaim(sc))
 		force_scan = true;
 
-	/* If we have no swap space, do not bother scanning anon pages. */
-	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		noswap = 1;
-		fraction[0] = 0;
-		fraction[1] = 1;
-		denominator = 1;
-		goto out;
-	}
-
 	anon  = get_lru_size(lruvec, LRU_ACTIVE_ANON) +
 		get_lru_size(lruvec, LRU_INACTIVE_ANON);
 	file  = get_lru_size(lruvec, LRU_ACTIVE_FILE) +
Signature · 1 line
1.7.3.2.146.gca209
#8 lore raw

Re: [PATCH 6/6] [RFC][HACK] mm: Change memory management of anonymous pages on swapless systems

Hi John,

Quoted 7 lines · John Stultz

Due to my newbie-ness, the following may not be precise, but I think it conveys the intent of what I'm trying to do here.

Anonymous memory is tracked on two LRU lists: LRU_INACTIVE_ANON and LRU_ACTIVE_ANON. This split is useful when we need to free up pages and are trying to decide what to swap out.

Quoted 5 lines

However, on systems that do no have swap, this partition is less clear. In many cases the code avoids aging active anonymous pages onto the inactive list. However in some cases pages do get moved to the inactive list, but we never call writepage, as there isn't anything to swap out.

I confess I don't look at your code still yet so I might be wrong. As I read your comment, pop old history.

Long time ago, I did prevent anon aging totally without swapless but dropped up by Rik's comment. We should think swapoff system and swapless(!CONFIG_SWAP) separately.

Of course, in swapless system, your code would work. Even, we might not need anon lru list itself. But in swap-off system, it is possible that user can do swapon anytime so we need keeping the aging.

That was why Rik didn't like my patch at that time.

Quoted 154 lines

This patch changes some of the active/inactive list management of anonymous memory when there is no swap. In that case pages are always added to the active lru. The intent is that since anonymous pages cannot be swapped out, they all shoudld be active.

The one exception is volatile pages, which can be moved to the inactive lru by calling deactivate_page().

In addition, I've changed the logic so we also do try to shrink the inactive anonymous lru, and call writepage. This should only be done if there are volatile pages on the inactive lru.

This allows us to purge volatile pages in writepage when the system does not have swap.

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]>
CC KOSAKI Motohiro <[email protected]>
---
 include/linux/pagevec.h |    5 +----
 include/linux/swap.h    |   23 +++++++++++++++--------
 mm/swap.c               |   13 ++++++++++++-
 mm/vmscan.c             |    9 ---------
 4 files changed, 28 insertions(+), 22 deletions(-)
include/linux/pagevec.h +1 -4
index 2aa12b8..e1312a5 100644
@@ -22,6 +22,7 @@ struct pagevec {
 
 void __pagevec_release(struct pagevec *pvec);
 void __pagevec_lru_add(struct pagevec *pvec, enum lru_list lru);
+void __pagevec_lru_add_anon(struct pagevec *pvec);
 unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
 		pgoff_t start, unsigned nr_pages);
 unsigned pagevec_lookup_tag(struct pagevec *pvec,
@@ -64,10 +65,6 @@ static inline void pagevec_release(struct pagevec *pvec)
 		__pagevec_release(pvec);
 }
 
-static inline void __pagevec_lru_add_anon(struct pagevec *pvec)
-{
-	__pagevec_lru_add(pvec, LRU_INACTIVE_ANON);
-}
 
 static inline void __pagevec_lru_add_active_anon(struct pagevec *pvec)
 {
include/linux/swap.h +15 -8
index c84ec68..639936f 100644
@@ -238,14 +238,6 @@ extern void swap_setup(void);
 
 extern void add_page_to_unevictable_list(struct page *page);
 
-/**
- * lru_cache_add: add a page to the page lists
- * @page: the page to add
- */
-static inline void lru_cache_add_anon(struct page *page)
-{
-	__lru_cache_add(page, LRU_INACTIVE_ANON);
-}
 
 static inline void lru_cache_add_file(struct page *page)
 {
@@ -474,5 +466,20 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent)
 }
 
 #endif /* CONFIG_SWAP */
+
+/**
+ * lru_cache_add: add a page to the page lists
+ * @page: the page to add
+ */
+static inline void lru_cache_add_anon(struct page *page)
+{
+	int lru = LRU_INACTIVE_ANON;
+	if (!total_swap_pages)
+		lru = LRU_ACTIVE_ANON;
+
+	__lru_cache_add(page, lru);
+}
+
+
 #endif /* __KERNEL__*/
 #endif /* _LINUX_SWAP_H */
mm/swap.c +12 -1
index 4e7e2ec..f35df46 100644
@@ -691,7 +691,7 @@ void lru_add_page_tail(struct page *page, struct page *page_tail,
 	SetPageLRU(page_tail);
 
 	if (page_evictable(page_tail, NULL)) {
-		if (PageActive(page)) {
+		if (PageActive(page) || !total_swap_pages) {
 			SetPageActive(page_tail);
 			active = 1;
 			lru = LRU_ACTIVE_ANON;
@@ -755,6 +755,17 @@ void __pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
 }
 EXPORT_SYMBOL(__pagevec_lru_add);
 
+
+void __pagevec_lru_add_anon(struct pagevec *pvec)
+{
+	if (!total_swap_pages)
+		__pagevec_lru_add(pvec, LRU_ACTIVE_ANON);
+	else
+		__pagevec_lru_add(pvec, LRU_INACTIVE_ANON);
+}
+EXPORT_SYMBOL(__pagevec_lru_add_anon);
+
+
 /**
  * pagevec_lookup - gang pagecache lookup
  * @pvec:	Where the resulting pages are placed
mm/vmscan.c +0 -9
index eeb3bc9..52d8ad9 100644
@@ -1597,15 +1597,6 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
 	if (!global_reclaim(sc))
 		force_scan = true;
 
-	/* If we have no swap space, do not bother scanning anon pages. */
-	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		noswap = 1;
-		fraction[0] = 0;
-		fraction[1] = 1;
-		denominator = 1;
-		goto out;
-	}
-
 	anon  = get_lru_size(lruvec, LRU_ACTIVE_ANON) +
 		get_lru_size(lruvec, LRU_INACTIVE_ANON);
 	file  = get_lru_size(lruvec, LRU_ACTIVE_FILE) +
Signature · 2 lines
Kind regards,
Minchan Kim