26
Windows Mobile 6.5 프프프프 프 프프프 프프 프프프 WEEG Manager [email protected]

Windows Mobile 6.5 메모리관리

Embed Size (px)

DESCRIPTION

Windows Mobile 6.5 메모리 관리

Citation preview

Page 1: Windows Mobile 6.5 메모리관리

Windows Mobile 6.5 프로세스 및 메모리 관리 최적화

WEEG Manager [email protected]

Page 2: Windows Mobile 6.5 메모리관리

• URL : http://cafe.naver.com/wincepro• Since : 2006. 4. 23• Members : about 20,000• Staff : about 15• Manager : [email protected]• Contents :

– - Windows Embedded CE– - Windows Mobile

Page 3: Windows Mobile 6.5 메모리관리

Windows CE 5.0 Memory Model

Virtual Memory Map- 2GB 커널영역- 2GB 의 모든 Processes 들의 영역

-각 Slot 당 32MB

32 개 Process 제한- 유저 영역의 상위 절반 (1GB)- Process 에 의해 읽기 / 쓰기

공유 메모리 (Shared memory)- 유저 영역의 상위 절반 (1GB)- Process 에 의해 읽기 / 쓰기

가상메모리 관리 단위- 64KB alignment

Page 4: Windows Mobile 6.5 메모리관리

Windows CE 5.0 Memory Model

::

Shared Memory

Kernel

32 Slots for Processes

Single2 GB VMfor allProcesses

Execution Slot and

Shared DLL SlotSlot 0 – ExecutionSlot 1 – ROM DLLsSlot 2 – NK.exeSlot 3 – Filesys.exeSlot 4 – Device.exeSlot 5 – GWES.exe

Slot 31Slot 32

Slot 7 – Services.exe

2 GBKernelSpace

Slot 7

Page 5: Windows Mobile 6.5 메모리관리

Application Memory Map

5

COREDLL.DLL

0000 00000001 0000

Read only data

03FF FFFF

Code

Read write data

reserved

Other ROM DLLs

Resources

Stack (reserved space) Heap (reserved space)

Free virtual space

Application Specific Space

: 프로세스의 실행 영역

ROM DLL space

0200 0000

DLL Space (Con-stant for all appli-

cations): 프로세스의 보관 영역

RAM based DLLs

Page 6: Windows Mobile 6.5 메모리관리

문제점과 원인

증상- RAM 에 있는 DLL, Driver 는 load/unload 하면서 실패- 시스템은 RAM 이 비어 있다고 reporting - 그러나 ! 메모리 할당 불가

원인- 가상 메모리 쪼개짐- 가상 메모리 영역을 벗어남

Page 7: Windows Mobile 6.5 메모리관리

VM Exhaustion

App1 DLL A 로드

App2 실행

App1 DLL B 로드 + more Heap

App2 DLL Z 로드

App2 DLL X 로드

App1 DLL C 로드 실패 !

Thread 2

Reserved

APP 1

Slot 0 System DLLs

Main Thread

Process Heap

DLL A

Reserved

APP 2

Slot 0 System DLLs

Main Thread

Process Heap

DLL A

DLL B DLL B

2nd Heap

DLL ZDLL Z

DLL X

DLL X

DLL C

Page 8: Windows Mobile 6.5 메모리관리

효과적인 방법

DLL 을 FILES SECTION 또는 STORAGE 에 위치

클라이언트 / 플러그인 드라이버PCMCIAUSBSDIOBluetoothetc…

어플리케이션이 DLL 실행

Page 9: Windows Mobile 6.5 메모리관리

효과적인 방법

DLL 을 FILES SECTION 또는 STORAGE 에 위치

클라이언트 / 플러그인 드라이버PCMCIAUSBSDIOBluetoothetc…

어플리케이션이 DLL 실행

Page 10: Windows Mobile 6.5 메모리관리

10

Windows Mobile 6

Slot 63 :: Resource-Only DLLs

Slot 0 :: Alias of Active Process from Other SlotsOverflow DLLs Reduce VM Space for All Processes

Slots 2-32 :: Application Processes

Slots 33-611 GB Large Memory Area

Memory-Mapped Files

2 G

B ::

Use

r Spa

ce

FILE DLLs are loaded into every slot which decreases VM space

to all slots

DLL Overflow Causes Instabil-

ity

Slot 62 :: Shared Heaps

Slot 1 :: ROM FILE DLLs + MODULE DLLs

Slot Fill Or-der

FILE DLLs MODULE DLLs

0 1, 0

MODULE DLLs are

4K page-aligned in-

stead of 64K due to

ARM architecture

saving 9MB of VM

Page 11: Windows Mobile 6.5 메모리관리

11

Windows Mobile 6.1

Slot 63 :: Resource-Only DLLs

Slot 1 :: ROM FILE DLLs + MODULE DLLs

Slots 2-32 :: Application Processes

