Skip to content

noushi/ruby-mincore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Ruby bindings for Linux cache manipulation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published