Cache Pressure: optimize Linux performance

RAMDisk icon

Cache Pressure  can help us improve the performance of our GNU Linux distribution. With Cache Pressure we will be able to optimize our RAM memory, since with this option we can modify the way in which the kernel introduces blocks of data into the main memory. Keep in mind that we can do a thousand things to configure our kernel and our system to better adapt to the team.

Apple offer hardware and softwareTherefore, the operating system is highly optimized for such hardware. On the contrary, we find that other systems such as Linux or Android distros must work in a multitude of hardware combinations for which they are not optimized, however they work correctly and sometimes even better than iOS or Mac OS X in certain specific tasks. The same thing happens with OS X when we try to install it on a PC, we will have verified that it does not go as fine as it would on a Mac machine ...

Well, on Linux we can use a multitude of options to improve performance. Its flexibility allows us to optimize it to the maximum and the options are so wide that it is difficult to list them all. We can use Swappines configurations, remove unnecessary kernel modules, do a deep kernel configuration to install it more cleanly, pull config files, etc.

One of them is the one we present here, Cache Pressure. If we make a few small changes, we will notice a performance improvement when using programs, daily operation of the system or when opening videos or multimedia content. Cache Pressure has a default value of 100, and it can be varied between 0 and 100, therefore it is the maximum figure. This means that the kernel moves more data that is not going to be used immediately. from RAM to hard disk SWAP partition.

If you have a lot of RAM, 16GB or more, you can choose to put a number close to 100 or leave the default value, but if you don't have too much (<4GB), perhaps such a high number would make the RAM too busy ... We will try with a value of 50 like this:

sudo sysctl -w vm.vfs_cache_pressure=50

So we put the value 50 with the first line and we can test if the performance has improved (opens videos, applications, etc.), if so,  we make it permanent with:


sudo gedit /etc/sysctl.conf

And we edit the line adding at the end:

vm.vfs_cache_pressure=50

We save the changes and now you can check the change with:

