tmem: add page deduplication (V2)
PATCH 1/1 tmem: add page deduplication (V2)
V1: Add "page deduplication" capability to Xen-side of tmem. (see below for log notes for V1 posting)
V2: Add support for optional "trailing zero elimination" (tze) and compression when page deduplication is enabled.
Tze saves significant tmem RAM when many data files are less than 1-3 pages and remaining (unused) space at the end of a page is zero-filled on disk or in memory, as may be the case for example when VMs are serving a large number of (deduplicate'able) web pages.
Compression already was a tmem option; v2 of this patch combines compression with deduplication to further improve tmem RAM utilization.
Either option (tmem_tze or tmem_compress) can be enabled at xen boot time in addition to deduplication (tmem_dedup) but compression overrides/disables tze. Both have a significant CPU cost so are useful primarily when memory is more constrained than CPU cycles, for example on a many-core machine with many low CPU-utilization RAM-needy VMs.
tools/misc/xen-tmem-list-parse.c | 25 +- xen/common/tmem.c | 468 ++++++++++++++++++++++++++++++++------- xen/common/tmem_xen.c | 35 ++ xen/include/xen/tmem_xen.h | 122 +++++++++- 4 files changed, 566 insertions(+), 84 deletions(-)
======
(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 +23 -2
@@ -110,13 +110,34 @@ 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" ); +unsigned long long pcd_tot_tze_size =parse (s,"Zt" ); +unsigned long long pcd_tot_csize =parse (s,"Gz" );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) " , 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); +if (pcd_count !=0 ) + { +printf ("pcds=%llu (max=%llu) " , + pcd_count,max_pcd_count); +printf ("dedup savings=%4.2f%% " , + (1.0 -(pcd_count*1.0 )/global_eph_count)*100 ); +if (pcd_tot_tze_size && (pcd_tot_tze_size < pcd_count*PAGE_SIZE )) +printf ("tze savings=%4.2f%% " , + (1.0 -(pcd_tot_tze_size*1.0 )/(pcd_count*PAGE_SIZE ))*100 ); +if (pcd_tot_csize && (pcd_tot_csize < pcd_count*PAGE_SIZE )) +printf ("compression savings=%4.2f%% " , + (1.0 -(pcd_tot_csize*1.0 )/(pcd_count*PAGE_SIZE ))*100 ); + } +printf ("\n" );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 +393 -75
656 lines not on this page · raw message
xen/common/tmem_xen.c +31 -4
@@ -17,8 +17,14 @@ EXPORT int opt_tmem = 0; EXPORT int opt_tmem = 0;boolean_param ("tmem" , opt_tmem); -EXPORT int opt_tmem_compress = 0; +EXPORT int opt_tmem_compress = 1;boolean_param ("tmem_compress" , opt_tmem_compress); + +EXPORT int opt_tmem_dedup = 1; +boolean_param ("tmem_dedup" , opt_tmem_dedup); + +EXPORT int opt_tmem_tze = 0; +boolean_param ("tmem_tze" , opt_tmem_tze); EXPORT int opt_tmem_shared_auth = 0;boolean_param ("tmem_shared_auth" , opt_tmem_shared_auth);
@@ -103,8 +109,8 @@ static inline void *cli_mfn_to_va(tmem_c#endif EXPORT int tmh_copy_from_client(pfp_t *pfp, -tmem_cli_mfn_t cmfn,uint32_t tmem_offset, -uint32_t pfn_offset,uint32_t len,void *cli_va) +tmem_cli_mfn_t cmfn,pagesize_t tmem_offset, +pagesize_t pfn_offset,pagesize_t len,void *cli_va) {unsigned long tmem_mfn;void *tmem_va;
@@ -148,7 +154,7 @@ EXPORT int tmh_compress_from_client(tmem } EXPORT int tmh_copy_to_client(tmem_cli_mfn_t cmfn, pfp_t *pfp, -uint32_t tmem_offset,uint32_t pfn_offset,uint32_t len,void *cli_va) +pagesize_t tmem_offset,pagesize_t pfn_offset,pagesize_t len,void *cli_va) {unsigned long tmem_mfn, cli_mfn =0 ;int mark_dirty =1 ;
@@ -195,6 +201,27 @@ EXPORT int tmh_decompress_to_client(tmemunmap_domain_page (cli_va);paging_mark_dirty (current->domain,cli_mfn); } +mb (); +return 1 ; +} + +EXPORT int tmh_copy_tze_to_client(tmem_cli_mfn_t cmfn, void *tmem_va, +pagesize_t len) +{ +void *cli_va; +unsigned long cli_mfn; + +ASSERT (!(len & (sizeof (uint64_t )-1 ))); +ASSERT (len <=PAGE_SIZE ); +ASSERT (len >0 || tmem_va ==NULL ); +if ( (cli_va =cli_mfn_to_va (cmfn,&cli_mfn)) ==NULL ) +return -EFAULT ; +if ( len >0 ) +memcpy ((char *)cli_va,(char *)tmem_va,len); +if ( len <PAGE_SIZE ) +memset ((char *)cli_va+len,0 ,PAGE_SIZE -len); +unmap_domain_page (cli_va); +paging_mark_dirty (current->domain,cli_mfn);mb ();return 1 ; }
xen/include/xen/tmem_xen.h +119 -3
148 lines not on this page · raw message
tools/misc/xen-tmem-list-parse.c +23 -2
@@ -110,13 +110,34 @@ 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" ); +unsigned long long pcd_tot_tze_size =parse (s,"Zt" ); +unsigned long long pcd_tot_csize =parse (s,"Gz" );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) " , 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); +if (pcd_count !=0 ) + { +printf ("pcds=%llu (max=%llu) " , + pcd_count,max_pcd_count); +printf ("dedup savings=%4.2f%% " , + (1.0 -(pcd_count*1.0 )/global_eph_count)*100 ); +if (pcd_tot_tze_size && (pcd_tot_tze_size < pcd_count*PAGE_SIZE )) +printf ("tze savings=%4.2f%% " , + (1.0 -(pcd_tot_tze_size*1.0 )/(pcd_count*PAGE_SIZE ))*100 ); +if (pcd_tot_csize && (pcd_tot_csize < pcd_count*PAGE_SIZE )) +printf ("compression savings=%4.2f%% " , + (1.0 -(pcd_tot_csize*1.0 )/(pcd_count*PAGE_SIZE ))*100 ); + } +printf ("\n" );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 +393 -75
656 lines not on this page · raw message
xen/common/tmem_xen.c +31 -4
@@ -17,8 +17,14 @@ EXPORT int opt_tmem = 0; EXPORT int opt_tmem = 0;boolean_param ("tmem" , opt_tmem); -EXPORT int opt_tmem_compress = 0; +EXPORT int opt_tmem_compress = 1;boolean_param ("tmem_compress" , opt_tmem_compress); + +EXPORT int opt_tmem_dedup = 1; +boolean_param ("tmem_dedup" , opt_tmem_dedup); + +EXPORT int opt_tmem_tze = 0; +boolean_param ("tmem_tze" , opt_tmem_tze); EXPORT int opt_tmem_shared_auth = 0;boolean_param ("tmem_shared_auth" , opt_tmem_shared_auth);
@@ -103,8 +109,8 @@ static inline void *cli_mfn_to_va(tmem_c#endif EXPORT int tmh_copy_from_client(pfp_t *pfp, -tmem_cli_mfn_t cmfn,uint32_t tmem_offset, -uint32_t pfn_offset,uint32_t len,void *cli_va) +tmem_cli_mfn_t cmfn,pagesize_t tmem_offset, +pagesize_t pfn_offset,pagesize_t len,void *cli_va) {unsigned long tmem_mfn;void *tmem_va;
@@ -148,7 +154,7 @@ EXPORT int tmh_compress_from_client(tmem } EXPORT int tmh_copy_to_client(tmem_cli_mfn_t cmfn, pfp_t *pfp, -uint32_t tmem_offset,uint32_t pfn_offset,uint32_t len,void *cli_va) +pagesize_t tmem_offset,pagesize_t pfn_offset,pagesize_t len,void *cli_va) {unsigned long tmem_mfn, cli_mfn =0 ;int mark_dirty =1 ;
@@ -195,6 +201,27 @@ EXPORT int tmh_decompress_to_client(tmemunmap_domain_page (cli_va);paging_mark_dirty (current->domain,cli_mfn); } +mb (); +return 1 ; +} + +EXPORT int tmh_copy_tze_to_client(tmem_cli_mfn_t cmfn, void *tmem_va, +pagesize_t len) +{ +void *cli_va; +unsigned long cli_mfn; + +ASSERT (!(len & (sizeof (uint64_t )-1 ))); +ASSERT (len <=PAGE_SIZE ); +ASSERT (len >0 || tmem_va ==NULL ); +if ( (cli_va =cli_mfn_to_va (cmfn,&cli_mfn)) ==NULL ) +return -EFAULT ; +if ( len >0 ) +memcpy ((char *)cli_va,(char *)tmem_va,len); +if ( len <PAGE_SIZE ) +memset ((char *)cli_va+len,0 ,PAGE_SIZE -len); +unmap_domain_page (cli_va); +paging_mark_dirty (current->domain,cli_mfn);mb ();return 1 ; }
xen/include/xen/tmem_xen.h +119 -3
148 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel