[Android Software/Hacking General [Developers Only]] zeppelinrox:
[TOOL/SCRIPT/RC2]FreeXplain-r / freex-BETTER than free & Why "free" RAM ISN'T WASTED!

See Post #2 for Installation/Requirements/Download

.

Now before getting into my new tool, I'd like to explain why I felt the need to even bother making it.

First of all, if you've ever typed "free" in terminal, you'd see that it shows almost no free ram while any app you check with would show lots of free ram.

This what it looks like.

Now if you're like me, you'd probably do a google search to figure out what the hell it means lol

Because I had over 200 mb "free" when I took that screen shot but that shows only 40mb free and it would be nice if it actually made some sense ;)

Some of you familiar with my V6 SuperCharger may have read this post of mine before: "Why 'Free RAM' Is NOT Wasted RAM!"

In there, I post some findings from my first hand experience and how it correlates with this article Linux Memory Consumption (which I had found afterwards)

Unfortunately, that page is now down but I had a saved copy in PDF format which I've attached.

In that pdf, it reads "The absolute free memory number is not only the value of MemFree, but the sum of the MemFree, Buffers and Cached fields."

There are many pages that can help you figure it out.

Here is a good one Check Linux Memory Usage Using Free Command

If you need to know exactly what buffers and cache actually are, click the button

Info taken from http://nilesh-joshi.blogspot.ca/2010/04/interpreting-output-of-free-command.html

The "buffers" column shows the amount of memory being used by the kernel buffer cache. The buffer cache is used to speed up disk operations, by allowing disk reads and writes to be serviced directly from memory. The buffer cache size will increase or decrease as memory usage on the system changes; this memory is reclaimed if it is needed by applications.

The "cache" column indicates how many memory pages the kernel has cached for faster access later. Since the memory used for buffers and cache can easily be reclaimed for use by applications, the second line (-/+ buffers/cache) provides an indication of the memory actually used by applications (the "used" column) or available to applications (the "free" column). The sum of the memory used by buffers and cache reported in the first line is subtracted from the total used memory and added to the total free memory to give the two figures on the second line.

Swap space is generally used as a last resort when the system can't reclaim physical memory in other ways.

Another light hearted link is Help! Linux ate my RAM! That page has this table:

The middle yellow bar above is referring to the buffers (91 mb) and cache (764 mb) values below (855 mb total).

$ free -m
total used free shared buffers cached
Mem: 1504 1491 13 0 91 764
-/+ buffers/cache: 635 [B][COLOR=Green]869[/COLOR][/B]
Swap: 2047 6 2041

869 mb is readily available and not just 13 mb!

So if you read that page, you'd know that 855 mb is NOT actually wasted,

it's being used by linux to speed things up

!

Basically, if you're not using the ram for apps, linux is using it for cache instead.

And when you need that ram for apps, you get to reclaim it instantly ;)

Therefore...

======================================================

Ok that's all nice nice but why did I bother making a new tool?

Well, if you look at the first screen shot up top, you'll see that the android/busybox free command does

NOT

have the cached column.

Therefore, the free command on Android actually tells us a

little

something...

...but whole lotta nothing!

So, this is what I did about it...

Basically, I:

Added the cached colum

Removed the useless shared column (which is always 0 and is a waste of real estate)

Added the swap -/+ adjustment line (notice that 4076 kB is actually available, not just 16 kB)

Then total everything up nice nice ;)

So here's a direct comparison of the 2 outputs

:

I added colour to the free output for easy comparison.

But notice how the -/+ adjustment line is COMPLETELY different.

The free command shows only 44,644 kB as being freely available but in reality, the value is 208,352 kB... not even close! Simply because free doesn't utilize the cached value (which is found /proc/meminfo along with all the other data.)

The math works both downwards... (add same colours to get the bold ie green plus green = green bold)

...and sideways ie. freely available(208352) = free(40104) + buffers(4540) + cached(163708)

Now, not everybody like rainbows so there is an alternate colour scheme...

Of course, while I was at it (it took me nearly a month to perfect it), I added a whole bunch of options...

So let's see it actually explain something with the -x option...

And explaing even more with -r... ( it's kinda like a mini tutorial ;) )

Since it has so many options, it would be a pita to remember all the options so that you can have your favourite output format all the time...

So it will actually remember your last command (but ignores -help and -install).

Just type "freex" and it automagically does what you did last time...

The output is different depending on whether swap is enabled...

I added the -o option from free which omits the -/+ adjustment line and added a -total only option...

Force -wide option when not using kilobytes (and using a smaller font)...

It's nice to see the percentage table along with kB and/or mb tables.

Also note that it automatically uses wide output when using kB.

Click the button for some gratuitous screen grabs...