Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE451 Section 7: Virtual memory. Table of content Real address space Process creation optimization Debugging: watch point.

Similar presentations


Presentation on theme: "CSE451 Section 7: Virtual memory. Table of content Real address space Process creation optimization Debugging: watch point."— Presentation transcript:

1 CSE451 Section 7: Virtual memory

2 Table of content Real address space Process creation optimization Debugging: watch point

3 Real address space User address spaceKernel space 0x00000000 0xc0000000 on x86 0xffffffff From Understanding The Linux Virtual Memory Manager

4 Kernel address space –Remain constant in user address space –Why does all processes have the same shape of address space? Kernel can’t access user address space directly –Why? Understanding The Linux Virtual Memory Manager –http://www.skynet.ie/~mel/projects/vm/http://www.skynet.ie/~mel/projects/vm/

5 Optimization What do you think about memory copy? –Inter Process Communication –Network packet processing –Booting embedded system Is it really fast?

6 Process creation Fork() –Allocate process control block –Copy address space including shared resources –Schedule new process Let’s analyze real cases

7 When do we use fork? Web server –Why? –Usage? What are shared? What are not shared? Shell –Why? –Usage? What are shared? What are not shared?

8 Optimize fork – Web server Most of address space is shared –Program code –Configuration of web server –Heap May contain useful data What is not shared? –Stack & Heap Do we need to copy entire address space?

9 Copy-on-write Principle of laziness –Do action when it is REALLY required Do copy when the data is really changed Effect on fork? –Code: never be copied –Heap & stack: copy only changed portion Much faster, eh? –Linux fork() implements copy-on-write

10 How is it implemented? P1P2 CODE1 STACK2 HEAP1 HEAP3 HEAP2 HEAP4 HEAP3 HEAP2 HEAP1 STACK1 STACK2 STACK1 CODE1 CODE2 HEAP4 HEAP3 HEAP1 STACK1 CODE1 CODE2 STACK2’ HEAP2’ HEAP2 STACK2STACK2’ HEAP2’ Fork Call function A’ Write HEAP2

11 More copy-on-write Packet processing: Router –Can be seen as a chain of filters http://pdos.csail.mit.edu/click/ –Copy a packet whenever it passes a filter? Ethernet: 1500Byte frame size 10Mbps ~ 1.25MB/s Sample NAT/firewall enabled configuration has 37 filters –30MB memory copies per second –300MB when 100Mbps –3GB when 1Gbps This is just pure overhead! Copy on write! –Comparison does not change the content Other applications?

12 Optimize fork – shell What is shared? –NOTHING! –exec() will overwrite entire address space Copy? –Noooooo! Do not copy page table –Suspend parents until child calls exec() –exec() builds a new address space from the scratch vfork does this

13 Implementing thread? Linux 2.6 thread implementation –NPTL: Native POSIX Thread Library –1:1 threading model –Process/thread creation is integrated in clone() NPTL design paper –http://people.redhat.com/drepper/nptl- design.pdf

14 Debugging: watch point Watch point –Stop execution whenever the value of interesting variable has been changed Naïve approach –The variable is in page P –Let P as unmapped –Accessing P will cause page fault –Intercept page fault and temporarily map the page –Single instruction step over –If it touches, watched area, TRAP debugger


Download ppt "CSE451 Section 7: Virtual memory. Table of content Real address space Process creation optimization Debugging: watch point."

Similar presentations


Ads by Google