RAM Usage discrepancy

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) RAM Usage discrepancy
# 1  
Old 12-30-2012
RAM Usage discrepancy

Hey there! I'm a new user here who registered because I couldn't get these kind of questions answered in the place I directly com from. Smilie

I've found a discrepancy in total RAM used and I can't figure out why it is. My only guess is there are some RAM used by some stuff impossible to identify, but seems pretty unlikely to me.

From the beginning:
1. Launch Activity Monitor and sum the Active Memory + Wired Memory in the Memory tab. This'll give you some number of GB used. (User RAM + system RAM that is if I'm correct).
2. Order processes by RAM and sum their RAM usage. It's not even close. And I'm talking almost 30% off.

Launch terminal and run:
(did it quickly so it's probably a little bit redundant)
Code:
top -l1 -o RSIZE | sed 1,12d | awk '{print $11}' | sed -e 's/[+,-]//g' -e 's/K//g' -e 's/M/*1024/g' | bc
  | awk '{RAM+=$1} END {printf "\nProcesses RAM:\t%.2fGB\n",RAM/1024/1024}';
active=`vm_stat | grep ' active' | awk '{print $3}'`;
wired=`vm_stat | grep wired | awk '{print $4}'`;
echo   $wired $active | awk '{printf "RAM Usage:\t%.2fGB\n\n",($1+$2)*4096/1024/1024/1024}'

It'll print out the total amount of RAM used by processes and then the active + wired RAM.

(See my example in the attached image. As you can see there's around a 25% off in this case).

Any ideas why this happens?
RAM Usage discrepancy-captura-de-pantalla-2012-12-20-la-174227png

Last edited by Scott; 12-30-2012 at 07:05 AM.. Reason: Format code
# 2  
Old 12-30-2012
Yup - file caches. All of UNIX - even OSX which loves to carve a unique path - uses memory to cache file data. For example, this is central to the way write() works.

write() does NOT guarantee the data written to a file is immediately part of the physical file on disk. Instead, the kernel parks data in free memory. Periodically this is flushed or "synced" to disk, i.e., dirty cache pages are written to disk.

read() also employs memory this way. Because disk is so much slower to find and return data, while memory is fast, when the filesystem returns data from a big file it parks big chunks of the data in memory. Subsequent reads are satisfied much faster.

You can see this in action. On a quiet system, find a ~100MB file that is human readable.
Code:
time cat bigfile > /dev/null
time cat bigfile > /dev/null

The second cat on quiet system is usually a lot faster than the first. Why? File cache. On hammered systems this may not be true. This is why hammered systems are disproportionately slower than their underused cousins. File cache availability.
# 3  
Old 12-30-2012
Created a 100MB file and did what you said.
Code:
b=0; while [ $b -eq 0 ]; do ps -A >> Desktop/file; if [ `du -d0 Desktop/file | awk '{print $1}'` -gt 204800 ]; then b=1; fi; done

Did it 4 times. Looks like there isn't a noticeable difference really.

Quote:
~ $ du -d0 -h Desktop/file;time cat Desktop/file > /dev/null
103M Desktop/file

real 0m0.019s
user 0m0.001s
sys 0m0.018s
~ $ du -d0 -h Desktop/file;time cat Desktop/file > /dev/null
103M Desktop/file

real 0m0.020s
user 0m0.001s
sys 0m0.018s
~ $ du -d0 -h Desktop/file;time cat Desktop/file > /dev/null
103M Desktop/file

real 0m0.020s
user 0m0.001s
sys 0m0.019s
~ $ du -d0 -h Desktop/file;time cat Desktop/file > /dev/null
103M Desktop/file

real 0m0.020s
user 0m0.001s
sys 0m0.018s
~ $
I then though that that same file might've been in RAM since the very first beginning as I had just created it, so ran find in terminal to find a 100MB file. Didn't have one so opted for a 50MB one. lol

Here's the output:

Code:
~ $ du -d0 -h Documents/Programación/Flash/Movement/Goma.fla; time cat Documents/Programación/Flash/Movement/Goma.fla > /dev/null 
 50M	Documents/Programación/Flash/Movement/Goma.fla

real	0m0.132s
user	0m0.002s
sys	0m0.023s
~ $ du -d0 -h Documents/Programación/Flash/Movement/Goma.fla; time cat Documents/Programación/Flash/Movement/Goma.fla > /dev/null 
 50M	Documents/Programación/Flash/Movement/Goma.fla

real	0m0.012s
user	0m0.001s
sys	0m0.011s
~ $

Second time is clearly faster now.

Thanks man!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Ubuntu 14.04 - how to less ram usage

Hello, I have an ubuntu14.04 installed pc with 32GB ram. Operating System: Ubuntu 14.04.5 LTS Kernel: Linux 4.9.148-xxxx-std-ipv6-64 Architecture: x86_64 When I check free memory it shows: total used free shared buffers cached Mem: 31882 ... (2 Replies)
Discussion started by: baris35
2 Replies

2. UNIX for Beginners Questions & Answers

Peak Ram Usage

grpdsku program allows user to check their group disk space in a server environment. The data in the dialog box queries a text file. Each text file is labeled with a current timestamp. Results output to a msgbox. Also, results output to a csv file. The csv file is sent to the user via email ... (13 Replies)
Discussion started by: dellanicholson
13 Replies

3. UNIX for Dummies Questions & Answers

Average CPU and RAM usage for a process

Hi, I will be creating a process myself and I want to know the average CPU and RAM used by the process over the lifetime of the process. I see that there are various tools available(pidstat) for doing , I was wondering if it possible to do it in a single command while creation. Thanks in... (3 Replies)
Discussion started by: koustubh
3 Replies

4. Solaris

Solaris Filesystem usage discrepancy after "copy"

I have a query someone may be able to shed some light on... We have a Solaris 10 OS Sun V490 server Sparc. I have a SAN attached EMC Clarrion LUN which we have app data stored on. Pseudo name=emcpower0a CLARiiON ID=CK200070300470 Due to storage requirements - I need to migrate this... (4 Replies)
Discussion started by: ru4n1
4 Replies

5. Red Hat

High RAM usage, extremely low swapping

Hi team I have three physical servers running on Red Hat Enterprise Linux Server release 6.2 with the following memory conditions: # cat /proc/meminfo | grep -i mem MemTotal: 8062888 kB MemFree: 184540 kB Shmem: 516 kB and the following swap conditions: ... (6 Replies)
Discussion started by: hedkandi
6 Replies

6. Solaris

Sun X4170 M2 RAM discrepancy

Hi all, We are seeing an odd problem on one of our new servers. It seems to be reporting 4MB less RAM than is installed: # prtconf | grep Mem Memory size: 32764 Megabytes Our other servers for example shows none missing: # prtconf | grep Mem Memory size: 32768 Megabytes Both... (5 Replies)
Discussion started by: wmd
5 Replies

7. Linux

Ram Usage

Hi one of our applications that runs on our Linux server leaks memory resulting in Ram that was used by the program not being released back to the operating system once a file has been processed. the result is over a very short period virtual all the memory has been used. an example currently ... (8 Replies)
Discussion started by: treds
8 Replies

8. Shell Programming and Scripting

RAM usage Information

Hi i just wanted to know what is the code to display amount of RAM and also the percentage used? I know i can possibly use the vmstat code but what part indicates the RAM? Any help would be much appreciated. Thanks (1 Reply)
Discussion started by: warlock129
1 Replies

9. UNIX for Dummies Questions & Answers

Command to check RAM usage

Hi Guys, How can i check the RAM usage for a particular user on the Linux machine. What command can be used. Thanks in advance, Swapna (1 Reply)
Discussion started by: Swapna173
1 Replies

10. Solaris

RAM Physical Memory usage by each Process.

Hi All, I am trying to find the physical memory usage by each process/users. Can you please let me know how to get the memory usage?. Thanks, bsraj. (12 Replies)
Discussion started by: bsrajirs
12 Replies
Login or Register to Ask a Question