Slots 33-58 :: Large Memory AreaMemory-Mapped Files

2 G

B ::

Use

r Spa

ce

Slot 62 :: Shared Heap Area

Slot 61 :: Read-Only FILE DLLs

Slot 60 :: Read-Only FILE DLLs

Slot 59 :: Device.exe Thread Stacks

Extra 64 MB of VM

Extra 8 MB of VM for Device Drivers

Slot 0 :: Alias of Active Process from Other SlotsOverflow DLLs Reduce VM Space for All Processes

Convert mshtml.dll to

FILE DLL to free 6 MB of VM

DLLs used ex-clusively by one process don’t take space from other pro-

cesses

Slot Fill Or-der

FILE DLLs MODULES

60, 61, 0 1, 0

Page 12: Windows Mobile 6.5 메모리관리

Windows Mobile 6.5

Slot 63 :: Resource-Only DLLs

Slot 1 :: ROM FILE DLLs + MODULE DLLs

Slots 2-32 :: Application Processes

Slots 33-58 :: Large Memory AreaMemory-Mapped Files

2 G

B ::

Use

r Spa

ce

Slot 62 :: Shared Heaps

Slot 61 :: FILE + MODULE DLLs

Slot 60 :: FILE + MODULE DLLs

Slot 59 :: Device.exe Thread Stacks

Slot 0 :: Alias of Active Process from Other SlotsOverflow DLLs Reduce VM Space for All Processes

Faster MODULE DLLs whose VM is allocated at build time instead of runtime can go ev-erywhere!

Process Threshold

of 28

Slot Fill Or-der

FILE DLLs MODULE DLLs

60, 61, 0 1, 61, 60, 0

Page 13: Windows Mobile 6.5 메모리관리

Windows Mobile 6.5Faster Performance

JPEG images decode faster by aligning buffer size to 128-byte boundary needed by hardware

Glyph Cache jumps from 8KB to 72KB for English and 128KB for Asian builds to boost font rendering speed

GDI used to draw text one character at a time; now draws the entire string in one shot

Switching Today screens and backgrounds repeatedly does not degrade device performance

Paging Pool is set to a minimum of 15 MB to boost application load performance

Minimum devices specs include a 400 MHz processor, 128 MB of RAM and 256 MB of ROM

Page 14: Windows Mobile 6.5 메모리관리

14

Application Verifier

• 응용프로그램의 안정성 평가 Tool

• 개발 중 실수 할 수 있는 Leak 을 감지– Memory Leaks– Handle Leaks– GDI Leaks

• 응용프로그램은 물론 드라이버도 가능• http://www.microsoft.com/downloads/details.aspx?FamilyId=D

275348A-D937-4D88-AE25-28702C78748D&displaylang=en

Page 15: Windows Mobile 6.5 메모리관리

15

Application Leak(1)

• AppVerifer 실행

Page 16: Windows Mobile 6.5 메모리관리

16

Application Leak(2)

• AppVerifer 클릭 “ Connect…”• Device Connection Windows 클릭

“ Settings…”

Page 17: Windows Mobile 6.5 메모리관리

17

Application Leak(3)

• CE Platform Manager– 클릭 “ Add Device”– 이름을 변경– Properties

Page 18: Windows Mobile 6.5 메모리관리

18

Application Leak(4)

• Device Properties 에서– CESH Server…– “OK”

Page 19: Windows Mobile 6.5 메모리관리

19

Application Leak(5)

• Device Connection 에서– 클릭 “ Connect…”– KITL 을 선택 “ OK”

Page 20: Windows Mobile 6.5 메모리관리

20

Application Leak(6)

• AppVerifer “Add…”• Add Application LeakApp.exe “Open”

Page 21: Windows Mobile 6.5 메모리관리

21

Application Leak(7)

• AppVerifer 에서– “LeakApp.exe”– “Heap Verifier” 체크 – “Run”

Page 22: Windows Mobile 6.5 메모리관리

22

Application Leak(8)

• LeakApp 에서– Leak Memory– “Exit”

Page 23: Windows Mobile 6.5 메모리관리

23

Application Leak(9)

• AppVerifer – “Get Logs…”– “View Exported Log…”– “Open”

Page 24: Windows Mobile 6.5 메모리관리

24

Application Leak(10)

• Exported Log– “Potention Leak: 3 items (3072 bytes)…”– 메모리 누수가 생긴 부분의 API 나 함수 노출

Page 25: Windows Mobile 6.5 메모리관리

25

Application Leak(11)

• Source Code

void Create_MemoryLeak( HWND hWnd ){

MessageBox(hWnd, _T("Create 1 KB (1024 bytes) memory leak"), _T("Leak App"),MB_OK);

// LPBYTE p = (LPBYTE)LocalAlloc(LPTR, 1024);////LocalFree((HLOCAL)p);

}

Page 26: Windows Mobile 6.5 메모리관리

26

Question?