c++ - Limit buffer cache used for mmap -


i have data structure i'd rework page out on-demand. mmap seems easy way run initial experiments. however, want limit amount of buffer cache mmap uses. machine has enough memory page entire data structure cache, test reasons (and production reasons too) don't want allow that.

is there way limit amount of buffer cache used mmap?

alternatively, mmap alternative can achieve similar , still limit memory usage work too.

from understanding, not possible. memory mapping controlled operating system. kernel make decisions how use available memory in best way, looks @ system in total. i'm not aware quotas caches on process level supported (at least, have not seen such apis in linux or bsd).

there madvise give kernel hints, not support limit cache used 1 process. can give hints madv_dontneed, reduce pressure on cache of other applications, expect more harm good, make caching less efficient, lead more io load on system in total.

i see 2 alternatives. on trying solve problem on os level, , other solve on application level.

on os level, see 2 options:

  1. you run virtual machine, not want. expect not improve overall system performance. still, @ least way define upper limits on memory consumption.
  2. docker idea comes mind, operating on os level, best of knowledge, not support define quotas on cache. don't think work.

that leaves 1 option, @ application level. instead of using memory mapped files, use explicit file system operations. if need have full control on buffer, think practical option. more work memory mapping, , not guaranteed perform better.

if want stay memory mapping, map parts of file in memory , unmap other parts when exceed memory quota. has same problem explicit file io operations (more implementation work , non-trivial tuning find caching strategy).

having said that, question requirement limit cache memory usage. expect kernel pretty job @ allocating memory resources in way. @ least, better solutions have sketched. (explicit file io, plus internal cache, might fast, not trivial implement , tune. here, comparison of trade-offs: mmap() vs. reading blocks.)

during testing, run application ionice -c 3 , nice -n 20 reduce impact on other productive applications. there tool called nocache. never used when reading through documentation, seems related question.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -