Skip to contentSkip to conversation

Frontswap (was Transcendent Memory): core code

PATCH In review Dan Magenheimer 1 participant 1 message May 28, 2010 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/4 Frontswap (was Transcendent Memory): core code

[PATCH V2 2/4] Frontswap (was Transcendent Memory): core code

Core frontswap_ops structure and functions

Diffstat:

 include/linux/frontswap.h                |   98 ++++++
 mm/frontswap.c                           |  301 +++++++++++++++++++++
 2 files changed, 399 insertions(+)
include/linux/frontswap.h +98 -0
@@ -0,0 +1,98 @@
+#ifndef _LINUX_FRONTSWAP_H
+#define _LINUX_FRONTSWAP_H
+
+#include <linux/swap.h>
+#include <linux/mm.h>
+
+#define FRONTSWAP_PUT_PAGE_SUCCESS 1
+#define FRONTSWAP_GET_PAGE_SUCCESS 1
+
+struct frontswap_ops {
+	int (*init)(unsigned);
+	int (*put_page)(int, unsigned, pgoff_t, struct page *);
+	int (*get_page)(int, unsigned, pgoff_t, struct page *);
+	void (*flush_page)(int, unsigned, pgoff_t);
+	void (*flush_area)(int, unsigned);
+};
+
+extern int frontswap_poolid;
+
+extern struct frontswap_ops *frontswap_ops;
+extern void frontswap_shrink(unsigned long);
+extern unsigned long frontswap_curr_pages(void);
+
+extern int __frontswap_put_page(struct page *page);
+extern int __frontswap_get_page(struct page *page);
+extern void __frontswap_flush_page(unsigned type, pgoff_t offset);
+extern void __frontswap_flush_area(unsigned type);
+
+#ifndef CONFIG_FRONTSWAP
+/* all inline routines become no-ops and all externs are ignored */
+#define frontswap_ops ((struct frontswap_ops *)NULL)
+#endif
+
+static inline int frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
+{
+	int ret = 0;
+
+	if (frontswap_ops && sis->frontswap_map)
+		ret = test_bit(offset % BITS_PER_LONG,
+			sis->frontswap_map[offset/BITS_PER_LONG]);
+	return ret;
+}
+
+static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
+{
+	if (frontswap_ops && sis->frontswap_map)
+		set_bit(offset % BITS_PER_LONG,
+			sis->frontswap_map[offset/BITS_PER_LONG]);
+}
+
+static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
+{
+	if (frontswap_ops && sis->frontswap_map)
+		clear_bit(offset % BITS_PER_LONG,
+			sis->frontswap_map[offset/BITS_PER_LONG]);
+}
+
+
+static inline void frontswap_init(unsigned type)
+{
+	if (frontswap_ops) {
+		/* only need one poolid regardless of number of swap types */
+		if (frontswap_poolid < 0)
+			frontswap_poolid = (*frontswap_ops->init)(type);
+	}
+}
+
+static inline int frontswap_put_page(struct page *page)
+{
+	int ret = 0;
+
+	if (frontswap_ops && frontswap_poolid >= 0)
+		ret = __frontswap_put_page(page);
+	return ret;
+}
+
+static inline int frontswap_get_page(struct page *page)
+{
+	int ret = 0;
+
+	if (frontswap_ops && frontswap_poolid >= 0)
+		ret = __frontswap_get_page(page);
+	return ret;
+}
+
+static inline void frontswap_flush_page(unsigned type, pgoff_t offset)
+{
+	if (frontswap_ops && frontswap_poolid >= 0)
+		__frontswap_flush_page(type, offset);
+}
+
+static inline void frontswap_flush_area(unsigned type)
+{
+	if (frontswap_ops && frontswap_poolid >= 0)
+		__frontswap_flush_area(type);
+}
+
+#endif /* _LINUX_FRONTSWAP_H */
mm/frontswap.c +301 -0

301 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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>