FORUMS
Remove All Ads from XDA
Honor 7x
Win an Honor 7X!

 View Poll Results: Is this better than free?

Yes
 
51 Vote(s)
96.23%
No
 
2 Vote(s)
3.77%

[TOOL/SCRIPT/RC2]FreeXplain-r / freex-BETTER than free & Why "free" RAM ISN'T WASTED!

9,374 posts
Thanks Meter: 21,806
 
Post Reply Email Thread
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...e-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).
Code:
$ free -m
             total       used       free     shared    buffers     cached
Mem:          1504       1491         13          0         91        764
-/+ buffers/cache:        635        869
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...





The Following 51 Users Say Thank You to zeppelinrox For This Useful Post: [ View ] Gift zeppelinrox Ad-Free
 
 
20th May 2014, 02:02 AM |#2  
zeppelinrox's Avatar
OP Senior Member
Flag IN THE FREAKIN' OP
Thanks Meter: 21,806
 
Donate to Me
More
Root is NOT required to use this script!

However, if not root, to actually install it for easy command line usage requires a little workaround.

Requirements:

1. An app that can run scripts lol

Fully compatible with Terminal Emulator and Script Manager/Script ManagerPro.
Other terminal apps probably won't display colours properly.
In fact Script Manager didn't either until I requested 256 colour support for it and @devwom updated it quite fast
So make sure to UPDATE Script Manager if that's your preference!

Tho it may not display all the colours, Terminal IDE will work too while installing BusyBox for itself.

2. BusyBox (for the grep and printf commands)

If you're rooted, then there is nothing else to do and go to the Install section.

If NOT rooted you have a few options.
a) download the attached busybox.zip and put it in the same place as the freex script. It is not a zip file. It's the busybox binary from Kbox2. I chose it for it's small size.
Just run freex as explained in the install section and freex will install "busybox.zip" for you as long as it's in the same location as the script.
b) install OneBox. It requires Terminal Emulator and automates the process to...
c) Install Kbox2
d) Easiest solution is probably BusyBox Non-Root but also for use with Terminal Emulator.
e) Use Terminal IDE (has its own BusyBox)

FreeXplain-r Installation:

(Pronounced "Free Explainer")

Note: Installation merely simplifies the execution of freex so that you can just type "freex" in your terminal app without having to type "sh /sdcard/freex*" all the time. Of course, if you're using a script runner like Script Manager, it doesn't matter too much since their purpose is to make it easy to run scripts.

1. Save attached script to sdcard. (No need to rename it from freex*.pdf)

2. Then just run the script!

If using Script Manager, no need for me to explain how to use that app.

If using a terminal app, do:
Code:
cd /sdcard
sh freex*
No need for the -i switch it should install automatically.

Use the -i switch for forced installation/update/refresh.

If not running as root, it will copy to your terminal app's data folder and give you further instructions.



Notice that it says to run with "sh freex" in the help section?
That's because the $PATH statement hasn't yet been setup in the terminal app's settings.

If running as root, it will automatically install to /system/xbin and it's easy as pie.




Here is a forced refresh/reinstall.
Not running as root at first but the $PATH is setup so it doesn't give the additional help info to set that up.
Then as root, of course it installs to /system/xbin

Attached Files
File Type: zip busybox.zip - [Click for QR Code] (465.8 KB, 395 views)
File Type: pdf freex_RC2.sh.pdf - [Click for QR Code] (18.2 KB, 1531 views)
The Following 29 Users Say Thank You to zeppelinrox For This Useful Post: [ View ] Gift zeppelinrox Ad-Free
20th May 2014, 01:24 PM |#4  
eushaun99's Avatar
Senior Member
Flag Subang Jaya
Thanks Meter: 948
 
More
Even for a simple(but not so simple ) script you can explain this much. This really sums up what an amazing developer you are zep.

Sent from my GT-P7500 using Tapatalk
The Following User Says Thank You to eushaun99 For This Useful Post: [ View ] Gift eushaun99 Ad-Free
20th May 2014, 02:05 PM |#5  
mrhnet's Avatar
Senior Member
Thanks Meter: 257
 
More
This is nice!! Explains all! I like rainbows of course..

Noted something.. when running (installing) the script saved to a folder which has a name with spaces, an error occurs (I'm using ScriptManager). "freex" didn't get installed to xbin properly (size=0). No issues otherwise.
The Following 2 Users Say Thank You to mrhnet For This Useful Post: [ View ] Gift mrhnet Ad-Free
20th May 2014, 05:04 PM |#6  
-Rhoby|™-Bugs's Avatar
Senior Member
Flag LocalHost
Thanks Meter: 141
 
More
i'll try it later, thanks man...
21st May 2014, 12:24 AM |#7  
zeppelinrox's Avatar
OP Senior Member
Flag IN THE FREAKIN' OP
Thanks Meter: 21,806
 
Donate to Me
More
Quote:
Originally Posted by Daniel D.

Another masterpiece from the GoRM!

ok I give up... what's GoRM? IMMA N00B and forgot the URL for google.com

Quote:
Originally Posted by eushaun99

Even for a simple(but not so simple ) script you can explain this much. This really sums up what an amazing developer you are zep.

Sent from my GT-P7500 using Tapatalk

I don't bother if it don't work on all devices
Quote:
Originally Posted by mrhnet

This is nice!! Explains all! I like rainbows of course..

Noted something.. when running (installing) the script saved to a folder which has a name with spaces, an error occurs (I'm using ScriptManager). "freex" didn't get installed to xbin properly (size=0). No issues otherwise.

Ah the scripter's life long nemesis... the evil space in a folder name.

I shall quash that empty soul in our next duel.

Btw you didn't update Script Manager... the rainbow is all wrong lol

Edit: Added a poll. For fun, I'm gonna view it as an IQ test. heh.
The Following 2 Users Say Thank You to zeppelinrox For This Useful Post: [ View ] Gift zeppelinrox Ad-Free
21st May 2014, 12:34 AM |#8  
Daniel D.'s Avatar
Senior Member
Thanks Meter: 505
 
Donate to Me
More
God of RAM Management
21st May 2014, 12:49 AM |#9  
eriknors's Avatar
Senior Member
Thanks Meter: 328
 
More
Hey zepp just wanted to confirm after running this script this is what my free ram should look like



sent from my DNA
Attached Thumbnails
Click image for larger version

Name:	1400626163517.jpg
Views:	512
Size:	49.5 KB
ID:	2754635  
21st May 2014, 04:34 AM |#10  
mrhnet's Avatar
Senior Member
Thanks Meter: 257
 
More
Quote:
Originally Posted by zeppelinrox

Btw you didn't update Script Manager... the rainbow is all wrong lol

Yup.. noted that. I meant rainbows in terminal emulator..


"watch freex" command lets me to enjoy the rainbows every 2 seconds :P
21st May 2014, 06:31 AM |#11  
eriknors's Avatar
Senior Member
Thanks Meter: 328
 
More
Ok any idea as to why I'm getting this

sent from my DNA
Attached Thumbnails
Click image for larger version

Name:	1400646648493.jpg
Views:	342
Size:	119.4 KB
ID:	2754929  
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes