Created
February 14, 2014 00:09
-
-
Save vivkin/8986655 to your computer and use it in GitHub Desktop.
mach zero fill count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/mman.h> | |
#include <mach/mach.h> | |
#include <mach/vm_statistics.h> | |
void vm_stat() | |
{ | |
int host = mach_host_self(); | |
vm_statistics64_data_t stat; | |
mach_msg_type_number_t count; | |
host_statistics64(host, HOST_VM_INFO64, (host_info_t)&stat, &count); | |
printf("active: %u, zero_fill: %llu\n", stat.active_count, stat.zero_fill_count); | |
} | |
int main() | |
{ | |
size_t length = 4096 * 999; | |
vm_stat(); | |
char *p = (char *)mmap(NULL, length, PROT_WRITE | PROT_READ, MAP_ANON | MAP_PRIVATE, -1, 0); | |
if (p != MAP_FAILED) | |
{ | |
vm_stat(); | |
for (size_t i = 0; i < length; i += 4096) p[i] = 1; | |
vm_stat(); | |
} | |
} | |
/* | |
viv@Ivans-MacBook-Pro-2 ~/none4$ clang vms.c && ./a.out && vm_stat | |
active: 0, zero_fill: 0 | |
active: 779976, zero_fill: 92674893 | |
active: 780975, zero_fill: 92675892 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment