Skip to contentSkip to conversation

transcendent memory ("tmem") linux-side changes

PATCH In review Dan Magenheimer 2 participants 4 messages Jun 9, 2009 – Jun 10, 2009

Subsystems (8)
Memory management VFS MM core OCFS2 +4 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 transcendent memory ("tmem") linux-side changes

Transcendent memory ("tmem") for Linux

Tmem, when called from a tmem-capable (paravirtualized) guest, makes use of otherwise unutilized ("fallow") memory to create and manage pools of pages that can be accessed from the guest either as "ephemeral" pages or as "persistent" pages. In either case, the pages are not directly addressible by the guest, only copied to and fro via the tmem interface. Ephemeral pages are a nice place for a guest to put recently evicted clean pages that it might need again; these pages can be reclaimed synchronously by Xen for other guests or other uses. Persistent pages are a nice place for a guest to put "swap" pages to avoid sending them to disk. These pages retain data as long as the guest lives, but count against the guest memory allocation.

This patch contains the Linux paravirtualization changes to complement the tmem Xen patch (xen-unstable c/s 19646). It implements "precache" (ext3 only as of now), "preswap", and limited "shared precache" (ocfs2 only as of now) support. CONFIG options are required to turn on
the support (but in this patch they default to "y"). If the underlying Xen does not have tmem support or has it turned off, this is sensed early to avoid nearly all hypercalls.

Lots of useful prose about tmem can be found at
http://oss.oracle.com/projects/tmem

fs/buffer.c +6 -0
diff -r ca12928cdafe fs/buffer.c
@@ -41,6 +41,7 @@
 #include <linux/bitops.h>
 #include <linux/mpage.h>
 #include <linux/bit_spinlock.h>
+#include <linux/precache.h>
 
 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
 static void invalidate_bh_lrus(void);
@@ -482,6 +483,11 @@ void invalidate_bdev(struct block_device
 	 * that, but not until that's cleaned up.
 	 */
 	invalidate_inode_pages(mapping);
+
+	/* 99% of the time, we don't need to flush the precache on the bdev.
+	 * But, for the strange corners, lets be cautious
+	 */
+	precache_flush_inode(mapping);
 }
 
 /*
fs/ext3/super.c +2 -0
diff -r ca12928cdafe fs/ext3/super.c
@@ -35,6 +35,7 @@
 #include <linux/namei.h>
 #include <linux/quotaops.h>
 #include <linux/seq_file.h>
+#include <linux/precache.h>
 
 #include <asm/uaccess.h>
 
@@ -1167,6 +1168,7 @@ static int ext3_setup_super(struct super
 	} else {
 		printk("internal journal\n");
 	}
+	precache_init(sb);
 	return res;
 }
 
fs/mpage.c +8 -0
diff -r ca12928cdafe fs/mpage.c
@@ -26,6 +26,7 @@
 #include <linux/writeback.h>
 #include <linux/backing-dev.h>
 #include <linux/pagevec.h>
+#include <linux/precache.h>
 
 /*
  * I/O completion handler for multipage BIOs.
@@ -296,6 +297,13 @@ do_mpage_readpage(struct bio *bio, struc
 		}
 	} else if (fully_mapped) {
 		SetPageMappedToDisk(page);
+	}
+
+	if (fully_mapped &&
+	    blocks_per_page == 1 && !PageUptodate(page) &&
+	    precache_get(page->mapping, page->index, page) == 1) {
+		SetPageUptodate(page);
+		goto confused;
 	}
 
 	/*
fs/ocfs2/super.c +5 -2
diff -r ca12928cdafe fs/ocfs2/super.c
@@ -39,6 +39,7 @@
 #include <linux/parser.h>
 #include <linux/crc32.h>
 #include <linux/debugfs.h>
+#include <linux/precache.h>
 
 #include <cluster/nodemanager.h>
 
@@ -1457,16 +1458,18 @@ static int ocfs2_initialize_super(struct
 
 	di = (struct ocfs2_dinode *) bitmap_bh->b_data;
 	osb->bitmap_cpg = le16_to_cpu(di->id2.i_chain.cl_cpg);
-	brelse(bitmap_bh);
 	mlog(0, "cluster bitmap inode: %llu, clusters per group: %u\n",
 	     (unsigned long long)osb->bitmap_blkno, osb->bitmap_cpg);
 
 	status = ocfs2_init_slot_info(osb);
 	if (status < 0) {
 		mlog_errno(status);
-		goto bail;
+		goto bail_rel;
 	}
+	shared_precache_init(sb, &di->id2.i_super.s_uuid[0]);
 
+bail_rel:
+	brelse(bitmap_bh);
 bail:
 	mlog_exit(status);
 	return status;
fs/super.c +8 -0
diff -r ca12928cdafe fs/super.c
@@ -37,6 +37,7 @@
 #include <linux/idr.h>
 #include <linux/kobject.h>
 #include <linux/mutex.h>
+#include <linux/precache.h>
 #include <asm/uaccess.h>
 
 
@@ -93,6 +94,9 @@ static struct super_block *alloc_super(s
 		s->s_qcop = sb_quotactl_ops;
 		s->s_op = &default_op;
 		s->s_time_gran = 1000000000;
+#ifdef CONFIG_PRECACHE
+		s->precache_poolid = -1;
+#endif
 	}
 out:
 	return s;
@@ -181,6 +185,7 @@ void deactivate_super(struct super_block
 		DQUOT_OFF(s);
 		down_write(&s->s_umount);
 		fs->kill_sb(s);
+		precache_flush_filesystem(s);
 		put_filesystem(fs);
 		put_super(s);
 	}
@@ -777,6 +782,9 @@ int get_sb_nodev(struct file_system_type
 		return error;
 	}
 	s->s_flags |= MS_ACTIVE;
+#ifdef CONFIG_PRECACHE
+	s->precache_poolid = -2;
+#endif
 	return simple_set_mnt(mnt, s);
 }
 
include/asm-i386/mach-xen/asm/hypercall.h +6 -0
diff -r ca12928cdafe include/asm-i386/mach-xen/asm/hypercall.h
@@ -404,6 +404,12 @@ HYPERVISOR_kexec_op(
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_tmem_op(
+	struct tmem_op *op)
+{
+	return _hypercall1(int, tmem_op, op);
+}
 
 
 #endif /* __HYPERCALL_H__ */
