Get The Remaining Size of A Typed Memory
Sometimes you may want to get the reamining size of a typed memory region, but you can't find the right tool to view the remaining size, you can use the following code to get it.
#include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include <sys/mman.h> #include <fcntl.h> int main(void) { int fd; int ret; struct posix_typed_mem_info info; fd = posix_typed_mem_open( "/memory/below4G/ram", O_RDWR, POSIX_TYPED_MEM_ALLOCATE_CONTIG); if (fd == -1) { printf("Can not open below4G ram\n"); return EXIT_FAILURE; } ret = posix_typed_mem_get_info( fd, &info); if (!ret) { printf("below4G ram: %.2fMB\n", (float)info.posix_tmi_length/1024/1024); } close(fd); return EXIT_SUCCESS; }