Skip to contentSkip to conversation

(frontswap.v16-tag)

GIT Konrad Rzeszutek Wilk 6 participants 8 messages May 18, 2012 – Jun 1, 2012 1 message not in the archive

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

Hey Linus,

Last time this patch was proposed for a merge a big technical discussion came about (https://lkml.org/lkml/2011/10/27/206), and also about proper linux-next procedures, how to deal with patches that distros are carrying, some poems, and some heated discussion. Then at this year LFS/MM this topic was proposed and the discussion was much more mellow (I wasn't there but that is what I got from Dan's email). Feeling reinvigorated I've posted these patches (http://lwn.net/Articles/493807/) on linux-mm but got no comments back. In the prior reviews the issues were not with the hooks this patch proposes but rather with the backends - and a couple of defects in one backend (zcache - which we hope to promote from staging and to be enabled by default) were identified and are being addressed.

There are three backends - two in staging and one in drivers/xen/tmem.c. I am proposing this patch set that introduces the hooks for the existing drivers and lays the foundation to emerge the ones in staging. The functions are _not_ to be set in stone - I think as folks walk through the zcache, ramster, and kvm-tmem (not yet in staging) TODOs, there will be modifications and enhancements.

Not many - and mostly it will be in terms of figuring out what kind of pages should be sent to the backends (or the backends telling frontswap to stop sending).

Oracle and SUSE are both carrying these set of patches to allow users better memory utilization. We found that irregardless of how much memory the customers have (1GB up to 1TB), they still want more and more memory in their guests. The frontswap is the ying-yang to the cleancache (which allows de-duplication on the filesystem layer of various guests) - but does it on the swap pages. Depending on the backend it allows de-duplication of swap pages (and compression). The zcache is a backend that can run in embedded baremetal cases can compress swap-pages benefiting even tiny embedded devices up to enterprise server machines.

The git tree is here:

git://git.kernel.org/pub/scm/linux/kernel/git/konrad/mm.git stable/frontswap.v16-tag

And I am including the full diff for easier overview following the credit list:

Dan Magenheimer (4):
mm: frontswap: add frontswap header file
mm: frontswap: core swap subsystem hooks and headers
mm: frontswap: core frontswap functionality
mm: frontswap: config and doc files

Konrad Rzeszutek Wilk (2):
MAINTAINER: Add myself for the frontswap API
frontswap: s/put_page/store/g s/get_page/load

 Documentation/vm/frontswap.txt        |  278 +++++++++++++++++++++++++++++
 MAINTAINERS                           |    7 +
 drivers/staging/ramster/zcache-main.c |    8 +-
 drivers/staging/zcache/zcache-main.c  |   10 +-
 drivers/xen/tmem.c                    |    8 +-
 include/linux/frontswap.h             |  127 +++++++++++++
 include/linux/swap.h                  |    4 +
 include/linux/swapfile.h              |   13 ++
 mm/Kconfig                            |   17 ++
 mm/Makefile                           |    1 +
 mm/frontswap.c                        |  314 +++++++++++++++++++++++++++++++++
 mm/page_io.c                          |   12 ++
 mm/swapfile.c                         |   54 +++++--
 13 files changed, 827 insertions(+), 26 deletions(-)
Documentation/vm/frontswap.txt new file +278 -0
new file mode 100644
index 0000000..37067cf
@@ -0,0 +1,278 @@
+Frontswap provides a "transcendent memory" interface for swap pages.
+In some environments, dramatic performance savings may be obtained because
+swapped pages are saved in RAM (or a RAM-like device) instead of a swap disk.
+
+(Note, frontswap -- and cleancache (merged at 3.0) -- are the "frontends"
+and the only necessary changes to the core kernel for transcendent memory;
+all other supporting code -- the "backends" -- is implemented as drivers.
+See the LWN.net article "Transcendent memory in a nutshell" for a detailed
+overview of frontswap and related kernel parts:
+https://lwn.net/Articles/454795/ )
+
+Frontswap is so named because it can be thought of as the opposite of
+a "backing" store for a swap device.  The storage is assumed to be
+a synchronous concurrency-safe page-oriented "pseudo-RAM device" conforming
+to the requirements of transcendent memory (such as Xen's "tmem", or
+in-kernel compressed memory, aka "zcache", or future RAM-like devices);
+this pseudo-RAM device is not directly accessible or addressable by the
+kernel and is of unknown and possibly time-varying size.  The driver
+links itself to frontswap by calling frontswap_register_ops to set the
+frontswap_ops funcs appropriately and the functions it provides must
+conform to certain policies as follows:
+
+An "init" prepares the device to receive frontswap pages associated
+with the specified swap device number (aka "type").  A "store" will
+copy the page to transcendent memory and associate it with the type and
+offset associated with the page. A "load" will copy the page, if found,
+from transcendent memory into kernel memory, but will NOT remove the page
+from from transcendent memory.  An "invalidate_page" will remove the page
+from transcendent memory and an "invalidate_area" will remove ALL pages
+associated with the swap type (e.g., like swapoff) and notify the "device"
+to refuse further stores with that swap type.
+
+Once a page is successfully stored, a matching load on the page will normally
+succeed.  So when the kernel finds itself in a situation where it needs
+to swap out a page, it first attempts to use frontswap.  If the store returns
+success, the data has been successfully saved to transcendent memory and
+a disk write and, if the data is later read back, a disk read are avoided.
+If a store returns failure, transcendent memory has rejected the data, and the
+page can be written to swap as usual.
+
+If a backend chooses, frontswap can be configured as a "writethrough
+cache" by calling frontswap_writethrough().  In this mode, the reduction
+in swap device writes is lost (and also a non-trivial performance advantage)
+in order to allow the backend to arbitrarily "reclaim" space used to
+store frontswap pages to more completely manage its memory usage.
+
+Note that if a page is stored and the page already exists in transcendent memory
+(a "duplicate" store), either the store succeeds and the data is overwritten,
+or the store fails AND the page is invalidated.  This ensures stale data may
+never be obtained from frontswap.
+
+If properly configured, monitoring of frontswap is done via debugfs in
+the /sys/kernel/debug/frontswap directory.  The effectiveness of
+frontswap can be measured (across all swap devices) with:
+
+failed_stores	- how many store attempts have failed
+loads		- how many loads were attempted (all should succeed)
+succ_stores	- how many store attempts have succeeded
+invalidates	- how many invalidates were attempted
+
+A backend implementation may provide additional metrics.
+
+FAQ
+
+1) Where's the value?
+
+When a workload starts swapping, performance falls through the floor.
+Frontswap significantly increases performance in many such workloads by
+providing a clean, dynamic interface to read and write swap pages to
+"transcendent memory" that is otherwise not directly addressable to the kernel.
+This interface is ideal when data is transformed to a different form
+and size (such as with compression) or secretly moved (as might be
+useful for write-balancing for some RAM-like devices).  Swap pages (and
+evicted page-cache pages) are a great use for this kind of slower-than-RAM-
+but-much-faster-than-disk "pseudo-RAM device" and the frontswap (and
+cleancache) interface to transcendent memory provides a nice way to read
+and write -- and indirectly "name" -- the pages.
+
+Frontswap -- and cleancache -- with a fairly small impact on the kernel,
+provides a huge amount of flexibility for more dynamic, flexible RAM
+utilization in various system configurations:
+
+In the single kernel case, aka "zcache", pages are compressed and
+stored in local memory, thus increasing the total anonymous pages
+that can be safely kept in RAM.  Zcache essentially trades off CPU
+cycles used in compression/decompression for better memory utilization.
+Benchmarks have shown little or no impact when memory pressure is
+low while providing a significant performance improvement (25%+)
+on some workloads under high memory pressure.
+
+"RAMster" builds on zcache by adding "peer-to-peer" transcendent memory
+support for clustered systems.  Frontswap pages are locally compressed
+as in zcache, but then "remotified" to another system's RAM.  This
+allows RAM to be dynamically load-balanced back-and-forth as needed,
+i.e. when system A is overcommitted, it can swap to system B, and
+vice versa.  RAMster can also be configured as a memory server so
+many servers in a cluster can swap, dynamically as needed, to a single
+server configured with a large amount of RAM... without pre-configuring
+how much of the RAM is available for each of the clients!
+
+In the virtual case, the whole point of virtualization is to statistically
+multiplex physical resources acrosst the varying demands of multiple
+virtual machines.  This is really hard to do with RAM and efforts to do
+it well with no kernel changes have essentially failed (except in some
+well-publicized special-case workloads).
+Specifically, the Xen Transcendent Memory backend allows otherwise
+"fallow" hypervisor-owned RAM to not only be "time-shared" between multiple
+virtual machines, but the pages can be compressed and deduplicated to
+optimize RAM utilization.  And when guest OS's are induced to surrender
+underutilized RAM (e.g. with "selfballooning"), sudden unexpected
+memory pressure may result in swapping; frontswap allows those pages
+to be swapped to and from hypervisor RAM (if overall host system memory
+conditions allow), thus mitigating the potentially awful performance impact
+of unplanned swapping.
+
+A KVM implementation is underway and has been RFC'ed to lkml.  And,
+using frontswap, investigation is also underway on the use of NVM as
+a memory extension technology.
+
+2) Sure there may be performance advantages in some situations, but
+   what's the space/time overhead of frontswap?
+
+If CONFIG_FRONTSWAP is disabled, every frontswap hook compiles into
+nothingness and the only overhead is a few extra bytes per swapon'ed
+swap device.  If CONFIG_FRONTSWAP is enabled but no frontswap "backend"
+registers, there is one extra global variable compared to zero for
+every swap page read or written.  If CONFIG_FRONTSWAP is enabled
+AND a frontswap backend registers AND the backend fails every "store"
+request (i.e. provides no memory despite claiming it might),
+CPU overhead is still negligible -- and since every frontswap fail
+precedes a swap page write-to-disk, the system is highly likely
+to be I/O bound and using a small fraction of a percent of a CPU
+will be irrelevant anyway.
+
+As for space, if CONFIG_FRONTSWAP is enabled AND a frontswap backend
+registers, one bit is allocated for every swap page for every swap
+device that is swapon'd.  This is added to the EIGHT bits (which
+was sixteen until about 2.6.34) that the kernel already allocates
+for every swap page for every swap device that is swapon'd.  (Hugh
+Dickins has observed that frontswap could probably steal one of
+the existing eight bits, but let's worry about that minor optimization
+later.)  For very large swap disks (which are rare) on a standard
+4K pagesize, this is 1MB per 32GB swap.
+
+When swap pages are stored in transcendent memory instead of written
+out to disk, there is a side effect that this may create more memory
+pressure that can potentially outweigh the other advantages.  A
+backend, such as zcache, must implement policies to carefully (but
+dynamically) manage memory limits to ensure this doesn't happen.
+
+3) OK, how about a quick overview of what this frontswap patch does
+   in terms that a kernel hacker can grok?
+
+Let's assume that a frontswap "backend" has registered during
+kernel initialization; this registration indicates that this
+frontswap backend has access to some "memory" that is not directly
+accessible by the kernel.  Exactly how much memory it provides is
+entirely dynamic and random.
+
+Whenever a swap-device is swapon'd frontswap_init() is called,
+passing the swap device number (aka "type") as a parameter.
+This notifies frontswap to expect attempts to "store" swap pages
+associated with that number.
+
+Whenever the swap subsystem is readying a page to write to a swap
+device (c.f swap_writepage()), frontswap_store is called.  Frontswap
+consults with the frontswap backend and if the backend says it does NOT
+have room, frontswap_store returns -1 and the kernel swaps the page
+to the swap device as normal.  Note that the response from the frontswap
+backend is unpredictable to the kernel; it may choose to never accept a
+page, it could accept every ninth page, or it might accept every
+page.  But if the backend does accept a page, the data from the page
+has already been copied and associated with the type and offset,
+and the backend guarantees the persistence of the data.  In this case,
+frontswap sets a bit in the "frontswap_map" for the swap device
+corresponding to the page offset on the swap device to which it would
+otherwise have written the data.
+
+When the swap subsystem needs to swap-in a page (swap_readpage()),
+it first calls frontswap_load() which checks the frontswap_map to
+see if the page was earlier accepted by the frontswap backend.  If
+it was, the page of data is filled from the frontswap backend and
+the swap-in is complete.  If not, the normal swap-in code is
+executed to obtain the page of data from the real swap device.
+
+So every time the frontswap backend accepts a page, a swap device read
+and (potentially) a swap device write are replaced by a "frontswap backend
+store" and (possibly) a "frontswap backend loads", which are presumably much
+faster.
+
+4) Can't frontswap be configured as a "special" swap device that is
+   just higher priority than any real swap device (e.g. like zswap,
+   or maybe swap-over-nbd/NFS)?
+
+No.  First, the existing swap subsystem doesn't allow for any kind of
+swap hierarchy.  Perhaps it could be rewritten to accomodate a hierarchy,
+but this would require fairly drastic changes.  Even if it were
+rewritten, the existing swap subsystem uses the block I/O layer which
+assumes a swap device is fixed size and any page in it is linearly
+addressable.  Frontswap barely touches the existing swap subsystem,
+and works around the constraints of the block I/O subsystem to provide
+a great deal of flexibility and dynamicity.
+
+For example, the acceptance of any swap page by the frontswap backend is
+entirely unpredictable. This is critical to the definition of frontswap
+backends because it grants completely dynamic discretion to the
+backend.  In zcache, one cannot know a priori how compressible a page is.
+"Poorly" compressible pages can be rejected, and "poorly" can itself be
+defined dynamically depending on current memory constraints.
+
+Further, frontswap is entirely synchronous whereas a real swap
+device is, by definition, asynchronous and uses block I/O.  The
+block I/O layer is not only unnecessary, but may perform "optimizations"
+that are inappropriate for a RAM-oriented device including delaying
+the write of some pages for a significant amount of time.  Synchrony is
+required to ensure the dynamicity of the backend and to avoid thorny race
+conditions that would unnecessarily and greatly complicate frontswap
+and/or the block I/O subsystem.  That said, only the initial "store"
+and "load" operations need be synchronous.  A separate asynchronous thread
+is free to manipulate the pages stored by frontswap.  For example,
+the "remotification" thread in RAMster uses standard asynchronous
+kernel sockets to move compressed frontswap pages to a remote machine.
+Similarly, a KVM guest-side implementation could do in-guest compression
+and use "batched" hypercalls.
+
+In a virtualized environment, the dynamicity allows the hypervisor
+(or host OS) to do "intelligent overcommit".  For example, it can
+choose to accept pages only until host-swapping might be imminent,
+then force guests to do their own swapping.
+
+There is a downside to the transcendent memory specifications for
+frontswap:  Since any "store" might fail, there must always be a real
+slot on a real swap device to swap the page.  Thus frontswap must be
+implemented as a "shadow" to every swapon'd device with the potential
+capability of holding every page that the swap device might have held
+and the possibility that it might hold no pages at all.  This means
+that frontswap cannot contain more pages than the total of swapon'd
+swap devices.  For example, if NO swap device is configured on some
+installation, frontswap is useless.  Swapless portable devices
+can still use frontswap but a backend for such devices must configure
+some kind of "ghost" swap device and ensure that it is never used.
+
+5) Why this weird definition about "duplicate stores"?  If a page
+   has been previously successfully stored, can't it always be
+   successfully overwritten?
+
+Nearly always it can, but no, sometimes it cannot.  Consider an example
+where data is compressed and the original 4K page has been compressed
+to 1K.  Now an attempt is made to overwrite the page with data that
+is non-compressible and so would take the entire 4K.  But the backend
+has no more space.  In this case, the store must be rejected.  Whenever
+frontswap rejects a store that would overwrite, it also must invalidate
+the old data and ensure that it is no longer accessible.  Since the
+swap subsystem then writes the new data to the read swap device,
+this is the correct course of action to ensure coherency.
+
+6) What is frontswap_shrink for?
+
+When the (non-frontswap) swap subsystem swaps out a page to a real
+swap device, that page is only taking up low-value pre-allocated disk
+space.  But if frontswap has placed a page in transcendent memory, that
+page may be taking up valuable real estate.  The frontswap_shrink
+routine allows code outside of the swap subsystem to force pages out
+of the memory managed by frontswap and back into kernel-addressable memory.
+For example, in RAMster, a "suction driver" thread will attempt
+to "repatriate" pages sent to a remote machine back to the local machine;
+this is driven using the frontswap_shrink mechanism when memory pressure
+subsides.
+
+7) Why does the frontswap patch create the new include file swapfile.h?
+
+The frontswap code depends on some swap-subsystem-internal data
+structures that have, over the years, moved back and forth between
+static and global.  This seemed a reasonable compromise:  Define
+them as global but declare them in a new include file that isn't
+included by the large number of source files that include swap.h.
+
+Dan Magenheimer, last updated April 9, 2012
MAINTAINERS +7 -0
index 2dcfca8..bc8905d 100644
@@ -2876,6 +2876,13 @@ F:	Documentation/power/freezing-of-tasks.txt
 F:	include/linux/freezer.h
 F:	kernel/freezer.c
 
