<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ronaldo Lanhellas</title>
    <description>The latest articles on DEV Community by Ronaldo Lanhellas (@rlanhellas).</description>
    <link>https://dev.to/rlanhellas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1471314%2Fc0750e06-df87-4576-9a66-782189f07530.jpeg</url>
      <title>DEV Community: Ronaldo Lanhellas</title>
      <link>https://dev.to/rlanhellas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rlanhellas"/>
    <language>en</language>
    <item>
      <title>Page cache fine tunning, dirty contents</title>
      <dc:creator>Ronaldo Lanhellas</dc:creator>
      <pubDate>Tue, 24 Sep 2024 19:30:20 +0000</pubDate>
      <link>https://dev.to/rlanhellas/page-cache-linux-tunning-4hp1</link>
      <guid>https://dev.to/rlanhellas/page-cache-linux-tunning-4hp1</guid>
      <description>&lt;p&gt;Hi folks, no matter the language you use, if you running under Linux this post is for you. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TLDR; Use dirty properties to set correct Page Cache usage on linux kernel. They are: &lt;code&gt;vm.dirty_background_ratio&lt;/code&gt; and &lt;code&gt;vm.dirty_ratio&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In your app, when you call a file write it does not write right away to disk, instead, it is saved on RAM, and this block is called Dirty content. During this "dirty period" you can lose data, just heads up. &lt;/p&gt;

&lt;p&gt;When is this dirty content saved to disk? To simplify this post, it depends on two properties most of the time: &lt;code&gt;vm.dirty_background_ratio&lt;/code&gt; and &lt;code&gt;vm.dirty_ratio&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;vm.dirty_background_ratio&lt;/code&gt;: A soft limit representing the percentage from total system RAM to trigger the &lt;code&gt;write back&lt;/code&gt; thread process. i.e.: 10% from 10GB RAM, meaning when you reach 1GB in page cache, Linux will flush the content to disk in a background thread.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;vm.dirty_ratio&lt;/code&gt;: A hard limit to avoid using more page cache than allowed. Then if you reach this hard limit percentage from total system RAM the content will be flushed to disk right away and might cause some performance degradation. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The recommendation is to use always &lt;code&gt;vm.dirty_background_ratio&lt;/code&gt; less than &lt;code&gt;vm.dirty_ratio&lt;/code&gt;. &lt;a href="https://www.suse.com/pt-br/support/kb/doc/?id=000017857" rel="noopener noreferrer"&gt;SUSE KB&lt;/a&gt; suggests dirty_background_ratio to be 1/4 or 1/2 of the dirty_ratio.&lt;/p&gt;

&lt;p&gt;In order to apply these to your Linux distro, you should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change the &lt;code&gt;/etc/sysctl.conf&lt;/code&gt; to apply permanently.&lt;/li&gt;
&lt;li&gt;Or execute the command bellow to a temporary change:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo 10 &amp;gt; /proc/sys/vm/dirty_ratio
echo 5 &amp;gt; /proc/sys/vm/dirty_background_ratio 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
    </item>
  </channel>
</rss>
