Here's what I understand about the VM in WM 6.5.x (by the way, anyone have troubles on ppcgeeks with firefox? I had to use IE8 to reply because ffox wouldn't let me type anywhere other than the first row..)
There's a 32 bit address space available - a total of 4GB potential memory (but not in practice as there is always overhead involved)
This total 4gb address space is split in half - 2gb to the kernel, 2gb to the user. Kernel address space is only accessible by processes/threads with kernel level access, whereas user address space is accessible by all processes/threads.
The user address space is from 0x00000000 to 0x7FFFFFFF, and the kernel address space is from 0x80000000 to 0xFFFFFFFF.
The user address space is split into 64 slots of 32mb a piece. (64x32=2048, or 2gb)
The first 33 slots (slot 0 and 1-32) are used for processes, and the remaining slots for object store, memory mapped files, and resources.
Each slot is easy to visualize in hex, you just increment a digit..
slot 0: 0x00000000 to 0x01FFFFFF, slot 1: 0x02000000 to 0x03FFFFFF, slot 2: 0x04000000 to 0x05FFFFFF, etc.
Each process gets assigned it's own slot, and there are 33 total, minus the kernel process which is always running, so that's where you get the 32 process limit (which is always lower in practice, since u have several processes running in windows mobile to support the os) - also why you have a 32mb limit per process - you can see that's all the address space available in one slot.
How does that all apply to our situation with modules?
When you create a module, you are telling Windows Mobile that you want that module to be memory-mapped, so that each time it loads, it's loading to the same, known area of ram - saving space in slot 0 - this is done on the computer-side, during 'cooking' and is the job of wmreloc, g'reloc, bepe's new kitchen, etc.
Virtual allocations are aligned to a 64KB border, so if you memory map a .dll that's only 3Kb large, it's still going to eat up 64KB of memory space.
There are also pages that can be allocated to these slots, that are aligned to a 4KB boundry, and process/general allocations that take place during normal operation. The way the system handles this is that modules allocated on rom build-time (modules we allocate with g'reloc et. al.) are allocated from top-down (for slot 1 for example, starting at 0x03FFFFFF for the first module, taking up space to the nearest 64kb boundry, then the next module, in a line down to the 0x02000000 address, which is the beginning of the slot)
General allocations that take place during normal system operations are allocated in the remaining space, from the bottom-up (so again with slot 1 as an example, starting at 0x02000000 and ending at 0x03FFFFFF)
As you fill up these slots more and more with modules, that leaves less space for windows to dynamically allocate other, general allocations, which can, and does result in out of memory errors (even when the device has plenty of physical memory left, it cannot address this memory when virtual memory is full)
Here's where the kicker comes in for the difference between 6.0/6.1/6.5 -
There are a total of 4 slots that can be used for module allocation, slot 0, 1, 60, and 61. 63 is also available to modules that contain no code (resource only modules, like .mui's)
WinMo 6 could allocate slot 0, 1 - (in order of 1 first, 0 last) for a total of 64mb of vm space (and the running process is always mapped to slot 0, so once you encroach on this memory space, you are removing available memory to each application running) - you can see how tight this is.
WinMo 6.1 improved on this by opening up slot 60 and 61 (now the allocation order is 61, 60, 1, 0) - but modules could not be allocated here, only files. So for our relocation tools, this was essentially no change. (st iill only slot 1, 0 for modules)
WinMo 6.5 improves on this by opening up slot 60 and 61 to modules - yielding an extra 64mb of potential virtual memory space. (the allocation order is now 1, 61, 60, 0 for modules, 60, 61, 0 for files)
In order for the kernel to recognize these new slots as being mappable for modules, it must be updated to the 6.5 codebase. This is where the 6.5 native nk.exe comes in, and why it's so important
Profiling Virtual Memory is an important job for an OEM - the less available in slot 0, the sooner a device will kick back out of memory errors (even if it's not truely out of memory) - and the worse the user experience will be. Some ROM's I have seen have less than 20MB available in slot 0 (and the user experience is as bad as you might imagine)
There are many more intracacies to the whole process - like balancing the load between services.exe and device.exe to best utilize the 32mb vm space available to each - storing all resource-only dlls as modules so they can be alloced to slot 63, etc.
This is also why it's important that the re-alloc tools be updated to support the new slots - g'reloc will not ever try to allocate modules to slot 60/61 because as far as it's aware, this is not possible.
For the moment I know of 2 tools that will realloc to slot 60/61, wmreloc 2.0, and bepe's new kitchen (used by ervius vk)
The memory addresses defined in .vm - judging from the manual xip porting tutorial, the first value defines the bottom of the allocation in slot 0 (how much space is reserved for dll's) - and the 2nd value defines the top of the allocation for the kernel memory address space.. these values should be dynamically calculated depending on the contents of your NK (XIP) partition.
Incidentally, romhdr.bin in ervius vk/bepes kitchen serves the same purpose.
And if all that isn't complicated enough, in WM 6.1 the process initvmmap.exe was introduced in the MSXIPKernel, NK partition..
This process draws a map of all virtual memory, and using the following registry key from the boot hive:
Code:
[HKEY_LOCAL_MACHINE\System\Loader\ModuleInfo]
[HKEY_LOCAL_MACHINE\System\Loader\ModuleInfo\dllname.dll]
"filename.exe"=dword:1
"filename2.exe"=dword:1
This tells the system that the module dllname.dll is only required when filename.exe is running, or filename2.exe is running - and whenever these processes are not running, the virtual memory space is available, and can be dynamically allocated to by the system. As you can imagine every little bit counts when it comes to running out of virtual memory! This key is grossly underused by OEM's IMO
Quote:
Originally Posted by joojoobee666
Not to bring back some old stuff, but I had a question on this. According to CMonex, Slot 0 and Slot 1 are defined by the .VM folder (specifically the imageinfo.bin) and this is what G'Reloc/WMReloc use to allocate. For example, my imageinfo.bin defines Slot 0 as 0x01F80000 to 0x00000000 and Slot 1 as 03D70000 to 0x02000000. This is for the 6.1 Kernel. Apparently, G'Reloc will then allocate SYS modules ONLY to these two slots when allocating.
Are you saying that WMReloc will also assign SYS modules to the 60 and 61 Slots as well now? After some further reading, slot 60 and 61 are not new to 6.5 as 6.1 and 6.5 use them for DLL's and EXE's that are larger than 64KB to free up Slot 0 to reduce the DLL crunch and VM memory pressure. So is the only difference that the 6.5 kernel allows you to allocate into those slots as well since they are not new? Anyone that knows my chime in
|