Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory - PowerPoint PPT Presentation

1 / 104
About This Presentation
Title:

Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory

Description:

memory management and file manipulation routines. System utilities, e.g. ... Compile. Example: Simple Code Sharing _STACK SEGMENT PUBLIC STACK' DB 4096 dup(?) Bottom: ... – PowerPoint PPT presentation

Number of Views:269
Avg rating:5.0/5.0
Slides: 105
Provided by: taiwe
Category:

less

Transcript and Presenter's Notes

Title: Operating Systems Principles Memory Management Lecture 9: Sharing of Code and Data in Main Memory


1
Operating Systems PrinciplesMemory
ManagementLecture 9 Sharing of Code and Data
in Main Memory
  • ??????

2
Content
  • Single-Copy Sharing
  • Reasons of Sharing
  • Requirements for Sharing
  • Static Linking and Sharing
  • Sharing in Systems w/o Segmentation or Paging
  • Sharing in Paging Systems
  • Sharing in Segmented Systems
  • Dynamic Linking and Sharing
  • Principles of Distributed Shared Memory (DSM)
  • The User's View of DSM
  • Implementations of DSM
  • Implementing Unstructured DSM
  • Implementing Structured DSM

3
Operating Systems PrinciplesMemory
ManagementLecture 9 Sharing of Code and Data
in Main Memory
  • Single-Copy Sharing

4
Sharing
  • Reusing Software Modules
  • Individual software modules are constructed
    separately.
  • Develop applications by linking with other
    well-developed software modules.
  • Reduce software developing cost.
  • Each process owns private copy of shared objects
  • Single-Copy Sharing
  • Processes share a single copy of code or data in
    memory
  • Why?
  • What?
  • How?

5
Why?
  • Processes need to access common data, e.g.,
  • Communication btw producer consumer
  • Cooperation among divide-and-conquer processes
  • Competition on resources
  • Better utilization of memory (code data)
  • Several active processes use the same code or
    data at the same time, e.g., many users running
    the same editor or debugger in a time-sharing
    system
  • Without sharing,
  • memory requirement would increase dramatically
    and, thus, reduce the number of login users.
  • increase I/O overhead to load excess copies
  • increase the page fault rate and, thus, the risk
    of thrashing.

6
What?
  • OS kernel routines
  • I/O drivers
  • System services, e.g.,
  • memory management and file manipulation routines.
  • System utilities, e.g.,
  • Compiler, linker, loader and debugger.
  • User-lever applications
  • A single copy of the same code applies to
    different data sets.

