News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Ram Defragmenter

Started by cman, October 07, 2009, 05:28:30 PM

Previous topic - Next topic

cman

I have a program that "defragments" my computers RAM resulting in quicker operation ( I guess it supposedly more RAM for use upon request ) . How does something like this work? What would be involved in coding something like this in assembly? Thanks for any tips..

nathanpc

Quote from: cman on October 07, 2009, 05:28:30 PM
How does something like this work?
It's like HD defragment, but for RAM.

redskull

RAM defragmentation?  I call B.S.  There's no way to control where in physical memory anything is, nor is there any benefit to having things "closer".  The best you could do is free up wasted RAM and possibly ensure that nothing was paged out, but then that's not really defragging, is it?

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Vortex

Hi cman,

Turn of the unnecessary services in your computer and remove the applications adding icons to your system tray if possible. Simple solutions will increase the perfomance of your RAM.

MichaelW

Quote from: redskull on October 07, 2009, 07:00:49 PM
RAM defragmentation?  I call B.S.

It would not be the first such scam, for example SoftRAM 95:

http://en.wikipedia.org/wiki/SoftRAM

eschew obfuscation

cman

I've been using something called "CyberLat Ram Cleaner" for a long time now and it seems to work pretty well ( one makes a request to "free" a certain amount of ram and the system speed seems to increase after the request ). I've often wondered how it works and thought about how to implement my own version. What API functions are involved in an application like this? Are algorithms like those used in Operating System memory allocation used ( First-Fit , Best-Fit storage selection strategies ? ). Thanks for any information......

redskull

There is no such thing as "free RAM"; there is either RAM in use by programs, or RAM in use by the operating system.  Windows loads old stuff in memory under the assumption that you'll use it again soon, only ditching it when there is an actual need (after all, what's the point of having oodles of RAM if it's actually empty?).   I would suppose the way this program "frees up" memory is to allocate a ridiculously huge chunk for itself, which would cause other memory to be paged out all at once.  Then the program frees it all, leaving a huge empty hole in memory that Windows will, eventually, fill back up; programs would potentially run faster while it does, because everything has been "prepaged out" already.  I suspect you could program your own version by just doing HeapAlloc(1000000000), and then a corresponding HeapFree.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

hutch--

Memory fragmentation is a well known problem which seriously impacts on performance, major gaps in the mapping of free memory to a memory block mean page thrashing with a performance hit every page change.

Here is a quick and dirty way to defrag memory, find out how much physical memory you have in your system, allocate the whole lot, deallocate it and let the OS decide what ends up where after the memory is freed. Used to have to do it regularly in Win9x otherwise when the free memory indicator went too low it would crash.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ThexDarksider

I use FreeRAM and it works like magic. When I use VirtualBox, my RAM is just dropping every second, until it hits near 20s and then FreeRAM cleans it up to 480s and for some time, all applications run slower until they re-allocate their stuff, at which point I have around 380 MB of RAM. So the real profit is around 360 MB. Not bad, eh? :wink
Btw my total amount of RAM is 1 GB, much of it being used by...stuff.

Right now I have 327 MB free - not running VirtualBox.
Just a second, lol, I'll start it.

Ok now I have 17 MB, let's run FreeRAM... It's cleaning atm and everything else is veryyy slow, that's normal - duh.

Ok finished, now I have 463 MB.
Now, Firefox froze... Now I have 455 MB.

Now I gave focus to VirtualBox and closed 2 windows which were open, now I have 424 MB.

Sometimes, VirtualBox won't start, when I'm low on RAM. That's also when FreeRAM comes into play.

-

All in all, it's definitely a GOOD choice to have. And DEFINITELY no bs. :wink

Now it was 432 MB and went up, 1 MB each few seconds, up to 443 MB - lol.

cman

Thanks for the information! I think redskull is correct in that the Operating System fills the RAM according to the "principle of temporal locality" , sticking everything in memory with the assumption that it will be accessed at a latter time ( soon ). Calling HeapAllocate() then probably removes any reference of the old memory from whatever data structure the OS uses to keep track of such things and then the call to HeapFree() allows the OS to start filling the memory again with new items according to the same principle. That sounds kind of like what the software does! If so I guess I could write my own version with just a few lines of code. :bg

BlackVortex

The solution to all problems is :

1) 4gb RAM or more and use win7 x64
2) 2gb RAM or more and use winXP 32bit

PBrennick

Reread Hutch's post, it says it all (and redskull is correct - as far as defragging goes, just not possible because of locks). As several of you guys have pointed out, the OS keeps a latent hold on some portions of memory in case of reuse. Forcing an allocation of all available physical memory and then releasing it forces windows to release its hold on all memory capable of being released thereby giving you a boost in available memory. I suspect that is all these type of programs are doing. When a program allocates memory that memory is locked from the system so it is impossible to relocate these areas in a defragmention sort of way so as to create contiguous areas. As Hutch suggests, write a program that works as he says (or if you ask R-E-A-L nice, he may see if he still has the said program - along with the millions of others he may have.
:U

Paul
The GeneSys Project is available from:
The Repository or My crappy website

jj2007

You might try using SetProcessWorkingSetSize on all minimised windows.

redskull

I'm dubious of any gains, however I'm nearing the end of my knowledge, so i won't presume.  The whole idea behind this (memory-leaky programs and majorly insufficient RAM aside), is that you can trick the MM into "giving back" all the just-in-case memory, which is then free for applications to use.  But it's already free for applications to use, albeit on a demand basis.  It seems as though all you are doing is paging stuff out all at once, instead of bit-by-bit, which I doubt would be a real improvement (though perhaps a apparent one).  Basically, you spend several seconds waiting all at once at the beginning, instead of a few ms here, a few ms there, etc (obviously rounded times).  I have a *very* hard time believing that on a modern NT system, with an appropriate amount of RAM for the demand placed on it, without running buggy programs that leak wicked bad, that any program can do better than what's already there.  Maybe that's just my cynical nature...

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Quote from: redskull on October 08, 2009, 11:04:34 PMyou can trick the MM into "giving back" all the just-in-case memory, which is then free for applications to use.  But it's already free for applications to use

I share your doubts. What happens, though, to mem that is reserved but not yet committed? Would the MM see a need to write that mem to the pagefile? Is fragmentation an issue?