Replace slab.c with a very simple allocator.
PATCH 3/3 Replace slab.c with a very simple allocator.
slab.c in Linux is not a very nice piece of code: the version in Xen has been hacked a certain amount and is not a vision of beauty either.
Given how rare and non-time-critical dynamic allocations are in Xen, this replaces the 1800-line slab.c with a 160-line malloc.c which is written as simply as possible for future enhancement.
Tested in userspace, boots Xen fine.
Rusty.
xen/arch/x86/setup.c +0 -4
@@ -598,10 +598,6 @@ void __init __start_xen(multiboot_info_t early_boot =0 ; -/* Initialise the slab allocator. */ -xmem_cache_init (); -xmem_cache_sizes_init (max_page); -start_of_day ();grant_table_init ();
xen/common/malloc.c +164 -0
164 lines not on this page · raw message
xen/common/page_alloc.c +1 -9
@@ -403,9 +403,8 @@ unsigned long alloc_xenheap_pages(unsign {unsigned long flags;struct pfn_info *pg; -int i, attempts =0 ; +int i; - retry:local_irq_save (flags); pg =alloc_heap_pages (MEMZONE_XEN , order);local_irq_restore (flags);
@@ -425,14 +424,7 @@ unsigned long alloc_xenheap_pages(unsignreturn (unsigned long )page_to_virt (pg); no_memory: -if ( attempts++ <8 ) - { -xmem_cache_reap (); - goto retry; - } -printk ("Cannot handle page request order %d!\n" , order); -dump_slabinfo ();return 0 ; }
xen/common/slab.c +0 -1844
1,844 lines not on this page · raw message
xen/include/xen/domain.h +0 -2
@@ -6,8 +6,6 @@* Arch-specifics. */ -extern void domain_startofday (void ); -extern struct domain *arch_alloc_domain_struct (void );extern void arch_free_domain_struct (struct domain *d);
xen/include/xen/lib.h +12 -0
@@ -20,6 +20,18 @@ struct domain;void cmdline_parse (char *cmdline); +/** +* container_of - cast a member of a structure out to the containing structure +* +* @ptr: the pointer to the member. +* @type: the type of the container struct this is embedded in. +* @member: the name of the member within the struct. +* +*/ +#define container_of (ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +#define printk printfvoid printf (const char *format, ...);void panic (const char *format, ...);
xen/include/xen/list.h +12 -0
@@ -174,5 +174,17 @@ static __inline__ void list_splice(struc pos = list_entry(pos->member.next, typeof(*pos), member), \ prefetch(pos->member.next)) +/** +* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry +* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @head: the head for your list. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_each_entry_safe (pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member))#endif /* _LINUX_LIST_H */
xen/include/xen/slab.h +4 -35
@@ -13,45 +13,14 @@#include <asm/slab.h> #else - -typedef struct xmem_cache_s xmem_cache_t ; -#include <xen/mm.h> #include <xen/cache.h> #include <xen/types.h> -/* Flags to pass to xmem_cache_create(). */ -/* NB. The first 3 are only valid when built with SLAB_DEBUG_SUPPORT. */ -#define SLAB_DEBUG_INITIAL 0x00000200UL/* Call constructor */ -#define SLAB_RED_ZONE 0x00000400UL/* Red zone objs in a cache */ -#define SLAB_POISON 0x00000800UL/* Poison objects */ -#define SLAB_NO_REAP 0x00001000UL/* never reap from the cache */ -#define SLAB_HWCACHE_ALIGN 0x00002000UL/* align obj on a cache line */ - -/* Flags passed to a constructor function. */ -#define SLAB_CTOR_CONSTRUCTOR 0x001UL/* if not set, then deconstructor */ -#define SLAB_CTOR_ATOMIC 0x002UL/* tell cons. it can't sleep */ -#define SLAB_CTOR_VERIFY 0x004UL/* tell cons. it's a verify call */ - -extern void xmem_cache_init (void ); -extern void xmem_cache_sizes_init (unsigned long ); - -extern xmem_cache_t *xmem_find_general_cachep (size_t ); -extern xmem_cache_t *xmem_cache_create ( -const char *,size_t ,size_t ,unsigned long , -void (*)(void *,xmem_cache_t *,unsigned long ), -void (*)(void *,xmem_cache_t *,unsigned long )); -extern int xmem_cache_destroy (xmem_cache_t *); -extern int xmem_cache_shrink (xmem_cache_t *); -extern void *xmem_cache_alloc (xmem_cache_t *); -extern void xmem_cache_free (xmem_cache_t *,void *); - -extern void *xmalloc (size_t ); -extern void xfree (const void *); - -extern int xmem_cache_reap (void ); - -extern void dump_slabinfo (); +#define xmalloc (size) __xmalloc(size, __FILE__, __LINE__) +#define xfree (ptr) __xfree(ptr, __FILE__, __LINE__) +extern void *__xmalloc (size_t size,const char *file,unsigned int line); +extern void __xfree (const void *p,const char *file,unsigned int line);/* Nicely typesafe for you. */ #define new (type) ((type *)xmalloc(sizeof(type)))
Signature · 9 lines
A bad analogy is like a leaky screwdriver -- Richard Braakman ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl
Quoted 8 lines
slab.cin Linux is not a very nice piece of code: the version in Xen has been hacked a certain amount and is not a vision of beauty either.Given how rare and non-time-critical dynamic allocations are in Xen, this replaces the 1800-line
slab.cwith a 160-linemalloc.cwhich is written as simply as possible for future enhancement.Tested in userspace, boots Xen fine.
Rusty,
This turns out to be an oversimplification -- it doesn't boot for me as exec_domain's aren't 16 byte aligned and hence fxsave fails.
I think we want to ensure that the object returned is always aligned to start on a L1 cache line boundary. I don't care that we burn some memory as we don't have lots of small allocs.
Please could you adjust your patch having resync'ed from usntable.
Thanks,
Ian
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl
Quoted 7 lines · Ian Pratt
Quoted 7 lines
slab.cin Linux is not a very nice piece of code: the version in Xen has been hacked a certain amount and is not a vision of beauty either.Given how rare and non-time-critical dynamic allocations are in Xen, this replaces the 1800-line
slab.cwith a 160-linemalloc.cwhich is written as simply as possible for future enhancement.
Quoted 7 lines
Quoted 1 line
Tested in userspace, boots Xen fine.
Rusty,
This turns out to be an oversimplification -- it doesn't boot for me as exec_domain's aren't 16 byte aligned and hence fxsave fails.
Damn, apologies for missing this requirement. Good catch.
Quoted 3 lines
I think we want to ensure that the object returned is always aligned to start on a L1 cache line boundary. I don't care that we burn some memory as we don't have lots of small allocs.
If I may suggest, I'd prefer to put this in the hands of the caller, with an explicit alignment arg. This simply falls out with this type-safe versions using __alignof__, and should neatly document this requirement, for example.
Quoted 1 line
Please could you adjust your patch having resync'ed from usntable.
Hmm, I hope that the bk snapshot is close enough.
Will do,
Rusty.
Signature · 9 lines
A bad analogy is like a leaky screwdriver -- Richard Braakman ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl