class File

The File mincore extension

Public Class Methods

PAGESIZE() click to toggle source

get system page size (4096 on Intel)

@example - On Intel machine

File.PAGESIZE #=> 4096

@return [Int] the page size

# File lib/mincore.rb, line 191
def self.PAGESIZE
  self._PAGESIZE
end
cachedel(filename, count=1) click to toggle source

Attempts to delete cached pages of a file, one or more times

@example Sample run - file pages would or would not get flushed

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

@param filename [String] file name @param count [Int] times `posix_fadvise()` will be run @return [Int] execution status of the last `posix_fadvise()` call

# File lib/mincore.rb, line 168
def self.cachedel(filename, count=1) 
  self._cachedel(filename, count)
end
mincore(filename) click to toggle source

Returns page cache status for a given file. Status is provided as a boolean array of size ( filesize + PAGESIZE -1 ) / PAGESIZE

@example Sample run - on a file of size 20KB

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

@param filename [String] file name @return [Int, Array] execution status and cache status array

# File lib/mincore.rb, line 181
def self.mincore(filename)
  self._mincore(filename)
end

Private Class Methods

_common_code(builder) click to toggle source
# File lib/mincore.rb, line 6
  def self._common_code(builder)
    builder.include("<stdio.h>")
    builder.include("<stdlib.h>")
    builder.include("<sys/stat.h>")

    builder.include("<sys/types.h>")
    builder.include("<fcntl.h>")
    builder.include("<unistd.h>")
    builder.include("<sys/mman.h>")
    builder.include("<errno.h>")
    #    builder.include("<fcntl.h>")

#    builder.prefix("#define exiterr(s) { perror(s); exit(-1); }")
    builder.prefix("#define exiterr(s) { rb_sys_fail(s); }")
  end

Public Instance Methods

numpages() click to toggle source

Returns the number of system pages required to store file in memory @example Sample run - on a file of size 20KB

File.open("/path/to/some/file").numpages #=> 5

@return [Int] number of cacheable pages

# File lib/mincore.rb, line 154
def numpages
  pagesize = self.class.PAGESIZE
  (self.stat.size + pagesize -1 ) / pagesize
end