SlideShare une entreprise Scribd logo
1  sur  104
Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory 主講人:虞台文
Content ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Single-Copy Sharing
Sharing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],OpenFileMapping(),  UnmapViewofFile (), CloseHandle() Shmdt () Shmctl () OpenFileMapping (),  MapViewofFile () Shmat () CreateFileMapping () shmget () Win32 Unix
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } Compile
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . .
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . . . . esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 5 . . . esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 5 7 . . . esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 5 7 . . . esp 7
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 5 7 . . . esp 7 5
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 5 7 . . . Return Address esp 7 5 Return Address
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 esp 7 5 Return Address
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 esp 7 5 Return Address old ebp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 i j esp 7 5 Return Address old ebp ebp ebp+8 ebp+12
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 i j eax= 5 7 5 Return Address old ebp ebp ebp+8 ebp+12
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 i j eax= 12 7 5 Return Address old ebp ebp ebp+8 ebp+12
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 i j eax= 24 7 5 Return Address old ebp ebp ebp+8 ebp+12
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 i j eax= 24 7 5 Return Address old ebp ebp ebp+8 ebp+12 esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 eax= 24 7 5 Return Address old ebp esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov  ebp,esp mov  eax, [bp+8] add  eax, [bp+8+4] shl  eax, 1 mov  esp,ebp pop  ebp ret . . . 5 7 eax= 24 _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 7 5 Return Address esp Return Address
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } . . . 5 7 eax= 24 _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 7 5 esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } . . . 5 7 eax= 24 _main: mov  ds:[x],5 mov  ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add  esp,8 mov  ds:[z],eax . . . . . . 24 esp
Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT   SEGMENT PUBLIC ‘CODE’ _AddMul2: . . .  // code for AddMul2 _main: . . .  // code for main _TEXT ENDS Pure  code  is  sharable   Each process has its  own  stack  segment  Each process has its  own  data  segment
Example: Simple Code Sharing Translate to the same physical process for different processes Access different data areas for different processes
Linking and Sharing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Static Linking and Sharing
Sharing without Virtual Memory ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Physical Memory System Components User Programs All  memory  of a process is  contiguous  physically. User Program 1 User Program 2
Sharing without Virtual Memory ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Physical Memory System Components User Programs All  memory  of a process is  contiguous  physically.
Sharing without Virtual Memory ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Sharing of  code
Sharing without Virtual Memory ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Sharing of  data code 1   code 2        stack 1   stack 2        data                      CBR 1 SBR 1 DBR 1        CBR 2 SBR 2 DBR 2 process 1 process 2
Sharing in Paging Systems   Sharing of Data Data Common data (without address) Database
Sharing in Paging Systems   Sharing of Data Data Data 1 Data 2 Data 3 Data 2 Data 3 Data 1 Database Physical Memory
Sharing in Paging Systems   Sharing of Data Data 2 Data 3 Data 1 n 2 ,  w n 1 ,  w Physical Memory . . . . . . PT 1 0 n 1 . . . . . . PT 2 0 n 2 Database
Sharing in Paging Systems   Sharing of Data Data 2 Data 3 Data 1 . . . . . . PT 1 0 n 1 . . . . . . PT 2 0 n 2 n 2 ,  w n 1 ,  w The page numbers of sharing processes can be different. Physical Memory Database
Sharing in Paging Systems   Sharing of Code Assemble bra  label1 label1 :  . . . . . . . . . 0x0000 0x2000 0x1000 4 k 4 k 4 k w bra  (2,w) label1 :  . . . . . . . . . 0x0000 0x2000 0x1000
Sharing in Paging Systems   Sharing of Code Virtual Memory n th   page Shared code bra  (2,w) label1 :  . . . . . . . . . 0x0000 0x2000 0x1000 bra  (n+2,w) label1 :  . . . . . . . . .
Sharing in Paging Systems   Sharing of Code Virtual Memory n th   page Physical Memory p q r bra  (n+2,w) label1 :  . . . . . . . . . bra  (n+2,w) . . . . . . Label1 :  . . .
Sharing in Paging Systems   Sharing of Code Virtual Memory n th   page Physical Memory p q r bra  (n+2,w) label1 :  . . . . . . . . . bra  (n+2,w) . . . . . . Label1 :  . . . r q p n n+1 n+2 PT
Sharing in Paging Systems   Sharing of Code n 2 ,  w n 1 ,  w p q r bra  (n+2,w) . . . . . . Label1 :  . . . Physical Memory r q p n1 n1+1 n1+2 PT 1 0 0 r q p n2 n2+1 n2+2 PT 2 0 0 r q p n n+1 n+2 PT
Sharing in Paging Systems   Sharing of Code n 2 ,  w n 1 ,  w p q r If  absolute  virtual address is used for coding, such a code sharing scheme is  workable  if n 1 =  n 2  =  n bra  (n+2,w) . . . . . . Label1 :  . . . Physical Memory r q p n1 n1+1 n1+2 PT 1 0 0 r q p n2 n2+1 n2+2 PT 2 0 0 r q p n n+1 n+2 PT
Sharing in Paging Systems   Sharing of Code n 2 ,  w n 1 ,  w r q p n1 n1+1 n1+2 PT 1 0 0 r q p n2 n2+1 n2+2 PT 2 0 0 r q p n n+1 n+2 PT p q r Can we assign different starting page numbers to a different processes? bra  (n+2,w) . . . . . . Label1 :  . . . Physical Memory
Sharing in Paging Systems   Sharing of Code Virtual Memory n th   page 1. Shared code is  self-contained Can we assign different starting page numbers to a different processes? 2.  Avoid  using  absolute  address ( page number ) in share code, i.e., using  address relative to CBR   instead . Yes, if … bra  (n+2,w) label1 :  . . . . . . . . .
Sharing in Paging Systems   Short Summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
Sharing in Paging Systems   Short Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],done  just-in-time  and only  once .
Dynamic Linking via Transfer Vector ... bri tv[i]  ... bri tv[i]  ... Transfer  Vectors  Currently  Executing  Code  Linking  just-in-time  and only  once . call the same shared function by  indirect  branch instruction. ... ... stub stub stub stub 0 1 i n  1
Dynamic Linking via Transfer Vector ... bri tv[i]  ... bri tv[i]  ... Transfer  Vectors  Currently  Executing  Code  Linking  just-in-time  and only  once . ... ... stub stub stub stub 0 1 i n  1 When the shared function is called  first time , the external reference is  resolved  by the corresponding  stub .
Dynamic Linking via Transfer Vector ... bri tv[i]  ... bri tv[i]  ... Transfer  Vectors  Currently  Executing  Code  Linking  just-in-time  and only  once . ... ... stub stub stub stub 0 1 i n  1 When the shared function is called  first time , the external reference is  resolved  by the corresponding  stub . Shared code When the external reference is  resolved , the stub  replaces  the corresponding transfer vector to point to the shared code.
Dynamic Linking via Transfer Vector ... bri tv[i]  ... bri tv[i]  ... Transfer  Vectors  Currently  Executing  Code  Linking  just-in-time  and only  once . ... ... stub stub stub stub 0 1 i n  1 Shared code Once the external reference is resolved, it can be  used directly later on . Used by  Win32  and  POSIX  ( DLLs ).
Sharing in Segmented Systems ,[object Object],[object Object],[object Object]
Sharing in Segmented Systems   Sharing of Data Shared Data s 2 ,  w s 1 ,  w ST entries of different processes point to the same segment in PM. Database Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
Sharing in Segmented Systems   Sharing of Data Shared Data s 2 ,  w s 1 ,  w ST entries of different processes point to the same segment in PM. How about if a segment is also paged? Database Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
Sharing in Segmented Systems   Sharing of Data s 2 ,  p ,  w s 1 ,  p ,  w ST entries of different processes point to the same page table in PM. Data 2 Data 3 Data 1 PT How about if a segment is also paged? Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2 p Paging
Sharing in Segmented Systems   Sharing of Code ? Shared Code s 2 ,  w s 1 ,  w ST entries of different processes point to the same segment in PM. In  what condition  the scheme is  workable ? The code must be  self-contained. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
Sharing in Segmented Systems   Sharing of Code ? Shared Code s 2 ,  w s 1 ,  w ST entries of different processes point to the same segment in PM. How about if a segment is also paged? In  what condition  the scheme is  workable ? The code must be  self-contained. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
Sharing in Segmented Systems   Sharing of Code ? In  what condition  the scheme is  workable ? s 2 ,  p ,  w s 1 ,  p ,  w ST entries of different processes point to the same page table in PM. Code 2 Code 3 Code 1 PT How about if a segment is also paged? The code must be  self-contained. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2 p Paging
Sharing in Segmented Systems   Sharing of Code ? In  what condition  the scheme is  workable ? s 2 ,  p ,  w s 1 ,  p ,  w ST entries of different processes point to the same page table in PM. Code 2 Code 3 Code 1 PT How about if the shared code is not self-contained? The code must be  self-contained. Assign the same segment numbers for all share codes in STs. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2 p
Sharing in Segmented Systems   Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Dynamic Linking and Sharing
Unrestricted Dynamic Linking/Sharing ,[object Object],[object Object],[object Object]
Unrestricted Dynamic Linking/Sharing Symbol table i j Segment table Code segment C load * l d ( S ,  W ) Linkage section for C CBR trap on d LBR
Unrestricted Dynamic Linking/Sharing ( S ,  W ) trap on Symbol table Addressing relative to linkage section Displacement Indirect addressing The address for external reference Not ready now i j Segment table Code segment C load * l d Linkage section for C CBR d LBR
Unrestricted Dynamic Linking/Sharing ( S ,  W ) trap on Symbol table Generated by the compiler i j Segment table Code segment C load * l d Linkage section for C CBR d LBR
Unrestricted Dynamic Linking/Sharing ( S ,  W ) Symbol table Resolve the external reference  dynamically  by the  exception handler  when the corresponding instruction is  executed . i j Segment table Code segment C load * l d Linkage section for C CBR trap on d LBR
Unrestricted Dynamic Linking/Sharing ( S ,  W ) Symbol table Resolve the external reference  dynamically  by the  exception handler  when the corresponding instruction is  executed . trap off ( s ,  w ) s i j Segment table Code segment C load * l d Linkage section for C CBR trap on d LBR Segment S w
Unrestricted Dynamic Linking/Sharing Before external reference is executed After external reference is executed
Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Principles of Distributed Shared Memory (DSM)
Memory Sharing on Different Computer Architecture Single processor/ Single memory module Multiple processor/ Single memory module Distributed System Memory Memory Memory Memory Memory
Distributed Share Memory (DSM) ,[object Object],[object Object],[object Object],[object Object],Memory Memory Memory Distributed System The illusion of a single shared memory
Distributed Share Memory (DSM) ,[object Object],[object Object],[object Object],[object Object],Memory Memory Memory Distributed System The illusion of a single shared memory
Distributed Share Memory (DSM) ,[object Object],[object Object],[object Object],[object Object],Memory Memory Memory Distributed System The illusion of a single shared memory ,[object Object],[object Object]
How to implement transfers efficiently? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Unstructured DSM ,[object Object],[object Object],[object Object],[object Object],P1 P2 P n MM1 MM2 MM n 0 p  1 0 p  1 0 p  1 DSM 0 np  1
Structured DSM ,[object Object],[object Object],[object Object],[object Object],[object Object],P1 P2 P n Local address space shared shared shared MM1 MM2 MM n DSM
Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Implementations of DSM
Implementations of DSM ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Unstructured DSM     Granularity  of Data Transfers ,[object Object],[object Object],[object Object],[object Object],[object Object],A  nature  choice is to use the  page size  (or its multiple) as the  granularity  for transfer.
Implementing Unstructured DSM     Replication  of Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Unstructured DSM     Replication  of Data ,[object Object],Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages.
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: P1 P2 MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only)
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B read
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B Operation is  done   locally .  No  extra action need to be taken. read
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B write
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B Operation is  done   locally .  No  extra action need to be taken. write
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B write
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B Invalidate copy in MM2; Upgrade copy in MM1 to writable. page B (writable) page B (writable) write
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) read
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 page A (writable) DSM page A (writable) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) Downgrade page in MM1 to read-only; Make copy in MM2. page A (read-only) page A (read-only) page A (read-only) read
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 DSM P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) page A (read-only) page A (read-only) page A (read-only) write
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 DSM P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) page A (read-only) page A (read-only) page A (read-only) page B (writable) Transfer page from MM1 to MM2. write
Implementing Unstructured DSM     Replication  of Data Allowing only  one  copy of  writable  page, but  multiple  copies of  read-only  pages. Example: MM1 MM2 DSM P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page A (read-only) page A (read-only) page A (read-only) page B (writable)
Implementing Unstructured DSM     Memory Consistency a1=1, b1=2 a2=1, b2=2 a1=1, b1=2 a2=0, b2=0 a1=1, b1=2 a2=0, b2=1 a1=1, b1=2 a2=1, b2=2
Implementing Unstructured DSM     Memory Consistency a1=1, b1=2 a2=1, b2=2 a1=1, b1=2 a2=0, b2=0 a1=1, b1=2 a2=0, b2=1 a1=1, b1=2 a2=1, b2=2 Strict Consistency Sequential Consistency
Implementing Unstructured DSM     Memory Consistency ,[object Object],[object Object],[object Object],[object Object]
Implementing Unstructured DSM     Tracking Data ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Unstructured DSM     Discussion ,[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Structured DSM     Consistencies ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Structured DSM     Weak Consistency  ,[object Object],[object Object]
Implementing Structured DSM     Release Consistency  ,[object Object],[object Object]
Implementing Structured DSM     Entry Consistency  ,[object Object],There is also a “ lazy release consistency ” (Keleher et al. 1992) which imports  all  shared variables before  entering  CS.
Object-Based DSM ,[object Object],[object Object],[object Object]

Contenu connexe

Tendances

12. stl örnekler
12.  stl örnekler12.  stl örnekler
12. stl örneklerkarmuhtam
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxyginecorehard_by
 
Python 표준 라이브러리
Python 표준 라이브러리Python 표준 라이브러리
Python 표준 라이브러리용 최
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowOswald Campesato
 
Python basic
Python basic Python basic
Python basic sewoo lee
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...tdc-globalcode
 
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice Sebastian Marek
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your BrowserOswald Campesato
 
Abusing text/template for data transformation
Abusing text/template for data transformationAbusing text/template for data transformation
Abusing text/template for data transformationArnaud Porterie
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationJacopo Mangiavacchi
 
Replication
ReplicationReplication
ReplicationMongoDB
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3hasi071
 
Spark AI 2020
Spark AI 2020Spark AI 2020
Spark AI 2020Li Jin
 

Tendances (20)

Property-based testing
Property-based testingProperty-based testing
Property-based testing
 
Whispered secrets
Whispered secretsWhispered secrets
Whispered secrets
 
12. stl örnekler
12.  stl örnekler12.  stl örnekler
12. stl örnekler
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
Python 표준 라이브러리
Python 표준 라이브러리Python 표준 라이브러리
Python 표준 라이브러리
 
DDS-20m
DDS-20mDDS-20m
DDS-20m
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and Tensorflow
 
Python basic
Python basic Python basic
Python basic
 
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
 
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
PHP Benelux 2012: Magic behind the numbers. Software metrics in practice
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your Browser
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
Abusing text/template for data transformation
Abusing text/template for data transformationAbusing text/template for data transformation
Abusing text/template for data transformation
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Replication
ReplicationReplication
Replication
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3
 
Spark AI 2020
Spark AI 2020Spark AI 2020
Spark AI 2020
 
Intro
IntroIntro
Intro
 

En vedette

Pizza Hut: It's Your Hut! Campaign
Pizza Hut: It's Your Hut! CampaignPizza Hut: It's Your Hut! Campaign
Pizza Hut: It's Your Hut! Campaignzikakiss
 
Milton mayorca
Milton mayorcaMilton mayorca
Milton mayorcamemb90
 
Etnografía guber rosana
Etnografía   guber rosanaEtnografía   guber rosana
Etnografía guber rosanaClimer
 
Os8 2
Os8 2Os8 2
Os8 2issbp
 
Os6 2
Os6 2Os6 2
Os6 2issbp
 
Historia de la fotografia
Historia de la fotografiaHistoria de la fotografia
Historia de la fotografiamemb90
 
Hoja de vida - Milton mayorca
Hoja de vida - Milton mayorcaHoja de vida - Milton mayorca
Hoja de vida - Milton mayorcamemb90
 
Heidegger el concepto de tiempo
Heidegger   el concepto de tiempoHeidegger   el concepto de tiempo
Heidegger el concepto de tiempoClimer
 
Filosofía de la ciencia leon olives y ana r. pérez 453
Filosofía de la ciencia leon olives y ana r. pérez 453Filosofía de la ciencia leon olives y ana r. pérez 453
Filosofía de la ciencia leon olives y ana r. pérez 453Climer
 
Class5
 Class5 Class5
Class5issbp
 
Os2 2
Os2 2Os2 2
Os2 2issbp
 
El paradigma perdido edgar morin
El paradigma perdido edgar morinEl paradigma perdido edgar morin
El paradigma perdido edgar morinClimer
 
Ch11 input output systems
Ch11 input output systemsCh11 input output systems
Ch11 input output systemsissbp
 
L'ergonomie d'un site web par Fred Colantonio
L'ergonomie d'un site web par Fred ColantonioL'ergonomie d'un site web par Fred Colantonio
L'ergonomie d'un site web par Fred ColantonioJ'ai besoin de com
 
"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat
"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat
"Créer une campagne Google Adwords étape par étape" par Christophe BouchatJ'ai besoin de com
 

En vedette (20)

Pizza Hut: It's Your Hut! Campaign
Pizza Hut: It's Your Hut! CampaignPizza Hut: It's Your Hut! Campaign
Pizza Hut: It's Your Hut! Campaign
 
Registro de telefono
Registro de telefonoRegistro de telefono
Registro de telefono
 
Os4
Os4Os4
Os4
 
Milton mayorca
Milton mayorcaMilton mayorca
Milton mayorca
 
Etnografía guber rosana
Etnografía   guber rosanaEtnografía   guber rosana
Etnografía guber rosana
 
DSW: The first 20 Years
DSW: The first 20 YearsDSW: The first 20 Years
DSW: The first 20 Years
 
Os8 2
Os8 2Os8 2
Os8 2
 
Os6 2
Os6 2Os6 2
Os6 2
 
Os6
Os6Os6
Os6
 
Historia de la fotografia
Historia de la fotografiaHistoria de la fotografia
Historia de la fotografia
 
Hoja de vida - Milton mayorca
Hoja de vida - Milton mayorcaHoja de vida - Milton mayorca
Hoja de vida - Milton mayorca
 
Os2
Os2Os2
Os2
 
Heidegger el concepto de tiempo
Heidegger   el concepto de tiempoHeidegger   el concepto de tiempo
Heidegger el concepto de tiempo
 
Filosofía de la ciencia leon olives y ana r. pérez 453
Filosofía de la ciencia leon olives y ana r. pérez 453Filosofía de la ciencia leon olives y ana r. pérez 453
Filosofía de la ciencia leon olives y ana r. pérez 453
 
Class5
 Class5 Class5
Class5
 
Os2 2
Os2 2Os2 2
Os2 2
 
El paradigma perdido edgar morin
El paradigma perdido edgar morinEl paradigma perdido edgar morin
El paradigma perdido edgar morin
 
Ch11 input output systems
Ch11 input output systemsCh11 input output systems
Ch11 input output systems
 
L'ergonomie d'un site web par Fred Colantonio
L'ergonomie d'un site web par Fred ColantonioL'ergonomie d'un site web par Fred Colantonio
L'ergonomie d'un site web par Fred Colantonio
 
"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat
"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat
"Créer une campagne Google Adwords étape par étape" par Christophe Bouchat
 

Similaire à Os9 2

The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202Mahmoud Samir Fayed
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing ScenarioTara Hardin
 
Assignment2 – Simplified DES Encrypt and Decrypt .docx
Assignment2 – Simplified DES Encrypt and Decrypt                  .docxAssignment2 – Simplified DES Encrypt and Decrypt                  .docx
Assignment2 – Simplified DES Encrypt and Decrypt .docxmckellarhastings
 
Assignment2 – Simplified DES Encrypt and Decrypt .docx
Assignment2 – Simplified DES Encrypt and Decrypt                  .docxAssignment2 – Simplified DES Encrypt and Decrypt                  .docx
Assignment2 – Simplified DES Encrypt and Decrypt .docxedmondpburgess27164
 
Chapter 2 Part2 C
Chapter 2 Part2 CChapter 2 Part2 C
Chapter 2 Part2 Cececourse
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...Functional Thursday
 
Task based Programming with OmpSs and its Application
Task based Programming with OmpSs and its ApplicationTask based Programming with OmpSs and its Application
Task based Programming with OmpSs and its ApplicationFacultad de Informática UCM
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4Abdul Haseeb
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataAnne Nicolas
 
PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...
PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...
PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...Andrey Karpov
 
Drizzles Approach To Improving Performance Of The Server
Drizzles  Approach To  Improving  Performance Of The  ServerDrizzles  Approach To  Improving  Performance Of The  Server
Drizzles Approach To Improving Performance Of The ServerPerconaPerformance
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210Mahmoud Samir Fayed
 
Information track presentation_final
Information track presentation_finalInformation track presentation_final
Information track presentation_finalKazuki Omo
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part iiJonah Marrs
 

Similaire à Os9 2 (20)

The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202The Ring programming language version 1.8 book - Part 53 of 202
The Ring programming language version 1.8 book - Part 53 of 202
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
Assignment2 – Simplified DES Encrypt and Decrypt .docx
Assignment2 – Simplified DES Encrypt and Decrypt                  .docxAssignment2 – Simplified DES Encrypt and Decrypt                  .docx
Assignment2 – Simplified DES Encrypt and Decrypt .docx
 
Assignment2 – Simplified DES Encrypt and Decrypt .docx
Assignment2 – Simplified DES Encrypt and Decrypt                  .docxAssignment2 – Simplified DES Encrypt and Decrypt                  .docx
Assignment2 – Simplified DES Encrypt and Decrypt .docx
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
Chapter 2 Part2 C
Chapter 2 Part2 CChapter 2 Part2 C
Chapter 2 Part2 C
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
 
Task based Programming with OmpSs and its Application
Task based Programming with OmpSs and its ApplicationTask based Programming with OmpSs and its Application
Task based Programming with OmpSs and its Application
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...
PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...
PVS-Studio 5.00, a solution for developers of modern resource-intensive appl...
 
Drizzles Approach To Improving Performance Of The Server
Drizzles  Approach To  Improving  Performance Of The  ServerDrizzles  Approach To  Improving  Performance Of The  Server
Drizzles Approach To Improving Performance Of The Server
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210
 
Information track presentation_final
Information track presentation_finalInformation track presentation_final
Information track presentation_final
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 

Plus de issbp

Os10 2
Os10 2Os10 2
Os10 2issbp
 
Os10
Os10Os10
Os10issbp
 
Os7 2
Os7 2Os7 2
Os7 2issbp
 
Os5 2
Os5 2Os5 2
Os5 2issbp
 
Os4 2
Os4 2Os4 2
Os4 2issbp
 
Os3 2
Os3 2Os3 2
Os3 2issbp
 
Class9
 Class9 Class9
Class9issbp
 
Class8
 Class8 Class8
Class8issbp
 
Class7
 Class7 Class7
Class7issbp
 
Class6
 Class6 Class6
Class6issbp
 
Class4
 Class4 Class4
Class4issbp
 
Class3
 Class3 Class3
Class3issbp
 
Class2
 Class2 Class2
Class2issbp
 
Class1
 Class1 Class1
Class1issbp
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguagesissbp
 

Plus de issbp (20)

Os10 2
Os10 2Os10 2
Os10 2
 
Os10
Os10Os10
Os10
 
Os9
Os9Os9
Os9
 
Os8
Os8Os8
Os8
 
Os7 2
Os7 2Os7 2
Os7 2
 
Os7
Os7Os7
Os7
 
Os5 2
Os5 2Os5 2
Os5 2
 
Os5
Os5Os5
Os5
 
Os4 2
Os4 2Os4 2
Os4 2
 
Os3 2
Os3 2Os3 2
Os3 2
 
Os3
Os3Os3
Os3
 
Class9
 Class9 Class9
Class9
 
Class8
 Class8 Class8
Class8
 
Class7
 Class7 Class7
Class7
 
Class6
 Class6 Class6
Class6
 
Class4
 Class4 Class4
Class4
 
Class3
 Class3 Class3
Class3
 
Class2
 Class2 Class2
Class2
 
Class1
 Class1 Class1
Class1
 
0227 regularlanguages
 0227 regularlanguages 0227 regularlanguages
0227 regularlanguages
 

Os9 2

  • 1. Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory 主講人:虞台文
  • 2.
  • 3. Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Single-Copy Sharing
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } Compile
  • 9. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . .
  • 10. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . . . . esp
  • 11. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 5 . . . esp
  • 12. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 5 7 . . . esp
  • 13. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 5 7 . . . esp 7
  • 14. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 5 7 . . . esp 7 5
  • 15. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 5 7 . . . Return Address esp 7 5 Return Address
  • 16. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 esp 7 5 Return Address
  • 17. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 esp 7 5 Return Address old ebp
  • 18. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 i j esp 7 5 Return Address old ebp ebp ebp+8 ebp+12
  • 19. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 i j eax= 5 7 5 Return Address old ebp ebp ebp+8 ebp+12
  • 20. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 i j eax= 12 7 5 Return Address old ebp ebp ebp+8 ebp+12
  • 21. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 i j eax= 24 7 5 Return Address old ebp ebp ebp+8 ebp+12
  • 22. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 i j eax= 24 7 5 Return Address old ebp ebp ebp+8 ebp+12 esp
  • 23. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 eax= 24 7 5 Return Address old ebp esp
  • 24. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } _AddMul2: push ebp mov ebp,esp mov eax, [bp+8] add eax, [bp+8+4] shl eax, 1 mov esp,ebp pop ebp ret . . . 5 7 eax= 24 _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 7 5 Return Address esp Return Address
  • 25. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } . . . 5 7 eax= 24 _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 7 5 esp
  • 26. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS int x, y, z; int AddMul2(int i, int j) { return (i+j)*2; } main() { x=5; y=7; z=AddMul2(x, y); . . . . . . . . } . . . 5 7 eax= 24 _main: mov ds:[x],5 mov ds:[y],7 push ds:[y] push ds:[x] call _AddMul2 add esp,8 mov ds:[z],eax . . . . . . 24 esp
  • 27. Example: Simple Code Sharing _STACK SEGMENT PUBLIC ‘STACK’ DB 4096 dup(?) Bottom: _STACK ENDS _DATA SEGMENT PULBIC ‘DATA’ x dd 1 dup(?) y dd 1 dup(?) z dd 1 dup(?) _DATA ENDS _TEXT SEGMENT PUBLIC ‘CODE’ _AddMul2: . . . // code for AddMul2 _main: . . . // code for main _TEXT ENDS Pure code is sharable Each process has its own stack segment Each process has its own data segment
  • 28. Example: Simple Code Sharing Translate to the same physical process for different processes Access different data areas for different processes
  • 29.
  • 30. Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Static Linking and Sharing
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. Sharing in Paging Systems  Sharing of Data Data Common data (without address) Database
  • 36. Sharing in Paging Systems  Sharing of Data Data Data 1 Data 2 Data 3 Data 2 Data 3 Data 1 Database Physical Memory
  • 37. Sharing in Paging Systems  Sharing of Data Data 2 Data 3 Data 1 n 2 , w n 1 , w Physical Memory . . . . . . PT 1 0 n 1 . . . . . . PT 2 0 n 2 Database
  • 38. Sharing in Paging Systems  Sharing of Data Data 2 Data 3 Data 1 . . . . . . PT 1 0 n 1 . . . . . . PT 2 0 n 2 n 2 , w n 1 , w The page numbers of sharing processes can be different. Physical Memory Database
  • 39. Sharing in Paging Systems  Sharing of Code Assemble bra label1 label1 : . . . . . . . . . 0x0000 0x2000 0x1000 4 k 4 k 4 k w bra (2,w) label1 : . . . . . . . . . 0x0000 0x2000 0x1000
  • 40. Sharing in Paging Systems  Sharing of Code Virtual Memory n th page Shared code bra (2,w) label1 : . . . . . . . . . 0x0000 0x2000 0x1000 bra (n+2,w) label1 : . . . . . . . . .
  • 41. Sharing in Paging Systems  Sharing of Code Virtual Memory n th page Physical Memory p q r bra (n+2,w) label1 : . . . . . . . . . bra (n+2,w) . . . . . . Label1 : . . .
  • 42. Sharing in Paging Systems  Sharing of Code Virtual Memory n th page Physical Memory p q r bra (n+2,w) label1 : . . . . . . . . . bra (n+2,w) . . . . . . Label1 : . . . r q p n n+1 n+2 PT
  • 43. Sharing in Paging Systems  Sharing of Code n 2 , w n 1 , w p q r bra (n+2,w) . . . . . . Label1 : . . . Physical Memory r q p n1 n1+1 n1+2 PT 1 0 0 r q p n2 n2+1 n2+2 PT 2 0 0 r q p n n+1 n+2 PT
  • 44. Sharing in Paging Systems  Sharing of Code n 2 , w n 1 , w p q r If absolute virtual address is used for coding, such a code sharing scheme is workable if n 1 = n 2 = n bra (n+2,w) . . . . . . Label1 : . . . Physical Memory r q p n1 n1+1 n1+2 PT 1 0 0 r q p n2 n2+1 n2+2 PT 2 0 0 r q p n n+1 n+2 PT
  • 45. Sharing in Paging Systems  Sharing of Code n 2 , w n 1 , w r q p n1 n1+1 n1+2 PT 1 0 0 r q p n2 n2+1 n2+2 PT 2 0 0 r q p n n+1 n+2 PT p q r Can we assign different starting page numbers to a different processes? bra (n+2,w) . . . . . . Label1 : . . . Physical Memory
  • 46. Sharing in Paging Systems  Sharing of Code Virtual Memory n th page 1. Shared code is self-contained Can we assign different starting page numbers to a different processes? 2. Avoid using absolute address ( page number ) in share code, i.e., using address relative to CBR instead . Yes, if … bra (n+2,w) label1 : . . . . . . . . .
  • 47.
  • 48.
  • 49. Dynamic Linking via Transfer Vector ... bri tv[i] ... bri tv[i] ... Transfer Vectors Currently Executing Code Linking just-in-time and only once . call the same shared function by indirect branch instruction. ... ... stub stub stub stub 0 1 i n  1
  • 50. Dynamic Linking via Transfer Vector ... bri tv[i] ... bri tv[i] ... Transfer Vectors Currently Executing Code Linking just-in-time and only once . ... ... stub stub stub stub 0 1 i n  1 When the shared function is called first time , the external reference is resolved by the corresponding stub .
  • 51. Dynamic Linking via Transfer Vector ... bri tv[i] ... bri tv[i] ... Transfer Vectors Currently Executing Code Linking just-in-time and only once . ... ... stub stub stub stub 0 1 i n  1 When the shared function is called first time , the external reference is resolved by the corresponding stub . Shared code When the external reference is resolved , the stub replaces the corresponding transfer vector to point to the shared code.
  • 52. Dynamic Linking via Transfer Vector ... bri tv[i] ... bri tv[i] ... Transfer Vectors Currently Executing Code Linking just-in-time and only once . ... ... stub stub stub stub 0 1 i n  1 Shared code Once the external reference is resolved, it can be used directly later on . Used by Win32 and POSIX ( DLLs ).
  • 53.
  • 54. Sharing in Segmented Systems  Sharing of Data Shared Data s 2 , w s 1 , w ST entries of different processes point to the same segment in PM. Database Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
  • 55. Sharing in Segmented Systems  Sharing of Data Shared Data s 2 , w s 1 , w ST entries of different processes point to the same segment in PM. How about if a segment is also paged? Database Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
  • 56. Sharing in Segmented Systems  Sharing of Data s 2 , p , w s 1 , p , w ST entries of different processes point to the same page table in PM. Data 2 Data 3 Data 1 PT How about if a segment is also paged? Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2 p Paging
  • 57. Sharing in Segmented Systems  Sharing of Code ? Shared Code s 2 , w s 1 , w ST entries of different processes point to the same segment in PM. In what condition the scheme is workable ? The code must be self-contained. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
  • 58. Sharing in Segmented Systems  Sharing of Code ? Shared Code s 2 , w s 1 , w ST entries of different processes point to the same segment in PM. How about if a segment is also paged? In what condition the scheme is workable ? The code must be self-contained. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2
  • 59. Sharing in Segmented Systems  Sharing of Code ? In what condition the scheme is workable ? s 2 , p , w s 1 , p , w ST entries of different processes point to the same page table in PM. Code 2 Code 3 Code 1 PT How about if a segment is also paged? The code must be self-contained. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2 p Paging
  • 60. Sharing in Segmented Systems  Sharing of Code ? In what condition the scheme is workable ? s 2 , p , w s 1 , p , w ST entries of different processes point to the same page table in PM. Code 2 Code 3 Code 1 PT How about if the shared code is not self-contained? The code must be self-contained. Assign the same segment numbers for all share codes in STs. Physical Memory . . . . . . ST 1 0 s 1 . . . . . . ST 2 0 s 2 p
  • 61.
  • 62. Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Dynamic Linking and Sharing
  • 63.
  • 64. Unrestricted Dynamic Linking/Sharing Symbol table i j Segment table Code segment C load * l d ( S , W ) Linkage section for C CBR trap on d LBR
  • 65. Unrestricted Dynamic Linking/Sharing ( S , W ) trap on Symbol table Addressing relative to linkage section Displacement Indirect addressing The address for external reference Not ready now i j Segment table Code segment C load * l d Linkage section for C CBR d LBR
  • 66. Unrestricted Dynamic Linking/Sharing ( S , W ) trap on Symbol table Generated by the compiler i j Segment table Code segment C load * l d Linkage section for C CBR d LBR
  • 67. Unrestricted Dynamic Linking/Sharing ( S , W ) Symbol table Resolve the external reference dynamically by the exception handler when the corresponding instruction is executed . i j Segment table Code segment C load * l d Linkage section for C CBR trap on d LBR
  • 68. Unrestricted Dynamic Linking/Sharing ( S , W ) Symbol table Resolve the external reference dynamically by the exception handler when the corresponding instruction is executed . trap off ( s , w ) s i j Segment table Code segment C load * l d Linkage section for C CBR trap on d LBR Segment S w
  • 69. Unrestricted Dynamic Linking/Sharing Before external reference is executed After external reference is executed
  • 70. Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Principles of Distributed Shared Memory (DSM)
  • 71. Memory Sharing on Different Computer Architecture Single processor/ Single memory module Multiple processor/ Single memory module Distributed System Memory Memory Memory Memory Memory
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78. Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory Implementations of DSM
  • 79.
  • 80.
  • 81.
  • 82.
  • 83. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: P1 P2 MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only)
  • 84. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B read
  • 85. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B Operation is done locally . No extra action need to be taken. read
  • 86. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B write
  • 87. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B Operation is done locally . No extra action need to be taken. write
  • 88. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B write
  • 89. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B Invalidate copy in MM2; Upgrade copy in MM1 to writable. page B (writable) page B (writable) write
  • 90. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) page B (read-only) DSM page A (writable) page B (read-only) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) read
  • 91. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 page A (writable) DSM page A (writable) P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) Downgrade page in MM1 to read-only; Make copy in MM2. page A (read-only) page A (read-only) page A (read-only) read
  • 92. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 DSM P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) page A (read-only) page A (read-only) page A (read-only) write
  • 93. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 DSM P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page B (writable) page A (read-only) page A (read-only) page A (read-only) page B (writable) Transfer page from MM1 to MM2. write
  • 94. Implementing Unstructured DSM  Replication of Data Allowing only one copy of writable page, but multiple copies of read-only pages. Example: MM1 MM2 DSM P1 P2 P1 reads A P1 writes A P1 writes B P2 reads A P2 writes B page B (writable) page A (read-only) page A (read-only) page A (read-only) page B (writable)
  • 95. Implementing Unstructured DSM  Memory Consistency a1=1, b1=2 a2=1, b2=2 a1=1, b1=2 a2=0, b2=0 a1=1, b1=2 a2=0, b2=1 a1=1, b1=2 a2=1, b2=2
  • 96. Implementing Unstructured DSM  Memory Consistency a1=1, b1=2 a2=1, b2=2 a1=1, b1=2 a2=0, b2=0 a1=1, b1=2 a2=0, b2=1 a1=1, b1=2 a2=1, b2=2 Strict Consistency Sequential Consistency
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.