rmuir commented on PR #13381:
URL: https://github.com/apache/lucene/pull/13381#issuecomment-2119287234

   Maybe if we didn't close the fd in mmapdir we could eventually think about 
making use of this on modern linux. it doesn't have a glibc wrapper yet... here 
is minimal sample code, but maybe just look at `fincore` for a more functional 
example: 
https://github.com/util-linux/util-linux/blob/master/misc-utils/fincore.c
   
   ```c
   #include <sys/syscall.h>
   #include <linux/mman.h>
   #include <fcntl.h>
   #include <stdio.h>
   #include <unistd.h>
   
   int
   cachestat(int fd, struct cachestat_range *range, struct cachestat *stats, 
int flags) {
     return syscall(SYS_cachestat, fd, range, stats, flags);
   }
   
   int main(int argc, char **argv) {
     int fd;
   
     if (argc != 2) {
       printf("usage: %s <file>\n", argv[0]);
       return 2;
     }
   
     if ((fd = open(argv[1], O_RDONLY)) < 0) {
       perror("couldn't open");
       return 1;
     }
   
     struct cachestat_range range = { 0, 0 };
     struct cachestat cstats;
     if (cachestat(fd, &range, &cstats, 0) != 0) {
       perror("couldn't cachestat");
       return 1;
     }
   
     printf("cached: %llu\ndirty: %llu\nwriteback: %llu\nevicted: 
%llu\nrecently_evicted: %llu\n",
         cstats.nr_cache, cstats.nr_dirty, cstats.nr_writeback, 
cstats.nr_evicted, cstats.nr_recently_evicted);
   
     return 0;
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to