[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] Free RAM 1.0

Ari Brown

8/6/2007 10:07:00 PM

Hey!

Despite your best efforts, Todd, I managed to create a tool which
will free RAM to be used by other programs.

At the moment, it is only usable on *nix machines (BSD, Linux, and
Mac). Will add Windows support soon.
move it to /bin and save it as free_ram

Usage: free_ram TIME
TIME is the amount of time you want Ruby to spend clearing the RAM. A
good amount is about 20. I can clear a large amount of RAM with that.

http://www.aribrown.com/ruby/f...


---------------------------------------------------------------|
~Ari
"I don't suffer from insanity. I enjoy every minute of it" --1337est
man alive




6 Answers

Alex Gutteridge

8/7/2007 12:36:00 AM

0

On 7 Aug 2007, at 07:06, Ari Brown wrote:

> Hey!
>
> Despite your best efforts, Todd, I managed to create a tool which
> will free RAM to be used by other programs.
>
> At the moment, it is only usable on *nix machines (BSD, Linux, and
> Mac). Will add Windows support soon.
> move it to /bin and save it as free_ram
>
> Usage: free_ram TIME
> TIME is the amount of time you want Ruby to spend clearing the RAM.
> A good amount is about 20. I can clear a large amount of RAM with
> that.
>
> http://www.aribrown.com/ruby/f...

Other people have explained why this really isn't such a great idea,
but in the spirit of experimentation...

If you want a portable version why not just:

require 'timeout'

z = ''
timeout(25){ while(true) do z << 0.chr * (2 ** 24) end}

Or for the 'moar power!!11!' user how about a RubyInline version:

require 'inline'

class IWantA
inline do |builder|
builder.c "
int way_to_die(int size){
return malloc(size);
}"
end
end

while(IWantA.new.way_to_die(2 ** 12) != 0)
end

Both managed to shunt almost every other process into swap in a few
seconds. Enjoy!

Alex Gutteridge

Bioinformatics Center
Kyoto University



Ari Brown

8/7/2007 1:07:00 AM

0


On Aug 6, 2007, at 8:35 PM, Alex Gutteridge wrote:
> Other people have explained why this really isn't such a great
> idea, but in the spirit of experimentation...
>

I can understand why it's not suggested that I forcefully clear the
RAM, but will it have a negative effect on my programs? And is there
a suggested way to clear the RAM using Ruby?

Ari
-------------------------------------------|
RUBY

R - Ruby
U - Understands
B - Badass
Y - YAML



Alex Gutteridge

8/7/2007 1:54:00 AM

0

On 7 Aug 2007, at 10:06, Ari Brown wrote:

>
> On Aug 6, 2007, at 8:35 PM, Alex Gutteridge wrote:
>> Other people have explained why this really isn't such a great
>> idea, but in the spirit of experimentation...
>>
>
> I can understand why it's not suggested that I forcefully clear the
> RAM, but will it have a negative effect on my programs? And is
> there a suggested way to clear the RAM using Ruby?

I think the point is that you should leave memory management to tools
that are designed to do it: usually the kernel of whatever operating
system you are using (which I'm guessing will have had many, many,
expert man hours spent on it). Forcefully clearing the RAM in this
way just shifts other processes into swap (the memory space held on
disk rather than in RAM). Trying to access these processes is then
very slow as they have to be read back into RAM from the disk.

For instance, if I have a copy of Firefox running, run your script
and then try to go back to Firefox it is extremely slow for 10
seconds or so. Once Firefox is back in RAM it then runs fine from
then on.

Having said that, I hate telling people what to do with their time,
and often designing something 'crazy' is a good way to learn new
stuff. So if running your script works for you and you learn about
memory management at the same time then go for it.

As for the suggested way to clear RAM, I think the semi-joking
suggestions people have given you are probably about right: allocate
a big string or Array (Ara suggested using mmap).

Alex Gutteridge

Bioinformatics Center
Kyoto University



Dan Zwell

8/7/2007 3:22:00 AM

0

