Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Linux Memory Management

6,536 views

Published on

  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Linux Memory Management

  1. 1. Linux –Memory Management D3 Tsung-Han “Johnny” Lin
  2. 2. 12/4/26 Linux - Memory Management 2
  3. 3. Outline• Memory in Linux – Dynamic Allocation – Contiguous Allocation•Memory Allocation – Buddy System – Zone – SLAB Allocator• Per-CPU data 12/4/26 Linux - Memory Management 3
  4. 4. MMU - Simple HistoryEarly Linux on x86 Linux 2.5.46 (MMU) Embedded Developer?! µClinux (Linux for microconcroller) Jeff Dionne et al.199812/4/26 Linux - Memory Management 4
  5. 5. All about PAGE• Physical page -> page frame – Page descriptor, page – All pages, mem_map12/4/26 Linux - Memory Management 5
  6. 6. Initialization query or invoke Kernel BIOS machine_specific_memory_setup() setup_memory_map() struct page* mem_map Physical Memory12/4/26 Linux - Memory Management 6
  7. 7. Memory12/4/26 Linux - Memory Management 7
  8. 8. How pages are allocated? 12/4/26 Linux - Memory Management 8
  9. 9. Kernel API• alloc_pages• __get_free_pages• kmalloc• …• But, seriously12/4/26 Linux - Memory Management 9
  10. 10. HOW?12/4/26 Linux - Memory Management 10
  11. 11. Hierarchy OverviewApp w/ glibc heap Zone Allocator Slab Allocator glibc Buddy Allocator MMU Kernel Physical Subsystems VM Subsystem Memory kswapdApp w/ heap bdflush Disk DriverUser Space Kernel Space Disk 12/4/26 Linux - Memory Management 11
  12. 12. Memory ZonePhysical Memory (mem_map) 0x37999999, 896MB ZONE_DMA ZONE_NORMAL ZONE_HIGHMEM 12/4/26 0x01000000, 16MB Linux - Memory Management 12 0x40000000, 1GB
  13. 13. Buddy Systemzone descriptor free_area[10] 1024 pages …… ……… ……… ……… free_area[11] free_area[4] free_area[3] free_area[2] 4 pages …… ……… free_area[1] 2 pages 2 pages …… free_area[0] 1 page 1 page 1 page …… 12/4/26 Linux - Memory Management 13
  14. 14. Zone, again• ZONE_DMA, 0 ~ 16 MB 896MB ?!• ZONE_NORMAL, 16 MB ~ 896 MB• ZONE_HIGHMEM, rest of them …12/4/26 Linux - Memory Management 14
  15. 15. Kernel View Linear – 4 GB Physical TASK_SIZE 0x0 3 GBPAGE_OFFSET ZONE_HIGHMEM0xc0000000 0x40000000, 1GB Kernel 8 MB Image Reserved 0x37999999, 896MB mem_map 128 MB ZONE_NORMAL 1 GB … 0x01000000, 16MB 896 MB ZONE_NORMAL ZONE_DMA + ZONE_DMA 0xffffffff 12/4/26 Linux - Memory Management 15
  16. 16. Do we need this large?!12/4/26 Linux - Memory Management 16
  17. 17. SLAB Allocator• First introduced in 大辞泉 SunOS 5.4 slab/slǽb/• Implemented in Linux 名 詞 2.2 1 (石木材金属などの)広い厚板;(材木 の)背板.• SLAB system 2 (食べ物などの)厚切り – SLAB a thick slab of apple pie|厚切りのアップル パイ. – SLOB, embedded system 3⦅ 俗語⦅ 〘野球〙ピッチャーズプレート. – SLUB, efficient ver. 4⦅ ~⦅⦅ the 俗語⦅ (病院などの)死体置 き台 – SLQB, per-CPU scaling on the slab|(死体となって)安置されて.• kmalloc()! 12/4/26 Linux - Memory Management Cache !! 17
  18. 18. Design of SLABcache_chain slab_full …… page struct cache slab slab object Page 1 page … cache slab_partial slab(kmem_cache) object page … slab object Page 2 cache page slab_partial …… 12/4/26 Linux - Memory Management 18
  19. 19. Per-CPU Allocation• Request/Release single page – Frequently• Per-CPU – Reducing cache invalidation – Reducing locking – A simple data array• In 2.4 kernel – get_cpu(), preemption disabled – Access array directly• In 2.6 kernel – Wrapper – percpu interface – Cache alignment12/4/26 Linux - Memory Management 19
  20. 20. ReviewApp w/ glibc heap Zone Allocator Slab Allocator glibc Buddy Allocator MMU Kernel Physical Subsystems VM Subsystem Memory kswapdApp w/ heap bdflush Disk DriverUser Space Kernel Space Disk 12/4/26 Linux - Memory Management 20
  21. 21. Reference• Linux Kernel Development, 3rd• Understanding the Linux Kernel, 3rd – http://www.makelinux.net/books/ulk3/t oc• Understanding the Virtual Memory Manager – http://www.kernel.org/doc/gorman/htm l/understand/index.html12/4/26 Linux - Memory Management 21

×