Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I usually run many programs and virtual machines on my desktop. The CPU isn't the bottleneck but the memory. (Buying more memory isn't a solution because it's not my own computer.)

I started experimenting with compcache and it works fine on compressing memory. I can increase it's usage by swappiness 100. But when real (uncompressed), memory starts to fill up then Linux starts to empty caches and buffers before massive swapping what is bad for me because switching between programs gets painfully slow.

I wasn't able to find a way to reserve memory for buffers and caches so I started to look alternate ways and found cgroups.

In cgroups you can't set memory limit for root resources so I tried to move all processes into a group with limited memory, but somehow it didn't seems working.

Please help how can I reserved memory for buffers and caches and start swapping to compcache at an early stage.

share|improve this question

migrated from serverfault.com Jan 5 '12 at 14:20

This question came from our site for professional system and network administrators.

    
I found flashcache. Now I do some tests with it backed up by compcache. –  Stone Feb 3 '12 at 8:18

3 Answers 3

If you want to reserve memory for cache and buffer: echo 10 > /proc/sys/vm/vfs_cache_pressure when 100 is the default value. Then you can limit the max ram used by each app: echo 8192 > /proc/sys/vm/max_map_count. I recommend a swapiness=30 and high /proc/sys/vm/dirty_writeback_centisecs and /proc/sys/vm/dirty_expire_centisecs values (both: 1250). It can also help to tweak the file system:

echo 8192 > /sys/block/mmcblk0/queue/max_sectors_kb
echo 8192 > /sys/block/mmcblk1/queue/max_sectors_kb
echo 0 > /sys/block/mmcblk0/queue/iosched/slice_idle
echo 0 > /sys/block/mmcblk1/queue/iosched/slice_idle
echo 160 > /sys/block/mmcblk0/queue/iosched/quantum
echo 160 > /sys/block/mmcblk1/queue/iosched/quantum
echo 800 > /sys/block/mmcblk0/queue/iosched/fifo_expire_sync
echo 800 > /sys/block/mmcblk1/queue/iosched/fifo_expire_sync
echo 180 > /sys/block/mmcblk0/queue/iosched/fifo_expire_async
echo 180 > /sys/block/mmcblk1/queue/iosched/fifo_expire_async
echo 1 > /sys/block/mmcblk0/queue/iosched/back_seek_penalty 
echo 1 > /sys/block/mmcblk1/queue/iosched/back_seek_penalty

These values are from my mobile and my laptop and it works really stable and makes things pretty fast. My mobile is memory limited but this tweaks helps a lot. My mobile has cgroups enabled too and I would recommend the 4k wonderpatch because this adds custom cgroups to each app a user is running from the terminal (not desktop) but I don't know how to limit memory with cgroups.

share|improve this answer
    
vfs_cache_pressure gives me some positive change but not as much as I expected. –  Stone Jan 16 '12 at 12:21

You can't directly reserve memory for buffers and cache. The kernel will use memory that isn't used for anything else for this, sometimes swapping out very old unused pages to make more room, so the way to resve memory for caches/buffers is to limit the amount of RAM applications (including your virtual machines) are using.

One common problem is allocating more memopry to VMs than is needed, so that the OS in the VM has room for disk caches. You can remove the need to do this by turning on caching support for your virtual disks (how to do this depends upon your virtualisation solution, which you don't state) thereby letting teh host decide how much memory globally is used for caching. That way you can reduce the amount of memory allocated to each VM with less I/O performance degredation than otherwise. A word of warning though: by doing this you do open yourself to extra danger of filesystem corruption on the virtual disks if your host machine has an unclean shutdown (such as caused by a power cut).

share|improve this answer
    
I understand what you write but using cgroups isn't it possible? I was able to limit memory of certain apps with cgroups and force them to swap. It worked well, but when tried to force all apps to a limited group somehow the root group consumed more memory than my group where all apps was and the memory usage was higher than the group limit. The kernel Documentation/controllers/memory.txt sais that "Create a cgroup with limited amount of memory, this can be used as a good alternative to booting with mem=XXXX." So this is why I supposed that it should work like how I seed. –  Stone Jan 5 '12 at 11:47

If you have limited memory, don't try to to dictate memory-usage to the kernel. The kernel is probably already doing a better job than you can do with cgroups or compcache.

The only real solution, if memory increase is not an option, is to limit your usage of the RAM. Increasing swap space may "solve" the problem but cause lengthy swapping between processes. Reducing RAM usage by VM can improve the situation.

See the article Reduce your Linux memory footprint. Although from 2007, it can still help.

You could also compile your own kernel, turning off every service and option that you don't need. See for example this article: Kernel Size Tuning Guide.

You might instead move to a small-memory version of Linux, as in this article : 8 of the best tiny Linux distros.

But I repeat that there is no miracle solution that can let you use lots of memory on a memory-starved computer, at least not without lots of slow swapping. You will have to optimize your usage patterns. Optimizing the kernel can help a bit, but has its limits.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.