sudo cat /proc/sys/vm/vfs_cache_pressure

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Turbo said

    Hello, very helpful! Can you have some type of associated contraindication, such as a safety or performance failure in specific tasks?

    1.    Isaac PE said

      Hello, why do you ask? For the memory dumps, for ...?

      Regards!

      1.    Turbo said

        I don't know, sometimes this kind of thing can have adverse effects.
        I already have it running and it is going very well, thanks for sharing :)

  2.   Mr. Paquito said

    This is interesting. What I am not quite clear is the benefit in performance in small machines and in sufficient or excess machines.

    I use Ubuntu 14.04, I have 8GB of RAM and I have reserved 2GB of SWAP. The system is installed on an SSD, but I left the SWAP on the HDD (I regret this because, for how little it works, it could well have stayed on the SSD; in the next installation, it will surely stay in the SSD). The temporary ones I send to the RAM.

    I had always heard of modifying the Cache Pressure for small machines, usually with a value of 50, but I had not read anything about doing it on more or less powerful machines. And I have three questions, if you will allow me:

    Can it really be advisable to do it on a powerful machine?

    Is it really useful for small machines?

    What can be monitored to see objectively where the improvement or the damage is?

    Greetings and thanks.

    1.    Isaac PE said

      Hello,

      The SWAP on the SSD is much better yes ...

      As for your doubts, it was a writing mistake of mine. Already solved.

      To your question 1: It wouldn't make much sense if you have plenty of RAM.

      To your question 2: Yes, because you avoid loading too much unnecessary data and leaving space for the most demanded at all times ...

      To your question 3: You can do a test with a machine with few resources with the default value and then modify it to see the difference, for example by timing the loading time of an application, the opening of multimedia files, etc.

      A greeting!

  3.   Mr. Paquito said

    Now it is clearer to me, it seemed to me that in a current machine, well equipped with RAM, it should not make sense.

    I have a laptop with limited micro and RAM which is the ideal equipment to test it.

    I'll try, let's see.

    Thank you very much.

    1.    Mr. Paquito said

      Hello again.

      Just after writing the previous comment I have looked at it on the laptop and, surprise, I already had it done.

      And now I remember. I had long ago looked at the following Ubuntu León blog post:

      http://www.ubuntuleon.com/2013/08/parametros-del-sysctlconf.html

      And I applied the modifications. In the laptop of yore I have Xubuntu 14.04 with the modifications indicated in the post and it does not go wrong. The main problem I have is that Chrome has a tendency to freeze, the disk starts to write like crazy with what things and locks the computer, there is no way. Firefox was better, but still I removed the disk cache and something has improved, but in Chrome it can't be done, I don't know how to do it, at least.

      Greetings.

      1.    Isaac PE said

        Hola!

        Yes, Chrome is unusually hungry for RAM and this hurts such RAM hungry programs.

        http://www.linuxadictos.com/los-mejores-navegadores-web-para-linux.html

        A greeting!

  4.   Leopold Cantillo said

    This article is very interesting, very practical, I am going to test on my laptop, with 4Gb of RAM, and a 64 Gb SDD disk. I only have one doubt, this does not affect the useful life of the SDD disk, it does not overload the writes in the SWAP ?, I ask this because when I installed this disk, I read several tutorials and forums to optimize them in Linux, (that was 2 years ago), and in some they even recommended not using SWAP. But I also understand that with the latest versions of the kernel and in general in modern distros, Trim and various things already automatically adapt to the environment with SDD disks, and the disks themselves bring better internal control, someone who knows the subject can clarify me how we are currently.
    Thanks for the article.

    1.    Mr. Paquito said

      I had replied before, but since I don't see the comment, I comment again. That is, if you see that two comments of mine appear saying more or less the same, it will be for that.

      The thing is, I think that today enough is known about SSDs not to worry about the writes that SWAP can do. That is, real tests have been carried out, stressing SSD disks to extremes that normal users would not reach in many years, no matter how hard we gave it. You can read about it here, for example:

      http://www.muycomputer.com/2014/12/05/test-de-resistencia-ssd

      Be careful, these tests refer to relatively current discs, with old models I could not tell you. But in view of the results, everything seems to indicate that any recent disk would last much longer than it will take to change computers.

      When I did my current installation (which was in the middle of last year, not that long ago) the information that was there was not clear and everyone was obsessed with reducing the writes to the SSD as much as possible, but now it is known that there is no reason to obsess over it. In fact, I'm even seriously considering switching my SWAP to the SSD; I've been reading about it and it doesn't seem to be too difficult, but I see that not everyone does it the same, I don't know which method will be better, for example:

      http://www.atareao.es/ubuntu/cambiando-swap-de-particion-en-ubuntu/

      or also

      http://foro.ubuntu-guia.com/Cambiar-particion-SWAP-en-UBUNTU-12-04-td4023366.html

      So I take this opportunity to thank you for help with this in advance.

      Greetings.

    2.    Mr. Paquito said

      I had replied before, but since I don't see the comment, I comment again. That is, if you see that two comments of mine appear saying more or less the same, it will be for that.

      The thing is, I think that today enough is known about SSDs not to worry about the writes that SWAP can do. That is, real tests have been carried out, stressing SSD disks to extremes that normal users would not reach in many years, no matter how hard we gave it. You can read about it here, for example:

      http://www.muycomputer.com/2014/12/05/test-de-resistencia-ssd

      Be careful, these tests refer to relatively current discs, with old models I could not tell you. But in view of the results, everything seems to indicate that any recent disk would last much longer than it will take to change computers.

      When I did my current installation (which was in the middle of last year, not that long ago) the information that was there was not clear and everyone was obsessed with reducing the writes to the SSD as much as possible, but now it is known that there is no reason to obsess over it. In fact, I'm even seriously considering switching my SWAP to the SSD; I've been reading about it and it doesn't seem to be too difficult, but I see that not everyone does it the same, I don't know which method will be better, for example:

      "Http://www.atareao.es/ubuntu/cambiando-swap-de-particion-en-ubuntu/"

      or also

      «Http://foro.ubuntu-guia.com/Cambiar-particion-SWAP-en-UBUNTU-12-04-td4023366.html»

      So I take this opportunity to thank you for help with this in advance.

      Greetings.

  5.   dhouard said

    Hello, does this have any contraindication or does it affect in any way if you already have a low value assigned to the vm.swapiness variable?

    I have currently assigned a value of 10 to said kernel variable and the performance is quite good. I do not know if modifying the cache_pressure will discolor something or I will be able to squeeze a little more my machine.

    1.    Mr. Paquito said

      I have read not long ago that real tests were made of the use of SSD disks, putting them to extremes that no PC user will reach, no matter how much we use it on a day-to-day basis, and the conclusion they drew is that they turned out to be much more resistant than previously believed. A news in this regard is the following:

      http://www.muycomputer.com/2014/12/05/test-de-resistencia-ssd

      As it seems that they resist much more than was believed (and I have a SAMSUNG 840 PRO, which comes out very well in the test), I think it is best to make the most of them, and use the speed of these discs so that the SWAP is not a drag seems like a good idea to me (of course, knowing this).

      Of course, at the time I did the installation that I have now, everyone recommended treating them with care and reducing the writes to the maximum, but I do not think that is necessary in view of this data, rather the opposite, it is say, that better to take advantage of them.

      For sure, the next installation I do (16.04 if all goes well) will have the SWAP on the SSD, but I'm even thinking of moving it already, because I've been reading around how to do it and it doesn't seem to be excessively difficult, although I have seen different ways of doing it and I don't know which is the good one, for example:

      http://www.atareao.es/ubuntu/cambiando-swap-de-particion-en-ubuntu/

      or also

      http://foro.ubuntu-guia.com/Cambiar-particion-SWAP-en-UBUNTU-12-04-td4023366.html

      I take this opportunity to thank you for advice in advance on this, if you allow me.

  6.   Mr. Paquito said

    Excuse me for so much comment.

    They really didn't appear and now they all come out at once.

    I'm sorry.

  7.   Joaquin Garcia said

    Nothing happens Mr. Paquito. Regarding the last thing you comment, it is true that the latest SSDs are not affected too much by the high number of writes, however when it comes to SSD disks it is talked about all and not only the current ones. I use an SSD disk but it is old and I do not want to test if it is resistant or not for fear of breaking, but otherwise it works very well and it was cheap. Even the current discs, there are some that are not resistant to as many writes. Therefore, for cases like yours, it is better that you choose your and in general warn about misuse since there are still many newbies in the Gnu / Linux world.
    Greetings and comment and write everything you want;)

    1.    Mr. Paquito said

      That's why I already said that the test in question refers to current records and Muy Computer seems to me to be a serious site, which does not usually publish things lightly. Mine, in fact, is a SAMSING 840 PRO, which comes out very well in the test. It was not particularly cheap, exactly one euro per GB, but I think it was one of the best investments I made.

      Obviously, with older or lower quality discs you still have to think about it more, but according to the data that is becoming known, it seems increasingly clear that they are more resistant than previously believed.

  8.   Paquito Turriano said

    It doesn't work for me :-(

    turriano @ turriano-Lenovo-B50-30: ~ $ sudo gedit /etc/sysctl.conf
    [sudo] password for turriano:
    sudo: gedit: command not found
    turriano @ turriano-Lenovo-B50-30: ~ $ sudo gedit / etc / sysctl.conf
    sudo: gedit / etc / sysctl.conf: command not found
    turriano @ turriano-Lenovo-B50-30: ~ $

  9.   franc said

    The explanation you give of what cache pressure does is lousy. Either you explain yourself very badly or you have no idea what cache pressure does.