Skip to contentSkip to conversation

Cleancache [PATCH 2/7] (was Transcendent Memory): core files

PATCH Dan Magenheimer 2 participants 4 messages Apr 22, 2010 – May 25, 2010

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

(Sorry for resend... Mail server DNS problems sending to some recipients)

Cleancache [PATCH 2/7] (was Transcendent Memory): core files

Cleancache core files.

Credits: Cleancache_ops design derived from Jeremy Fitzhardinge design for tmem; sysfs code modelled after mm/ksm.c

Note that CONFIG_CLEANCACHE defaults to on; all hooks devolve to a compare-pointer-to-NULL so performance impact should be negligible, but can be reduced to zero impact if config'ed off.

Diffstat:

 include/linux/cleancache.h               |   88 +++++++++
 mm/Kconfig                               |   22 ++
 mm/Makefile                              |    1 
 mm/cleancache.c                          |  198 +++++++++++++++++++++
 4 files changed, 309 insertions(+)
include/linux/cleancache.h +88 -0
@@ -0,0 +1,88 @@
+#ifndef _LINUX_CLEANCACHE_H
+#define _LINUX_CLEANCACHE_H
+
+#include <linux/fs.h>
+#include <linux/mm.h>
+
+struct cleancache_ops {
+	int (*init_fs)(unsigned long);
+	int (*init_shared_fs)(char *uuid, unsigned long);
+	int (*get_page)(int, unsigned long, unsigned long, struct page *);
+	int (*put_page)(int, unsigned long, unsigned long, struct page *);
+	int (*flush_page)(int, unsigned long, unsigned long);
+	int (*flush_inode)(int, unsigned long);
+	void (*flush_fs)(int);
+};
+
+extern struct cleancache_ops *cleancache_ops;
+extern int __cleancache_get_page(struct page *);
+extern int __cleancache_put_page(struct page *);
+extern int __cleancache_flush_page(struct address_space *, struct page *);
+extern int __cleancache_flush_inode(struct address_space *);
+
+#ifndef CONFIG_CLEANCACHE
+#define cleancache_ops ((struct cleancache_ops *)NULL)
+#endif
+
+static inline int cleancache_init_fs(unsigned long pagesize)
+{
+	int ret = -1;
+
+	if (cleancache_ops)
+		ret = (*cleancache_ops->init_fs)(pagesize);
+	return ret;
+}
+
+static inline int cleancache_init_shared_fs(char *uuid, unsigned long pagesize)
+{
+	int ret = -1;
+
+	if (cleancache_ops)
+		ret = (*cleancache_ops->init_shared_fs)(uuid, pagesize);
+	return ret;
+}
+
+static inline int cleancache_get_page(struct page *page)
+{
+	int ret = 0;
+
+	if (cleancache_ops)
+		ret = __cleancache_get_page(page);
+	return ret;
+}
+
+static inline int cleancache_put_page(struct page *page)
+{
+	int ret = 0;
+
+	if (cleancache_ops)
+		ret = __cleancache_put_page(page);
+	return ret;
+}
+
+static inline int cleancache_flush_page(struct address_space *mapping,
+					struct page *page)
+{
+	int ret = 0;
+
+	if (cleancache_ops)
+		ret = __cleancache_flush_page(mapping, page);
+	return ret;
+}
+
+static inline int cleancache_flush_inode(struct address_space *mapping)
+{
+	int ret = 0;
+
+	if (cleancache_ops)
+		ret = __cleancache_flush_inode(mapping);
+	return ret;
+}
+
+static inline void cleancache_flush_fs(int pool_id)
+{
+	if (cleancache_ops && pool_id >= 0)
+		(*cleancache_ops->flush_fs)(pool_id);
+}
+
+#endif /* _LINUX_CLEANCACHE_H */
mm/cleancache.c +198 -0

198 lines not on this page · raw message

mm/Kconfig +22 -0
@@ -287,3 +287,25 @@ config NOMMU_INITIAL_TRIM_EXCESS
 	  of 1 says that all excess pages should be trimmed.
 
 	  See Documentation/nommu-mmap.txt for more information.
+
+config CLEANCACHE
+	bool "Enable cleancache pseudo-RAM driver to cache clean pages"
+	default y
+	help
+ 	  Cleancache can be thought of as a page-granularity victim cache
+	  for clean pages that the kernel's pageframe replacement algorithm
+	  (PFRA) would like to keep around, but can't since there isn't enough
+	  memory.  So when the PFRA "evicts" a page, it first attempts to put
+	  it into a synchronous concurrency-safe page-oriented pseudo-RAM
+	  device (such as Xen's Transcendent Memory, aka "tmem") which is not
+	  directly accessible or addressable by the kernel and is of unknown
+	  (and possibly time-varying) size.  And when a cleancache-enabled
+	  filesystem wishes to access a page in a file on disk, it first
+	  checks cleancache to see if it already contains it; if it does,
+ 	  the page is copied into the kernel and a disk access is avoided.
+	  When a pseudo-RAM device is available, a significant I/O reduction
+	  may be achieved.  When none is available, all cleancache calls
+	  are reduced to a single pointer-compare-against-NULL resulting
+	  in a negligible performance hit.
+
+	  If unsure, say Y to enable cleancache
mm/Makefile +1 -0
@@ -44,3 +44,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_CLEANCACHE) += cleancache.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>

