Otto Moerbeek wrote: > a future goal for malloc is to use multiple pools in threaded > environments, to reduce lock contention. > > This is a small first step towards that goal: move two globals to the > pool-specific struct dir_info. Currently there's only a single pool, > but that will change one day. > > Lightly tested by myself on amd64, you can help by reviewing and > testing this.
Thanks for this - I've been meaning to study the pool logic more. One minor thing I noticed: > Index: malloc.c > =================================================================== > RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v > retrieving revision 1.182 > diff -u -p -r1.182 malloc.c > --- malloc.c 25 Feb 2016 00:38:51 -0000 1.182 > +++ malloc.c 9 Mar 2016 08:31:52 -0000 > @@ -93,13 +93,13 @@ > #define MQUERY(a, sz) mquery((a), (size_t)(sz), PROT_READ | > PROT_WRITE, \ > MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, (off_t)0) > > -#define _MALLOC_LEAVE() if (__isthreaded) do { \ > - malloc_active--; \ > +#define _MALLOC_LEAVE(d) if (__isthreaded) do { \ > + (d)->active--; \ > _MALLOC_UNLOCK(); \ > } while (0) > -#define _MALLOC_ENTER() if (__isthreaded) do { \ > +#define _MALLOC_ENTER(d) if (__isthreaded) do { \ > _MALLOC_LOCK(); \ > - malloc_active++; \ > + (d)->active++; \ > } while (0) Are you sure these are guarded properly? I think the do-while block should wrap the entire thing, including the if condition. Otherwise, else conditions can still associate with the if.