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
->left
) {
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
);
64 struct mset
*mset
= mem
->mset
;
65 mset
->left
-= mem
->size
;
66 if (!mset
->left
&& mset
!= pool
)
67 munmap(mset
, mset
->size
);
69 munmap(mem
, mem
->size
);