7

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.

1
  • I found flashcache. Now I do some tests with it backed up by compcache.
    – Stone
    Feb 3, 2012 at 8:18

4 Answers 4

6
+50

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.

1
  • vfs_cache_pressure gives me some positive change but not as much as I expected.
    – Stone
    Jan 16, 2012 at 12:21
1

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).

1
  • 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, 2012 at 11:47
1

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.

0

Go to terminal then go to root mode then do: nano /etc/sysctl.conf and at the bottom copy this.

vm.swappiness = 60

vm.overcommit_ratio = 100

vm.min_free_kbytes = 1000000

This is the current config I am using, the 2 bottom lines equate to 1gb as I am limited to 10gb of my 12gb of ram so it reserves 10% for me and adjust it of course as it needs to be.

2
  • It is very difficult to tell what you are trying to say. Please use grammar and formatting to make your answer more clear. Mar 16, 2018 at 18:31
  • 1
    Sorry, how I typed it in the draft was presented differently then my edit, my edit is what I intendedd to post.
    – theman5142
    Mar 17, 2018 at 3:11

You must log in to answer this question.

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