4

I am trying to analyze from where the amount of swap is from, and looking at smem display I get a completely different amount of swap usage.

Free shows the following :

[root@server1 ~/smem-1.3]# free -k
             total       used       free     shared    buffers     cached
Mem:      24554040   24197360     356680          0     510200   14443128
-/+ buffers/cache:    9244032   15310008
Swap:     20980880    2473120   18507760

And smem shows :

  PID User     Command                         Swap      USS      PSS      RSS
...
18829 oracle   oracle_1 (LOCAL=NO)             0     3.9M    98.3M    10.1G
18813 oracle   oracle_1 (LOCAL=NO)             0     3.9M    98.6M    10.1G
18809 oracle   oracle_1 (LOCAL=NO)             0     4.1M    99.2M    10.0G
28657 oracle   ora_lms0_1                 56.0K    54.1M   100.3M     4.2G
29589 oracle   ora_lms1_1                964.0K    69.7M   118.9M     4.5G
29886 oracle   ora_dbw1_1                  5.7M    20.8M   130.9M    10.2G
29857 oracle   ora_dbw0_1                  4.2M    22.6M   133.0M    10.3G
11075 ccm_user /usr/java/jre1.6/bin/java -   197.8M   133.9M   135.9M   140.7M
21688 bsuser   /usr/local/java/bin/java -c    30.7M   145.1M   147.2M   152.1M
29930 oracle   ora_lck0_1                  2.3M    58.6M   169.8M     1.0G
29901 oracle   ora_smon_1                     0    78.0M   195.6M     4.3G
15604 oracle   /var/oragrid/jdk/jre//bin/j    65.4M   253.9M   254.3M   262.2M
-------------------------------------------------------------------------------
  359 10                                     678.8M     2.5G    13.5G     1.2T

Why free shows me "2.4G" and smem only shows me 679M? One of them is showing some wrong result.

I need to find out where are the remaining 1.8G, or prove that free is showing wrong results.

Last but not least, the kernel is 2.6.18.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user2360915
  • 1,100
  • 11
  • 30

1 Answers1

1

Well, the main issue is RSS(resident set size) and PSS(proportional set size). From http://www.selenic.com/smem/ as it says - "PSS instead measures each application's "fair share" of each shared area to give a realistic measure". On the otherhand, RSS overestimates by calculating shared memory area of multiple applications as their own. And this is why, you see the difference. In simple word, smem can differentiate between applications shared memory and rather than treating shared area as every applications own!

rakib_
  • 136,911
  • 4
  • 20
  • 26
  • 1
    I can understand RSS is big because of shared mem, and PSS is somehow showing the "real" amount of memory used by each applications. Now, the point is how "Free" can say that 2.4G is swapped out, when smem can say only "678M". I was thinking that free is displaying the amount of unused shared pages swapped out. True? If yes, are we here saying that "Free" is wrongly displaying the swapped memory? – user2360915 May 08 '13 at 06:19
  • Well, I won't say wrongly, but inaccurately, though it depends on how you want to see the stat. On smem, it shows both RSS, PSS so there supposed to be no confusion! – rakib_ May 08 '13 at 06:30
  • No confusion for the active memory, but still some confusion regarding the swap. – user2360915 May 08 '13 at 09:01
  • Free shows three entries for swap memory usages - a) "total" the total swap memory on your system; b) "used" amount of swap mem used from total swap memory; c) "free" amount of free swap memory. I'm having bit problem understanding your comment - "free is displaying the amount of unused shared pages swapped out", it confuses me. Swap memory gets used when your primary Mem is full. And free will show much mem is used/free/avail on your system. Hope you'll get the difference! – rakib_ May 08 '13 at 09:20
  • Yes, but if you look at the data i posted, Free shows "2473120" used, but smem shows "678.8M" used. This is what I dont understand. Why such a huge difference? Is "free" correct? Is "smem" correct? How can I find out what is really using the swap? – user2360915 May 08 '13 at 09:24
  • 1
    This is exactly what i tried to answer on my first post! For ex. say you've 2 program name "sam1","sam2" - it uses a shared library "shared.so", sizeof sam1 and sam2 is 5k and "shared.so" is 10k. Let your system has 50k mem. When you'll run free (sam1 and sam2 are running), it'll show 30k(sam1+shared.so = 15 + sam2+shared.so=15) is used. And if you run smem, you'll see (sam1+sam1+shared.so=20) 20k is used. Shared object loads once, so it needs to be calculated once, not twice (which is done by free, this is what it does wrong). Do I make myself clear? – rakib_ May 08 '13 at 09:35
  • 2
    Have to disagree with whith rakib comments. I see two possible factors accounting for the difference as asked by OP. 1) If launched by != root, `smem` can only report the user's process 2) it only accounts process, i.e. not the **[Page cache](https://www.thomas-krenn.com/en/wiki/Linux_Page_Cache_Basics)**. Also 75% of *shared memory* is very unlikely to my limited knowledge. And why would `free` differenciates between *Used* and *shared* memory for RAM (displayed in my case, free v3.3.11) then mix them for swap? – tuk0z Jun 22 '16 at 17:57
  • Well, the issue is more related with PSS and RSS. please refer to the wiki entries them. And `free` doesn't differentiate between used and shared ram, it simply shows whatever it finds at `/proc/meminfo` where meminfo gets dumped by the kernel. – rakib_ Jun 23 '16 at 05:13