include/asm-x86_64/mach-xen/asm/hypercall.h +7 -0
diff -r ca12928cdafe include/asm-x86_64/mach-xen/asm/hypercall.h
@@ -405,4 +405,11 @@ HYPERVISOR_kexec_op(
 	return _hypercall2(int, kexec_op, op, args);
 }
 
+static inline int __must_check
+HYPERVISOR_tmem_op(
+	struct tmem_op *op)
+{
+	return _hypercall1(int, tmem_op, op);
+}
+
 #endif /* __HYPERCALL_H__ */
include/linux/fs.h +3 -0
diff -r ca12928cdafe include/linux/fs.h
@@ -907,6 +907,9 @@ struct super_block {
 	/* Granularity of c/m/atime in ns.
 	   Cannot be worse than a second */
 	u32		   s_time_gran;
+#ifdef CONFIG_PRECACHE
+	u32                precache_poolid;
+#endif
 };
 
 extern struct timespec current_fs_time(struct super_block *sb);
include/linux/precache.h new file +55 -0

55 lines not on this page · raw message

include/linux/swap.h +63 -1

84 lines not on this page · raw message

include/linux/sysctl.h +1 -0
diff -r ca12928cdafe include/linux/sysctl.h
@@ -200,6 +200,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 */
 };
 
 
include/xen/interface/xen.h +25 -0
diff -r ca12928cdafe include/xen/interface/xen.h
@@ -91,6 +91,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
 #define __HYPERVISOR_sysctl               35
 #define __HYPERVISOR_domctl               36
 #define __HYPERVISOR_kexec_op             37
+#define __HYPERVISOR_tmem_op              38
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
@@ -324,6 +325,30 @@ DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
 #define VMASST_TYPE_pae_extended_cr3     3
 
 #define MAX_VMASST_TYPE                  3
+
+#ifndef __ASSEMBLY__
+struct tmem_op {
+    uint32_t cmd;
+    int32_t pool_id; /* private > 0; shared < 0; 0 is invalid */
+    union {
+        struct {  /* for cmd == TMEM_NEW_POOL */
+            uint64_t uuid[2];
+            uint32_t flags;
+        };
+        struct {
+            uint64_t object;
+            uint32_t index;
+            uint32_t tmem_offset;
+            uint32_t pfn_offset;
+            uint32_t len;
+            XEN_GUEST_HANDLE(void) gmfn; /* guest machine page frame */
+        };
+    };
+};
+typedef struct tmem_op tmem_op_t;
+DEFINE_XEN_GUEST_HANDLE(tmem_op_t);
+
+#endif
 
 #ifndef __ASSEMBLY__
 
kernel/sysctl.c +12 -0
diff -r ca12928cdafe kernel/sysctl.c
@@ -965,6 +965,18 @@ static ctl_table vm_table[] = {
 		.proc_handler	= &proc_dointvec,
 		.strategy	= &sysctl_intvec,
 		.extra1		= &zero,
+	},
+#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
 	{ .ctl_name = 0 }
