os9

21
ICS 143 1 9. Linking and Sharing 9.1 Single-Copy Sharing Why Share Requirements for Sharing 9.2 Static Linking and Sharing Sharing in Systems w/o Segmentation or Paging Sharing in Paging Systems Sharing in Segmented Systems 9.3 Dynamic Linking and Sharing 9.4 Principles of Distributed Shared Memory (DSM) The User's View of DSM 9.5 Implementations of DSM Implementing Unstructured DSM Implementing Structured DSM

Upload: issbp

Post on 29-Nov-2014

340 views

Category:

Documents


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Os9

ICS 143 1

9. Linking and Sharing9.1 Single-Copy Sharing

– Why Share

– Requirements for Sharing

9.2 Static Linking and Sharing – Sharing in Systems w/o Segmentation or Paging

– Sharing in Paging Systems

– Sharing in Segmented Systems

9.3 Dynamic Linking and Sharing

9.4 Principles of Distributed Shared Memory (DSM) – The User's View of DSM

9.5 Implementations of DSM – Implementing Unstructured DSM

– Implementing Structured DSM

Page 2: Os9

ICS 143 2

Single-Copy Sharing• Why share

– Processes need to access common data

– Better utilization of memory (code, system tables, data bases)

• Requirement for sharing– How to express what is shared

• A priori agreement (e.g., system components)

• Language construct (e.g., UNIX’s shmget/shmat)

– Shared code must be reentrant (read-only, “pure”)

– Stack, heap must be replicated per process

Page 3: Os9

ICS 143 3

Linking and Sharing

• Linking resolves external references• Sharing links to the same module• Static linking/sharing:

– Resolve referencesbefore execution starts

• Dynamic linking/sharing:– While executing

Figure 9-1

Page 4: Os9

ICS 143 4

Sharing without Virtual Memory

• With one or no Relocation Register (RR)– All memory of a process is contiguous

– Sharing user programs:

• Possible only with 2 user programs by partial overlap

• 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.

Page 5: Os9

ICS 143 5

Sharing without Virtual Memory

• With multiple RRs– CBR = Code Base Register

Point to shared copy of code

– SBR = Stack Base Register Point to private copy of stack

– DBR = Data Base Register Point to private copy of data

Figure 9-2

Page 6: Os9

ICS 143 6

Sharing in Paging Systems• PT entries of different processes

point to the same page frame

• Data pages: No Restrictions

• Code pages: Must have thesame page numbers in all PTsto allow for self-references.– Meeting this requirement can be

tricky: swapping, sharing with >2

• Avoid page numbers in shared code:Address relative to CBR

• Resolving external references could really slow down load, unless done only just-in-time and only once. Figure 9-3

Page 7: Os9

ICS 143 7

Dynamic Linking via Transfer Vector

• Each Transfer Vector corresponds to aReference to Shared Code

• Reference starts as Stub

• Stub replaced byReal Valueonly when first used

Figure 9-4

Page 8: Os9

ICS 143 8

Sharing in Segmented Systems• 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)

Page 9: Os9

ICS 143 9

Unrestricted Dynamic Linking/Sharing

• Basic Principles (see Figure 9-5 on next page):– Self-references resolved using CBR

– External references are indirectvia a private linkage section

– External reference (S,W), where S & W are symbolic names,is resolved to (s,w) at runtime when first used.

– (s,w) is entered in linkage section of process

– Code is unchanged

– Subsequent references use (s,w) without involving OSbut does force additional memory accessfor every external reference

Page 10: Os9

ICS 143 10

Dynamic Linking/Sharing

Figure 9-5a: Before Figure 9-5b: After

Before and After External Reference is Executed

Page 11: Os9

ICS 143 11

Distributed Shared Memory• Create Illusion of Single Shared Memory

– (Ugly) Reality is that Physical Memory is Distributed.

– References to remote memory triggerhidden remote/local memory transfer,enabling local access to effect remote access.

– Impractical/Impossible to do 1 reference at a time.

– How to implement transfers efficiently?

• Optimize the implementation.Most important with Unstructured DSM.

• Restrict the user. (Exploit what the user knows.)Basic to Structured DSM.

Page 12: Os9

ICS 143 12

Unstructured DSM

Simulate single, fully shared, unstructured memory.(Unlike paging, a CPU has no private space.)

Figure 9-6

– Advantage: Fully transparent” to user– Disadvantage: Efficiency

Page 13: Os9

ICS 143 13

Structured DSM

• Each CPU has both private and shared space.

• Add restrictions on use of shared variables:– Access only within

(explicitly declared) Critical Sections

• Use “objects” instead of shared variables: “object-based DSM”

Figure 9-7

Page 14: Os9

ICS 143 14

Implementing Unstructured DSM• Key Issues:

– Granularity of Transfers• Transfer to little:

– Time wasted in latency

• Transfer to much:– Time wasted in transfer

– False sharing

– Replication of Data– Memory Consistency: Strict vs Sequential– Tracking Data: Where is it stored now?

Page 15: Os9

ICS 143 15

Implementing Unstructured DSM• Replication of Data: Move or Copy?

– Copying saves time on later references.

– Copying causes (cache or real) consistency confusion.

• Reads work fine.• Writes require others to update or invalidate.

Figure 9-9

Page 16: Os9

ICS 143 16

Implementing Unstructured DSM• 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.

Figure 9-11

– Reads of x in p1 will always produce 1 & 2 respectively

– Reads of x in p1 can produce: 0&0, 0&1, 1&2, or 2&2

Page 17: Os9

ICS 143 17

Implementing Unstructured DSM

• Tracking Data: Where is it stored now?• Approaches:

– Have “owner” track it by maintaining “copy set” (list).Only owner is allowed to write. Ownership can change.Now need to find the owner. Use broadcast.

– Central Manager → Bottleneck“Replicated”/multiple managers share/split responsibilities.

– “Probable owner” gets tracked down.Retrace data’s migration.Update links traversed to show current owner.

• Bottom line on Unstructured DSM:– Isn’t there a better way?

Page 18: Os9

ICS 143 18

Implementing Structured DSM

Weak, Release, and Entry Memory Consistency• Weak Memory Consistency

– Introduce “synchronization variable,” S.Processes access it when they areready to adjust/reconcile their shared variables.

Figure 9-12

Page 19: Os9

ICS 143 19

Implementing Structured DSM

• Release Memory Consistency– Synchronize upon leaving CS

Figure 9-13

– A waste if p2 never looks at x.

Page 20: Os9

ICS 143 20

Implementing Structured DSM

• Entry Memory Consistency– Before entering CS, import only those variables used

Figure 9-14

There is also a (confusingly named?) “lazy release” which imports all shared variables before entering CS

Page 21: Os9

ICS 143 21

Object-Based DSM

• An object’s functions/methods are part of it.• 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.