mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #472 from chrox/master
calculate maximum global cache size from free RAM
This commit is contained in:
@@ -19,7 +19,14 @@ DGLOBALGAMMA = 1.0
|
||||
-- See comments in djvureader.lua:DJVUReader:select_render_mode()
|
||||
DRENDER_MODE = 0 -- 0 is COLOUR
|
||||
|
||||
DGLOBAL_CACHE_SIZE = 1024*1024*10
|
||||
-- minimum cache size
|
||||
DGLOBAL_CACHE_SIZE_MINIMUM = 1024*1024*10
|
||||
|
||||
-- proportion of system free memory used as global cache
|
||||
DGLOBAL_CACHE_FREE_PROPORTION = 0.2
|
||||
|
||||
-- maximum cache size
|
||||
DGLOBAL_CACHE_SIZE_MAXIMUM = 1024*1024*30
|
||||
|
||||
-- background colour in non scroll mode: 8 = gray, 0 = white, 15 = black
|
||||
DBACKGROUND_COLOR = 0
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
--[[
|
||||
A global LRU cache
|
||||
]]--
|
||||
local function calcFreeMem()
|
||||
local meminfo = io.open("/proc/meminfo", "r")
|
||||
local freemem = 0
|
||||
if meminfo then
|
||||
for line in meminfo:lines() do
|
||||
local free, buffer, cached, n
|
||||
free, n = line:gsub("^MemFree:%s-(%d+) kB", "%1")
|
||||
if n ~= 0 then freemem = freemem + tonumber(free)*1024 end
|
||||
buffer, n = line:gsub("^Buffers:%s-(%d+) kB", "%1")
|
||||
if n ~= 0 then freemem = freemem + tonumber(buffer)*1024 end
|
||||
cached, n = line:gsub("^Cached:%s-(%d+) kB", "%1")
|
||||
if n ~= 0 then freemem = freemem + tonumber(cached)*1024 end
|
||||
end
|
||||
meminfo:close()
|
||||
end
|
||||
return freemem
|
||||
end
|
||||
|
||||
local function calcCacheMemSize()
|
||||
local min = DGLOBAL_CACHE_SIZE_MINIMUM
|
||||
local max = DGLOBAL_CACHE_SIZE_MAXIMUM
|
||||
local calc = calcFreeMem()*(DGLOBAL_CACHE_FREE_PROPORTION or 0)
|
||||
return math.min(max, math.max(min, calc))
|
||||
end
|
||||
|
||||
local Cache = {
|
||||
-- cache configuration:
|
||||
max_memsize = DGLOBAL_CACHE_SIZE,
|
||||
max_memsize = calcCacheMemSize(),
|
||||
-- cache state:
|
||||
current_memsize = 0,
|
||||
-- associative cache
|
||||
|
||||
Reference in New Issue
Block a user