at work i have allocate often memorychunks of giant size (several 100 MByte to GigaByte), which often don't work even while the total amount of free memory seems way enough.
So i had to learn that there is something like virtual memory fragmentation. I explored this topic and found that there is an solvable reason for this on win32 system why the available memory and the maximum (on block) allocateable memory differs sometimes massive.
The reasons are often DLLs which are loaded in memoryregions which divide the available memory in 2 pieces instead of setting this DLLs on begin or end of this free region.
here an typical report from matlab memdump (win2000)
Startadress | size | free mem. after (with* it is allocatable)
...
<anonymous> 21610000 00010000 00000000
<anonymous> 21620000 00100000 418e0000*
C:\WINNT\system32\DDRAW.dll 63000000 00049000 00fb7000*
C:\Programme\MATLAB\bin\win32\MFC42.DLL 64000000 000f2000 052ae000*
C:\WINNT\system32\OPENGL32.dll 693a0000 000c7000 02d69000*
C:\WINNT\system32\MFC42LOC.DLL 6c1d0000 0000e000 02152000*
C:\WINNT\system32\INDICDLL.dll 6e330000 00006000 016ba000*
C:\WINNT\system32\GLU32.dll 6f9f0000 00020000 01d00000*
C:\WINNT\system32\COMCTL32.DLL 71710000 00084000 0107c000*
C:\WINNT\system32\DCIMAN32.dll 72810000 00006000 0277a000*
C:\WINNT\system32\WS2HELP.DLL 74f90000 00008000 00008000
C:\WINNT\system32\WS2_32.DLL 74fa0000 00014000 0000c000
C:\WINNT\system32\WSOCK32.dll 74fc0000 00009000 000f7000*
...
As you can see the loaded DLLs are not as near as possible together... the memory is fragmented.
But why the dlls want to reside in this special places? Because in the PE header of an DLL (or exe) a prefered
adress is defined (standard value = 10000000h).
The OS tries to load an DLL on this prefered place...but what happens when this place is already used by another DLL?
Then the OS has to do an dynamical reallocating which got some disadvantages.
First, loading is slower, and all adress calculations have to be recalculated in realtime on access. Second is that an dll which is loaded by several process (like several open explorer windows) has to be loaded several times in memory -> real memory loss. If the dll can live on the prefered place the system can 'map' the same loaded dll to several process (physical memory saved).
So, for an optimal behaving system the Dlls have be placed on optimal adresses.
Microsoft tried this for their dlls but it seems they do it not anymore consequently (especially for fixed files for win9x!).
the region which they tried to fill continously is 0x70000000 to 0x7FFFFFFF.
So why not try to do this again for our uSP2?
------------------------------------
Tools for Rebasing
-To get an overview over loaded DLLs (and reallocations and memory fragmentation), Sysinternals ProcessExplorer is very usefull.
http://www.sysintern...ssExplorer.html
-Cygwin rebasing tool (works for also for stripped files but not for MS files)
http://www.tishler.n...oftware/rebase/
-For MS DLLs rebase.exe from MS Visualstudio (search the folder)
More Info
- Dr.dobbs articel on rebasing
http://www.ddj.com/184416272
-nice explanation of dll rebasing
http://www.codeproje.../dll/rebase.asp
-load performance test
http://msdn.microsof...sues/0500/hood/
-interessting link about security reasons for DLL rebasing
http://archive.cert.uni-stuttgart.de/archi...2/msg00018.html
PS:
Contras
- why not doing this for ALL System DLLs? because some 'bad' written software have hardcoded stuff like absolute jumps inside which need the original base address but this is some kind of hack, which could break this software also in other circumstances.
- rebasing conflicts possibly with the MS eula because it is some kind of binary hack(?)
Pros
- sligthly faster loading times for dlls
- sligthly faster dll functions
- slightly more physical memory
- much more virtual memory
- maleware which needs those known bases don't work anymore
This post has been edited by shaddam: 26 October 2006 - 10:04 AM



Help

Back to top










