1

I've got a virtual server and my provider charges me on per-resource-usage basis. I can set a limit on maximum RAM, but I'm still charged for actually used RAM, not the maximum (the price is calculated every 5 minutes based on actual usage).

Using all RAM would be okay normally, but Linux policy "unused RAM is wasted RAM" falls short for this kind of accounting, since the machine will eventually end up using all available RAM, and even though most of it as a disk cache only, I still have to pay for it.

I like to set the limit at provider a bit higher to accommodate peak needs for RAM. Can I, somehow, limit how much memory is going to be used for caching etc? Let's say I reserve 3 GB and my application + system services normally needs 1GB, but if there is a real need, my application can use 2GB of RAM extra, but when idling I want to limit the cache to take e.g. only up to 500 MB of free RAM, so that I don't have to pay for 3 GB all the time.

2
  • Have you verified that it's really the case? Since the "server" has variable (and presumably shared with other users) amount of memory, that sounds like it's merely an OpenVZ container, which does not have its own cache (nor kernel) – it shares one with all other containers on the host. Sep 22, 2016 at 8:24
  • Interesting point. The container is indeed OpenVZ. I've however checked both htop and free -m commands and the free command says cca 900 MB in "cached" column. I suppose it's disk cache, maybe I'm wrong? Maybe it's not the kernel cache, but some memory mapped disk files serving as app cache in userland? Sep 22, 2016 at 9:28

1 Answer 1

0

The linked answer how-do-you-empty-the-buffers-and-cache-on-a-linux-system shows you how to free your caches (pagecache, dentries and inodes). You would need to do this freeing activity repeatedly, perhaps from cron. I do not know if it would work the way you want in an OpenVZ container, because OpenVZ's memory management seems complex (or maybe not documented well enough). I do not mean to criticize OpenVZ; it is a great virtualization solution and can squeeze many systems onto a physical server.

Cool, linux-ftools can help you see how many cache pages are being used per file.

You could also experiment with swappiness, and set it to 100 for aggressive swapping.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .