calculate maximum global cache size from free RAM

In reflowing scroll mode with 2 pages hinting, 4 full page blitbuffers
and koptcontexts should stay well in cache in the most demanding cases,
with two pages shown on screen and two pages rendered in background.
Since blitbuffer size is halved the size of page, we need cache size
to be 6 times an average reflowed page size.

For Kobo Aura HD which has a resolution of 1440×1080, a reflowed page
could become 1080×4800. So 30MB of cache is demanded for this case.

This PR implements dynamic cache size allocating according to size of
system free memory. By default it will use 20 percent of free RAM with
a clip specified by DGLOBAL_CACHE_SIZE_MINIMUM and
DGLOBAL_CACHE_SIZE_MAXIMUM which are 10MB and 30MB respectively by default.
pull/472/head
chrox 10 years ago
parent 44b2026028
commit 904a5f1ebe

@ -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

Loading…
Cancel
Save