tmem: add page deduplication
PATCH 1/1 tmem: add page deduplication
(This is for post-4.0, but I'm posting now for feedback.)
Add "page deduplication" capability to Xen-side of tmem. (Transparent to tmem-enabled guests.) Ephemeral pages that have the exact same content are "combined" so that only one page frame is needed. Since ephemeral pages are essentially read-only, no C-O-W (and thus no equivalent of swapping) is necessary.
Anybody know of any good fast (SSE2?) assembly memory compare routines? (See tmh_page_cmp() in the patch.)
Points of interest:
- Modifications to LRU eviction algorithm to accommodate dedup'ed pages
- New data structures to allow lookup of matching pages and track references. (Algorithm used is similar to that used by KSM in KVM/Linux: No hashing required.)
- Lock (and rbtree) chosen by first byte of data to allow reasonably high concurrency without greatly complicating lock management.
- Statistics added so "dedup ratio" can be monitored.
- Dedup is disabled/enabled by Xen command line option.
I'm seeing 1.08-1.52 dedup ratio for two self-ballooned guests simultaneously/continuously building linux; that's up to a 34% reduction in physical ephemeral pages used by tmem. Clearly this is very workload-dependent. YMMV. To obtain this savings, approx double the time is spent in tmem (increasing from roughly 0.1% to roughly 0.2%). This compares favorably to compression which costs approximately 10x for an approximate savings of 50%.
tools/misc/xen-tmem-list-parse.c +9 -2
@@ -110,13 +110,20 @@ void parse_global(char *s)unsigned long long rtree_node_max =parse (s,"Nm" );unsigned long long pgp_count =parse (s,"Pc" );unsigned long long pgp_max =parse (s,"Pm" ); +unsigned long long page_count =parse (s,"Fc" ); +unsigned long long max_page_count =parse (s,"Fm" ); +unsigned long long pcd_count =parse (s,"Sc" ); +unsigned long long max_pcd_count =parse (s,"Sm" );printf ("total tmem ops=%llu (errors=%llu) -- tmem pages avail=%llu\n" , total_ops, errored_ops, avail_pages);printf ("datastructs: objs=%llu (max=%llu) pgps=%llu (max=%llu) " -"nodes=%llu (max=%llu)\n" , +"nodes=%llu (max=%llu) pages=%llu (max=%llu) pcds=%llu (max=%llu) " +"dedup ratio=%f\n" , obj_count, obj_max, pgp_count, pgp_max, - rtree_node_count, rtree_node_max); + rtree_node_count, rtree_node_max, + page_count,max_page_count,pcd_count,max_pcd_count, + (pcd_count==0 )?0.0 :(global_eph_count*1.0 )/pcd_count);printf ("misc: failed_copies=%llu alloc_failed=%llu alloc_page_failed=%llu " "low_mem=%llu evicted=%llu/%llu relinq=%llu/%llu, " "max_evicts_per_relinq=%llu, flush_pools=%llu, "
xen/common/tmem.c +217 -44
387 lines not on this page · raw message
xen/common/tmem_xen.c +3 -0
@@ -19,6 +19,9 @@ boolean_param("tmem", opt_tmem); EXPORT int opt_tmem_compress = 0;boolean_param ("tmem_compress" , opt_tmem_compress); + +EXPORT int opt_tmem_dedup = 1; +boolean_param ("tmem_dedup" , opt_tmem_dedup); EXPORT int opt_tmem_shared_auth = 0;boolean_param ("tmem_shared_auth" , opt_tmem_shared_auth);
xen/include/xen/tmem_xen.h +28 -0
@@ -52,6 +52,12 @@ static inline int tmh_compression_enablestatic inline int tmh_compression_enabled (void ) {return opt_tmem_compress; +} + +extern int opt_tmem_dedup; +static inline int tmh_dedup_enabled (void ) +{ +return opt_tmem_dedup; }extern int opt_tmem_shared_auth;
@@ -326,6 +332,28 @@ static inline bool_t tmh_current_is_privreturn IS_PRIV (current->domain); } +static inline uint8_t tmh_get_first_byte (pfp_t *pfp) +{ +void *p =__map_domain_page (pfp); + +return (uint8_t )(*(char *)p); +} + +static inline int tmh_page_cmp (pfp_t *pfp1,pfp_t *pfp2) +{ +const uint64_t *p1 = (uint64_t *)__map_domain_page (pfp1); +const uint64_t *p2 = (uint64_t *)__map_domain_page (pfp2); +int i; + +// FIXME: code in assembly? +for ( i =PAGE_SIZE /sizeof (uint64_t ); *p1 == *p2; i--, *p1++, *p2++ ); +if ( !i ) +return 0 ; +if ( *p1 < *p2 ) +return -1 ; +return 1 ; +} +/* these typedefs are in the public/tmem.h interface typedef XEN_GUEST_HANDLE(void) cli_mfn_t; typedef XEN_GUEST_HANDLE(char) cli_va_t;
tools/misc/xen-tmem-list-parse.c +9 -2
@@ -110,13 +110,20 @@ void parse_global(char *s)unsigned long long rtree_node_max =parse (s,"Nm" );unsigned long long pgp_count =parse (s,"Pc" );unsigned long long pgp_max =parse (s,"Pm" ); +unsigned long long page_count =parse (s,"Fc" ); +unsigned long long max_page_count =parse (s,"Fm" ); +unsigned long long pcd_count =parse (s,"Sc" ); +unsigned long long max_pcd_count =parse (s,"Sm" );printf ("total tmem ops=%llu (errors=%llu) -- tmem pages avail=%llu\n" , total_ops, errored_ops, avail_pages);printf ("datastructs: objs=%llu (max=%llu) pgps=%llu (max=%llu) " -"nodes=%llu (max=%llu)\n" , +"nodes=%llu (max=%llu) pages=%llu (max=%llu) pcds=%llu (max=%llu) " +"dedup ratio=%f\n" , obj_count, obj_max, pgp_count, pgp_max, - rtree_node_count, rtree_node_max); + rtree_node_count, rtree_node_max, + page_count,max_page_count,pcd_count,max_pcd_count, + (pcd_count==0 )?0.0 :(global_eph_count*1.0 )/pcd_count);printf ("misc: failed_copies=%llu alloc_failed=%llu alloc_page_failed=%llu " "low_mem=%llu evicted=%llu/%llu relinq=%llu/%llu, " "max_evicts_per_relinq=%llu, flush_pools=%llu, "
xen/common/tmem.c +217 -44
387 lines not on this page · raw message
xen/common/tmem_xen.c +3 -0
@@ -19,6 +19,9 @@ boolean_param("tmem", opt_tmem); EXPORT int opt_tmem_compress = 0;boolean_param ("tmem_compress" , opt_tmem_compress); + +EXPORT int opt_tmem_dedup = 1; +boolean_param ("tmem_dedup" , opt_tmem_dedup); EXPORT int opt_tmem_shared_auth = 0;boolean_param ("tmem_shared_auth" , opt_tmem_shared_auth);
xen/include/xen/tmem_xen.h +28 -0
@@ -52,6 +52,12 @@ static inline int tmh_compression_enablestatic inline int tmh_compression_enabled (void ) {return opt_tmem_compress; +} + +extern int opt_tmem_dedup; +static inline int tmh_dedup_enabled (void ) +{ +return opt_tmem_dedup; }extern int opt_tmem_shared_auth;
@@ -326,6 +332,28 @@ static inline bool_t tmh_current_is_privreturn IS_PRIV (current->domain); } +static inline uint8_t tmh_get_first_byte (pfp_t *pfp) +{ +void *p =__map_domain_page (pfp); + +return (uint8_t )(*(char *)p); +} + +static inline int tmh_page_cmp (pfp_t *pfp1,pfp_t *pfp2) +{ +const uint64_t *p1 = (uint64_t *)__map_domain_page (pfp1); +const uint64_t *p2 = (uint64_t *)__map_domain_page (pfp2); +int i; + +// FIXME: code in assembly? +for ( i =PAGE_SIZE /sizeof (uint64_t ); *p1 == *p2; i--, *p1++, *p2++ ); +if ( !i ) +return 0 ; +if ( *p1 < *p2 ) +return -1 ; +return 1 ; +} +/* these typedefs are in the public/tmem.h interface typedef XEN_GUEST_HANDLE(void) cli_mfn_t; typedef XEN_GUEST_HANDLE(char) cli_va_t;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel