1 / 42

Sharing of Data and Code in Main Memory

Sharing of Data and Code in Main Memory. Single-Copy Sharing Sharing in Systems without Virtual Memory Sharing in Paging Systems Sharing in Segmented Systems Principles of Distributed Shared Memory Implementations of Distributed Shared Memory. 9.1 Single-Copy Sharing.

Télécharger la présentation

Sharing of Data and Code in Main Memory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sharing of Data and Code in Main Memory • Single-Copy Sharing • Sharing in Systems without Virtual Memory • Sharing in Paging Systems • Sharing in Segmented Systems • Principles of Distributed Shared Memory • Implementations of Distributed Shared Memory

  2. 9.1 Single-Copy Sharing 9.1.1 Reasons for Sharing • Data Sharing: -- communicating, cooperating, and competing among processes • Code Sharing -- reuse of modules( simplifying the engineering of software systems) -- better utilizing main memory

  3. P1’s Virtual address space Main memory P2’s Virtual address space 0x00000000 0x00000000 . . . User 3GB 3GB User Kernel Kernel 1GB 1GB . . . Figure1: Sharing OS Kernel among processes

  4. 9.1.2 Requirements for Sharing • Designating Resources as Shared -- at the time of linking or loading( statically) -- at runtime( dynamically) int shmget( key_t key, int size, int shmflg); void *shmat(int shmid, const void *shmaddr, int shmflg); • Reentrant Code -- being kept as read-only segments -- addresses generated by the shared code should be translated correctly

  5. . . . Shared code branch . . . load . . . Data of process p1 Data of process p2 Figure2: addresses in shared code

  6. 9.1.3 Linking and Sharing • Linking -- relocation of individual object modules -- binding of external references • Sharing -- static( links prior to execution) -- dynamic( links are resolved at runtime) ( the linking of the same copy of a module into two or more address spaces)

  7. 9.2 Sharing in Systems without Virtual Memory • Background -- absence of any dynamic relocation mechanisms -- having only a single relocation register • Sharing of user code or data --partially overlapping processes’ memory spaces • Sharing of system components -- being assigned specific agreed-upon addresses -- linker replaces each reference to a shared system module by its known memory address -- the shared system component cannot easily differentiate between the different processes that invoke it

  8. CBR1 CBR2 SBR1 SBR2 DBR1 DBR2 . . . . . . Example: Sharing of Code Using Relocation Registers . . . Register contents when p1 running Register contents when p2 running code Branch x(CBR) . . . stack1 . . . stack2 . . . data2 . . . data1 . . . Main memory

  9. n w . . . . . . 9.3 Sharing in Paging Systems Virtual address . . . . . . 0 . . . . . . n (n, w) . . . . . . Page table Virtual memory Physical memory

  10. . . . . . . . . . . . . 9.3.1 Sharing of data Main memory PT1 . . . 0 Load n1,w n1 . . . Load n2,w PT2 0 . . . Shared page n2 . . .

  11. 9.3.2 Sharing of Code • Branch instructions to other location within the shared page -- the branch address is compiled to absolute one 1. shared pages must be assigned the same page numbers; 2. potential page number conflicts; 3. wasted table space. -- the branch address is compiled relative to the code base register

  12. . . . . . . . . . . . . Main memory PT1 . . . 0 Load n1,w n1 . . . n1==n2 Load n2,w PT2 0 . . . Shared page Branch (n,w) n2 (n, w) XXX . . .

  13. External references -- static linking&binding 1. assigning page numbers and replace every external reference wasted table space 2. filling page table entries Unable to know whether the shared page is on disk or in memory -- dynamic linking&binding postpone the assignment of page numbers and locating the routines until runtime, when a particular function is actually being invoked

  14. . . . bri . . . bri . . . . . . bri . . . bri . . . . . . . . . stub stub Transfer vectors stub stub stub . . . . . . Shared code Dynamic linking through transfer vector

  15. Virtual address space (ELF) …… Func(); …… …… call 0xaabbccdd …… …… 0xaabbccdd PLT[i] Jmp *GOT[i] …… …… GOT[i] 0xaffffff0 Stub Transfer vector 0xaffffff0 ……

  16. Virtual address space (ELF) …… Func(); …… …… call 0xaabbccdd …… …… 0xaabbccdd PLT[i] Jmp *GOT[i] …… …… GOT[i] 0xbbbbbbb0 Stub Transfer vector 0xaffffff0 …… Func(){ …… } …… …… Shared page …… 0xbbbbbbb0

  17. #include "stdio.h" #include "dlfcn.h" #define SOFILE "./my.so" #define SHARED #include "date.h" main(){ DATETYPE d; void *dp; char *error; puts("dll demo!"); dp=dlopen(SOFILE,RTLD_LAZY); if(dp==NULL){ fputs(dlerror(),stderr); exit(1); } getdate=dlsym(dp,"getdate"); error=dlerror(); if(error){ fputs(error,stderr); exit(1); } getdate(&d); printf("current date:%04d-%02d-%02d\n",d.year,d.mon,d.day); dlclose(dp); exit(0); } #include "time.h" #include "date.h" int getdate(DATETYPE *d){ long ti; struct tm *tm; time(&ti); tm=localtime(&ti); d->year=tm->tm_year+1900; d->mon=tm->tm_mon+1; d->day=tm->tm_mday; }

  18. (gdb) disassemble main Dump of assembler code for function main: 0x08048544 <main+0>: push %ebp 0x08048545 <main+1>: mov %esp,%ebp 0x08048547 <main+3>: sub $0x28,%esp …… 0x080485ae <main+106>: pushl 0xffffffe4(%ebp) 0x080485b1 <main+109>: call 0x8048404 <dlsym> 0x080485b6 <main+114>: add $0x10,%esp 0x080485b9 <main+117>: mov %eax,0x8049840 Disassembly of section .plt: 080483f4 <.plt>: 80483f4: ff 35 08 98 04 08 pushl 0x8049808 80483fa: ff 25 0c 98 04 08 jmp *0x804980c 8048400: 00 00 add %al,(%eax) 8048402: 00 00 add %al,(%eax) 8048404: ff 25 10 98 04 08 jmp *0x8049810 804840a: 68 00 00 00 00 push $0x0 804840f: e9 e0 ff ff ff jmp 80483f4 <_init+0x18> 8048414: ff 25 14 98 04 08 jmp *0x8049814 804841a: 68 08 00 00 00 push $0x8 804841f: e9 d0 ff ff ff jmp 80483f4 <_init+0x18>

  19. (gdb) list main 2 #include "stdio.h" 3 #include "dlfcn.h" 4 #define SOFILE "./my.so" 5 #define SHARED 6 #include "date.h" 7 main(){ 8 DATETYPE d; 9 void *dp; 10 char *error; 11 puts("dll demo!"); (gdb) 12 dp=dlopen(SOFILE,RTLD_LAZY); 13 if(dp==NULL){ 14 fputs(dlerror(),stderr); 15 exit(1); 16 } 17 getdate=dlsym(dp,"getdate"); 18 error=dlerror(); 19 if(error){ 20 fputs(error,stderr); 21 exit(1); Breakpoint 8, main () at date.c:17 17 getdate=dlsym(dp,"getdate"); (gdb) x 0x8049810 0x8049810 <_GLOBAL_OFFSET_TABLE_+12>: 134513674 (gdb) continue Continuing. Breakpoint 9, main () at date.c:18 18 error=dlerror(); (gdb) x 0x8049810 0x8049810 <_GLOBAL_OFFSET_TABLE_+12>: 1073926128 (gdb)

  20. 15 3 2 1 0 TI PTL privilege level TI=0:GDTR TI=1:LDTR selector CS structure 9.4 Sharing in Segmented Systems • Same segment number in all virtual spaces -- example: I386 processor’s sharing of system segments GDT( global descriptor table) LDT( local descriptor table) • Using base registers

  21. Linkage Section Transfer Vector • Unrestricted dynamic linking • A single transfer vector is provided for the entire process • Containing entries for every external references • Each segment has its own linkage section • Recording the external references for only that segment

  22. Segment table . . . j . . . i Code segment C Linkage section for C . . . . . . LBR . . . d CBR load * l d Trap on . . . . . . . . . Symbol table (S,W) . . .

  23. Segment table Segment S . . . . . . s w . . . i . . . . . . i . . . Code segment C Linkage section for C . . . LBR . . . d CBR load * l d Trap on (s,w) . . . . . .

  24. Memory bus Memory bus Memory bus CPU Main Memory Memory bus NETWORK CPU1 CPUn Main Memory1 Main Memoryn Bridge Bridge I/O bus I/O bus … CPU1 Main Memory CPU2 . . . CPUn … … Network controller Network controller 9.5 Principles of Distributed Shared Memory

  25. Main memory Main memory Main memory CPU1 MM1 CPU1 CPU2 CPU CPU2 MM2 . . . . . . . . . CPUn MMn CPUn Multi-processor & Single Memory Single Processor &Single Memory Multi-processor & Multi-Memory

  26. Distributed Shared Memory • Objective of DSM Alleviating the burden on the programmer by hiding the fact that physical memory is distributed and not accessible in its entirety to all processors. • scheme Creating the illusion of a shared memory that should be mapped into distributed physical memory.

  27. The User’s View of DSM • Main questions concerned by users -- which portions of memory are shared and which portions are private among the different processors? -- Is the sharing fully transparent(must the user do anything special to accomplish the sharing)? • Unstructured Distributed Shared Memory simulating the behavior of a single, physically shared memory( from the user’s point of view, there is only a single linear address space) • Structured Distributed Shared Memory segregating shared and nonshared portions of each logical spaces of processes. When any of the processors writes into the shared portion, the change becomes visible automatically and transparently by all other processors.

  28. MM1 MM1 MM1 Main memory CPU1 CPU2 DSM . . . . . . CPUn Unstructured DSM

  29. Logical Address Space MM1 MM2 MMn CPU1 (process1) CPU2 (process2) . . . . . . . . . DSM CPUn (processn)

  30. 9.6 Implementations of Distributed Shared Memory • Implementing Unstructured DSM • Replication of Data • Strict Versus Sequential Consistency • Granularity of Data Transfers • Finding pages

  31. MM1 MM2 . . . . . . Page A Page B . . . . . . DSM . . . • Replication of Data Page A P1 . . . Page B Page B Replicating Write B . . . P2 Maintaining multiple copies of a page are decreased network traffic, less thrashing, and reduced delays resulting from page faults

  32. Initial: x=0 Real time: t1 t2 t3 t4 P1: {x=1; a1=x; x=2; b1=x;} P2: { a2=x; b2=x;} Protocol for handling DSM pages

  33. MM1 MM2 DSM . . . . . . . . . Page A Page B Page A P1 . . . . . . . . . Page B Page B . . . P2

  34. Initial: x=0 P1:{ x=1; a1=x; x=2; b1=x; } P2:{ a2=x; b2=x; } • Strict Versus Sequential Consistency (a) P1:{ x=1; a1=x; x=2; b1=x;} P2:{ a2=x; b2=x;} (b) P1:{ x=1; a1=x; x=2; b1=x;} P2:{ a2=x; b2=x;} (c) P1:{ x=1; a1=x; x=2; b1=x;} P2:{ a2=x; b2=x;}

  35. Strict consistency A DSM is said to obey strict consistency if reading a variable x always returns the value written to x by the most recently executed write operation. • Sequential consistency A DSM is said to obey sequential consistency if the sequence of values read by the different processes corresponds to some sequential interleaved execution of the same processes.

  36. Granularity of Data Transfers • Decreased granularity Conflicting with the principle of locality • Increased granularity False sharing phenomenon

  37. X … … X … … X … … Y … … Y … … Y … P1 MM1 MM1 … X … … X … MM2 … Y … … Y … MM3 MM3 P3

  38. Finding Pages • Owner of pages • Broadcasting • Central manager • Probable Owner P1 P2 P3 . . . . . . . . . A P2 A P3 A . . . . . . . . . Page A

  39. Implementing Structured Distributed Shared Memory • Distributed shared memory with weak consistency • Distributed shared memory with release or entry consistency • Object-based distributed shared memory

  40. ② x x x x ① ① ③ x=1 a1=x S x=2 b1=x S a2=x b2=x Lock x=2 unlock lock a=x unlock Delayed until p1 unlocks Cause propagation Weak memory consistency Release memory consistency

  41. x x ① ③ Cause propagation Lock x=2 unlock lock a=x unlock Delayed until p1 unlocks Release memory consistency

  42. Object-based distributed shared memory If the system provides the ability to perform remote methods invocation, there is no need to transfer a remote object into local memory to access the data objects encapsulate Exercises: P298—302: 2,5,6,8

More Related