7
How?
  • How to express what is shared?
  • System Components
  • Designated at the time of system design or
    initialization
  • User-Level Applications
  • Shared code must be reentrant (read-only, pure)
  • Stack and heap must be replicated per process

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 (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
Compile
9
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
10
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
11
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
12
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
13
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
14
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
15
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
16
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
17
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
18
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
i
j
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
19
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
i
j
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
eax5
20
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
i
j
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
eax12
21
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
i
j
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
eax24
22
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
i
j
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
eax24
23
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
eax24
24
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_AddMul2 push ebp mov ebp,esp mov eax,
bp8 add eax, bp84 shl eax, 1 mov
esp,ebp pop ebp ret
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
eax24
25
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
eax24
26
Example Simple Code Sharing
int x, y, z int AddMul2(int i, int j)
return (ij)2 main() x5 y7
zAddMul2(x, y) . . . . . . . .
_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
. . .
5
7
24
_main mov dsx,5 mov dsy,7 push
dsy push dsx call _AddMul2 add
esp,8 mov dsz,eax . . . . . .
eax24
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
Each process has its own stack segment
Each process has its own data segment
Pure code is sharable
28
Example Simple Code Sharing
Translate to the same physical process for
different processes
Access different data areas for different
processes
29
Linking and Sharing
  • Sharing are closely related to linking
  • Linking resolves external references
  • Sharing links to the same module
  • Static linking/sharing
  • Resolve references before execution starts
  • Dynamic linking/sharing
  • Resolve references while executing

30
Operating Systems PrinciplesMemory
ManagementLecture 9 Sharing of Code and Data
in Main Memory
  • Static Linking and Sharing

31
Sharing without Virtual Memory
All memory of a process is contiguous physically.
  • With one or no Relocation Register (RR)
  • Sharing user programs
  • Possible only by partial overlapping
  • Too restrictive and difficult generally not used
  • Sharing system components
  • Agree on a starting positions
  • Linker resolves references to those locations
  • Can also use a block of transfer addresses,but
    this involves additional memory references.
  • Issues ? difficult to identify the invoking
    processes by system components.

Physical Memory
System Components
User Programs
User Program 1
User Program 2
32
Sharing without Virtual Memory
All memory of a process is contiguous physically.
  • With one or no Relocation Register (RR)
  • Sharing user programs
  • Possible only by partial overlapping
  • Too restrictive and difficult generally not used
  • Sharing system components
  • Agree on a starting positions
  • Linker resolves references to those locations
  • Can also use a block of transfer addresses,but
    this involves additional memory references.
  • Issues ? difficult to identify the invoking
    processes by system components.

Physical Memory
System Components
User Programs
33
Sharing without Virtual Memory
  • With multiple RRs
  • CBR Code Base Reg.
  • Point to shared copy of code
  • SBR Stack Base Reg.
  • Point to private copy of stack
  • DBR Data Base Reg.
  • Point to private copy of data

Sharing of code
34
Sharing without Virtual Memory
  • With multiple RRs
  • CBR Code Base Reg.
  • Point to private copy of code
  • SBR Stack Base Reg.
  • Point to private copy of stack
  • DBR Data Base Reg.
  • Point to shared copy of data

Sharing of data
35
Sharing in Paging Systems ?Sharing of Data
Common data (without address)
Data
36
Sharing in Paging Systems ?Sharing of Data
Data3
Data
Data1
Data2
Data1
Data3
Data2
37
Sharing in Paging Systems ?Sharing of Data
n1, w
n2, w
Data3
Data1
Data2
38
Sharing in Paging Systems ?Sharing of Data
The page numbers of sharing processes can be
different.
PT2
PT1
n1, w
0
0
. . .
. . .
n2, w
n2
n1
Data3
. . .
. . .
Data1
Data2
39
Sharing in Paging Systems ?Sharing of Code
Assemble
40
Sharing in Paging Systems ?Sharing of Code
nth page
Shared code
Virtual Memory
41
Sharing in Paging Systems ?Sharing of Code
p
nth page
q
r
Virtual Memory
Physical Memory
42
Sharing in Paging Systems ?Sharing of Code
p
nth page
q
r
Virtual Memory
Physical Memory
43
Sharing in Paging Systems ?Sharing of Code
n1, w
n2, w
p
q
r
44
Sharing in Paging Systems ?Sharing of Code
If absolute virtual address is used for coding,
such a code sharing scheme is workable if n1
n2 n
n1, w
n2, w
p
q
r
45
Sharing in Paging Systems ?Sharing of Code
PT
n
r
n1
q
n2
p
Can we assign different starting page numbers to
a different processes?
n1, w
PT1
PT2
n2, w
p
0
0
0
0
q
n1
n2
r
r
n11
n21
q
q
n12
n22
p
p
r
46
Sharing in Paging Systems ?Sharing of Code
Can we assign different starting page numbers to
a different processes?
Yes, if
nth page
1. Shared code is self-contained
2. Avoid using absolute address (page number) in
share code, i.e., using address relative to CBR
instead.
Virtual Memory
47
Sharing in Paging Systems ?Short Summary
  • PT entries of different processes point to the
    same page frame
  • Data pages No Restrictions
  • Code pages
  • Must have the same page numbers in all PTs.
  • For generalization, avoid using page numbers in
    shared code (self-contained), i.e., using address
    relative to CBR instead.

48
Sharing in Paging Systems ?Short Summary
  • PT entries of different processes point to the
    same page frame
  • Data pages No Restrictions
  • Code pages
  • Must have the same page numbers in all PTs.
  • How to know the page numbers of shared
    components?
  • Solutions
  • The total set of shared modules is known a
    priori.
  • Resolved by an effective loader ?

done just-in-time and only once.
49
Dynamic Linking via Transfer Vector
Linking just-in-time and only once.
... bri tvi ... bri tvi ...
Currently Executing Code
call the same shared function by indirect branch
instruction.
Transfer Vectors
50
Dynamic Linking via Transfer Vector
Linking just-in-time and only once.
... bri tvi ... bri tvi ...
Currently Executing Code
When the shared function is called first time,
the external reference is resolved by the
corresponding stub.
0
Transfer Vectors
... ...
stub
1
stub
i
stub
n?1
stub
51
Dynamic Linking via Transfer Vector
Linking just-in-time and only once.
... bri tvi ... bri tvi ...
Currently Executing Code
When the shared function is called first time,
the external reference is resolved by the
corresponding stub.
When the external reference is resolved, the stub
replaces the corresponding transfer vector to
point to the shared code.
0
Transfer Vectors
... ...
stub
1
stub
i
stub
n?1
stub
Shared code
52
Dynamic Linking via Transfer Vector
Linking just-in-time and only once.
... bri tvi ... bri tvi ...
Currently Executing Code
Once the external reference is resolved, it can
be used directly later on.
0
Transfer Vectors
... ...
stub
Used by Win32 and POSIX (DLLs).
1
stub
i
stub
n?1
stub
Shared code
53
Sharing in Segmented Systems
  • Much the same as with paged systems
  • Using segments instead of pages
  • Actually, simpler and more elegant because
    segments represent logical program entities.

54
Sharing in Segmented Systems ?Sharing of Data
s1, w
s2, w
Shared Data
ST entries of different processes point to the
same segment in PM.
55
Sharing in Segmented Systems ?Sharing of Data
How about if a segment is also paged?
s1, w
s2, w
Shared Data
ST entries of different processes point to the
same segment in PM.
56
Sharing in Segmented Systems ?Sharing of Data
How about if a segment is also paged?
s1, p, w
s2, p, w
PT
ST entries of different processes point to the
same page table in PM.
Data3
Data1
Data2
57
Sharing in Segmented Systems ?Sharing of Code
s1, w
s2, w
?
Shared Code
In what condition the scheme is workable?
ST entries of different processes point to the
same segment in PM.
The code must be self-contained.
58
Sharing in Segmented Systems ?Sharing of Code
How about if a segment is also paged?
s1, w
s2, w
?
Shared Code
In what condition the scheme is workable?
ST entries of different processes point to the
same segment in PM.
The code must be self-contained.
59
Sharing in Segmented Systems ?Sharing of Code
How about if a segment is also paged?
s1, p, w
s2, p, w
PT
?
Code3
ST entries of different processes point to the
same page table in PM.
Code1
In what condition the scheme is workable?
Code2
The code must be self-contained.
60
Sharing in Segmented Systems ?Sharing of Code
How about if the shared code is not
self-contained?
s1, p, w
s2, p, w
PT
?
Assign the same segment numbers for all share
codes in STs.
Code3
ST entries of different processes point to the
same page table in PM.
Code1
In what condition the scheme is workable?
Code2
The code must be self-contained.
61
Sharing in Segmented Systems ?Summary
  • Much the same as with Paged Systems
  • Actually, simpler and more elegant
    becauseSegments represent logical program
    entities
  • ST entries of different processes point to
    thesame segment in physical memory (PM)
  • Data pages No restrictions
  • Code pages
  • Assign same segment numbers in all STs, or
  • Use base registers
  • Function call loads CBR
  • Self-references have the form w(CBR)
  • Other references have the form (s,w)

62
Operating Systems PrinciplesMemory
ManagementLecture 9 Sharing of Code and Data
in Main Memory
  • Dynamic Linking and Sharing

63
Unrestricted Dynamic Linking/Sharing
  • Segmentation facilitates to implement a fully
    general scheme of dynamic linking and sharing.
  • Any two processes (user or system) can share any
    portion of their space.
  • Pioneered in the MULTICS operating system.

64
Unrestricted Dynamic Linking/Sharing
Symbol table
65
Unrestricted Dynamic Linking/Sharing
The address for external reference
Addressing relative to linkage section
trap on
Indirect addressing
Symbol table
Not ready now
Displacement
(S, W)
66
Unrestricted Dynamic Linking/Sharing
trap on
Symbol table

Generated by the compiler
(S, W)
67
Unrestricted Dynamic Linking/Sharing
Symbol table
(S, W)
Resolve the external reference dynamically by the
exception handler when the corresponding
instruction is executed.
68
Unrestricted Dynamic Linking/Sharing
s
trap off
(s, w)
Symbol table
(S, W)
Resolve the external reference dynamically by the
exception handler when the corresponding
instruction is executed.
69
Unrestricted Dynamic Linking/Sharing
After external reference is executed
Before external reference is executed
70
Operating Systems PrinciplesMemory
ManagementLecture 9 Sharing of Code and Data
in Main Memory
  • Principles of Distributed Shared Memory (DSM)

71
Memory Sharing onDifferent Computer Architecture
Single processor/ Single memory module
Multiple processor/ Single memory module
Distributed System
72
Distributed Share Memory (DSM)
Memory
The illusion of a single shared memory
  • VM
  • Creates the illusion of a memory that is larger
    than the available physical memory
  • DSM
  • Creates the illusion of a single shared memory

Memory
Memory
Distributed System
73
Distributed Share Memory (DSM)
Memory
The illusion of a single shared memory
  • Goal of DSM
  • To alleviate the burden of programmer by hiding
    the fact that physical memory is distributed
  • DSM
  • Creates the illusion of a single shared memory

Memory
Memory
Distributed System
74
Distributed Share Memory (DSM)
Memory
The illusion of a single shared memory
  • Goal of DSM
  • To alleviate the burden of programmer by hiding
    the fact that physical memory is distributed
  • DSM
  • Creates the illusion of a single shared memory
  • Great overhead on message-passing to resolve
    remote memory access.
  • To make DSM viable, efficiency on data transfer
    is an important consideration.

Memory
Memory
Distributed System
75
How to implement transfers efficiently?
  • Two approaches
  • Optimize the implementation
  • Exploiting locality of reference or using data
    replication
  • Most important with Unstructured DSM
  • Restrict the full generality of the DSM
  • Exploiting what the user knows
  • Basic to Structured DSM

76
Unstructured DSM
  • Simulate single, fully shared, unstructured
    memory.
  • Advantage
  • Fully transparent to user
  • Disadvantage Efficiency

0
0
MM1
DSM
P1
p?1
0
MM2
P2
p?1
0
MMn
Pn
p?1
np?1
77
Structured DSM
Local address space
  • Share only portion of memory, e.g., a collection
    of functions and shared variables, determined by
    user.
  • For efficiency, add restrictions on use of shared
    variables
  • Access only within (explicitly declared) Critical
    Sections
  • Variant object-based DSM
  • Use objects instead of shared variables

P1
shared
P2
shared
Pn
shared
78
Operating Systems PrinciplesMemory
ManagementLecture 9 Sharing of Code and Data
in Main Memory
  • Implementations of DSM

79
Implementations of DSM
  • Implementing Unstructured DSM
  • Granularity of data transfers
  • Replication of data
  • Memory consistency
  • Tracking data
  • Implementing Structured DSM
  • Critical-section based
  • Object based

80
Implementing Unstructured DSM ? Granularity of
Data Transfers
A nature choice is to use the page size (or its
multiple) as the granularity for transfer.
  • Transfer too little
  • Time wasted in latency (startup cost)
  • Transfer too much
  • Time wasted in transfer
  • False sharing

81
Implementing Unstructured DSM ? Replication of
Data
  • What action should be taken when a page fault?
  • Two possible choices
  • Move the page from the remote to the requesting
    processor
  • Problems Heavy network traffic, trashing, and
    delay
  • Make a copy of the page from the remote to the
    requesting processor
  • Advantages decrease network traffic, less
    trashing, and reduce delay
  • Issue How to maintain memory consistency?
  • Read work fine ? no action needed
  • Writes require others to update or invalidate.

82
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
  • Rules to maintain memory consistency

83
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
P1
P2
84
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
P1 writes A
page B (read-only)
P1 writes B
MM2
P2 reads A
P2 writes B
page B (read-only)
P2
85
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Operation is done locally. No extra action need
to be taken.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
P1 writes A
page B (read-only)
P1 writes B
MM2
P2 reads A
P2 writes B
page B (read-only)
P2
86
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
P1 writes A
page B (read-only)
P1 writes B
MM2
P2 reads A
P2 writes B
page B (read-only)
P2
87
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Operation is done locally. No extra action need
to be taken.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
P1 writes A
page B (read-only)
P1 writes B
MM2
P2 reads A
P2 writes B
page B (read-only)
P2
88
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
P1 writes A
page B (read-only)
P1 writes B
MM2
P2 reads A
P2 writes B
page B (read-only)
P2
89
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
page B (writable)
P1 writes A
page B (read-only)
page B (writable)
P1 writes B
MM2
P2 reads A
P2 writes B
page B (read-only)
P2
Invalidate copy in MM2 Upgrade copy in MM1 to
writable.
90
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (writable)
P1
page A (writable)
P1 reads A
page B (read-only)
page B (writable)
P1 writes A
page B (read-only)
page B (writable)
P1 writes B
MM2
P2 reads A
P2 writes B
P2
91
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (writable)
page A (read-only)
P1
page A (writable)
page A (read-only)
P1 reads A
page B (writable)
P1 writes A
page B (writable)
P1 writes B
MM2
P2 reads A
P2 writes B
page A (read-only)
P2
Downgrade page in MM1 to read-only Make copy in
MM2.
92
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (read-only)
P1
page A (read-only)
P1 reads A
page B (writable)
P1 writes A
page B (writable)
P1 writes B
MM2
P2 reads A
P2 writes B
page A (read-only)
P2
93
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (read-only)
P1
page A (read-only)
P1 reads A
page B (writable)
P1 writes A
page B (writable)
P1 writes B
MM2
P2 reads A
P2 writes B
page A (read-only)
P2
page B (writable)
Transfer page from MM1 to MM2.
94
Implementing Unstructured DSM ? Replication of
Data
Allowing only one copy of writable page, but
multiple copies of read-only pages.
Example
MM1
DSM
page A (read-only)
P1
page A (read-only)
P1 reads A
P1 writes A
page B (writable)
P1 writes B
MM2
P2 reads A
P2 writes B
page A (read-only)
P2
page B (writable)
95
Implementing Unstructured DSM ? Memory
Consistency
a11, b12
a21, b22
a11, b12
a20, b20
a11, b12
a20, b21
a11, b12
a21, b22
96
Implementing Unstructured DSM ? Memory
Consistency
Strict Consistency
a11, b12
a21, b22
a11, b12
a20, b20
a11, b12
Sequential Consistency
a20, b21
a11, b12
a21, b22
97
Implementing Unstructured DSM ? Memory
Consistency
  • Strict Consistency
  • Reading a variable x returns the value written to
    x by the most recently executed write operation.
  • Sequential Consistency
  • Sequence of values of x read by different
    processes corresponds to some sequential
    interleaved execution of those processes.

98
Implementing Unstructured DSM ? Tracking Data
  • Tracking Data Where is it stored now?
  • Approaches
  • Have owner track it by maintaining copy set .
  • Only owner is allowed to write.
  • Ownership can change.
  • To find the owner using broadcast.
  • Central Manager ? Bottleneck
  • Multiple replicated managers split the
    responsibilities.
  • Probable owner gets tracked down ? e.g., via
    page table.
  • Retrace datas migration.
  • Update links traversed to show current owner.

99
Implementing Unstructured DSM ? Discussion
  • All variables in the shared space are assumed
    consistent all the time.
  • Moving and/or invalidating pages may be needed on
    write
  • Much network traffic can be generated, resulting
    in poor performance.
  • Solution
  • Structured DSM ? requires a new model of memory
    consistency

100
Implementing Structured DSM ? Consistencies
  • Weak Consistency (Dubois et al. 1988)
  • Consistency by requesting synchronization
    explicitly.
  • Release Consistency (Gharachorloo 1990)
  • Consistency upon leaving a CS
  • Entry Consistency (Bershad 1993)
  • Consistency upon entering a CS

101
Implementing Structured DSM ? Weak Consistency
  • Introduce synchronization variable, S
  • Processes access it when they are ready to
    adjust/reconcile their shared variables.

102
Implementing Structured DSM ? Release
Consistency
  • Synchronize upon leaving CS
  • A waste if p2 never looks at x.

103
Implementing Structured DSM ? Entry Consistency
  • Before entering CS, import only those variables
    used

There is also a lazy release consistency
(Keleher et al. 1992) which imports all shared
variables before entering CS.
104
Object-Based DSM
  • An object encapsulates data and methods.
  • Can use remote method invocation(like remote
    procedure calls, covered earlier)instead of
    copying or moving an object intolocal memory.
  • One can move an object to improve performance.
Write a Comment
User Comments (0)
About PowerShow.com