Gets a shared memory segment and attaches it to a resource.
Standard C library (libc.a)
#include <sys/rset.h>
#include <sys/shm.h>
int ra_shmget(key, size, flags, rstype, rsid, att_flags)
key_t key;
size64_t size;
int flags;
rstype_t rstype;
rsid_t rsid;
unsigned int att_flags;
int ra_shmgetv(key, size, flags, rangecnt, rangevec)
key_t key;
size64_t size;
int flags;
int rangecnt;
subrange_t *rangevec;
As per existing shmget usage, plus the following new parameters:
Item | Description |
---|---|
rstype | Specifies the type of resource the new shared
memory segment is to be attached to. This parameter must have one
of the following values:
|
rsid | Identifies the resource to which the new shared
memory segment is to be attached. All attachments are advisory. If
memory cannot be allocated from the RAD(s) specified by rstype/rsid
parameters, memory is allocated from any RAD in the system that has
memory available.
|
att_flags | Specifies an advisory memory allocation policy
that is to be applied to the new shared memory segment. This parameter
must have one of the following values defined in sys/rset.h:
|
rangecnt | Specifies the number of subrange_t structures pointed to by rangevec. |
rangevec | Specifies a pointer to an array of subrange_t structures describing the desired subrange attachments. |
The ra_shmget subroutine returns the shared memory identifier associated with the specified key, size and flags parameters, attaching it to the resource set (R_RSET) specified by rstype, and rsid. The ra_shmget subroutine supports the sradid attachments. If the shared memory is attached to a set of physical resources involving multiple resource allocation domains (RADs), its memory allocation is distributed among these RADs according to att_flags. In an R_RSET type attachment, the processors specified in the input resource set are used for memory associativity; the resource set memory regions are ignored. All memory allocation attachments and policies are advisory.
If the new shared memory segment is to be attached in its entirety to a resource (that is, no subranges are involved), then the rstype or rsid parameters identify the memory attachment.
The ra_shmgetv subroutine is similar to the ra_shmget subroutine, and allows multiple subranges of the new shared memory segment to be attached to multiple resources in a single ra_shmgetv call. The rangevec argument is a pointer to an array of subrange_t structures describing the attachments to be performed. The rangecnt argument specifies the number of subrange_t structures pointed to by rangevec. All unused subrange_t structure fields, including those marked as reserved, must be initialized to the value of 0. Although it is not failing, the behavior with overlapping subranges is undefined.
On successful completion, a shared memory identifier is returned. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.
As per existing shmget usage, plus the following errors:
Item | Description |
---|---|
EINVAL | One of the following conditions is true:
|
EPERM | One of the following conditions is true:
|
ENODEV | An invalid rsid SRADID is specified. |
ENOTSUP | An attempt to get a shared memory region with an SRADID attachment is made and ENHANCED_AFFINITY is disabled. |
The following example attempts to use ra_shmgetv to create a shmat attachable shared memory region, whose first 32 megabytes are distributed using the P_BALANCED policy and the next 48 megabytes using the P_FIRST_TOUCH policy.
int flags, shm_id;
char *shm_at;
rsethandle_t rsetid;
subrange_t subranges[2] = { 0 };
rsetid = rs_alloc(RS_PARTITION);
subranges[0].su_offset = 0x0000000;
subranges[0].su_length = 0x2000000;
subranges[0].su_rstype = R_RSET;
subranges[0].su_rsid.at_rset = rsetid;
subranges[0].su_policy = P_BALANCED;
subranges[1].su_offset = 0x2000000;
subranges[1].su_length = 0x3000000;
subranges[1].su_rstype = R_RSET;
subranges[1].su_rsid.at_rset = rsetid;
subranges[1].su_policy = P_FIRST_TOUCH;
flags = (IPC_CREAT | SHM_PIN);
shm_id = ra_shmgetv (IPC_PRIVATE, 0x5000000, flags,
sizeof(subranges) / sizeof(subrange_t), subranges
);
if (shm_id == -1)
{
perror("ra_shmgetv failed!\n");
exit(1);
}
The ra_shmget and ra_shmgetv subroutines are part of the Base Operating System (BOS) Runtime.