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

._common_code(builder) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mincore.rb', line 5

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("<fcntl.h>")
  #    builder.include("<fcntl.h>")

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

.cachedel(filename, count = 1) ⇒ Object

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

Example:

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

Arguments:

filename: (String)
count: (Int)


161
162
163
# File 'lib/mincore.rb', line 161

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

.mincore(*args) ⇒ Object

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

Example:

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

Arguments:

filename: (String)


176
177
178
# File 'lib/mincore.rb', line 176

def self.mincore(*args)
  self._mincore(*args)
end

.PAGESIZEObject

get system pagesize (4096 on Intel)

Example:

>> File.PAGESIZE
=> 4096


185
186
187
# File 'lib/mincore.rb', line 185

def self.PAGESIZE
  self._PAGESIZE
end

Instance Method Details

#numpagesObject

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



145
146
147
148
# File 'lib/mincore.rb', line 145

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