Ari Brown wrote:
>
> On Aug 6, 2007, at 8:35 PM, Alex Gutteridge wrote:
>> Other people have explained why this really isn't such a great idea,
>> but in the spirit of experimentation...
>>
>
> I can understand why it's not suggested that I forcefully clear the RAM,
> but will it have a negative effect on my programs? And is there a
> suggested way to clear the RAM using Ruby?
>
> Ari

It's good when your computer uses most of its ram. Seriously, you didn't
pay for it to look pretty. That being said, memory is used primarily for
two things: file caching and storing CPU instructions (running
programs). Now, if you clear the memory that was holding file caches,
you don't lose much (unless you need to re-read a file that had been in
the cache), but you don't gain anything, either. Like I said, unused
memory serves no purpose. If you clear ram that was holding CPU
instructions, those instructions will be pushed into swap. Because swap
is on your hard disk, it thousands of times slower than main memory.
When a program you are running tries to load data that is not in main
memory, the data needs to be dragged out of swap before the program can
continue running. This slows down your system terribly.

There is one thing you can do to speed up your system if you are on
Linux. You can tell it to use more ram. That's right, the opposite of
freeing ram. The OS has a setting called "swappiness". A higher
swappiness means to use more swap (and have more free ram, which is used
for file caching). A lower swappiness means you will have less file
cache, but applications are less likely to get swapped out. That means
that, for example, when you restore an application that has been
minimized to your system tray for three days, it is instantaneous--no
delay as the application data gets read into memory from swap, because
it isn't swapped out. You need enough ram for this to be of any benefit.
Use the command "free -m" to see how much memory you are using total,
and for file caching. If you have little free ram (but are using a
significant portion of it for file caching), or your computer just isn't
using as much of your ram as you would like, try the following:

The default "swappiness" is 60 (out of 100). Try changing it to 15.
# echo 15 > /proc/sys/vm/swappiness
If you don't like it, change it back.
# echo 60 > /proc/sys/vm/swappiness

If you want to make this change permanent, you will have to consult your
distro's documentation.

I hope someone finds this useful. If there is a similar trick that can
be used in Windows, I would love to hear about it.

Dan

M. Edward (Ed) Borasky

8/7/2007 3:32:00 AM

0

Alex Gutteridge wrote:
> On 7 Aug 2007, at 07:06, Ari Brown wrote:
>
>> Hey!
>>
>> Despite your best efforts, Todd, I managed to create a tool which will
>> free RAM to be used by other programs.
>>
>> At the moment, it is only usable on *nix machines (BSD, Linux, and
>> Mac). Will add Windows support soon.
>> move it to /bin and save it as free_ram
>>
>> Usage: free_ram TIME
>> TIME is the amount of time you want Ruby to spend clearing the RAM. A
>> good amount is about 20. I can clear a large amount of RAM with that.
>>
>> http://www.aribrown.com/ruby/f...
>
> Other people have explained why this really isn't such a great idea, but
> in the spirit of experimentation...
>
> If you want a portable version why not just:
>
> require 'timeout'
>
> z = ''
> timeout(25){ while(true) do z << 0.chr * (2 ** 24) end}
>
> Or for the 'moar power!!11!' user how about a RubyInline version:
>
> require 'inline'
>
> class IWantA
> inline do |builder|
> builder.c "
> int way_to_die(int size){
> return malloc(size);
> }"
> end
> end
>
> while(IWantA.new.way_to_die(2 ** 12) != 0)
> end
>
> Both managed to shunt almost every other process into swap in a few
> seconds. Enjoy!
>
> Alex Gutteridge
>
> Bioinformatics Center
> Kyoto University
>
>
>
>
But wait!! I'll C your Ruby Inline and raise you one stress test, i.e.,

http://weather.ou.edu/~apw/proje...

I can take a machine down instantaneously with their memory hog. ;)

Todd Benson

8/7/2007 6:38:00 PM

0

On 8/6/07, Ari Brown <ari@aribrown.com> wrote:
> Hey!
>
> Despite your best efforts, Todd, I managed to create a tool which
> will free RAM to be used by other programs.

Ruby is super flexible. Do whatever you want with it. This, I
thought, was common knowledge.

Todd