mm/Kconfig +31 -0
diff -r ca12928cdafe mm/Kconfig
@@ -152,3 +152,34 @@ config RESOURCES_64BIT
 	default 64BIT
 	help
 	  This option allows memory and IO resources to be 64 bit.
+
+#
+# support for transcendent memory
+#
+config TMEM
+	bool "Transcendent memory support"
+	def_bool y
+	depends on XEN
+	help
+	  In a virtualized environment, allows unused and underutilized
+	  system physical memory to be made accessible through a narrow
+	  well-defined page-copy-based API.  If unsure, say Y.
+
+config PRECACHE
+	bool "Cache clean pages in transcendent memory"
+	def_bool y
+	depends on TMEM
+	help
+	  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.  If unsure, say Y.
+
+config PRESWAP
+	bool "Swap pages to transcendent memory"
+	def_bool y
+	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.  If unsure, say Y.
+
mm/Makefile +3 -0
diff -r ca12928cdafe mm/Makefile
@@ -13,6 +13,9 @@ obj-y			:= bootmem.o filemap.o mempool.o
 			   prio_tree.o util.o mmzone.o vmstat.o $(mmu-y)
 
 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_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
mm/filemap.c +11 -0
diff -r ca12928cdafe mm/filemap.c
@@ -30,6 +30,7 @@
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/cpuset.h>
+#include <linux/precache.h>
 #include "filemap.h"
 #include "internal.h"
 
