{"id":39444,"date":"2016-08-26T12:35:33","date_gmt":"2016-08-26T07:05:33","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=39444"},"modified":"2024-01-02T17:46:20","modified_gmt":"2024-01-02T12:16:20","slug":"understanding-memory-utilization-in-linux","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/understanding-memory-utilization-in-linux\/","title":{"rendered":"Understanding Memory Utilization in Linux"},"content":{"rendered":"<p>Linux is an awesome\u00a0operating system. It performs good with fewer resources and tries to maximize utilization of available resources automatically and because of this, it&#8217;s slightly difficult to understand resource utilization.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/01\/5654683066_6703251656.jpg\" alt=\"Image result for linux\" \/><\/p>\n<p>Linux comes with many commands to check memory usage. The &#8220;<strong>free&#8221;<\/strong> command usually displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The &#8220;<strong>top&#8221;<\/strong> command provides a dynamic real-time view of a running system. The top command can display system summary information as well as a list of the process\u00a0currently being managed by the Linux kernel.<\/p>\n<p>We will use free and top to understand the memory utilization of our operating system.<\/p>\n<p>the free command\u00a0comes with the set of options you can choose to modify the results, like with option &#8220;-m&#8221; result will display\u00a0memory in MegaByte. you can read more about options on the <a title=\"manpage\" href=\"http:\/\/man7.org\/linux\/man-pages\/man1\/free.1.html\">manpage.<\/a><\/p>\n<p>Let&#8217;s see the below example and understand:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-39445 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_007.png\" alt=\"free\" width=\"590\" height=\"85\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_007.png 590w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_007-300x43.png 300w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/><\/p>\n<p>In this example, total memory is 11901 MB, 8957 MB is used and 2943 MB free. But that does not just mean that application now can only request for 2943 MB free memory, If you look at the usage figures you can see that 5941 MB memory use is for buffers and cache. So, if applications request memory, then Linux OS will free up the buffers and cache to yield memory for the new application requests. So, a question arises, why to cache and buffer at the first place?<\/p>\n<p>Linux by default tries to use RAM in order to speed up disk operations by making use of available memory for creating buffers (file system metadata) and cache (pages with actual contents of files or block devices), helping the system to run faster because disk information is already in memory which saves I\/O operations.<\/p>\n<p>Now, let us understand the memory utilization by processes, we will use &#8220;<strong>top&#8221;<\/strong>\u00a0command to get the required information. &#8220;<strong>top&#8221;<\/strong> comes with a lot\u00a0of information by default, but to get all the information we needed we will add two more columns CODE and DATA. please read more about modifying default behavior of top command on the manpage.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-39448 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_009.png\" alt=\"\" width=\"759\" height=\"136\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_009.png 759w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_009-300x53.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/Selection_009-624x111.png 624w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/p>\n<p>In the above example let&#8217;s discuss first process &#8220;Xorg&#8221;. The important \u00a0tables for memory to look are %MEM, VIRT, RES, SHR, CODE, DATA.<\/p>\n<p><strong>%MEM<\/strong> is directly related to RES, it&#8217;s the percentage use of total physical\u00a0memory by the process.<br \/>\n<strong>VIRT<\/strong> is the total memory that this process has access to shared memory, mapped pages, swapped out pages, etc.<br \/>\n<strong>RES<\/strong> is the total physical\u00a0memory used shared or private that the process has access to.<br \/>\n<strong>SHR<\/strong> is the total physical shared memory that the process has access to.<br \/>\n<strong>DATA<\/strong> is the total private memory mapped to process physical or not.<br \/>\n<strong>CODE<\/strong> also known as &#8220;text\u00a0resident set&#8221; is total physical memory used to load application code.<\/p>\n<p>So, to sum up,\u00a0<strong>RES<\/strong> is most close to the memory used by the process in memory, excluding what&#8217;s swapped out. but keep in mind that includes the <strong>SHR<\/strong> (shared physical memory) which mean it could have been used by some other process as well.<\/p>\n<p>This is just a brief introduction about memory utilization in Linux. I will soon be making a screencast explaining all of these concepts in depth.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux is an awesome\u00a0operating system. It performs good with fewer resources and tries to maximize utilization of available resources automatically and because of this, it&#8217;s slightly difficult to understand resource utilization. Linux comes with many commands to check memory usage. The &#8220;free&#8221; command usually displays the total amount of free and used physical and swap [&hellip;]<\/p>\n","protected":false},"author":747,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":364},"categories":[2348],"tags":[260,3918,3292,3920,3921,3919],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39444"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/747"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=39444"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39444\/revisions"}],"predecessor-version":[{"id":59841,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39444\/revisions\/59841"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=39444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=39444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=39444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}