Skip to contentSkip to conversation

(Take 2): tmem: Implement preswap on top of tmem layer

RFC PATCH In review Dan Magenheimer 1 participant 1 message Jul 7, 2009

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

RFC PATCH 3/4 (Take 2): tmem: Implement preswap on top of tmem layer

Tmem [PATCH 3/4] (Take 2): Implement preswap on top of tmem layer.

Hooks added to existing page swap routines
and data structures to:
1) create a tmem pool when any swap "type" is created (one pool covers all open swap types)
2) attempt to "put" pages to preswap prior to writing to a swap disk and fallback to writing to swap disk if put fails
3) track successfully put pages with a new bit-per-page preswap_map array
4) "get" pages from preswap if preswap_map indicates
5) destroy the tmem pool when no more swap types are in use
6) implement "shrinking" to repatriate pages from preswap into the swap cache (or purge entirely if no longer needed)
7) Provide a sysctl interface to support both userland shrinking and determine number of pages currently in preswap

 include/linux/swap.h                     |   57 ++++
 include/linux/sysctl.h                   |    1 
 kernel/sysctl.c                          |   12 
 mm/Kconfig                               |    8 
 mm/Makefile                              |    1 
 mm/page_io.c                             |   12 
 mm/preswap.c                             |  273 +++++++++++++++++++++
 mm/swapfile.c                            |   46 +++
 8 files changed, 404 insertions(+), 6 deletions(-)
mm/page_io.c +12 -0
@@ -102,6 +102,12 @@ int swap_writepage(struct page *page, st
 		unlock_page(page);
 		goto out;
 	}
+	if (preswap_put(page) == 1) {
+		set_page_writeback(page);
+		unlock_page(page);
+		end_page_writeback(page);
+		goto out;
+	}
 	bio = get_swap_bio(GFP_NOIO, page_private(page), page,
 				end_swap_bio_write);
 	if (bio == NULL) {
@@ -134,6 +140,12 @@ int swap_readpage(struct file *file, str
 		ret = -ENOMEM;
 		goto out;
 	}
+	if (preswap_get(page) == 1) {
+		SetPageUptodate(page);
+		unlock_page(page);
+		bio_put(bio);
+		goto out;
+	}
 	count_vm_event(PSWPIN);
 	submit_bio(READ, bio);
 out:
mm/swapfile.c +40 -6

131 lines not on this page · raw message

include/linux/swap.h +57 -0

77 lines not on this page · raw message

mm/preswap.c +273 -0

273 lines not on this page · raw message

include/linux/sysctl.h +1 -0
@@ -205,6 +205,7 @@ enum
 	VM_PANIC_ON_OOM=33,	/* panic at out-of-memory */
 	VM_VDSO_ENABLED=34,	/* map VDSO into new processes? */
 	VM_MIN_SLAB=35,		 /* Percent pages ignored by zone reclaim */
+	VM_PRESWAP_PAGES=36,	/* pages/target_pages in preswap */
 };
 
 
kernel/sysctl.c +12 -0
@@ -1282,6 +1282,18 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= &scan_unevictable_handler,
 	},
 #endif
+#ifdef CONFIG_PRESWAP
+	{
+		.ctl_name	= VM_PRESWAP_PAGES,
+		.procname	= "preswap",
+		.data		= NULL,
+		.maxlen		= sizeof(unsigned long),
+		.mode		= 0644,
+		.proc_handler	= &preswap_sysctl_handler,
+		.extra1		= (void *)&preswap_zero,
+		.extra2		= (void *)&preswap_infinity,
+	},
+#endif
 /*
  * NOTE: do not add new entries to this table unless you have read
  * Documentation/sysctl/ctl_unnumbered.txt
mm/Kconfig +8 -0
@@ -271,3 +271,11 @@ config PRECACHE
 	  Allows the transcendent memory pool to be used to store clean
 	  page-cache pages which, under some circumstances, will greatly
 	  reduce paging and thus improve performance.
+
+config PRESWAP
+	bool "Swap pages to transcendent memory"
+	depends on TMEM
+	help
+	  Allows the transcendent memory pool to be used as a pseudo-swap
+	  device which, under some circumstances, will greatly reduce
+	  swapping and thus improve performance.
mm/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_PROC_PAGE_MONITOR) += pagew
 obj-$(CONFIG_BOUNCE)	+= bounce.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o thrash.o
 obj-$(CONFIG_TMEM)	+= tmem.o
+obj-$(CONFIG_PRESWAP)	+= preswap.o
 obj-$(CONFIG_PRECACHE)	+= precache.o
 obj-$(CONFIG_HAS_DMA)	+= dmapool.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o

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