[Motorola Droid RAZR] Ohmster:
What is "Memory"?

Educational Post: What is "Memory" and how do we know when we "run out" of it?

Please do not kill me! If you hate long posts, skip over this one, NOW.

This will be a somewhat lengthy post. Geeks welcome. To make this point clear, I want to run a mini Android education refresher, if you guys don't mind. All of you are smart and are welcome to speak your mind at any time. :o

Hey Guys, for whatever reason, Android seriously plays fast and loose with the word "memory". As we all know, a computer (smart phones are computers) needs a few things to actually work. Just basics here, not listing every piece of hardware.

A CPU

RAM - Random Access Memory or "Memory"

Disk Space for files, OS, swap space, etc. Can be hard drive or sdcard

Pretty basic right? Never mind the keyboard, display, NIC, ,etc. This is good for today's discussion. When people say "Oh, I need more memory in my phone." What do they really mean? More RAM, more internal sdcard free space, a bigger ext-sdcard, a larger /system. /data, or /cache partition, what is this "Memory" of which we speak?

To be conventional, I will speak of "memory" as in Random Access Memory, RAM, a small electronic chip of memory cells which acts like storage but is exponentially faster to be useful to the CPU in terms of GHz. So how much of this real, electronic memory do we have? Let's check the stats on the Droid Razr and Droid Razr Maxx here.

Motorola DROID RAZR MAXX vs Motorola DROID RAZR

System memory 1024 MB RAM 1024 MB RAM

Okay, Razr Maxx and Razr both have 1Gb of random access memory. For this chat, I don't want to get side-tracked with partition or sdcard space "memory". To me, memory is RAM. Period. We can also bring up swap space here because it is used by Linux and Android as extra memory, a partition of the disk or sdcard is actually used as RAM when physical RAM is very low. Stored memory information is written and read to the swap space partition to "give us more RAM" when we need it. Although it is used as RAM, it is WAY # of times slower than electronic RAM because the CPU now has to read and write to a physical media such as sdcard or hard disk instead of access data stored electronically in "live" chip memory cells. ...I do hope that is not too confusing and that everyone can follow along. This is "General Consensus" or agreed on by everyone, yes? Any "Doubting Thomas'" out there? :)

How do we know how much of this 1 Gb internal electronic RAM is in use and how much of it is free?

I think there are apps for this, but one of my favorite "Swiss Army Knife" tools is a simple Terminal Emulator for Android. (Wow, I love this Terminal, in the play store screen shots, the guy is actually compiling a binary file in one of them!)

Okay, what do we do with this terminal?

Well, a terminal is called a "CLI" or "Command Line Interface", meaning you run commands on it to perform various actions. It will run in a SHELL such as the Bourne shell. Much like computers in the old days that used DOS. A handy terminal guid would be helpful, suggest you bookmark this page:

XDA Guide: Using the Terminal

Now what about the commands we need to use? Several of the most common are listed in the above mentioned guide, but the shell command we need is listed elsewhere, give you a list in a sec. The actual CLI commands are a part of the chosen shell in Linux, BASH is the most commonly used shell. In Android, the CLI commands are provided courtesy of Busybox, which is installed when you root your phone.

Busybox Command List for Android

The command we are looking for here to determine the amount of Android RAM memory, used, and free is called "free" as in "how much free memory do I have?".

Linux is cool because you can run the free command with switches to show the memory in Gigabytes, Megabytes, Kilobytes, or Bytes. Android Busybox is not that sophisticated so all values will be in Bytes of memory.

So how do I find out how much memory I have, is used, and is available and free to use?

Well, you type the word "free" into a terminal window and read the results. Since the Razr screen is very small, there will be "word wrap" that makes it harder to read. So I will give some screenshots from Linux, Android in an PC ADB terminal, and finally, the results in a terminal emulator on the phone itself. The easiest one to read is by doing it with ADB on a PC and the results look like this:

[paul@paulspcworks ~]$ free total used free shared buffers cached

Mem: 2979220 1121596 1857624 1928 269604 617996

-/+ buffers/cache: 233996 2745224

Swap: 5210108 0 5210108

[paul@paulspcworks ~]$

The columns do not line up very good so some screenshots would help a lot here to simplify what you are looking at.

First up, a Linux CLI showing the free command:

[IMG="Linux free command in terminal"]http://home.comcast.net/~theohmster/razr-img/linux-free.jpg[/IMG]

Next is the actual Razr memory displayed with "free" in an ADB shell so the columns line up. This is really my phone.

[IMG="Razr free command on ADB"]http://home.comcast.net/~theohmster/razr-img/adb-free.jpg[/IMG]

Hopefully, the above two shots teach you how the columns line up so you can interpret what you will find when you run free in a terminal emulator on your phone.

