Successfully reported this slideshow.

Memory_AllocationUNIX_MINIX-COSCUP2012

2,158 views

Published on

http://hawxchen.blogspot.tw/2012/08/talk-memory-allocation-in-classic.html

I presented this slide at COSCUP 2012 with 907 attendees in Taiwan.

Published in: Design, Technology, Education
  • Be the first to comment

Memory_AllocationUNIX_MINIX-COSCUP2012

  1. 1. Memory Allocation In Classic Monolithic Kernel And Classic Micro Kernel陳膺正 (Hawx Chen )yingjheng.chen@gmail.comhttp://gplus.to/HawxChenhttp://hawxchen.blogspot.tw Presented at COSCUP2012- JuluOS Workshop/JuluOSDev http://www.juluos.org/
  2. 2. Who Am I• Experience – 2008 NCTU CS Bachelor – 2010 NTU CSIE Master – 2010~presnet Mstar Semiconductor • Senior software engineer• Open Source – https://github.com/HawxChen/MIT-6.828- Adventure Enjoy to implement OS
  3. 3. Memory Management• Importance of History.• Based Arch: – Classic Monolithic: UNIX v6 – Classic Microkernel: MINIX• UNIX – Kernel(Physical) Memory Allocator – User(virtual) Memory Allocator• MINIX – Kernel(Physical) Memory Allocator – User Memory Allocator
  4. 4. Memory Management• Importance of History.• Based Arch: – Classic Monolithic: UNIX v6 – Classic Microkernel: MINIX• UNIX – Kernel(Physical) Memory Allocator – User(virtual) Memory Allocator• MINIX – Kernel(Physical) Memory Allocator – User Memory Allocator
  5. 5. Importance of History• Computer programmming is Art?Fromhttp://www2.uwstout.edu/content/profdev/images/kelly_art_history.jpghttp://www.informit.com/ShowCover.aspx?isbn=0201485419
  6. 6. Importance of history• Having an understanding of the battles fought in the past will give you the ammunition for your current battles 了解過去的戰場在爭什麼,會讓你得到現行戰場的火藥。
  7. 7. Importance of history
  8. 8. Importance of history
  9. 9. Memory Management• Importance of History.• Based Arch: – Classic Monolithic: UNIX v6 – Classic Microkernel: MINIX• UNIX – Kernel(Physical) Memory Allocator – User(virtual) Memory Allocator• MINIX – Kernel(Physical) Memory Allocator – User Memory Allocator
  10. 10. UNIX Arch User Process System Call Process Management I/O Services Device Drivers Scheduler Hardware I/O BuffersMemoryManagement File System Kernel Space Interface (Library Routines) User Process
  11. 11. MINIX Arch Kernel Space
  12. 12. MINIX Scheduling• When to run each component?• Scheduler – Multilevel Queue – Lazy scheduling
  13. 13. Memory Management• Importance of History.• Based Arch: – Classic Monolithic: UNIX v6 – Classic Microkernel: MINIX• UNIX – Kernel(Physical) Memory Allocator – User(virtual) Memory Allocator• MINIX – Kernel(Physical) Memory Allocator – User Memory Allocator• How to start
  14. 14. Some UNIX v6 Features HW: PDP machine• 2Byte (1 Word) Alignment• Block Addressed: 64 Bytes KISA0 KISD0 UISA0 UISD0
  15. 15. UNIX Kernel Addressing Space Physical• Kernel segment registers Loader/ initialized at m40.S INT&Trap – KISA0 ~ KISA5 : 0~48KB functions – KISA6 KISD6: Per process data and structure. Kernel context – KISA7 KISD7: IO Segment Kernel data/bss u per-process data• #0 system process(scheduler) IO address space• #1 init process
  16. 16. UNIX Kernel Addressing Space• Kernel segment registers initialized at m40.S – KISA0 ~ KISA5 : 0~48KB – KISA6 KISD6: Per process data and structure. – KISA7 KISD7: IO Segment stack kernel stack u per- process data 1K struct user data structure• #0 system process(scheduler)• #1 init process
  17. 17. UNIX Kernel Memory Allocation• coremap counted from *ka6+USIZE Loader/ INT&Trap functions Kernel context First Fit Avail Memory Kernel data/bss u per-process 48K data stack struct user Avail Memory 49K IO address space
  18. 18. UNIX User Memory Allocation • User segment registers initialized at main – UISA/UISD – Text+Data(BSS)+Stack + U(Kernel Stack/Internal PCB) <= 64KB 0 Virtual Physical 0 Context Context Data Data Stack unmapped64KB Stack 256KB
  19. 19. Memory Management• Importance of History.• Based Arch: – Classic Monolithic: UNIX v6 – Classic Microkernel: MINIX – UNIX – Kernel(Physical) Memory Allocator – User(virtual) Memory Allocator• MINIX – Kernel(Physical) Memory Allocator – User Memory Allocator
  20. 20. MINIX Kernel Address Space• Kernel don’t use any dynamic memory• Hardware independent• View entire available memory as CLIKCS (1024 Byte)
  21. 21. MINIX Memory Manager PM Mm Pm • Almost hardware independent • User mode
  22. 22. MINIX Physical Memory Manager• Hole List manager Hole structure hole_head Base1 Base1 Base1 BaseN Size1 Size1 Size1 … SizeN …
  23. 23. MINIX User Memory Allocation• Holes: Free memory slot – Unit: # clicks (1024 Bytes) 0x25863• Size calculated from file header Context• Gap: Available memory Data 0x25863• No memory relocation(Before swapped 0x31945 out) Gap• No memory expansion Gap – Gap adjustment Stack• No memory translation 0x31945 – No virtual memory (Before 3.1.4)
  24. 24. Something I want to convey!
  25. 25. • History is the ONE PIECE.• How to start to implement OS? – What’s the most important? – Keep others to be as simple as possible.• Join us.
  26. 26. Reference

×