4 #define MSET_SIZE (1 << 15)
5 #define MMAP_MIN (1 << 12)
17 static struct mset
*pool
;
19 static void mk_pool(void)
21 if (pool
&& !pool
->refs
) {
22 pool
->size
= sizeof(*pool
);
25 pool
= mmap(NULL
, MSET_SIZE
, PROT_READ
| PROT_WRITE
,
26 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
27 if (pool
== MAP_FAILED
) {
31 pool
->size
= sizeof(*pool
);
40 mem
= mmap(NULL
, n
, PROT_READ
| PROT_WRITE
,
41 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
42 if (mem
== MAP_FAILED
)
46 return (void *) mem
+ sizeof(*mem
);
48 if (!pool
|| MSET_SIZE
- pool
->size
< n
)
52 mem
= (void *) pool
+ pool
->size
;
56 pool
->size
+= (n
+ 7) & ~7;
57 return (void *) mem
+ sizeof(*mem
);
62 struct mem
*mem
= v
- sizeof(struct mem
);
66 struct mset
*mset
= mem
->mset
;
68 if (!mset
->refs
&& mset
!= pool
)
69 munmap(mset
, mset
->size
);
71 munmap(mem
, mem
->size
);