EDIT:

I changed the font size for this shot in terminal to 12 point so the columns would line up.

Feel free to use a larger font like 16 point for general use.

[IMG="free command in Android terminal emulator window"]http://home.comcast.net/~theohmster/razr-img/droid-free.jpg[/IMG]

All three of these screen shots show the RAM that is:

total used free shared buffers cached

By reading the above terminal screen shot, I see that my phone currently has a total of 859Mb of RAM (total ram is supposed to be 1024Mb or 1Gb per specs.), 828Mb in use, and 31Mb of free, actual electronic RAM free. Next paragraph explains the discrepancy.

31Mb of available RAM does not sound like much or even enough for the device to function. BUT, Linux (Android is a scaled down version of Linux) interprets RAM a LOT differently than Windows or DOS. Linux/Android actually leaves finished processes in memory, they are dead and the space they occupy is actually available for use. So even though I apparently have ony 31Mb of "free" RAM, the amount free to use is much higher. The htop command (Details listed at bottom list of useful commands with screenshot.) shows Memory, free and total.

Running it right now shows I really have 245Mb free RAM available.

Many of the items listed in top or htop (Colorful version with graphs.) show very little % memory use and if you could see the entire list, LOTS of them are using hardly any memory at all!

You also get the amount of swap space free and in use. In the top screenshot which is Linux, you see I have 5,210,108 Bytes of swap space and none of it is in use. For the other two Android swap space, there is zero swap space available and zero swap space in use.

So what is all this loquacious yak supposed to prove, Ohmster?

Just to teach and refresh us on what "Memory" really is. The apps complain "Out of memory", we get toasts that say out of memory, cannot install anything because we are out of memory, and none of this stuff means the same thing. Memory is electronic RAM. Anything else is external or internal sdcard space, regardless of the partition.

Well, at least now we have a pretty good idea of what Memory is, how much of it the phone actually has (1Gb), and now to check it to see if there is any left, is it all used up, and how much memory do we really have free.

Can I help Tom with his "Insufficient Memory" messages when trying to install apps? Not yet, but at least now all of us can speak on the same page and know what exactly we are talking about, and therefor what is the answer.

[MENTION=1807728]brkahughes[/MENTION] that is a neat partition and sdcard space use readout in Titanium Backup. I never even really looked down there before. Thanks for sharing. Another one comes with ES File Explorer on the built in "Homepage", but Brian's Titanium Backup list show more details.

Summary:

Guys, I am really sorry for all of this very long post, but I have to make my points clear, one by one, to show you exactly what I am talking about. Now at least if I ask you "Do you mean RAM or some partition free space?", you will know what the heck I or anyone else is talking about. And, as a bonus, newbies get an introductory course on how to use the Terminal Emulator to gather system information about your phone. Some other cool and useful commands for the terminal are:

htop - gives a colorful dynamic list of running processes on the phone plus a dual core bar graph of %CPU usage, and bar graphs for used and free space Memory and Swap space.

Total Memory 839MB - Memory in use 594MB = Free Memory 245MB

Tap the Q button to exit. This is a really neat window to watch, see the dual cores showing CPU use? Also note the Memory, used and total. These are dynamic graphs and update once every second. Notice the F1-F8 key tags at the bottom. By using the F keys, you can sort this list by CPU, memory, PID, and several others. You can search, kill a process, filter the list for what you want to watch, etc. To use the F keys in Terminal, /menu/Special keys/ and read the legend. See image.

* htop is such a useful screen and the colors mean different things, it is worth taking a look on the htop page to see all it does.

Understanding and using htop to monitor system resources

[IMG="htop command in an Android terminal window"]http://home.comcast.net/~theohmster/razr-img/htop.jpg[/IMG]

su - allows you to become root in the terminal window. Changes your $ prompt to a # prompt. CAUTION: When you run su in a terminal, you are now the root administrator so if you make a mistake in the terminal such as using the rm command, you will delete files! Anything you do in that terminal with a root # prompt will be carried out w/out question! Use this command wisely and not often.

clear - clear the screen

ls - list files, same as the "dir" command in Windows.

df - "disk free" gives you a list of all partitions on the phone, the size, used space, free space, and block size.

free - shows all memory present, available, and free on the phone. Similar to the mem command in Windows.

dmesg - gives a summary of the system log at the current time.

There are a lot more but I have to end this now before someone puts me in a sleeper hold for taking too much of your time. :p Thank you for your time and patience if you actually took the time to read all of this and especially if you understand it. Class is out, pickup your diploma from the clerk on your way out. Seniors with years of experience need not attend. :D

I am not a professor nor do I have a degree in computer science. Those that find an error or wish to correct me, comments are very welcome. :o