+FRONTSWAP API
+M:	Konrad Rzeszutek Wilk <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	mm/frontswap.c
+F:	include/linux/frontswap.h
+
 FS-CACHE: LOCAL CACHING FOR NETWORK FILESYSTEMS
 M:	David Howells <[email protected]>
 L:	[email protected]
drivers/staging/ramster/zcache-main.c +4 -4
index 68b2e05..2627b3d 100644
@@ -3002,7 +3002,7 @@ static inline struct tmem_oid oswiz(unsigned type, u32 ind)
 	return oid;
 }
 
-static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
+static int zcache_frontswap_store(unsigned type, pgoff_t offset,
 				   struct page *page)
 {
 	u64 ind64 = (u64)offset;
@@ -3025,7 +3025,7 @@ static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
 
 /* returns 0 if the page was successfully gotten from frontswap, -1 if
  * was not present (should never happen!) */
-static int zcache_frontswap_get_page(unsigned type, pgoff_t offset,
+static int zcache_frontswap_load(unsigned type, pgoff_t offset,
 				   struct page *page)
 {
 	u64 ind64 = (u64)offset;
@@ -3080,8 +3080,8 @@ static void zcache_frontswap_init(unsigned ignored)
 }
 
 static struct frontswap_ops zcache_frontswap_ops = {
-	.put_page = zcache_frontswap_put_page,
-	.get_page = zcache_frontswap_get_page,
+	.store = zcache_frontswap_store,
+	.load = zcache_frontswap_load,
 	.invalidate_page = zcache_frontswap_flush_page,
 	.invalidate_area = zcache_frontswap_flush_area,
 	.init = zcache_frontswap_init
drivers/staging/zcache/zcache-main.c +5 -5
index 2734dac..784c796 100644
@@ -1835,7 +1835,7 @@ static int zcache_frontswap_poolid = -1;
  * Swizzling increases objects per swaptype, increasing tmem concurrency
  * for heavy swaploads.  Later, larger nr_cpus -> larger SWIZ_BITS
  * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from
- * frontswap_get_page(), but has side-effects. Hence using 8.
+ * frontswap_load(), but has side-effects. Hence using 8.
  */
 #define SWIZ_BITS		8
 #define SWIZ_MASK		((1 << SWIZ_BITS) - 1)
@@ -1849,7 +1849,7 @@ static inline struct tmem_oid oswiz(unsigned type, u32 ind)
 	return oid;
 }
 
-static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
+static int zcache_frontswap_store(unsigned type, pgoff_t offset,
 				   struct page *page)
 {
 	u64 ind64 = (u64)offset;
@@ -1870,7 +1870,7 @@ static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
 
 /* returns 0 if the page was successfully gotten from frontswap, -1 if
  * was not present (should never happen!) */
-static int zcache_frontswap_get_page(unsigned type, pgoff_t offset,
+static int zcache_frontswap_load(unsigned type, pgoff_t offset,
 				   struct page *page)
 {
 	u64 ind64 = (u64)offset;
@@ -1919,8 +1919,8 @@ static void zcache_frontswap_init(unsigned ignored)
 }
 
 static struct frontswap_ops zcache_frontswap_ops = {
-	.put_page = zcache_frontswap_put_page,
-	.get_page = zcache_frontswap_get_page,
+	.store = zcache_frontswap_store,
+	.load = zcache_frontswap_load,
 	.invalidate_page = zcache_frontswap_flush_page,
 	.invalidate_area = zcache_frontswap_flush_area,
 	.init = zcache_frontswap_init
drivers/xen/tmem.c +4 -4
index dcb7952..89f264c 100644
@@ -269,7 +269,7 @@ static inline struct tmem_oid oswiz(unsigned type, u32 ind)
 }
 
 /* returns 0 if the page was successfully put into frontswap, -1 if not */
-static int tmem_frontswap_put_page(unsigned type, pgoff_t offset,
+static int tmem_frontswap_store(unsigned type, pgoff_t offset,
 				   struct page *page)
 {
 	u64 ind64 = (u64)offset;
@@ -295,7 +295,7 @@ static int tmem_frontswap_put_page(unsigned type, pgoff_t offset,
  * returns 0 if the page was successfully gotten from frontswap, -1 if
  * was not present (should never happen!)
  */
-static int tmem_frontswap_get_page(unsigned type, pgoff_t offset,
+static int tmem_frontswap_load(unsigned type, pgoff_t offset,
 				   struct page *page)
 {
 	u64 ind64 = (u64)offset;
@@ -362,8 +362,8 @@ static int __init no_frontswap(char *s)
 __setup("nofrontswap", no_frontswap);
 
 static struct frontswap_ops __initdata tmem_frontswap_ops = {
-	.put_page = tmem_frontswap_put_page,
-	.get_page = tmem_frontswap_get_page,
+	.store = tmem_frontswap_store,
+	.load = tmem_frontswap_load,
 	.invalidate_page = tmem_frontswap_flush_page,
 	.invalidate_area = tmem_frontswap_flush_area,
 	.init = tmem_frontswap_init
include/linux/frontswap.h new file +127 -0

127 lines not on this page · raw message

include/linux/swap.h +4 -0
index b1fd5c7..50a55e2 100644
@@ -197,6 +197,10 @@ struct swap_info_struct {
 	struct block_device *bdev;	/* swap device or bdev of swap file */
 	struct file *swap_file;		/* seldom referenced */
 	unsigned int old_block_size;	/* seldom referenced */
+#ifdef CONFIG_FRONTSWAP
+	unsigned long *frontswap_map;	/* frontswap in-use, one bit per page */
+	atomic_t frontswap_pages;	/* frontswap pages in-use counter */
+#endif
 };
 
 struct swap_list_t {
include/linux/swapfile.h new file +13 -0
new file mode 100644
index 0000000..e282624
@@ -0,0 +1,13 @@
+#ifndef _LINUX_SWAPFILE_H
+#define _LINUX_SWAPFILE_H
+
+/*
+ * these were static in swapfile.c but frontswap.c needs them and we don't
+ * want to expose them to the dozens of source files that include swap.h
+ */
+extern spinlock_t swap_lock;
+extern struct swap_list_t swap_list;
+extern struct swap_info_struct *swap_info[];
+extern int try_to_unuse(unsigned int, bool, unsigned long);
+
+#endif /* _LINUX_SWAPFILE_H */
mm/Kconfig +17 -0
index e338407..2613c91 100644
@@ -379,3 +379,20 @@ config CLEANCACHE
 	  in a negligible performance hit.
 
 	  If unsure, say Y to enable cleancache
+
+config FRONTSWAP
+	bool "Enable frontswap to cache swap pages if tmem is present"
+	depends on SWAP
+	default n
+	help
+	  Frontswap is so named because it can be thought of as the opposite
+	  of a "backing" store for a swap device.  The data is stored into
+	  "transcendent memory", memory that is not directly accessible or
+	  addressable by the kernel and is of unknown and possibly
+	  time-varying size.  When space in transcendent memory is available,
+	  a significant swap I/O reduction may be achieved.  When none is
+	  available, all frontswap calls are reduced to a single pointer-
+	  compare-against-NULL resulting in a negligible performance hit
+	  and swap data is stored as normal on the matching swap device.
+
+	  If unsure, say Y to enable frontswap.
mm/Makefile +1 -0
index 50ec00e..306742a 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_HAVE_MEMBLOCK) += memblock.o
 
 obj-$(CONFIG_BOUNCE)	+= bounce.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o thrash.o
+obj-$(CONFIG_FRONTSWAP)	+= frontswap.o
 obj-$(CONFIG_HAS_DMA)	+= dmapool.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
mm/frontswap.c new file +314 -0

314 lines not on this page · raw message

mm/page_io.c +12 -0
index dc76b4d..34f0292 100644
@@ -18,6 +18,7 @@
 #include <linux/bio.h>
 #include <linux/swapops.h>
 #include <linux/writeback.h>
+#include <linux/frontswap.h>
 #include <asm/pgtable.h>
 
 static struct bio *get_swap_bio(gfp_t gfp_flags,
@@ -98,6 +99,12 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
 		unlock_page(page);
 		goto out;
 	}
+	if (frontswap_store(page) == 0) {
+		set_page_writeback(page);
+		unlock_page(page);
+		end_page_writeback(page);
+		goto out;
+	}
 	bio = get_swap_bio(GFP_NOIO, page, end_swap_bio_write);
 	if (bio == NULL) {
 		set_page_dirty(page);
@@ -122,6 +129,11 @@ int swap_readpage(struct page *page)
 
 	VM_BUG_ON(!PageLocked(page));
 	VM_BUG_ON(PageUptodate(page));
+	if (frontswap_load(page) == 0) {
+		SetPageUptodate(page);
+		unlock_page(page);
+		goto out;
+	}
 	bio = get_swap_bio(GFP_KERNEL, page, end_swap_bio_read);
 	if (bio == NULL) {
 		unlock_page(page);
mm/swapfile.c +41 -13

175 lines not on this page · raw message

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
In reply to a message not in the archive
Quoted 5 lines · Konrad Rzeszutek Wilk

I posted this while I was on vacation and just realized that I hadn't put in the usual "GIT PULL" subject. Sorry about that - so sending this in case this GIT PULL got lost in your 'not-git-pull-ignore-for-two-weeks' folder. Cheers!

So that isn't actually the main reason I hadn't pulled, although being emailed a few days before the merge window opened did mean that it was fairly low down in my mailbox anyway..

No, the real reason is that for new features like this - features that I don't really see myself using personally and that I'm not all that personally excited about - I *really* want others to pipe up with "yes, we're using this, and yes, we want this to be merged".

It doesn't seem to be huge, which is great, but the deathly silence of nobody speaking up and saying "yes please", makes me go "ok, I won't pull if nobody speaks up for the feature".

Linus

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Linus Torvalds

No, the real reason is that for new features like this - features that I don't really see myself using personally and that I'm not all that personally excited about - I *really* want others to pipe up with "yes, we're using this, and yes, we want this to be merged".

It doesn't seem to be huge, which is great, but the deathly silence of nobody speaking up and saying "yes please", makes me go "ok, I won't pull if nobody speaks up for the feature".

Hmm, I had thought that Dan already went through this exercise, but in case I'm mis-remembering, I'd just like to make clear that for the last couple of years we've been making this (or its predecessor versions) available to our SLE and openSUSE users. I can't, however, provide numbers of actual employments of it in the field (such simply don't exist).

Jan

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Linus Torvalds

Hi Linus,

Quoted 12 lines · Linus Torvalds
Quoted 5 lines · Konrad Rzeszutek Wilk

I posted this while I was on vacation and just realized that I hadn't put in the usual "GIT PULL" subject. Sorry about that - so sending this in case this GIT PULL got lost in your 'not-git-pull-ignore-for-two-weeks' folder. Cheers!

So that isn't actually the main reason I hadn't pulled, although being emailed a few days before the merge window opened did mean that it was fairly low down in my mailbox anyway..

Quoted 8 lines

No, the real reason is that for new features like this - features that I don't really see myself using personally and that I'm not all that personally excited about - I *really* want others to pipe up with "yes, we're using this, and yes, we want this to be merged".

It doesn't seem to be huge, which is great, but the deathly silence of nobody speaking up and saying "yes please", makes me go "ok, I won't pull if nobody speaks up for the feature".

We (IBM LTC) are interested in this feature being included. We are using it to enable main memory compression via the zcache driver in the staging tree. A lot of development is happening on the zcache and zsmalloc drivers by Nitin, Minchan, and me. But it is all (mostly) in vain unless we can get frontswap.

I posted some numbers here...
https://lkml.org/lkml/2012/3/22/383

that demonstrate the benefit of zcache (another topic), but all that isn't even an option without frontswap.

Frontswap is the swap-space complement to Cleancache which has already been accepted.

Sorry for my late response, but we would be very interested in seeing this feature in mainline.

Thanks,
Seth Jennings
IBM Linux Technology Center
POWER Virtualization

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds
Quoted 5 lines · Konrad Rzeszutek Wilk

I posted this while I was on vacation and just realized that I hadn't put in the usual "GIT PULL" subject. Sorry about that - so sending this in case this GIT PULL got lost in your 'not-git-pull-ignore-for-two-weeks' folder. Cheers!

So that isn't actually the main reason I hadn't pulled, although being emailed a few days before the merge window opened did mean that it was fairly low down in my mailbox anyway..

Ah, I was thinking that you might have gotten bored during that weekend and would pounce on some new code :-) I was probably projecting as I was near the vacation and needed my code-fix.

Quoted 9 lines

No, the real reason is that for new features like this - features that I don't really see myself using personally and that I'm not all that personally excited about - I *really* want others to pipe up with "yes, we're using this, and yes, we want this to be merged".

It doesn't seem to be huge, which is great, but the deathly silence of nobody speaking up and saying "yes please", makes me go "ok, I won't pull if nobody speaks up for the feature".

Ooh, Wim Coekaerts just posted over the weekend a blog about his excitement about it: https://blogs.oracle.com/wim/entry/from_the_research_department_ramster

Also over the last couple of months I had gotten emails about people using it. Let me see if I can get their consent to either quote their emails or just ask them to reply to this thread.

Also both Jan (SuSE) and Seth (IBM) are equally excited about this code as it is being used in a distro and in embedded hardware.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
In reply to Linus Torvalds
Quoted 4 lines · Linus Torvalds

No, the real reason is that for new features like this - features that I don't really see myself using personally and that I'm not all that personally excited about - I *really* want others to pipe up with "yes, we're using this, and yes, we want this to be merged".

I do not like some of the implementation details in the code, but I have no idea how to do it better.

The functionality, especially zram and frontswap, are very desirable and would be good to have.

Pulling this code seems like the right thing to do.

Signature · 8 lines
All rights reversed

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 3 lines

Also over the last couple of months I had gotten emails about people using it. Let me see if I can get their consent to either quote their emails or just ask them to reply to this thread.

Asked some of the folks to pipe in, but in the mean-time here are some links.

Quoted 1 line

From Oracle: Kurt Hackel says "interest in seeing frontswap merged upstream" because

it is already used in OracleVM. https://lkml.org/lkml/2011/10/27/215
Avi Miller says "we see this as a critical feature."
https://lkml.org/lkml/2011/10/27/252 (product manager).

Some Android ports have picked it up [mainly to use zcache which depends on frontswap]:
- An LG and HTC kernel ROM has incorporated frontswap.
http://androidforums.com/spectrum-all-things-root/522953-rom-5-26-12-broken-out-spectrum-3-0-w-blitzkrieg-kernel.html
- A GalaxyS-based kernel port has included frontswap.
http://hdtechvideo.com/community/index.php?threads/devil2_0-94.245/
- CyanogenMod just added frontswap.
http://www.andro9.in/2012/05/cyanogenmod-9-ics-404-weeklies-for-lg.html

Many people piped up last year at a previous merge proposal. Here are some from LKML postings:
- Brian King says IBM is actively looking at utilizing frontswap for IBM Power and would welcome its inclusion in mainline.
https://lkml.org/lkml/2011/10/27/273
- Nitin Gupta, author of zram, has stated that zcache is in many ways superior to zram... but this assumes frontswap is merged.
https://lkml.org/lkml/2011/10/28/8
- Ed Tomlinson says "I'd love to see this in the kernel."
https://lkml.org/lkml/2011/10/29/53
- Sasha Levin and "CJ" worked on the KVM PoC and commented that
https://lkml.org/lkml/2011/10/28/8
- Ed Tomlinson says "I'd love to see this in the kernel."
https://lkml.org/lkml/2011/10/29/53
- While Andrea Arcangeli voiced objections last year
https://lkml.org/lkml/2011/10/31/186 he expressed at LSF/MM 2012 that many of his issues are now resolved and sufficient progress has been made to merge frontswap (with more work needed in zcache before zcache can be promoted out of staging).
- James Bottomley requested more benchmarking on zcache and some excellent results were published and presented at LSF/MM 2012.
http://lwn.net/Articles/490501/
- Valdis Kletnieks points out that he needs it in machines that are maxed out on RAM. https://lkml.org/lkml/2011/11/6/157

Thanks!

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 8 lines
Quoted 8 lines

No, the real reason is that for new features like this - features that I don't really see myself using personally and that I'm not all that personally excited about - I *really* want others to pipe up with "yes, we're using this, and yes, we want this to be merged".

It doesn't seem to be huge, which is great, but the deathly silence of nobody speaking up and saying "yes please", makes me go "ok, I won't pull if nobody speaks up for the feature".

Hey Linus.

A couple of folks here and in the past replies shared their thoughts, but I don't think I said anything beyond dry technical details.

So I am really really excited about this. I think this "memory-that-is-not-your-old-memory" is an aspect of technology that is going to evolve in interesting ways. The same way that SSDs kicked the notion that "we have tons of milliseconds to do stuff before it hits the platter" without costing a lot of money, the PCIe memory cards (or whatever marketing name is used), PCIe inter-machine links, or even on the embedded side of stuffing more in less, offer fantastic opportunities. The frontswap provides a means to bridge a lot of these technologies and share common concepts among them - there is the compression for the embedded world, there is de-duplication for the starving virtualization world, there is memory sharing across nodes, and in my crystal ball I see are those PCIe memory cards being used too. It is really fun and invigorating and this patchset provides the basic underpinnings for a lot of it.

So yes please pull!

git://git.kernel.org/pub/scm/linux/kernel/git/konrad/mm.git
stable/frontswap.v16-tag

Thanks!

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>