小编waz*_*oox的帖子

Linux:识别内存中的页面

我想知道一个巨大的文件的哪个部分被缓存在内存中.我正在使用fincore的一些代码,这样就可以了:文件是mmaped,然后fincore循环遍历地址空间并使用mincore检查页面,但由于文件大小(几TB),它很长(几分钟) ).

有没有办法循环使用的RAM页面呢?它会快得多,但这意味着我应该从某个地方获取已用过的页面列表...但是我找不到一个方便的系统调用来实现这一点.

代码如下:

#include <errno.h> 
#include <fcntl.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <sys/stat.h> 
#include <sys/types.h> 
#include <unistd.h> 
/* } */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/sysinfo.h>


void
fincore(char *filename) {
   int fd;
   struct stat st;

   struct sysinfo info;
   if (sysinfo(& info)) {
    perror("sysinfo");
    return;
   }

   void *pa = (char *)0;
   char *vec = (char *)0;
   size_t pageSize = getpagesize();
   register size_t pageIndex;

   fd = open(filename, 0);
   if (0 > …
Run Code Online (Sandbox Code Playgroud)

c linux

6
推荐指数
1
解决办法
1977
查看次数

标签 统计

c ×1

linux ×1