Project

mincore

0.0
No commit activity in last 3 years
No release in over 3 years
mincore provides Ruby bindings for Linux cache manipulation, including cache inspection and deletion for a specific file. IMPORTANT : versions <= 0.0.9.2 have a buggy File.mincore(), 0.0.9.3 and upwards work.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.10.1

Runtime

>= 3.10.1
 Project Readme

ruby-mincore - Ruby bindings for Linux cache manipulation

Gem Version | Build Status | Code Climate | Dependency Status | Coverage Status

mincore provides Ruby bindings for Linux cache manipulation, including cache inspection and deletion for a specific file.

This project is heavily inspired from Feh/nocache.

IMPORTANT

Versions <= 0.0.9.2 have a buggy File.mincore(). Versions 0.0.9.3 and upwards work.

Usage

Currently, most mincore features are implemented as class methods:

size=File.PAGESIZE
# 4096 

File.open("/path/to/file").numpages #The only instance method
# 5

File.mincore("/path/to/file")
# [true, true, false, false, true]

File.cachedel("/path/to/file")
# 0

File.mincore("/path/to/file")
# [true, true, false, false, true]

File.cachedel("/path/to/file", 2)
# 0

File.mincore("/path/to/file")
# [true, true, false, false, true]

File.cachedel("/path/to/file", 2)
# 0

File.mincore("/path/to/file")
# [false, false, false, false, false]

This is an illustration of the fact that cachedel may or may not actually purge cached pages even if run multiple times (through the second parameter).

Full documentation available in the source code ^H^H, Ruby Doc.

Status & Limitations

Currently, the File class is extended as such:

  • mincore(filename) is exported to Ruby in the form of an array of booleans corresponding to each page of the file.
  • cachedel(filename, count=1) calls posix_fadvise(2) to purge all file pages from the cache
  • PAGESIZE is a simple helper that returns the value of PAGESIZE (4KB on Intel)

The bindings are implemented using Ruby Inline, instead of the classic mkmf ext C.

There is a gem module generated, and the code is still beta.

Since File.cachedel() isn't guaranteed to work (no matter how many time you call it), the test_cachedel_non_empty_file most always succeeds without properly asserting that posix_fadvise() has worked.

Also, the tests use a ./writable_tmp_dir/ directory to store the temporary test files. /tmp can't be used since it's usually a ramfs, and files will always be in cache, until they're deleted.

Supported systems

Linux (on any arch) is supported.

FreeBSD/OpenBSD/NetBSD should work, but feedback is needed.

MacOSX requires a different set of headers to properly compile (Testers needed).

Since Debian/kFreeBSD doesn't honor posix_fadvise(), mincore won't work.

Contributing

Contributions are most welcome, you know the drill:

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request