Chapter 2 Process, Thread and Chapter 2 Process, Thread and Scheduling Scheduling —— Soloris IPC 1
Outline Generic System V IPC Support Shared Memory Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door 2
Generic System V IPC Support Module Creation The System V IPC kernel modules are implemented as dynamically loadable modules Each facility has a corresponding loadable module in the /kernel/sys directory(shmsys, semsys, and msgsys). When an IPC resource is initially created, a positive integer, known as an identifier , is assigned to identify the IPC object. 3
Generic System V IPC Support Resource Maps Two of the three IPC facilities use a low-level kernel memory allocation scheme known as resource maps. message queues Semaphores Resource maps are a means by which small units of kernel memory can be allocated and freed from a larger pool of kernel pages that have been preallocated. The amount of space allocated for resource maps for the IPC facilities is determined by kernel tunable parameters, one parameter each for message queues and semaphores. 4
Outline Generic System V IPC Support Shared Memory Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door 5
Shared Memory What is shared Memory Shared memory provides an extremely efficient means of sharing data between multiple processes on a Solaris system The data need not actually be moved from one process’s address space to another The sharing of the same physical memory (RAM) pages by multiple processes Each process has mappings to the same physical pages and can access the memory through pointer dereferencing in code 6
Shared Memory APIs Some implementation APIs shmat(2) shmget(2) shmdt(2) shmctl(2) 7
Shared Memory APIs 8
namespace(shmid) shmid identifier A shared memory identifier, shmid, is initialized and maintained by the operating system whenever a shmget(2) system call is executed successfully The shmid identifies a shared segment that has two components : The actual shared RAM pages A data structure that maintains information about the shared segment, the shmid_ds data structure 9
Intimate Shared Memory (ISM) ISM shared segment Intimate shared memory (ISM) is an optimization introduced first in Solaris 2.2 Allows for the sharing of the translation tables involved in the virtual -to-physical address translation for shared memory pages As opposed to just sharing the actual physical memory pages With many processes attaching to shared memory, this scheme creates a lot of redundant mappings to the same physical pages that the kernel must maintain. 10
ISM versus Non-ISM The difference 11
ISM useful feature ISM provides useful feature Translation table sharing Small TLB Page Size System V Semaphores Locked pages Default shared memory mode for Oracle RDBMS 12
Outline Generic System V IPC Support Shared Memory Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door 13
System V Semaphores What is semaphore A semaphore, as defined in the dictionary, is a mechanical signalling device or a means of doing visual signalling The analogy typically used is the railroad mechanism of signalling trains, where mechanical arms would swing down to block a train from a section of track that another train was currently using. When the track was free, the arm would swing up, and the waiting train could then proceed. 14
System V Semaphores Two semaphore operations wait and signal (which correlate nicely to the railroad example). The operations were referred to as P and V operations. The P operation was the wait, which decremented the value of the semaphore if it was greater than zero The V operation was the signal, which incremented the semaphore value. 15
System V Semaphores Some features about Solaris semaphore The semaphore implementation in Solaris (System V semaphores) allows for semaphore sets. The actual value of a semaphore can never be negative. A kernel mutex lock is created for each semaphore set. The creation of a semaphore set by an application requires a call to semget(2). 16
Outline Generic System V IPC Support Shared Memory Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door 17
System V Message Queues Something about System V Message Queues Message queues provide a means for processes to send and receive messages of various size in an asynchronous fashion on a Solaris system . Sent messages are placed at the back of the queue, and messages are received from the front of the queue; thus the queue is implemented as a FIFO (First In, First Out). 18
System V Message Queues Kernel Resources for Message Queues The number of resources that the kernel allocates for message queues is tunable. Values for various message queue tunable parameters can be increased from their default values so more resources are made available for systems running applications that make heavy use of message queues. 19
msgque points to the beginning of the kernel System V Message Queues The beginning of the space allocated to hold all map structures used the system msqid_ds for maintaining structures. resource allocation maps 20
Outline Generic System V IPC Support Shared Memory Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door 21
OVERVIEW OF POSIX IPC The evolution of the POSIX standard and associated APIs resulted in a set of industry- standard interfaces that provide the same types of facilities as the System V IPC set: shared memory semaphores message queues 22
POSIX APIs for the three IPC facilities 23
POSIX Shared Memory Something about POSIX shared memory The POSIX shared memory interfaces provide an API for support of the POSIX IPC name abstraction. The interfaces, shm_open(3R) and shm_unlink(3R), do not allocate or map memory into a calling process’s address space. The programmer using POSIX shared memory must create the address space mapping with an explicit call to mmap(2) 24
POSIX Semaphores The POSIX specification provides for two types of semaphores POSIX named semaphores follow the POSIX IPC name convention discussed earlier and are created with the sem_open(3R) call POSIX unnamed semaphores, which do not have a name in the file system space and are memory based 25
POSIX Named Semaphores The linked list exists within the process’s sad_next provides address space, not in the kernel. the pointer for support of a singly linked list. Semheadp points to the first semaddr structure on the list 26
POSIX Message Queues POSIX message queues are constructed on a linked list built by the internal libposix4 library code. The essential interfaces for using message queues are mq_open(3R) which opens, or creates and opens, a queue, making it available to the calling process 27
POSIX Message Queue Structures total size in bytes maximum size of each And so on message maximum number of messages allowed on the queue 28
Outline Generic System V IPC Support Shared Memory Shared Memory System V Semaphores System V Message Queues POSIX IPC Signal Door 29
Introduction to Solaris signals What is signal Signals are a means by which a process or thread can be notified of a particular event. Signals are often compared with hardware interrupts, when a hardware subsystem, such as a disk I/O interface (e.g., a SCSI host adapter), generates an interrupt to a processor as a result of an I/O being completed. The signal facility provides a means interrupt a process or thread within a process as a result of a specific event 30
Introduction to Solaris signals Exit Terminate the process Core Create a core image of the process and terminate Stop Suspend process execution (typically, job control or debug) Ignore Discard the signal and take no action, even if the signal is blocked 31
Introduction to Solaris signals Signal representation Each signal has a unique signal number, we use a structure member of sufficient width, such that we can represent every signal by simply setting the bit that responds to the signals number of the signal we wish to post. 32
Signal Implementation Figure illustrates all the structures, data types, and linked lists required to support signals in Solaris. There are, of course, differences between a multithreaded process and a nonthreaded process. 33
Signal Implementation High-Level Signal Flow 34
Synchronous signals Synchronous signals occur as a direct result of the executing instruction stream, where an unrecoverble error requires an immediate termination of the process. Synchronous signals are sometimes referred to as traps 35
Asynchronous signals Asynchronous signals are as the term implies external (and in some cases unrelated) to the current execution context. Asynchronous signals are also referred to as interrupts. 36
Recommend
More recommend