#include #include #include #include #include #include #include #include #include #define SIZE (5 * 1024 * 1024 * 1024) int64_t current_time_ms() { struct timeval time; gettimeofday(&time, NULL); int64_t s1 = (int64_t)(time.tv_sec) * 1000; int64_t s2 = (time.tv_usec / 1000); return s1 + s2; } int main(int argc, char* argv[]) { void * buf; size_t size = SIZE; int64_t start, cost; buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0); if (buf < 0 ) { printf("mmap failed\n"); exit(-1); } start = current_time_ms(); mlock(buf, size); cost = current_time_ms() - start; printf("cost: %" PRId64 " ms\n", cost); munmap(buf, size); return 0; }