Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F5541230
mapper4.c
dougm (Doug Moore)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
dougm
Oct 10 2019, 4:41 AM
2019-10-10 04:41:52 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
mapper4.c
View Options
#include
<sys/mman.h>
#include
<sys/time.h>
#include
<stdlib.h>
#include
<stdio.h>
enum
{
MAX_MAPS
=
16384
,
PAGE_SIZE
=
4096
};
int
main
(
int
argc
,
const
char
*
argv
[])
{
int
i
;
int
nmappings
=
0
;
void
*
mappings
[
MAX_MAPS
];
struct
timeval
beg
,
end
;
struct
timezone
tz
=
{
0
,
0
};
if
(
argc
>=
2
)
srandom
(
atoi
(
argv
[
1
]));
for
(
i
=
0
;
i
<
MAX_MAPS
;
++
i
)
mappings
[
i
]
=
MAP_FAILED
;
gettimeofday
(
&
beg
,
&
tz
);
for
(
i
=
0
;
i
<
2048
*
MAX_MAPS
;
++
i
)
{
long
r
=
random
()
%
MAX_MAPS
;
if
(
mappings
[
r
]
==
MAP_FAILED
)
{
mappings
[
r
]
=
mmap
(
0
,
3
*
PAGE_SIZE
,
PROT_WRITE
,
MAP_ALIGNED
(
14
)
|
MAP_ANON
,
-1
,
0
);
if
(
mappings
[
r
]
!=
MAP_FAILED
)
++
nmappings
;
}
else
{
munmap
(
mappings
[
r
],
3
*
PAGE_SIZE
);
mappings
[
r
]
=
MAP_FAILED
;
--
nmappings
;
}
}
gettimeofday
(
&
end
,
&
tz
);
end
.
tv_sec
-=
beg
.
tv_sec
;
end
.
tv_usec
-=
beg
.
tv_usec
;
if
(
end
.
tv_usec
<
0
)
{
end
.
tv_usec
+=
1000000
;
end
.
tv_sec
--
;
}
printf
(
"nmappings = %d, time %ld.%ld; ok?
\n
"
,
nmappings
,
(
long
)
end
.
tv_sec
,
(
long
)
end
.
tv_usec
);
return
0
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1933369
Default Alt Text
mapper4.c (1 KB)
Attached To
Mode
D21964: Make vm_map a threaded tree
Attached
Detach File
Event Timeline
Log In to Comment