ia64/xen-unstable

view xen/include/xen/lib.h @ 19646:f210a633571c

Transcendent memory ("tmem") for Xen.

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.

Tmem pages may optionally be compressed and, in certain cases, can be
shared between guests. Tmem also handles concurrency nicely and
provides limited QoS settings to combat malicious DoS attempts.
Save/restore and live migration support is not yet provided.

Tmem is primarily targeted for an x86 64-bit hypervisor. On a 32-bit
x86 hypervisor, it has limited functionality and testing due to
limitations of the xen heap. Nearly all of tmem is
architecture-independent; three routines remain to be ported to ia64
and it should work on that architecture too. It is also structured to
be portable to non-Xen environments.

Tmem defaults off (for now) and must be enabled with a "tmem" xen boot
option (and does nothing unless a tmem-capable guest is running). The
"tmem_compress" boot option enables compression which takes about 10x
more CPU but approximately doubles the number of pages that can be
stored.

Tmem can be controlled via several "xm" commands and many interesting
tmem statistics can be obtained. A README and internal specification
will follow, but lots of useful prose about tmem, as well as Linux
patches, can be found at http://oss.oracle.com/projects/tmem .

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 11:05:04 2009 +0100 (2009-05-26)
parents 5369133d772c
children 50634c215234
line source
1 #ifndef __LIB_H__
2 #define __LIB_H__
4 #include <xen/inttypes.h>
5 #include <xen/stdarg.h>
6 #include <xen/config.h>
7 #include <xen/types.h>
8 #include <xen/xmalloc.h>
9 #include <xen/string.h>
10 #include <asm/bug.h>
12 void __bug(char *file, int line) __attribute__((noreturn));
13 void __warn(char *file, int line);
15 #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
16 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
18 /* Force a compilation error if condition is true */
19 #define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))
21 /* Force a compilation error if condition is true, but also produce a
22 result (of value 0 and type size_t), so the expression can be used
23 e.g. in a structure initializer (or where-ever else comma expressions
24 aren't permitted). */
25 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
27 #ifndef assert_failed
28 #define assert_failed(p) \
29 do { \
30 printk("Assertion '%s' failed, line %d, file %s\n", #p , \
31 __LINE__, __FILE__); \
32 BUG(); \
33 } while (0)
34 #endif
36 #ifndef NDEBUG
37 #define ASSERT(p) \
38 do { if ( unlikely(!(p)) ) assert_failed(p); } while (0)
39 #else
40 #define ASSERT(p) ((void)0)
41 #endif
43 #define SWAP(_a, _b) \
44 do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
46 #define DIV_ROUND(x, y) (((x) + (y) / 2) / (y))
48 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
50 #define reserve_bootmem(_p,_l) ((void)0)
52 struct domain;
54 void cmdline_parse(char *cmdline);
56 /*#define DEBUG_TRACE_DUMP*/
57 #ifdef DEBUG_TRACE_DUMP
58 extern void debugtrace_dump(void);
59 extern void debugtrace_printk(const char *fmt, ...);
60 #else
61 #define debugtrace_dump() ((void)0)
62 #define debugtrace_printk(_f, ...) ((void)0)
63 #endif
65 /* Allows us to use '%p' as general-purpose machine-word format char. */
66 #define _p(_x) ((void *)(unsigned long)(_x))
67 extern void printk(const char *format, ...)
68 __attribute__ ((format (printf, 1, 2)));
69 extern void panic(const char *format, ...)
70 __attribute__ ((format (printf, 1, 2)));
71 extern long vm_assist(struct domain *, unsigned int, unsigned int);
72 extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
73 extern int printk_ratelimit(void);
75 /* vsprintf.c */
76 #define sprintf __xen_has_no_sprintf__
77 #define vsprintf __xen_has_no_vsprintf__
78 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
79 __attribute__ ((format (printf, 3, 4)));
80 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
81 __attribute__ ((format (printf, 3, 0)));
82 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
83 __attribute__ ((format (printf, 3, 4)));
84 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
85 __attribute__ ((format (printf, 3, 0)));
86 extern int sscanf(const char * buf, const char * fmt, ...)
87 __attribute__ ((format (scanf, 2, 3)));
88 extern int vsscanf(const char * buf, const char * fmt, va_list args)
89 __attribute__ ((format (scanf, 2, 0)));
91 long simple_strtol(
92 const char *cp,const char **endp, unsigned int base);
93 unsigned long simple_strtoul(
94 const char *cp,const char **endp, unsigned int base);
95 long long simple_strtoll(
96 const char *cp,const char **endp, unsigned int base);
97 unsigned long long simple_strtoull(
98 const char *cp,const char **endp, unsigned int base);
100 unsigned long long parse_size_and_unit(const char *s, const char **ps);
102 #define TAINT_UNSAFE_SMP (1<<0)
103 #define TAINT_MACHINE_CHECK (1<<1)
104 #define TAINT_BAD_PAGE (1<<2)
105 #define TAINT_SYNC_CONSOLE (1<<3)
106 #define TAINT_ERROR_INJECT (1<<4)
107 extern int tainted;
108 #define TAINT_STRING_MAX_LEN 20
109 extern char *print_tainted(char *str);
110 extern void add_taint(unsigned);
112 #endif /* __LIB_H__ */