cs1550 lab 2people.cs.pitt.edu/.../cs1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · week 9...

21
CS 1550 Week 9 – Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter

Upload: others

Post on 19-Jan-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

CS 1550Week 9 – Lab Assignment 3

Pt 2

Teaching Assistant

Henrique Potter

Page 2: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

xv6 allocates memory statically

Kernel Space

Stack

BSS

Data

Text

High address

Low address

Mapping

Program break 0x7000000

• User asks for 10MB of memory

Page 3: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates 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

Page 4: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates 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

• May not be used straight away

Page 5: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 6: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 7: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 8: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 9: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 10: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 11: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 12: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

Page 13: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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)

Page 14: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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;

Page 15: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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;

Page 16: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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;

Page 17: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

growproc

The growproc() in proc.c:

if(n > 0) {

allocuvm();

} else if (n < 0) {

deallocuvm();

}

Page 18: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

growproc

The growproc() in proc.c:

if(n > 0) { // allocation

allocuvm(); // allocate physical pages, update page table

} else if (n < 0) {

deallocuvm();

}

Page 19: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

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

}

Page 20: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

CS 1550 – Lab 3

• Due: Friday, November 2, 2018 @11:59pm

• Late: Sunday, November 4, 2018 @11:59pm • 10% reduction per late day

Page 21: CS1550 Lab 2people.cs.pitt.edu/.../CS1550_week_9_lab3_assignment2.pdf · 2019. 4. 10. · Week 9 –Lab Assignment 3 Pt 2 Teaching Assistant Henrique Potter. xv6 allocates memory

CS 1550Week 9 – Lab Assignment 3

Pt 2

Teaching Assistant

Henrique Potter