The release of Windows Mobile 6 (WM6) gave us a few more tools for dealing with Virtual Memory (VM) issues. Compaction of slot 1 is new for WM6, in previous releases all slot 1 modules were aligned on 64k boundaries, causing VM address space to be wasted when modules sizes aren’t perfectly divisible by the alignment size of 64KB were mapped into slot 1. The new alignment size of 4k allows more modules to be packed closer together, thus better compaction.
To illustrate this point, Figure 1 below shows 4 files totaling 142k in size taking up 320k using 64k alignment. Figure 2 shows the same 4 files only taking up 144k using 4k alignment. The white space is unused memory.
Along with compaction, the WM6 release also provides a way to map OEM driver’s modules into slot 1 with the package OEMDRIVERSHIGH. This is important because all the modules that do not fit into slot 1 rollover into slot 0, and thus reducing available VM for all slots. Further exacerbating the situation of modules rolling over into slot 0 is the fact slot 0 aligns modules on 64k boundaries. The OEMDRIVERSHIGH package enables OEMs, SVs, and system integrators to change the packaging priority of OEM drivers, which is typically near the end in the list of packages processed by makeimg.
When it comes to reconfiguring modules, OEM’s don’t have the ability to rearrange packages or to change the modules that go into a particular package. All that is available at this stage of building an image is reconfiguring the modules that go into the OEMDRIVERS package. Now with the addition of OEMDRIVERSHIGH package an OEM can target selected DLL’s to be processed, which will push larger modules out of slot 1 and into slot 0.
Optimizing OEMDRIVERSHIGH usage
To save VM using OEMDRIVERSHIGH we are going to identify the modules at the bottom of slot 1 on the verge of rolling over into slot 0. Through careful comparison of these modules and those currently in the OEMDRIVERS package we will reassign OEMDRIVERS modules to OEMDRIVERHIGH. By doing so the modules in OEMDRIVERSHIGH will be processed before the modules at the bottom of slot 1, and through this careful calculation the OEMDRIVERSHIGH modules targeted for slot 1 will rollover files on the slot 1 / 0 boundary. The VM savings will come from rolling over larger modules that are 100’s of KB into slot 0 which is 64KB align and filling the freed slot 1 space with smaller modules. It is the relocation, for example, of three 16KB modules to slot 1 that will free 192KB in slot 0 and only consume 48KB in slot 1.
To achieve this, the first place to start is analyzing the output of makeimg from a baseline build. The output isn’t always captured so you many need to run it once capturing the output (makeimg > makeimg.out 2>&1). Search through makeimg.out and look for “fixing up”. These are modules rolling over from slot 1 into slot 0. Below is an example of modules that just made it into slot 1 and modules that started rolling over into slot 0. This list of modules will be different for every project based on SYSGEN, BSP flags, IMG flags and the type of image.
Using the data from makeimg.out we will build a table to calculate the size of each module sitting at the bottom of slot1. Later we will use this data to determine how many modules to move into OEMDRIVERSHIGH, which will cause these modules to rollover.
FIGURE 3
Module cespell.dll at offset 01d8a000 data, 0210b000 code
Module MsgStore.dll at offset 01d89000 data, 02106000 code
Module msim.dll at offset 01d87000 data, 020e4000 code
Module mscoree.dll at offset 01d86000 data, 020d4000 code
Module netcfagl2_0.dll at offset 01d85000 data, 02099000 code
Module netcfd3dm2_0.dll at offset 01d84000 data, 02072000 code
Module ccoredrv.dll at offset 01d83000 data, 02051000 code
Module ccoreutl.dll at offset 01d82000 data, 02042000 code
Module cspvoice.dll at offset 01d81000 data, 02032000 code
Module simsec.dll at offset 01d80000 data, 02026000 code
Module sms.dll at offset 01d7f000 data, 02020000 code
Code space full, fixing up supsvcs.dll to ram space
Code space full, fixing up btagsvc.dll to ram space
Code space full, fixing up BthAGPhonebook.dll to ram space
Code space full, fixing up celltsp.dll to ram space
Code space full, fixing up cplphone.dll to ram space
Code space full, fixing up phone.dll to ram space
Code space full, fixing up ril.dll to ram space
Taking the modules code offset from Figure 3, and subtracting it from the code offset of the previously listed module will determine the slot 1 space that can be recouped. (The data segment is need regardless of what we do and will remain the same.) So for msim.dll the code size is 0x02106000 – 0x020E4000, which is 136KB. The rollover order will be the same for every run of makeimg, the only exception is when slot 1 is low on space, it will pack in modules small enough to fit into remaining space. This is good news because one less module in slot 0 saves an additional 64KB. The consistent rollover order enables us to predict which files will rollover and in what order, this is illustrated in Table 1. The last two columns of this table illustrate the total space saved in slot 1 and total space used by these modules as they rollover. Notice how sms.dll consumes 24K of space in slot 1 and will consume 64K in slot 0.
|
Table 1
|
|
Rollover Order |
Name |
Space used
in slot 1 (KB)* |
Space used
in slot 0 (KB)
if rolled over* |
Incremental space freed in slot 1 (KB) |
Incremental space used in slot 0 (KB) |
|
1st |
sms.dll |
24 |
64 |
24 |
64 |
|
2nd |
simsec.dll |
48 |
64 |
72 |
128 |
|
3rd |
cspvoice.dll |
64 |
64 |
136 |
192 |
|
4th |
ccoreutl.dll |
60 |
64 |
196 |
256 |
|
5th |
ccordrv.dll |
132 |
192 |
328 |
448 |
|
6th |
netcfd3dm2_0.dll |
156 |
192 |
484 |
640 |
|
7th |
netcfag12_0.dll |
236 |
256 |
720 |
896 |
|
8th |
mscoree.dll |
64 |
64 |
784 |
960 |
|
9th |
msim.dll |
|