21

RAM Meter 4

Posted in System by chris_at_uo 1334 days ago

Description This is an update of enochou's RAM Meter 3. I wanted to have it identify the amount of memory automatically, and not require editing the script within the geeklet to set that value. Also, I wanted to not only show the amount of used and free memory, but also identify the memory that is used but can be freed up by purging the data to swap space or compressed memory space.

This information is provided by having the meter presents 3 sets of "ticks" for memory. The first set, on the left, is memory that is in use and can not be purged or freed in any way, short of closing programs. The second set, in the middle, is the rest of the memory that is in use, but can be purged out by swapping to disk. The third set, on the right, is the memory that is not in use.

Be default, the colors are red for non-purgeable memory, black for in-use but purgeable, and white for free memory.

Customizing By default the geeklet uses 20 tick marks, therefore each one represents roughly 5% of memory. You can change the number of ticks used by changing the ticks variable. Since this is an expression of percentage of memory, do not use a number greater than 100. If you use a number that isn't a positive divisor of 100 (like 50, 25, 20, 10, 5) then the accuracy goes down, and the fewer ticks you use the less "accurate" the value becomes.

You can also change the color of the non-purgeable memory via the nonpurgeColor variable, the color of the remainder of used memory via usedColor, and the color of free memory via the freeColor variable. The color values available are 0m for "no color" or white, 30m for black, and 31m for red. Other values include 32m through 37m. You could also use 40m through 47m for color ticks in a square background color, but that could be more distracting. The color values can be seen at the ANSI escape code wikipedia page.

Coding tidbits Previously, I used a memory meter based on pulling data from the top command's PhysMem line, but with newer versions of OS X it is a little more complicated. OS X will often set aside memory for storing compressed pages (instead of swapping to disc with those pages) and it won't free up "inactive" pages, that are marked as no longer needed, but haven't been cleared and moved to free pages yet. Therefore, the amount of free memory reported by PhysMem is always lower than what is actually free to use.

This script uses data from the vm_stat command to identify how memory is being used. This includes all used memory, which is the done by adding together the values for Pages active, Pages speculative, Pages throttled, and Pages wired down. All memory is the used memory value along with the values for Pages free and Pages inactive added to it. Those last two values, Pages free and Pages inactive, are added together to show the amount of free memory. The non-purgeable memory is the used memory value with the value of Pages purgeable subtracted from it.

The Pages purgeable is memory that is in use, but is accessed so infrequently, that it can be swapped out to either the compressed memory pages, which takes up less space by compressing the memory stored in it, or swapped out to disc-based swap space. Compressed memory space is faster than disc-based swap space, but does continue to use up memory space, just less of it than normally. Disc-based swap space is good that it doesn't take up any memory space (or very little for indexing of where things are in the swap space), but takes far longer to access.


Geeklet files to download

Comments

Log in to comment or register here.