8 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
11 #define MAP_ANONYMOUS 0
14 /* max mmap size, *start is the largest power-of-2 size considered */
15 static size_t mmax(int fd
, size_t *start
)
20 for (i
=n
=*start
; i
>=PAGE_SIZE
; i
/=2) {
21 if ((p
=mmap(0, n
, PROT_NONE
, MAP_PRIVATE
|MAP_ANONYMOUS
, fd
, 0)) == MAP_FAILED
) {
30 return n
& -PAGE_SIZE
;
34 fills the virtual memory with anonymous PROT_NONE mmaps,
35 returns the mappings in *p and *n in decreasing size order,
36 the return value is the number of mappings or -1 on failure.
38 int t_vmfill(void **p
, size_t *n
, int len
)
40 int fd
= MAP_ANONYMOUS
? -1 : open("/dev/zero", O_RDWR
);
41 size_t start
= SIZE_MAX
/2 + 1;
50 q
= mmap(0, m
, PROT_NONE
, MAP_PRIVATE
|MAP_ANONYMOUS
, fd
, 0);