|
|
#1 |
|
Automate "purge" command?
Is there a way to automate terminal running the "purge" command when inactive memory reaches a certain level? I know it's not a huge hassle to open up terminal and do it that way, but I would prefer that it just happens automatically when inactive memory reaches 500mb. Thanks.
__________________
14" iBook G4/1.42GHz/1.5GB RAM 60GB HDD/OS X 10.5.8; 12" iBook G4/ 1.33GHz/ 1.5GB/ 40GB HDD/ Leopard 10.5.8; 32GB iPad 1 WiFi+3G. |
|
|
|
0
|
|
|
#2 |
|
I'll add another parts when I'll find something that works:
![]() For now, I'd suggest automating this command somehow: top -l 1 | grep PhysMem: | awk '{print $10}' And if variable_$10" > 500 then purge.. I'll try to make that somehow First edit; work and non-working-cop of bash script ; top -l 1 | grep PhysMem: | awk -F, '{$10 > 500} END {print "I'm taking too much memory "} '
__________________
MBP 2008 Late 2,53 GHz, 8GB RAM @ Moutain Lion ( ), iPad 2 iOS 6.0.1 64GB 3G ( ), iPhone 3G 4.2.1 ( ) - JBPSPad for Mac Cider games [ Spore, C&C 3 etc.] fix Last edited by meme1255; Dec 14, 2012 at 02:48 PM. |
|
|
|
0
|
|
|
#3 |
|
Thanks! I did an initial automator with the basic "purge" command in a shell script and then saved as an application on my desktop(and it works pretty well), I just wanted it simpler; so thanks!
__________________
14" iBook G4/1.42GHz/1.5GB RAM 60GB HDD/OS X 10.5.8; 12" iBook G4/ 1.33GHz/ 1.5GB/ 40GB HDD/ Leopard 10.5.8; 32GB iPad 1 WiFi+3G. |
|
|
|
0
|
|
|
#4 |
|
But that Automator workflow isn't cleaning automatically, is it?
__________________
MBP 2008 Late 2,53 GHz, 8GB RAM @ Moutain Lion ( ), iPad 2 iOS 6.0.1 64GB 3G ( ), iPhone 3G 4.2.1 ( ) - JBPSPad for Mac Cider games [ Spore, C&C 3 etc.] fix |
|
|
|
0
|
|
|
#5 | |
|
I'm proceeding forward..
Quote:
---> Find the way how to remove "M" from the grep result and it should work ( instead echo memory use do "purge" (I'm not sure with syntax, sorry) )
__________________
MBP 2008 Late 2,53 GHz, 8GB RAM @ Moutain Lion ( ), iPad 2 iOS 6.0.1 64GB 3G ( ), iPhone 3G 4.2.1 ( ) - JBPSPad for Mac Cider games [ Spore, C&C 3 etc.] fix Last edited by meme1255; Dec 14, 2012 at 03:32 PM. |
||
|
|
0
|
|
|
#6 | |
|
Quote:
__________________
14" iBook G4/1.42GHz/1.5GB RAM 60GB HDD/OS X 10.5.8; 12" iBook G4/ 1.33GHz/ 1.5GB/ 40GB HDD/ Leopard 10.5.8; 32GB iPad 1 WiFi+3G. |
||
|
|
0
|
|
|
#7 |
|
RE: bash scripts...string versus arithmetic values...
Hi RedCroissant and meme1255,
I hope you don't mind if I jump in here? (meme1255, you were close in your code, except for one small detail...) The following bash script works to do what you wish to do. (Now there are many ways of achieving your goal, this is just one way.) I attempted to comment the script to describe what it does. The chief thing to remember here is that strings are compared differently than arithmetic values. For instance, the string "6" is always lexicographically greater than the string "599", while the arithmetic value 6 is less than 599. The following bash code extracts the inactive memory as a string, then deletes the M at the back of the string, then compares the arithmetic values and if inactive memory is too large it performs a purge. By the way, the 'spaces' (or lack thereof) in the code are important, do not delete them (or add new ones). This script file is named "purge.sh". Code:
#!/bin/bash
# purge.sh:
# This bash script will compare the amount of inactive
# memory to a specified value. If the amount of inactive
# memory is lower, nothing is done, if it is greater then
# a purge is performed. -- Switon
#
# Setup the threshold for purging,
# any inactive memory above this will cause a purge:
# (Note that the second assignment is commented out, i.e.,
# it has a pound # character before it. If you remove
# the # character then you can test this routine further.)
NN="100M"
#NN="5000M"
# Get the amount of inactive memory:
memory=$( top -l 1 | grep PhysMem: | awk '{print $6}' )
# Remove the M at the back of these strings:
NNN=${NN%%M}
inactive=${memory%%M}
# Echo the strings:
echo "\$NN: $NN , \$memory: $memory"
echo "\$NNN: $NNN , \$inactive: $inactive"
# Check if the arithmetic value of $NNN is less than the
# arithmetic value of $inactive:
if [ $((NNN)) -lt $((inactive)) ]; then
echo "Too much inactive memory: $NNN < $inactive"
echo "Performing the purge! "; purge
else
echo "Inactive memory is okay: $NNN > $inactive"
echo "Not doing a purge."
fi
Code:
switon$ sh purge.sh $NN: 100M , $memory: 1640M $NNN: 100 , $inactive: 1640 Too much inactive memory: 100 < 1640 Performing the purge! Code:
switon$ sh purge.sh $NN: 5000M , $memory: 1642M $NNN: 5000 , $inactive: 1642 Inactive memory is okay: 5000 > 1642 Not doing a purge. Now I have to ask, why do you want to do the purge? The Mac OS X already takes care of this for you, so the above purge is superfluous to a running system. When free memory is exhausted, the Mac OS X will free up the inactive memory when more memory is needed. But until it is needed, the inactive memory remains --- and one would argue that this is just what you want to happen, since if you go back and rerun something that is in inactive memory, the OS does not have to reload it so it runs faster the second time. Regards, Switon Last edited by switon; Dec 15, 2012 at 01:14 PM. |
|
|
|
2
|
|
|
#8 | |
|
Quote:
Unless you are experiencing NOTICEABLE performance issues (i.e. noticeable when you're not looking at Activity Monitor), then there is absolutely no need to purge memory. I've seen loads of threads here with worries about the amount of RAM that ML is using; I've not seen any that point to any actual problems as a result. |
||
|
|
2
|
|
|
#9 |
|
RE: that purge...
Hi benwiggy,
Absolutely! In fact, if you purge then in general you will get poorer performance for the typical usage since the OS will have to reload the program into memory the next time you rerun it. I have only ever used the purge command for code testing purposes. Thanks for the verification, Switon Last edited by switon; Dec 15, 2012 at 08:33 AM. |
|
|
|
1
|
|
|
#10 |
|
And if you wrap it all into while(1), it could probably run automatically (I'm not sure )
, but I think that wouldn't help you much
__________________
MBP 2008 Late 2,53 GHz, 8GB RAM @ Moutain Lion ( ), iPad 2 iOS 6.0.1 64GB 3G ( ), iPhone 3G 4.2.1 ( ) - JBPSPad for Mac Cider games [ Spore, C&C 3 etc.] fix |
|
|
|
0
|
|
|
#11 | |
|
RE: automator...scripts...
Quote:
But then again, as I and benwiggy pointed out, you really wouldn't want to do "purge"s continuously, since your performance would then decrease not increase. There is a reason for inactive memory, and it is based upon how a typical user uses his/her machine. Typically, a user will jump between applications, and if the application is already in inactive memory, then this jumping will happen very quickly as the application is already in RAM. But if you purge the inactive memory, then when jumping to a previous app the OS will have to load the app into RAM from the HDD, something that takes a much longer time. Switon |
||
|
|
0
|
|
|
#12 |
|
RE: ...précis...
Hi,
Allow me to quickly summarize: (1) There is an important distinction between lexicographical and arithmetic comparisons in bash, thus lexicographically the string "6" is always greater than the string "59999", while arithmetically the value 6 is less than the value 59999. This means that one has to be careful if you are comparing strings versus comparing numerical values. The string comparisons will not necessarily give you what you might expect. (2) If you are attempting to improve your computer's performance by doing "purge"s, then you are actually more likely to be decreasing performance, not increasing performance. Inactive memory serves a useful purpose for the OS. RAM memory that is not actually being used is superfluous to performance --- if you have 1000GB of RAM, but your applications only use 10GB, then the extra 990GB of RAM does you no good, it does not improve performance. So the Mac OS X attempts to make use of the extra unused RAM by marking it as "inactive" when a program has finished with it instead of erasing its contents. If the system runs out of free RAM, then the OS will recover memory from the inactive portion. But there is always a chance that the user will rerun an app that is already in inactive memory, and when this happens the OS does not have to reload the app from the HDD into RAM (this takes time), rather it just makes the inactive RAM active again. Regards, Switon P.S. I have only ever used the "purge" command when testing code, never for performance reasons. |
|
|
|
0
|
|
|
#13 | |
|
Quote:
__________________
14" iBook G4/1.42GHz/1.5GB RAM 60GB HDD/OS X 10.5.8; 12" iBook G4/ 1.33GHz/ 1.5GB/ 40GB HDD/ Leopard 10.5.8; 32GB iPad 1 WiFi+3G. |
||
|
|
0
|
|
|
#14 | |
|
RE: inactive and VirtualBox...
Quote:
I wonder if this is somehow due to the way VirtualBox works? Maybe it is slowing how Mac OS X recovers inactive memory?! I have to say that I have never seen this myself, as I find the Mac OS X does a good and efficient and fast job of recovering inactive memory when required. I also do not use VirtualBox... ...just my experience... Regards, Switon |
||
|
|
0
|
|
|
#15 | |
|
Quote:
And something that I have found interests is that when using Windows in a virtual machine, my inactive memory increases more rapidly than when using Linux. The Windows OS also usually tries to utilize more RAM than I initially assign to it(but then that might be a side effect of Vista as well). Handbrake does the same tang for me, but not as extreme as VB, and the reason I really liked that fact that you write that script is because I shouldn't have to en up terminal to do the purge command. It's great.
__________________
14" iBook G4/1.42GHz/1.5GB RAM 60GB HDD/OS X 10.5.8; 12" iBook G4/ 1.33GHz/ 1.5GB/ 40GB HDD/ Leopard 10.5.8; 32GB iPad 1 WiFi+3G. Last edited by RedCroissant; Dec 15, 2012 at 10:29 AM. |
||
|
|
0
|
|
|
#16 | |
|
RE: VB and memory leaks and ...
Quote:
Switon |
||
|
|
0
|
|
|
#17 | |
|
Quote:
__________________
14" iBook G4/1.42GHz/1.5GB RAM 60GB HDD/OS X 10.5.8; 12" iBook G4/ 1.33GHz/ 1.5GB/ 40GB HDD/ Leopard 10.5.8; 32GB iPad 1 WiFi+3G. |
||
|
|
0
|
|
|
#18 | |
|
RE: that shell script...
Quote:
And, in regards to that script...of course you can "comment out" the "echo"es so that they won't print to your console when the script is executed. Hope you find it useful. Switon |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 08:14 PM.







;
), iPad 2 iOS 6.0.1 64GB 3G (
), iPhone 3G 4.2.1 ( 
, but I think that wouldn't help you much
Linear Mode
