Skip to contentSkip to conversation

use tlsf for xmalloc engine

PATCH In review Dan Magenheimer 3 participants 4 messages Oct 15, 2008 – Oct 16, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use tlsf for xmalloc engine

This patch replaces the Xen xmalloc engine with tlsf, an allocation engine that is both more space efficient and time-bounded, especially for allocation sizes between PAGE_SIZE/2 and PAGE_SIZE.

The file xmalloc.c is deprecated but not yet deleted. A simple switch of a comment line in common/Makefile will change back to the legacy xmalloc/xfree if needed for testing.

Code adapted from Nitin Gupta's tlsf-kmod, rev 229, found here:
http://code.google.com/p/compcache/source/browse/trunk/sub-projects/allocators/tlsf-kmod
with description and performance details here:
http://code.google.com/p/compcache/wiki/TLSFAllocator
(new Xen code uses 4K=PAGE_SIZE for the region size)

For detailed info on tlsf, see:
http://rtportal.upv.es/rtmalloc/

(NOTE to Isaku-san: There may be some subtle alignment or PAGE_SIZE issues to get tlsf to work on ia64. I have not tried it. If problems, use an ifdef in common/Makefile to change to the legacy xmalloc on ia64.)

Signed-off by: Dan Magenheimer <[email protected]>

xen/common/Makefile +2 -1
diff -r 8c3144b1ff63 xen/common/Makefile
@@ -25,7 +25,8 @@ obj-y += trace.o
 obj-y += trace.o
 obj-y += version.o
 obj-y += vsprintf.o
-obj-y += xmalloc.o
+#obj-y += xmalloc.o
+obj-y += xmalloc_tlsf.o
 obj-y += rcupdate.o
 
 obj-$(perfc)       += perfc.o
xen/common/xmalloc_tlsf.c new file +669 -0

669 lines not on this page · raw message

xen/include/xen/xmalloc_tlsf.h new file +93 -0

93 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 14 lines · Dan Magenheimer

This patch replaces the Xen xmalloc engine with tlsf, an allocation engine that is both more space efficient and time-bounded, especially for allocation sizes between PAGE_SIZE/2 and PAGE_SIZE.

The file xmalloc.c is deprecated but not yet deleted. A simple switch of a comment line in common/Makefile will change back to the legacy xmalloc/xfree if needed for testing.

Code adapted from Nitin Gupta's tlsf-kmod, rev 229, found here:
http://code.google.com/p/compcache/source/browse/trunk/sub-projects/allocators/tlsf-kmod
with description and performance details here:
http://code.google.com/p/compcache/wiki/TLSFAllocator
(new Xen code uses 4K=PAGE_SIZE for the region size)

Quoted 7 lines

For detailed info on tlsf, see:
http://rtportal.upv.es/rtmalloc/

(NOTE to Isaku-san: There may be some subtle alignment or PAGE_SIZE issues to get tlsf to work on ia64. I have not tried it. If problems, use an ifdef in common/Makefile to change to the legacy xmalloc on ia64.)

I did a very light test. It booted and pv domain and hvm domain can boot.
Looking at xmalloc use in ia64 specific code, it seems ok to allow cache line size alignment at most.

Thank you for reminding me.

Signature · 1 line
yamahata
#2 lore raw
In reply to Dan Magenheimer
Quoted 7 lines · Dan Magenheimer

This patch replaces the Xen xmalloc engine with tlsf, an allocation engine that is both more space efficient and time-bounded, especially for allocation sizes between PAGE_SIZE/2 and PAGE_SIZE.

The file xmalloc.c is deprecated but not yet deleted. A simple switch of a comment line in common/Makefile will change back to the legacy xmalloc/xfree if needed for testing.

Fixed for style, fixed to satisfy requested alignment parameter to xmalloc(), and fixed for multi-page allocations to include the BHDR_OVERHEAD. Checked in as c/s 18638.

-- Keir

#3 lore raw
Quoted 1 line

Checked in as c/s 18638.

Excellent!

However, I should have mentioned that I had a reason for exposing the tlsf-direct (non-xmalloc) interface, which you have hidden by static'izing some of the routines and removing xmalloc_tlsf.h:

The pool capability can be used to "group" allocated pages so as to improve locality and reduce fragmentation (kind of similar to slab/slub but across a wide range of allocation sizes). IOW, if I want to allocate a large and diverse set of data structures of types X, Y, and Z, and I can "partition" them into pools A, B, and C, I should get fewer page translation misses when I walk the A-specific data structures than if the allocations are all done via xmalloc. Further, if I free all of A's data structures, all the pages will be returned to the free page pool, whereas if I use xmalloc/xfree, B's and C's allocations will be intermingled so many/most pages may not be freed.

Since you've retained the getmem/putmem function parameters and struct pool parameter, this should be easy to patch later, but please don't specialize it further to meet only xmalloc's needs as I intend to use pools in my current project (hcache).

Thanks,
Dan

Quoted 28 lines

-----Original Message-----
From: Keir Fraser [mailto:[email protected]]
Sent: Thursday, October 16, 2008 4:12 AM
To: Dan Magenheimer; Xen-Devel (E-mail)
Cc: Diwaker Gupta; Isaku Yamahata; Kurt Hackel; Nitin Gupta
Subject: Re: [Xen-devel] [PATCH] use tlsf for xmalloc engine

Quoted 2 lines · Dan Magenheimer

This patch replaces the Xen xmalloc engine with tlsf, an allocation engine that is both more space efficient and time-bounded,

especially

Quoted 5 lines

for allocation sizes between PAGE_SIZE/2 and PAGE_SIZE.

The file xmalloc.c is deprecated but not yet deleted. A simple switch of a comment line in common/Makefile will change back to the legacy xmalloc/xfree if needed for testing.

Fixed for style, fixed to satisfy requested alignment parameter to xmalloc(), and fixed for multi-page allocations to include the BHDR_OVERHEAD. Checked in as c/s 18638.

-- Keir