Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/mincore.rb

Overview

The File mincore extension

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cachedel(filename, count = 1) ⇒ Int

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

Examples:

Sample run - file pages would or would not get flushed

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

Parameters:

  • filename (String)

    file name

  • count (Int) (defaults to: 1)

    times posix_fadvise() will be run

Returns:

  • (Int)

    execution status of the last posix_fadvise() call



168
169
170
# File 'lib/mincore.rb', line 168

def self.cachedel(filename, count=1) 
  self._cachedel(filename, count)
end

.mincore(filename) ⇒ Int, Array

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

Examples:

Sample run - on a file of size 20KB

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

Parameters:

  • filename (String)

    file name

Returns:

  • (Int, Array)

    execution status and cache status array



181
182
183
# File 'lib/mincore.rb', line 181

def self.mincore(filename)
  self._mincore(filename)
end

.PAGESIZEInt

get system page size (4096 on Intel)

Examples:

  • On Intel machine
File.PAGESIZE #=> 4096

Returns:

  • (Int)

    the page size



191
192
193
# File 'lib/mincore.rb', line 191

def self.PAGESIZE
  self._PAGESIZE
end

Instance Method Details

#numpagesInt

Returns the number of system pages required to store file in memory

Examples:

Sample run - on a file of size 20KB

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

Returns:

  • (Int)

    number of cacheable pages



154
155
156
157
# File 'lib/mincore.rb', line 154

def numpages
  pagesize = self.class.PAGESIZE
  (self.stat.size + pagesize -1 ) / pagesize
end