Shared Memory Objects Revisited

   

When a program filename is passed to exec(), it must find the file (also called the front store) and open it. If the file is already open, there will be an existing vnode for the file in the kernel memory. If not, a new vnode, pseudo vas, a single pregion, and a region are created, as illustrated in Figure 9-7. In most cases, a vas structure is pointed to by a proc structure (p_vas), but in the case of an executable or memory-mapped file, it is a vnode (v_vas) that references it. In turn, the vas (va_fp) points back to the vnode for which it was created.

Figure 9-7. Executable and Memory Mapped Files

graphics/09fig07.gif


When a process needs to attach a text region or a memory-mapped file to its virtual view, it simply copies the file's pregion structure and increments the associated region reference count.

Shared Memory, System-V, and POSIX

In a very similar manner system-V, shared memory regions are also maintained by first allocating an entry from the system's shared memory descriptor table, shmem[]. An active table entry points to a pseudo vas, pregion, and region created to manage the shared memory space (see Figure 9-8). The System-V shared memory allocation, attach, detach, and deallocation requests are mapped through this table and its related structures.

Figure 9-8. Shared Memory Objects

graphics/09fig08.gif


The following kernel-tunable parameters are used to size and configure System-V shared memory capabilities.

  • shmmni sets the maximum number of shared memory regions the kernel may manage.

  • shmmax sets the maximum size in bytes for a shared memory region.

  • shmseg sets the maximum number of shared memory regions a single process may attach to its virtual view at one time.

System-V shared memory regions are managed as independent kernel resources; that is, they may continue to exist even if there are no current processes attached to them. If a programmer decides to use shared memory regions, he or she is responsible for their allocation and eventual cleanup. The administrative commands ipcs and ipcrm may be used to check the status of shared memory regions and, if necessary, to remove them from the system.

Note that some programmatic schemes involve creating a shared memory region and having it persist as various daemons or agents are launched and momentarily attach to and detach from it. In a production environment, just because a shared memory region has no processes currently attached does not necessarily mean that you should remove it!

The POSIX system definition also has a set of shared memory calls. The calls are implemented on HP-UX as shared memory mapped files. Programmers are encouraged to use the System-V shared memory calls over the POSIX calls but both will function.



HP-UX 11i Internals
HP-UX 11i Internals
ISBN: 0130328618
EAN: 2147483647
Year: 2006
Pages: 167

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net