Skip to main content

Understanding Memory Usage

Working Set is the set of actively used pages. A process needs that amount of physical memory to run properly. If there is not enough physical memory, process will spent considerable amount of time to swapping. Thus performance will be degraded. If this problem is system wide, all process are hungry for physical memory, system will spent most of time to swapping witout any actual work. This is called thrasing.

Linux


top Command for Process Memory Usage


Column explanations from Understanding Process memory:
·         RES shows the actual physical RAM used by your process.
·         VIRT shows the actual virtual memory reserved by your process.
·         DATA shows the amount of virtual private anonymous memory reserved by your process. That memory may or may not be mapped to physical RAM. It corresponds to the amount of memory intended to store process specific data (not shared).
·         SHR shows the subset of resident memory that is file-backed (including shared anonymous memory). It represents the amount of resident memory that may be used by other processes.





Additionally to understand total and free memory stats:
1-      Shows total amount of physical memory
2-      Shows free amount of free memory  availble to applicatios. It is sum of buffers, cached and free memory fields. This is because linux uses memory to cache disk content for performance reasons. If memory is needed it is reclaimed and given to applications.


pmap Command for Detailed Process Memory Usage



Pmap command lists details about all mappings made by process. With –x switch:
-          Column 1 shows address of the mapping
-          Column 2 shows size of mapping
-          Column 3 shows resident size of mapping, in other words physical memory used.
-          Column 4 shows dirty mappings. Those are file backed shared mappings which are modified but not synchronized with backing file.
-          Column 5 shows details about access rights:
o   r shows readable mappings
o   w shows writable mappings
o   x shows executable mappings
o   s shows shared mappings
-          Column 6 shows Mapping type of the mapping. If it is file backed, backing file is shown. If it is anonymous, anon is displayed. Stack areas are shown with stack label.
Last line displays total of each column. A closer look will reveal that same files are mappend mutiple times with different access rights. This is because executable files contains different blocks like text, data, rodata, bss.

With –d switch, pmap shows details about total mapped memory, total writable/private memory and total shared memory. Writeable/private stat is worth mentioning. If There are multiple process of the same executable, this stat shows memory cost of this particular process. All other mappings are shared with other processes. For such processes pmap –d gives more accurate information than top command.


Pmap command uses data that is resident in /proc/[pid]/maps file. In some cases this file may contain more usable information.


Windows


Task Manager for Memory Stats


Details about stats can be found in What do the Task Manager memory columns mean?. Columns worth mentioning are:
-          Working Set is similar to RSS in linux top command and shows total amount of physical memory used including shared memory.
-          Private Working Set is like Workig Set, except it excludes shared memory.
-          Commit Size is similar to VIRT in linux top command and shows total amount of virtual memory reserverd for process.


VMMap for Detailed Memory Stats


VMMap is a utility program that can be downloaded separetly for learning detailed memory mapping information of a process.


Quick Help menu will display definitions of columns.

Comments

Popular posts from this blog

Obfuscating Spring Boot Projects Using Maven Proguard Plugin

Introduction Obfuscation is the act of reorganizing bytecode such that it becomes hard to decompile. Many developers rely on obfuscation to save their sensitive code from undesired eyes. Publishing jars without obfuscation may hinder competitiveness because rivals may take advantage of easily decompilable nature of java binaries. Objective Spring Boot applications make use of public interfaces, annotations which makes applications harder to obfuscate. Additionally, maven Spring Boot plugin creates a fat jar which contains all dependent jars. It is not viable to obfuscate the whole fat jar. Thus obfuscating Spring Boot applications is different than obfuscating regular java applications and requires a suitable strategy. Audience Those who use Spring Boot and Maven and wish to obfuscate their application using Proguard are the target audience for this article. Sample Application As the sample application, I will use elastic search synch application from my GitHub repository.

Hadoop Installation Document - Standalone Mode

This document shows my experience on following apache document titled “Hadoop:Setting up a Single Node Cluster”[1] which is for Hadoop version 3.0.0-Alpha2 [2]. A. Prepare the guest environment Install VirtualBox. Create a virtual 64 bit Linux machine. Name it “ubuntul_hadoop_master”. Give it 500MB memory. Create a VMDK disc which is dynamically allocated up to 30GB. In network settings in first tab you should see Adapter 1 enabled and attached to “NAT”. In second table enable adapter 2 and attach to “Host Only Adaptor”. First adapter is required for internet connection. Second one is required for letting outside connect to a guest service. In storage settings, attach a Linux iso file to IDE channel. Use any distribution you like. Because of small installation size, I choose minimal Ubuntu iso [1]. In package selection menu, I only left standard packages selected.  Login to system.  Setup JDK. $ sudo apt-get install openjdk-8-jdk Install ssh and pdsh, if not already i

Java: Cost of Volatile Variables

Introduction Use of volatile variables is common among Java developers as a way of implicit synchronization. JIT compilers may reorder program execution to increase performance. Java memory model[1] constraints reordering of volatile variables. Thus volatile variable access should has a cost which is different than a non-volatile variable access. This article will not discuss technical details on use of volatile variables. Performance impact of volatile variables is explored by using a test application. Objective Exploring volatile variable costs and comparing with alternative approaches. Audience This article is written for developers who seek to have a view about cost of volatile variables. Test Configuration Test application runs read and write actions on java variables. A non volatile primitive integer, a volatile primitive integer and an AtomicInteger is tested. Non-volatile primitive integer access is controlled with ReentrantLock and ReentrantReadWriteLock  to compa