Memory%20Management%20in%20Linux - PowerPoint PPT Presentation

About This Presentation
Title:

Memory%20Management%20in%20Linux

Description:

Memory Management in Linux. DgN Chou. RT-Lab., CS, NTHU, Taiwain. Agenda ... Getting continuous free pages from physical memory. ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 17
Provided by: haz12
Category:

less

Transcript and Presenter's Notes

Title: Memory%20Management%20in%20Linux


1
Memory Management in Linux
DgN Chou
RT-Lab., CS, NTHU, Taiwain
2
Agenda
  • Allocation and Deallocation
  • Data Structure
  • Initialization
  • Tracing Code

3
Agenda
  • __get_free_pages()
  • kmalloc()
  • vmalloc()
  • do_mmap()

4
__get_free_pages
  • __get_free_pages(int priority, unsigned long
    order, int dma)
  • Getting continuous free pages from physical
    memory.
  • priority GFP_BUFFER,GFP_IO,GFP_KERNEL,GFP_USER,
    GFP_ATOMIC, GFP_NFS
  • order allocation size
  • dma allocation memory type

5
Buddy System In Linux
free_area
struct page mem_map
0
1
2
bitmap
next
1
1
0
1
1
1
0
0
0
1
0
1
6
Buddy System In Linux
free_areaNR_MEM_LISTS
Linked list
order 0
1 page
Bit map
Linked list
order 1
2 page
Bit map
Linked list
order 2
4 page
Bit map
Linked list
order 3
8 page
Bit map
Linked list
16 page
order 4
Bit map
Linked list
order 5
32 page
Bit map
7
Buddy System In Linux
  • struct page
  • type mem_map_t
  • (prev and next) used in double linked list
  • (next_hash, prev_hash, inode, offset) used for
    file-oriented caching
  • count, dirty, age..are attributes
  • map_nr is page number.

8
kmalloc
  • kmalloc(size_t size, int priority)
  • allocate memory from physical memory
  • 32 bytes, 64 bytes, 128bytes..
  • size the memory size allocated
  • priority the same as the priority in
    __get_free_pages()

9
kmalloc
Struct size_descriptor
32
64
1 page
1 page
...
page_des
page_des
128
2 page
...
block_des
block_des
page_des
.
4080
block_des
block_des
8176
10
kmalloc
No_free_page
no_bucket_page
No
No
No
Return Null
__get_free_pages
Check free page
Get cache page
yes
yes
yes
found_it
Found_cache_page
Data initialization
Data processing and return addr
11
kfree
  • kfree(void __ptr)
  • free the memory allocated by kmalloc
  • __ptr the start address of the memory to be free

12
kfree
Found the addr of the page and block
Check addr
Add block
Can add this page
Is nblocks1
Can free page
Add this page
No
yes
yes
No
yes
No
Free_page
return
13
vmalloc
  • vmalloc(unsigned long size)
  • allocate virtual memory
  • size the mallocation size

14
vmalloc
next
size
addr
Virtual memory
next
size
addr
vmlist
15
vmalloc
Round_size and check it
Kmalloc (area)
Search memory hole
Add it to the vmlist
Change Page table
16
vfree
  • vfree(void addr)
  • free the memory allocated by vmalloc
  • addr the start address of the memory
Write a Comment
User Comments (0)
About PowerShow.com