Update reserve-address-space

This commit is contained in:
Stefanos Kornilios Misis Poiitidis 2022-05-14 18:22:19 +03:00
parent 667a30cbef
commit 8ce1c4b930
3 changed files with 14 additions and 4 deletions

Binary file not shown.

View File

@ -15,4 +15,4 @@ gcc signals-nested-2.cpp -g -o ../signals-nested-2 -lpthread
gcc smc-shmatdt.cpp -g -o ../smc-shmatdt
gcc prot-growsdown.cpp -g -o ../prot-growsdown
gcc memfd.cpp -g -o ../memfd
gcc reserve-address-space.cpp -g -o ../reserve-address-space
g++ reserve-address-space.cpp -g -o ../reserve-address-space

View File

@ -9,10 +9,13 @@
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
#include <chrono>
// Based on discussion in https://github.com/FEX-Emu/FEX/issues/1708
int main() {
auto start_time = std::chrono::high_resolution_clock::now();
size_t total_len = 0;
size_t alloc_len = 1ULL << 51;
while (alloc_len >= PAGE_SIZE) {
@ -23,15 +26,22 @@ int main() {
// No more free VM gaps of this size.
if (result == MAP_FAILED) {
assert(errno == ENOMEM);
if (errno != ENOMEM && errno != EPERM /* when len is too big ?*/) {
printf("Error, errno: %d\n", errno);
return -1;
} else {
break;
}
}
total_len += alloc_len;
}
// Halve the size and continue filling in gaps.
alloc_len >>= 1;
}
printf("done, allocated %ld\n", total_len);
std::chrono::duration<double, std::milli> duration = std::chrono::high_resolution_clock::now() - start_time;
printf("done, allocated %ld in %.3f ms\n", total_len, duration.count());
return 0;
}