CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9...
Transcript of CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9...
CS 1550Week 9 – Lab Assignment 3
Pt 2
Teaching Assistant
Henrique Potter
xv6 allocates memory statically
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7000000
• User asks for 10MB of memory
xv6 allocates memory statically
Kernel Space
Stack
Heap
BSS
Data
Text
High address
Low address
Mapping
Program break 0x8000000
• User asks for 10MB of memory• That exact amount is allocated
xv6 allocates memory statically
Kernel Space
Stack
Heap
BSS
Data
Text
High address
Low address
Mapping
Program break 0x8000000
• User asks for 10MB of memory• That exact amount is allocated
• May not be used straight away
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7000000
• So we are going to allocate on demand
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7000000
• So we are going to allocate on demand• When the program asks we will make it
think it actually have allocated all it needs
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7000000
• So we are going to allocate on demand• When the program asks we will make it
think it actually have allocated all it needs
• Then we actually allocate memory on demand when errors occur
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7004000
• So we are going to allocate on demand• When the program asks we will make it
think it actually have allocated all it needs
• Then we actually allocate memory on demand when errors occur
Heap
Heap
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7008000
• So we are going to allocate on demand• When the program asks we will make it
think it actually have allocated all it needs
• Then we actually allocate memory on demand when errors occur
Heap
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7012000
• So we are going to allocate on demand• When the program asks we will make it
think it actually have allocated all it needs
• Then we actually allocate memory on demand when errors occur
Heap
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7012000
• So we are going to allocate on demand• When the program asks we will make it
think it actually have allocated all it needs
• Then we actually allocate memory on demand when errors occur
Heap
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7012000
• When the application attempts to access memory that was not allocated
Heap
xv6 Lazy memory allocation
Kernel Space
Stack
BSS
Data
Text
High address
Low address
Mapping
Program break 0x7012000
• When the application attempts to access memory that was not allocated• The Trap function is called with a
T_PGFLT(14)
Sbrk on XV6
The sys_sbrk() in sysproc.c is the XV-6 implementation for sbrk.
…
addr = proc->sz;
if(growproc(n) < 0)
return -1;
return addr;
Sbrk on XV6
The sys_sbrk() in sysproc.c is the XV-6 implementation for sbrk.
…
addr = proc->sz; // get current brk
if(growproc(n) < 0)
return -1;
return addr;
Sbrk on XV6
The sys_sbrk() in sysproc.c is the XV-6 implementation for sbrk.
…
addr = proc->sz; // get current brk
if(growproc(n) < 0) // increase brk by n
return -1;
return addr;
growproc
The growproc() in proc.c:
…
if(n > 0) {
allocuvm();
} else if (n < 0) {
deallocuvm();
}
growproc
The growproc() in proc.c:
…
if(n > 0) { // allocation
allocuvm(); // allocate physical pages, update page table
} else if (n < 0) {
deallocuvm();
}
growproc
The growproc() in proc.c:
…
if(n > 0) { // allocation
allocuvm(); // allocate physical pages, update page table
} else if (n < 0) { // deallocation
deallocuvm(); // update page table, free physical page
}
CS 1550 – Lab 3
• Due: Friday, November 2, 2018 @11:59pm
• Late: Sunday, November 4, 2018 @11:59pm • 10% reduction per late day
CS 1550Week 9 – Lab Assignment 3
Pt 2
Teaching Assistant
Henrique Potter