Skip to contentSkip to conversation

Tmem [PATCH 3/5] (Take 3): Implement frontswap on top of tmem layer

PATCH Dan Magenheimer 1 participant 1 message Dec 18, 2009

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

Tmem [PATCH 3/5] (Take 3): Implement frontswap 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 frontswap 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 frontswap_map array
4) "get" pages from frontswap if frontswap_map indicates
5) destroy the tmem pool when no more swap types are in use
6) implement "shrinking" to repatriate pages from frontswap 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 frontswap

The term "frontswap" is coined because it is the opposite of a "backing store" for swap disks. The previous term ("preswap") was deemed too generic and overloaded.

 include/linux/swap.h                     |   51 +++
 include/linux/sysctl.h                   |    1 
 kernel/sysctl.c                          |   11 
 mm/frontswap.c                           |  319 +++++++++++++++++++++
 mm/page_io.c                             |   12 
 mm/swapfile.c                            |   43 ++
 6 files changed, 430 insertions(+), 7 deletions(-)
mm/page_io.c +12 -0
@@ -102,6 +102,12 @@ int swap_writepage(struct page *page, st
 		unlock_page(page);
 		goto out;
 	}
+	if (frontswap_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 page *page)
 		ret = -ENOMEM;
 		goto out;
 	}
+	if (frontswap_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 +37 -6

122 lines not on this page · raw message

include/linux/swap.h +51 -0

71 lines not on this page · raw message

mm/frontswap.c +319 -0

319 lines not on this page · raw message

include/linux/sysctl.h +0 -1
@@ -206,7 +206,6 @@ enum
 	VM_MIN_SLAB=35,		 /* Percent pages ignored by zone reclaim */
 };
 
-
 /* CTL_NET names: */
 enum
 {
kernel/sysctl.c +11 -0
@@ -195,6 +195,9 @@ extern struct ctl_table inotify_table[];
 #ifdef CONFIG_EPOLL
 extern struct ctl_table epoll_table[];
 #endif
+#ifdef CONFIG_TMEM
+extern struct ctl_table tmem_table[];
+#endif
 
 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
 int sysctl_legacy_va_layout;
@@ -1422,6 +1425,14 @@ static struct ctl_table vm_table[] = {
 		.extra2		= &one,
 	},
 #endif
+#ifdef CONFIG_TMEM
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "tmem",
+		.mode		= 0555,
+		.child		= tmem_table,
+	},
+#endif
 
 /*
  * NOTE: do not add new entries to this table unless you have read

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