maintainer
#1 lore raw

include/linux/cleancache.h line 8

Quoted 2 lines · Dan Magenheimer
include/linux/cleancache.h +2 -0
+struct cleancache_ops {
+	int (*init_fs)(unsigned long);

unsigned long? Really? Not even size_t?

include/linux/cleancache.h line 9

Quoted 1 line
include/linux/cleancache.h +1 -0
+	int (*init_shared_fs)(char *uuid, unsigned long);

Ditto.

include/linux/cleancache.h line 10

Quoted 1 line
include/linux/cleancache.h +1 -0
+	int (*get_page)(int, unsigned long, unsigned long, struct page *);

Ugh. First of all, presumably you have some structure behind that index, don't you? Might be a better way to do it.

What's more, use of ->i_ino is simply wrong. How stable do you want that to be and how much do you want it to outlive struct address_space in question?

Quoted 1 line

From my reading of your code, it doesn't outlive that anyway, so...

The third one is pgoff_t; again, use sane types, _if_ you actually want the argument #3 at all - it can be derived from struct page you are passing there as well.

include/linux/cleancache.h line 14

Quoted 4 lines
include/linux/cleancache.h +4 -0
+	int (*put_page)(int, unsigned long, unsigned long, struct page *);
+	int (*flush_page)(int, unsigned long, unsigned long);
+	int (*flush_inode)(int, unsigned long);
+	void (*flush_fs)(int);

Same questions as above...

#2 lore raw
Quoted 2 lines

From: Al Viro [mailto:[email protected]]
Subject: Re: Cleancache [PATCH 2/7] (was Transcendent Memory): core files

Hi Al!

Thanks for the feedback! Sorry for the delayed response.

Quoted 1 line

...again, use sane types...

Good point. Will fix types for next rev (using size_t, ino_t, and pgoff_t).

Quoted 4 lines
Quoted 1 line

+=09int (*get_page)(int, unsigned long, unsigned long, struct page *);

=20
Ugh. First of all, presumably you have some structure behind that index, don't you? Might be a better way to do it.

Not quite sure what you mean here. The index is really just part of a unique handle for cleancache to identify the (page of) data.

Quoted 2 lines

What's more, use of ->i_ino is simply wrong. How stable do you want that to be and how much do you want it to outlive struct address_space in ques=

tion?

Quoted 1 line

From my reading of your code, it doesn't outlive that anyway, so...

Unless I misunderstand your point, no, the inode never outlives the address space because the specification requires the kernel to ensure coherency; if the inode were about to outlive the address space, the cleancache_flush operations must be invoked (and I think the patch covers all the necessary cases).

Quoted 3 lines

The third one is pgoff_t; again, use sane types, _if_ you actually want the argument #3 at all - it can be derived from struct page you are passing there as well.

I thought it best to declare the _ops so that the struct page is opaque to the "backend" (driver). The kernel-side ("frontend") defines the handle and ensures coherency, so the backend shouldn't be allowed to derive or muck with the three-tuple passed by the kernel. In the existing (Xen tmem) driver, the only operation performed on the struct page parameter is page_to_pfn(). OTOH, I could go one step further and pass a pfn_t instead of a struct page, since it is really only the physical page frame that the backend needs to know about and (synchronously) read/write from/to.

Thoughts?

Thanks again!
Dan

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

#3 lore raw
Quoted 4 lines
Quoted 1 line

The third one is pgoff_t; again, use sane types, _if_ you actually

want

Quoted 2 lines

the argument #3 at all - it can be derived from struct page you are passing there as well.

Quoted 12 lines

=20
I thought it best to declare the _ops so that the struct page is opaque to the "backend" (driver). The kernel-side ("frontend") defines the handle and ensures coherency, so the backend shouldn't be allowed to derive or muck with the three-tuple passed by the kernel. In the existing (Xen tmem) driver, the only operation performed on the struct page parameter is page_to_pfn(). OTOH, I could go one step further and pass a pfn_t instead of a struct page, since it is really only the physical page frame that the backend needs to know about and (synchronously) read/write from/to. =20
Thoughts?

Silly me. pfn_t is a Xen/KVM type not otherwise used in the kernel AFAICT. Please ignore...

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