@@ -115,6 +116,16 @@ void __remove_from_page_cache(struct pag
 void __remove_from_page_cache(struct page *page)
 {
 	struct address_space *mapping = page->mapping;
+
+	/*
+	 * if we're uptodate, flush out into the precache, otherwise
+	 * invalidate any existing precache entries.  We can't leave
+	 * stale data around in the precache once our page is gone
+	 */
+	if (PageUptodate(page))
+		precache_put(page->mapping, page->index, page);
+	else
+		precache_flush(page->mapping, page->index);
 
 	radix_tree_delete(&mapping->page_tree, page->index);
 	page->mapping = NULL;
mm/page_io.c +16 -1
diff -r ca12928cdafe mm/page_io.c
@@ -99,10 +99,18 @@ int swap_writepage(struct page *page, st
 		ret = -ENOMEM;
 		goto out;
 	}
+
+	set_page_writeback(page);
+	if (preswap_put(page) == 1) {
+		unlock_page(page);
+		end_page_writeback(page);
+		bio_put(bio);
+		goto out;
+	}
+
 	if (wbc->sync_mode == WB_SYNC_ALL)
 		rw |= (1 << BIO_RW_SYNC);
 	count_vm_event(PSWPOUT);
-	set_page_writeback(page);
 	unlock_page(page);
 	submit_bio(rw, bio);
 out:
@@ -116,6 +124,13 @@ int swap_readpage(struct file *file, str
 
 	BUG_ON(!PageLocked(page));
 	ClearPageUptodate(page);
+
+	if (preswap_get(page) == 1) {
+		SetPageUptodate(page);
+		unlock_page(page);
+		goto out;
+	}
+
 	bio = get_swap_bio(GFP_KERNEL, page_private(page), page,
 				end_swap_bio_read);
 	if (bio == NULL) {
mm/precache.c new file +140 -0

140 lines not on this page · raw message

mm/preswap.c new file +271 -0

271 lines not on this page · raw message

mm/swapfile.c +29 -4
diff -r ca12928cdafe mm/swapfile.c
@@ -284,6 +284,7 @@ static int swap_entry_free(struct swap_i
 				swap_list.next = p - swap_info;
 			nr_swap_pages++;
 			p->inuse_pages--;
+			preswap_flush(p - swap_info, offset);
 		}
 	}
 	return count;
@@ -623,7 +624,7 @@ static int unuse_mm(struct mm_struct *mm
  * Recycle to start on reaching the end, returning 0 when empty.
  */
 static unsigned int find_next_to_unuse(struct swap_info_struct *si,
-					unsigned int prev)
+				unsigned int prev, unsigned int preswap)
 {
 	unsigned int max = si->max;
 	unsigned int i = prev;
@@ -649,6 +650,12 @@ static unsigned int find_next_to_unuse(s
 			prev = 0;
 			i = 1;
 		}
+		if (preswap) {
+			if (preswap_test(si, i))
+				break;
+			else
+				continue;
+		}
 		count = si->swap_map[i];
 		if (count && count != SWAP_MAP_BAD)
 			break;
@@ -660,8 +667,12 @@ static unsigned int find_next_to_unuse(s
  * We completely avoid races by reading each swap page in advance,
  * and then search for the process using it.  All the necessary
  * page table adjustments can then be made atomically.
+ *
+ * if the boolean preswap is true, only unuse pages_to_unuse pages;
+ * pages_to_unuse==0 means all pages
  */
-static int try_to_unuse(unsigned int type)
+int try_to_unuse(unsigned int type, unsigned int preswap,
+		unsigned long pages_to_unuse)
 {
 	struct swap_info_struct * si = &swap_info[type];
 	struct mm_struct *start_mm;
@@ -697,7 +708,7 @@ static int try_to_unuse(unsigned int typ
 	 * one pass through swap_map is enough, but not necessarily:
 	 * there are races when an instance of an entry might be missed.
 	 */
-	while ((i = find_next_to_unuse(si, i)) != 0) {
+	while ((i = find_next_to_unuse(si, i, preswap)) != 0) {
 		if (signal_pending(current)) {
 			retval = -EINTR;
 			break;
@@ -876,6 +887,8 @@ static int try_to_unuse(unsigned int typ
 		 * interactive performance.
 		 */
 		cond_resched();
+		if (preswap && pages_to_unuse && !--pages_to_unuse)
+			break;
 	}
 
 	mmput(start_mm);
@@ -1198,7 +1211,7 @@ asmlinkage long sys_swapoff(const char _
 	spin_unlock(&swap_lock);
 
 	current->flags |= PF_SWAPOFF;
-	err = try_to_unuse(type);
+	err = try_to_unuse(type, 0, 0);
 	current->flags &= ~PF_SWAPOFF;
 
 	if (err) {
@@ -1242,9 +1255,12 @@ asmlinkage long sys_swapoff(const char _
 	swap_map = p->swap_map;
 	p->swap_map = NULL;
 	p->flags = 0;
+	preswap_flush_area(p - swap_info);
 	spin_unlock(&swap_lock);
 	mutex_unlock(&swapon_mutex);
 	vfree(swap_map);
+	if (p->preswap_map)
+		vfree(p->preswap_map);
 	inode = mapping->host;
 	if (S_ISBLK(inode->i_mode)) {
 		struct block_device *bdev = I_BDEV(inode);
@@ -1553,6 +1569,9 @@ asmlinkage long sys_swapon(const char __
 
 		error = 0;
 		memset(p->swap_map, 0, maxpages * sizeof(short));
+		p->preswap_map = preswap_malloc(maxpages / sizeof(long));
+		if (p->preswap_map)
+			memset(p->preswap_map, 0, maxpages / sizeof(long));
 		for (i = 0; i < swap_header->info.nr_badpages; i++) {
 			int page_nr = swap_header->info.badpages[i];
 			if (page_nr <= 0 || page_nr >= swap_header->info.last_page)
@@ -1615,6 +1634,7 @@ asmlinkage long sys_swapon(const char __
 	} else {
 		swap_info[prev].next = p - swap_info;
 	}
+	preswap_init(p - swap_info);
 	spin_unlock(&swap_lock);
 	mutex_unlock(&swapon_mutex);
 	error = 0;
@@ -1729,6 +1749,8 @@ int valid_swaphandles(swp_entry_t entry,
 
 	if (!page_cluster)	/* no readahead */
 		return 0;
+	if (preswap_test(swapdev, swp_offset(entry)))
+		return 0;
 	toff = (swp_offset(entry) >> page_cluster) << page_cluster;
 	if (!toff)		/* first page is swap header */
 		toff++, i--;
@@ -1744,6 +1766,9 @@ int valid_swaphandles(swp_entry_t entry,
 			break;
 		if (swapdev->swap_map[toff] == SWAP_MAP_BAD)
 			break;
+		/* Don't read in preswap pages */
+		if (preswap_test(swapdev, toff))
+			break;
 		toff++;
 		ret++;
 	} while (--i);
mm/tmem.c new file +41 -0

41 lines not on this page · raw message

mm/tmem.h new file +111 -0

111 lines not on this page · raw message

mm/truncate.c +10 -1
diff -r ca12928cdafe mm/truncate.c
@@ -12,13 +12,14 @@
 #include <linux/module.h>
 #include <linux/pagemap.h>
 #include <linux/pagevec.h>
+#include <linux/precache.h>
 #include <linux/buffer_head.h>	/* grr. try_to_release_page,
 				   do_invalidatepage */
-
 
 static inline void truncate_partial_page(struct page *page, unsigned partial)
 {
 	memclear_highpage_flush(page, partial, PAGE_CACHE_SIZE-partial);
+	precache_flush(page->mapping, page->index);
 	if (PagePrivate(page))
 		do_invalidatepage(page, partial);
 }
@@ -46,6 +47,10 @@ truncate_complete_page(struct address_sp
 	ClearPageUptodate(page);
 	ClearPageMappedToDisk(page);
 	remove_from_page_cache(page);
+	/* this must be after the remove_from_page_cache which
+	 * calls precache_put
+	 */
+	precache_flush(mapping, page->index);
 	page_cache_release(page);	/* pagecache ref */
 }
 
@@ -118,6 +123,7 @@ void truncate_inode_pages_range(struct a
 	pgoff_t next;
 	int i;
 
+	precache_flush_inode(mapping);
 	if (mapping->nrpages == 0)
 		return;
 
@@ -191,6 +197,7 @@ void truncate_inode_pages_range(struct a
 		}
 		pagevec_release(&pvec);
 	}
+	precache_flush_inode(mapping);
 }
 EXPORT_SYMBOL(truncate_inode_pages_range);
 
@@ -324,6 +331,7 @@ int invalidate_inode_pages2_range(struct
 	int did_range_unmap = 0;
 	int wrapped = 0;
 
+	precache_flush_inode(mapping);
 	pagevec_init(&pvec, 0);
 	next = start;
 	while (next <= end && !ret && !wrapped &&
@@ -379,6 +387,7 @@ int invalidate_inode_pages2_range(struct
 		pagevec_release(&pvec);
 		cond_resched();
 	}
+	precache_flush_inode(mapping);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(invalidate_inode_pages2_range);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Re: [PATCH] [linux-2.6.18-xen] transcendent memory ("tmem")linux-side changes

Quoted 1 line
Quoted 1 line
Quoted 1 line

Dan Magenheimer <[email protected]> 10.06.09 00:17 >>>

A few general remarks:

Quoted 11 lines
include/linux/swap.h +1 -0
@@ -6,6 +6,7 @@
 #include <linux/mmzone.h>
 #include <linux/list.h>
 #include <linux/sched.h>
+#include <linux/vmalloc.h>
 
 #include <asm/atomic.h>
 #include <asm/page.h>

include/linux/swap.h struct swap_info_struct { · line 148

Quoted 5 lines
include/linux/swap.h +2 -0
@@ -143,8 +144,69 @@ struct swap_info_struct {
 	unsigned int pages;
 	unsigned int max;
 	unsigned int inuse_pages;
+	unsigned long *preswap_map;
+	unsigned int preswap_pages;

Missing #ifdef CONFIG_PRESWAP?

Quoted 13 lines
include/linux/swap.h +11 -0
 	int next;			/* next entry on swap list */
 };
+
+#ifdef CONFIG_PRESWAP
+
+#include <linux/sysctl.h>
+extern int preswap_sysctl_handler(struct ctl_table *, int, struct file *,
+	void __user *, size_t *, loff_t *);
+extern const unsigned long preswap_zero, preswap_infinity;
+
+extern void preswap_shrink(unsigned long);
+extern int preswap_test(struct swap_info_struct *, unsigned long);
+extern void preswap_init(unsigned);

include/linux/swap.h struct swap_info_struct { · line 171

Quoted 10 lines
include/linux/swap.h +10 -0
+extern int preswap_put(struct page *);
+extern int preswap_get(struct page *);
+extern void preswap_flush(unsigned, unsigned long);
+extern void preswap_flush_area(unsigned);
+/* in swapfile.c */
+extern int try_to_unuse(unsigned int, unsigned int, unsigned long);
+
+static inline void *preswap_malloc(unsigned long size)
+{
+	return vmalloc(size);

I would view this as problematic on 32-bit, as the vmalloc space is rather restricted there. Not because the allocation here may fail, but because it may cause failures elsewhere. Some feedback on the amount of vmalloc space used and/or still available is going to be needed here I'd think.

include/linux/swap.h extern int can_share_swap_page(struct pa · line 315

Quoted 10 lines

...

include/linux/swap.h +1 -1
@@ -247,7 +309,7 @@ extern int can_share_swap_page(struct pa
 extern int can_share_swap_page(struct page *);
 extern int remove_exclusive_swap_page(struct page *);
 struct backing_dev_info;
-
+extern struct swap_list_t swap_list;
 extern spinlock_t swap_lock;
 
 /* linux/mm/thrash.c */

That's not good - swap_list being non-static in 2.6.18 is just an oversight afaict, which is being fixed in later kernels. I think it would be cleaner (also wrt. a possible pv-ops implementation) to move some or all of the code in mm/preswap.c into mm/swapfile.c (would likewise eliminate the need to remove the 'static' from try_to_unuse()).

Quoted 27 lines
mm/Kconfig +21 -0
@@ -152,3 +152,34 @@ config RESOURCES_64BIT
 	default 64BIT
 	help
 	  This option allows memory and IO resources to be 64 bit.
+
+#
+# support for transcendent memory
+#
+config TMEM
+	bool "Transcendent memory support"
+	def_bool y
+	depends on XEN
+	help
+	  In a virtualized environment, allows unused and underutilized
+	  system physical memory to be made accessible through a narrow
+	  well-defined page-copy-based API.  If unsure, say Y.
+
+config PRECACHE
+	bool "Cache clean pages in transcendent memory"
+	def_bool y
+	depends on TMEM
+	help
+	  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.  If unsure, say Y.

mm/Kconfig config RESOURCES_64BIT · line 185

Quoted 10 lines
mm/Kconfig +10 -0
+
+config PRESWAP
+	bool "Swap pages to transcendent memory"
+	def_bool y
+	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.  If unsure, say Y.
+

'bool' followed by 'def_bool'? And even more, an experimental (as I would view it at this stage) feature that defaults to 'yes'?

Also, does have selecting TMEM on its own any meaning? If not (which I think is the case), then 'select'ing TMEM from the other two options may be more appropriate (while TMEM then shouldn't have a prompt anymore).

mm/tmem.c line 9

Quoted 12 lines
mm/tmem.c new file +9 -0
@@ -0,0 +1,41 @@
+/*
+ * Xen implementation for transcendent memory (tmem)
+ *
+ * Dan Magenheimer <[email protected]> 2009
+ */
+
+#include <linux/types.h>
+#include <xen/interface/xen.h>
+#include <asm/hypervisor.h>

This is Xen-only code sitting in an apparently generic source file. Wouldn't that better be placed in drivers/xen/core/ if it's architecture neutral?

Also, it doesn't include its own header (but see below for comments on that one)...

Quoted 7 lines
mm/tmem.h new file +4 -0
@@ -0,0 +1,111 @@
+/*
+ * linux/mm/tmem.h
+ *
+ * Interface to transcendent memory, used by mm/precache.c and mm/preswap.c

mm/tmem.h line 13

Quoted 10 lines
mm/tmem.h new file +9 -0
+ * Currently implemented on XEN, but may be implemented elsewhere in future.
+ *
+ * Copyright (C) 2008,2009 Dan Magenheimer, Oracle Corp.
+ */
+
+
+#define TMEM_CONTROL               0
+#define TMEM_NEW_POOL              1
+#define TMEM_DESTROY_POOL          2
...

While I partly understand your intention of potentially sharing the implementation with other hypervisors, I don't think Xen interface definitions belong here - you're not using include/xen/interface/tmem.h at all, while that's where the definitions should come from imo. If you really want this to represent an abstract interface, then ensuring consistency with the Xen interface would be a minimal requirement (by e.g. including the Xen header in the #ifdef CONFIG_XEN block). Otoh I'm getting the impression that the patch as a whole isn't following this abstract interface goal, so it should probably be consistent here and not try to do so in a just single place.

mm/tmem.h line 77

Quoted 4 lines

...

mm/tmem.h new file +3 -0
+static inline int tmem_new_pool(u64 uuid_lo, u64 uuid_hi, u32 flags)
+{
+	flags |= (PAGE_SHIFT - 12) << TMEM_POOL_PAGESIZE_SHIFT;

This hard-coded literal 12 seems dubious: Is this part of the tmem hypervisor interface? If so, there should be a #define in the interface header, plus a (ideally build-time) check that the value really fits TMEM_POOL_PAGESIZE_MASK.

Jan

#2 lore raw

RE: [PATCH] [linux-2.6.18-xen] transcendent memory ("tmem")linux-side changes

Quoted 1 line

A few general remarks:

Excellent! Thanks very much for the feedback!

A few comments and explanations below.

Your comments and feedback will be especially useful when proposing the patch upstream. After reading my replies, please let me know if there is anything you see as a *must-fix* for the patch to be put into the (soon-to-be-obsolescent) 2.6.18-xen tree, where its primary goal is to allow tmem to be more easily used by xen developers and leading-edge xen users.

Quoted 4 lines

include/linux/swap.h struct swap_info_struct { · line 148

Quoted 2 lines
include/linux/swap.h +2 -0
+	unsigned long *preswap_map;
+	unsigned int preswap_pages;

Missing #ifdef CONFIG_PRESWAP?

I had one there in an earlier draft but it causes more ifdef's elsewhere. Since swap_info_struct is so rarely instantiated (one per swap device), I thought maybe avoiding additional ifdef's might be more attractive than saving a few bytes system-wide. Thoughts?

Quoted 11 lines

include/linux/swap.h struct swap_info_struct { · line 171

Quoted 3 lines
include/linux/swap.h +3 -0
+static inline void *preswap_malloc(unsigned long size)
+{
+	return vmalloc(size);

I would view this as problematic on 32-bit, as the vmalloc space is rather
restricted there. Not because the allocation here may fail, but because it
may cause failures elsewhere. Some feedback on the amount of vmalloc space used and/or still available is going to be needed here I'd think.

The swapmap requires one byte vmalloc'ed for every page in every swap device. Preswap_map requires one additional bit to be vmalloc'ed for every swapmap byte. Is this likely to be a problem then? By "some feedback", do you mean I should add a comment?

Quoted 11 lines
Quoted 2 lines

+extern struct swap_list_t swap_list;
extern spinlock_t swap_lock;

That's not good - swap_list being non-static in 2.6.18 is just an oversight
afaict, which is being fixed in later kernels. I think it would be cleaner (also
wrt. a possible pv-ops implementation) to move some or all of the code in
mm/preswap.c into mm/swapfile.c (would likewise eliminate the need to remove the 'static' from try_to_unuse()).

I noticed in recent kernel versions that swap_list has seemed to bounce back and forth between static and non-static. It isn't clear to me if this is for data-hiding or just because someone noticed it wasn't being used in other source files.

I thought about adding list-walking macros, but it seemed a bit extreme just to avoid extern-ifying a single static.

In any case, unless you object, I'd like to leave this as is for 2.6.18-xen but I do expect some feedback and possible changes when proposing it upstream. (And for upstream, I'd rather start with a cleaner diffstat, then move chunks of code to swapfile.c in response to maintainer feedback :-)

Quoted 4 lines
Quoted 4 lines
mm/Kconfig +4 -0
+config TMEM
+	bool "Transcendent memory support"
+	def_bool y
+	depends on XEN
Quoted 8 lines

mm/Kconfig config RESOURCES_64BIT · line 166

Quoted 4 lines
mm/Kconfig +4 -0
+	help
+	  In a virtualized environment, allows unused and underutilized
+	  system physical memory to be made accessible through a narrow
+	  well-defined page-copy-based API.  If unsure, say Y.

'bool' followed by 'def_bool'? And even more, an experimental (as I would
view it at this stage) feature that defaults to 'yes'?

I have to admit complete bafflement at Kconfig syntax. It seems I can never get it right. (Is there a good README someplace that I can learn from?)

It would certainly never default to 'yes' upstream, but I thought it might be OK in 2.6.18-xen, especially since it does essentially nothing if Xen doesn't have tmem (or if it has it but it is not enabled).

If 'no' is best, what's the best Kconfig syntax for that? (I tried changing "def_bool y" to "def_bool n" once and it didn't make any difference!)

Quoted 4 lines

Also, does have selecting TMEM on its own any meaning? If not (which I think is the case), then 'select'ing TMEM from the other two options may
be more appropriate (while TMEM then shouldn't have a prompt anymore).

I am anticipating other kernel uses for tmem, though what you suggest makes sense (if I could figure out the Kconfig syntax to do it! :-)

Quoted 12 lines
Quoted 1 line

+++ b/mm/tmem.c Tue Jun 09 15:37:03 2009 -0600

This is Xen-only code sitting in an apparently generic source
...
While I partly understand your intention of potentially sharing the implementation
with other hypervisors, I don't think Xen interface definitions belong here - you're
not using include/xen/interface/tmem.h at all, while that's where the definitions
should come from imo. If you really want this to represent an abstract interface,
then ensuring consistency with the Xen interface would be a

Quoted 8 lines

minimal requirement
(by e.g. including the Xen header in the #ifdef CONFIG_XEN block). Otoh I'm
getting the impression that the patch as a whole isn't following this abstract
interface goal, so it should probably be consistent here and not try to do so in
a just single place.

The concept of tmem is very generic and I foresee uses for it in the native kernel. I agree that the patch is kind of halfway between xen-specific and abstract. I hesitate to completely xen-ify it but nor can I fully abstract it yet unless/until there is another user for it.

Quoted 10 lines

mm/tmem.h line 77

Quoted 3 lines
mm/tmem.h new file +3 -0
+static inline int tmem_new_pool(u64 uuid_lo, u64 uuid_hi, u32 flags)
+{
+	flags |= (PAGE_SHIFT - 12) << TMEM_POOL_PAGESIZE_SHIFT;

This hard-coded literal 12 seems dubious: Is this part of the tmem hypervisor
interface? If so, there should be a #define in the interface header, plus a
(ideally build-time) check that the value really fits TMEM_POOL_PAGESIZE_MASK.

Good point. To explain, the tmem API supports other pagesizes than 4K, but only pagesizes that are a multiple of 4K. I agree that I should have a mask (which is 4 bits, allowing pagesizes up to 128MB) and a define for "12" (TMEM_POOL_MIN_PAGESIZE_SHIFT).

Thanks again, Jan!

Dan

#3 lore raw

RE: [PATCH] [linux-2.6.18-xen] transcendent memory("tmem")linux-side changes

Quoted 11 lines
Quoted 5 lines

include/linux/swap.h struct swap_info_struct { · line 148

Quoted 3 lines

Dan Magenheimer <[email protected]> 10.06.09 16:51 >>>

include/linux/swap.h +2 -0
+	unsigned long *preswap_map;
+	unsigned int preswap_pages;

Missing #ifdef CONFIG_PRESWAP?

I had one there in an earlier draft but it causes more ifdef's elsewhere. Since swap_info_struct is so rarely instantiated (one per swap device), I thought maybe avoiding additional ifdef's might be more attractive than saving a few bytes system-wide. Thoughts?

Of course in the end it's up to you, but in our kernels we're trying to keep the native kernel as unaffected as possible, which means that conditonals should be where-ever code is added without abstracting macros/inline functions which would expand to nothing in native.

Quoted 12 lines
Quoted 11 lines

include/linux/swap.h struct swap_info_struct { · line 171

Quoted 3 lines
include/linux/swap.h +3 -0
+static inline void *preswap_malloc(unsigned long size)
+{
+	return vmalloc(size);

I would view this as problematic on 32-bit, as the vmalloc space is rather
restricted there. Not because the allocation here may fail, but because it
may cause failures elsewhere. Some feedback on the amount of vmalloc space used and/or still available is going to be needed here I'd think.

Quoted 3 lines

The swapmap requires one byte vmalloc'ed for every page in every swap device. Preswap_map requires one additional bit to be vmalloc'ed for every swapmap byte. Is this

Okay, I thought I saw it to be a pointer per page. In any case, the question is how large a swap file is "reasonable" on 32-bits, and what consequences exceeding "reasonable" would have. In any case, the supported limit is 4G pages afair, and having a swap file anywhere in the tens or hundreds of Gb range could become a problem. But I agree that this may be more a theoretical issue, since such configurations should rather use 64-bit setups.

Quoted 2 lines

likely to be a problem then? By "some feedback", do you mean I should add a comment?

No, I really meant feedback from the vmalloc allocator.

Quoted 8 lines

I noticed in recent kernel versions that swap_list has seemed to bounce back and forth between static and non-static. It isn't clear to me if this is for data-hiding or just because someone noticed it wasn't being used in other source files.

I thought about adding list-walking macros, but it seemed a bit extreme just to avoid extern-ifying a single static.

Quoted 6 lines

In any case, unless you object, I'd like to leave this as is for 2.6.18-xen but I do expect some feedback and possible changes when proposing it upstream. (And for upstream, I'd rather start with a cleaner diffstat, then move chunks of code to swapfile.c in response to maintainer feedback :-)

As above, it's your choice, but will make integrating this into our kernels mode difficult (until there's a production ready pv-ops based kernel that we could leverage).

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
mm/Kconfig +4 -0
+config TMEM
+	bool "Transcendent memory support"
+	def_bool y
+	depends on XEN
Quoted 8 lines

mm/Kconfig config RESOURCES_64BIT · line 166

Quoted 4 lines
mm/Kconfig +4 -0
+	help
+	  In a virtualized environment, allows unused and underutilized
+	  system physical memory to be made accessible through a narrow
+	  well-defined page-copy-based API.  If unsure, say Y.

'bool' followed by 'def_bool'? And even more, an experimental (as I would
view it at this stage) feature that defaults to 'yes'?

Quoted 3 lines

I have to admit complete bafflement at Kconfig syntax. It seems I can never get it right. (Is there a good README someplace that I can learn from?)

I've never seen one other than Linux' Documentation/kbuld/kconfig-language.txt (which likely isn't what you're after).

Quoted 9 lines

It would certainly never default to 'yes' upstream, but I thought it might be OK in 2.6.18-xen, especially since it does essentially nothing if Xen doesn't have tmem (or if it has it but it is not enabled).

If 'no' is best, what's the best Kconfig syntax for that? (I tried changing "def_bool y" to "def_bool n" once and it didn't make any difference!)

Quoted 8 lines
Quoted 4 lines

Also, does have selecting TMEM on its own any meaning? If not (which I think is the case), then 'select'ing TMEM from the other two options may
be more appropriate (while TMEM then shouldn't have a prompt anymore).

I am anticipating other kernel uses for tmem, though what you suggest makes sense (if I could figure out the Kconfig syntax to do it! :-)

Here a completely untested suggestion:

#

# support for transcendent memory
#
config TMEM
	bool

config PRECACHE
bool "Cache clean pages in transcendent memory" depends on XEN
select TMEM
help
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. If unsure, say Y.

config PRESWAP
bool "Swap pages to transcendent memory"
depends on XEN
select 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. If unsure, say Y.

(whether you'd want to keep the help previously associated with TMEM is a matter of taste - an option without prompt has no way to ever display its help text, so it would just serve documentation purposes in the Kconfig file itself).

Jan