hoytech / vmtouch

Portable file system cache diagnostics and control
https://hoytech.com/vmtouch/
BSD 3-Clause "New" or "Revised" License
1.82k stars 214 forks source link

Can do mincore warning #78

Closed johnmay closed 4 years ago

johnmay commented 4 years ago

As reported by #74, on Kernal 5.2+ mincore does not report correctly if you don't have write permission. Touch and evict still work as expect it's just the reporting that is wrong. This PR adds a runtime can_do_mincore function for __linux__ which checks the Kernal version and if the user running the process has write permission to the file. If o_verbose and vmtouch can't get accurate information it issues a warning: vmtouch: WARNING: Process does not have write permission, residency chart will not be accurate.

Actual kernal check: https://github.com/torvalds/linux/blob/b7a16c7ad790d0ecb44dcb08a6a75d0d0455ab5f/mm/mincore.c#L181-L195

Example:

[john@machine vmtouch]$ ./vmtouch -v /nvme/arthor/pubchem.smi.atdb
/nvme/arthor/pubchem.smi.atdb
vmtouch: WARNING: Process does not have write permission, residency chart will not be accurate
[OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO] 3543272/3543272

           Files: 1
     Directories: 0
  Resident Pages: 3543272/3543272  13G/13G  100%
         Elapsed: 0.014981 seconds
# sudo can see the residency correctly and doesn't get a warning
[john@machine vmtouch]$ sudo ./vmtouch -v /nvme/arthor/pubchem.smi.atdb
/nvme/arthor/pubchem.smi.atdb
[OOOOOOOOOOOOOOOo                                            ] 904352/3543272

           Files: 1
     Directories: 0
  Resident Pages: 904352/3543272  3G/13G  25.5%
         Elapsed: 0.13137 seconds
# allow group/other write access, residency is correct - no warning
[john@machine vmtouch]$ sudo chmod ugo+w /nvme/arthor/pubchem.smi.atdb
[john@machine vmtouch]$ ./vmtouch -v /nvme/arthor/pubchem.smi.atdb
/nvme/arthor/pubchem.smi.atdb
[OOOOOOOOOOOOOOOo                                            ] 904352/3543272

           Files: 1
     Directories: 0
  Resident Pages: 904352/3543272  3G/13G  25.5%
         Elapsed: 0.13547 seconds
hoytech commented 4 years ago

Good idea, thank you!