1
Chapter 2 Process, Thread and Chapter 2 Process, Thread and - - PowerPoint PPT Presentation
Chapter 2 Process, Thread and Chapter 2 Process, Thread and - - PowerPoint PPT Presentation
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
2
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
3
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.
4
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.
5
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
6
Shared Memory
What is shared Memory
- Shared memory provides an extremely efficient
means of sharing data between multiple processes
- n 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
7
Shared Memory APIs
Some implementation APIs
- shmat(2)
- shmget(2)
- shmdt(2)
- shmctl(2)
8
Shared Memory APIs
9
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
10
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.
11
ISM versus Non-ISM
The difference
12
ISM useful feature
ISM provides useful feature
- Translation table sharing
- Small TLB Page Size
- Locked pages
- Default shared memory mode for Oracle RDBMS
System V Semaphores
13
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
14
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.
15
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
- perations.
- 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.
16
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).
17
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
18
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).
19
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.
20
System V Message Queues
The beginning of the map structures used for maintaining resource allocation maps msgque points to the beginning of the kernel space allocated to hold all the system msqid_ds structures.
21
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
22
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
23
POSIX APIs for the three IPC facilities
24
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)
25
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
26
POSIX Named Semaphores
The linked list exists within the process’s address space, not in the kernel.
Semheadp points to the first semaddr structure on the list sad_next provides the pointer for support of a singly linked list.
27
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
28
POSIX Message Queue Structures
total size in bytes maximum size of each message maximum number of messages allowed on the queue
And so on
29
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
30
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
Introduction to Solaris signals
31
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
Introduction to Solaris signals
32
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.
Introduction to Solaris signals
33
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.
Signal Implementation
34
High-Level Signal Flow
Signal Implementation
35
Synchronous signals occur as a direct result
- f the executing instruction stream, where an
unrecoverble error requires an immediate termination of the process.
Synchronous signals are sometimes referred
to as traps
Synchronous signals
36
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.
Asynchronous signals
37
Outline
Generic System V IPC Support
Shared Memory Shared Memory
System V Semaphores
System V Message Queues
POSIX IPC Signal Door
38
Door’s function
- Doors provide a facility for processes to issue
procedure calls to functions in other
- Using the APIs, a process can become a door
server, exporting a function through a door it creates by using the door_create(3X) interface
- Other processes can then invoke the procedure by
issuing a door_call(3X), specifying the correct door descriptor
Solaris Doors
39
How doors provide an IPC
40
Doors are implemented in the kernel as a
pseudofile system, doorfs, which is loaded from the /kernel/sys directory during boot
Within a process, a door is referenced
through its door descriptor, which is similar in form a function to a file descriptor, and, in fact, the allocation of a door descriptor in a process uses an available file descriptor slot
Doors Implementation
41
Solaris Doors Structures
42
Jim Mauro, Richard McDougall, Solaris
Internals-Core Kernel Components, Sun Microsystems Press, 2000
Max Bruning, Threading Model In Solaris,
Training lectures,2005
Solaris internals and performance
management, Richard McDougall, 2002
Reference
43