libsysve  3.1.0
VH-VE SHM

VH-VE SHM is a feature for VE programs to register System V shared memory created at VH side to DMAATB of VE. More...

Functions

int vh_shmget (key_t key, size_t size, int shmflag)
 This function gets the identifier of system V shared memory on VH. More...
 
void * vh_shmat (int shmid, const void *shmaddr, int shmflag, void **vehva)
 This function attaches system V shared memory on VH and register it with DMAATB. More...
 
int vh_shmdt (const void *shmaddr)
 This function detaches system V shared memory on VH and releases DMAATB entry. More...
 

Detailed Description

VH-VE SHM is a feature for VE programs to register System V shared memory created at VH side to DMAATB of VE.

Please include "vhshm.h".

Note
VH-VE SHM feature does not provide a function to create System V shared memory. A user program at VH side needs to create System V shared memory.
System V shared memory needs to be created with SHM_HUGETLB flag to allocate huge pages (2MB pages). The kernel parameter "vm.nr_hugepages" needs to be set, in order to allocate huge pages.
  1. Check whether "vm.nr_hugepages" exists in /etc/sysctl.conf and files under /etc/sysctl.d and /usr/lib/sysctl.d.
  2. If "vm.nr_hugepages" does not exists, add "vm.nr_hugepages = 4096" to /etc/sysctl.conf. 4096 is tentative value. Please set required value for your program.
  3. If "vm.nr_hugepages" exists, add the required value to the current value of "vm.nr_hugepages"
  4. Execute "sysctl --system" command
VE programs can use VE DMA feature to transfer data between System V shared memory and VE memory registered to DMAATB.

Function Documentation

int vh_shmget ( key_t  key,
size_t  size,
int  shmflag 
)

This function gets the identifier of system V shared memory on VH.

Note
Argument is similar to shmget(2). Different points are shown below.
If a specified size is smaller than actual shared memory size, actual shared memory size is used.
Invoking this function is not required if the program knows the shared memory identifier.
Parameters
[in]keyA key value associated with System V shared memory segment on VH. Don't specify IPC_PRIVATE.
[in]sizeSize of System V shared memory segment on VH
[in]shmflagSHM_HUGETLB must be specified. Don't specify SHM_NORESERVE IPC_EXCL and IPC_CREAT.
Returns
A valid shared memory identifier on Success, -1 on Failure.
  • EINVAL SHM_HUGETLB is not specified as 3rd argument. SHM_NORESERVE or IPC_EXCL or IPC_CREAT are specified as 3rd argument.
  • EINVAL IPC_PRIVATE is specified as 1st argument.
  • EINVAL A segment with given key existed, but size is greater than the size of the segment.
  • EACCES The user does not have permission to access the shared memory segment, and does not have the CAP_IPC_OWNER capability.
  • ENOENT No segment exists for the given key.
void* vh_shmat ( int  shmid,
const void *  shmaddr,
int  shmflag,
void **  vehva 
)

This function attaches system V shared memory on VH and register it with DMAATB.

Note
Argument is similar to shmat(2). Different points are shown below.
On Linux, it is possible to attach a shared memory segment even if it is already marked to be deleted. vh_shmat() follows it.
Parameters
[in]shmidSystem V shared memory segment identifier.
[in]shmaddrThis argument must be NULL.
[in]shmflagSHM_RDONLY can be specified. Don't specify SHM_EXEC, SHM_REMAP and SHM_RND.
[in]vehvaAn address of pointer to store VEHVA.
Returns
A valid shared memory identifier on Success, (void *)-1 on Failure.
  • EINVAL shmaddr is not NULL.
  • EINVAL SHM_EXEC, SHM_REMAP or SHM_RND are specified.
  • EINVAL Invalid shmid value.
  • EFAULT vehva is invalid or the specified segment is not huge page.
  • ENOMEM Can't allocate DMAATB more. No enough memory at VH side.
  • ECANCELED Failed to update resource information (VEOS internal error).
  • EACCES The calling process does not have the required permissions for the requested attach type, and does not have the CAP_IPC_OWNER capability.
  • ENOTSUP VEOS does not connect to IVED.
  • EIDRM shmid points to a removed identifier.
int vh_shmdt ( const void *  shmaddr)

This function detaches system V shared memory on VH and releases DMAATB entry.

Parameters
[in]shmaddrAn address which is attached to System V shared memory on VH
Returns
0 on Success, -1 on Failure.
  • ECANCELED Failed to update resource information (VEOS internal error).
  • EINVAL shmaddr is invalid. There is no shared memory segment attached at shmaddr, or shmaddr is not aligned on a page boundary.