---
name: "hwlocality_shmem"
section: "3"
platform: "linux"
package: "hwloc"
version: "2.15.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/hwlocality_shmem"
---

# hwlocality\_shmem(3)

Sharing topologies between processes

## NAME

hwlocality\_shmem - Sharing topologies between processes

## SYNOPSIS

### Functions

int **hwloc\_shmem\_topology\_get\_length** (**hwloc\_topology\_t** topology, size\_t \*lengthp, unsigned long flags)\
 int **hwloc\_shmem\_topology\_write** (**hwloc\_topology\_t** topology, int fd, hwloc\_uint64\_t fileoffset, void \*mmap\_address, size\_t length, unsigned long flags)\
 int **hwloc\_shmem\_topology\_adopt** (**hwloc\_topology\_t** \*topologyp, int fd, hwloc\_uint64\_t fileoffset, void \*mmap\_address, size\_t length, unsigned long flags)\

## Detailed Description

These functions are used to share a topology between processes by duplicating it into a file-backed shared-memory buffer.

The master process must first get the required shared-memory size for storing this topology with **hwloc\_shmem\_topology\_get\_length()**.

Then it must find a virtual memory area of that size that is available in all processes (identical virtual addresses in all processes). On Linux, this can be done by comparing holes found in /proc/\<pid\>/maps for each process.

Once found, it must open a destination file for storing the buffer, and pass it to **hwloc\_shmem\_topology\_write()** together with virtual memory address and length obtained above.

Other processes may then adopt this shared topology by opening the same file and passing it to **hwloc\_shmem\_topology\_adopt()** with the exact same virtual memory address and length.

## Function Documentation

### int hwloc\_shmem\_topology\_adopt (hwloc\_topology\_t \* topologyp, int fd, hwloc\_uint64\_t fileoffset, void \* mmap\_address, size\_t length, unsigned long flags)

Adopt a shared memory topology stored in a file. Map a file in virtual memory and adopt the topology that was previously stored there with **hwloc\_shmem\_topology\_write()**.

The returned adopted topology in topologyp can be used just like any topology. And it must be destroyed with **hwloc\_topology\_destroy()** as usual.

However the topology is read-only. For instance, it cannot be modified with **hwloc\_topology\_restrict()** and object userdata pointers cannot be changed.

The segment of the file pointed by descriptor fd, starting at offset fileoffset, and of length length (in bytes), will be mapped at virtual address mmap\_address.

The file pointed by descriptor fd, the offset fileoffset, the requested mapping virtual address mmap\_address and the length length must be identical to what was given to **hwloc\_shmem\_topology\_write()** earlier.

**Note**

Flags flags are currently unused, must be 0.

The object userdata pointer should not be used unless the process that created the shared topology also placed userdata-pointed buffers in shared memory.

This function takes care of calling **hwloc\_topology\_abi\_check()**.

**Returns**

0 on success.

\-1 with errno set to EBUSY if the virtual memory mapping defined by mmap\_address and length isn't available in the process.

\-1 with errno set to EINVAL if fileoffset, mmap\_address or length aren't page-aligned, or do not match what was given to **hwloc\_shmem\_topology\_write()** earlier.

\-1 with errno set to EINVAL if the layout of the topology structure is different between the writer process and the adopter process.

### int hwloc\_shmem\_topology\_get\_length (hwloc\_topology\_t topology, size\_t \* lengthp, unsigned long flags)

Get the required shared memory length for storing a topology. This length (in bytes) must be used in **hwloc\_shmem\_topology\_write()** and **hwloc\_shmem\_topology\_adopt()** later.

**Returns**

the length, or -1 on error, for instance if flags are invalid.

**Note**

Flags flags are currently unused, must be 0.

### int hwloc\_shmem\_topology\_write (hwloc\_topology\_t topology, int fd, hwloc\_uint64\_t fileoffset, void \* mmap\_address, size\_t length, unsigned long flags)

Duplicate a topology to a shared memory file. Temporarily map a file in virtual memory and duplicate the topology topology by allocating duplicates in there.

The segment of the file pointed by descriptor fd, starting at offset fileoffset, and of length length (in bytes), will be temporarily mapped at virtual address mmap\_address during the duplication.

The mapping length length must have been previously obtained with **hwloc\_shmem\_topology\_get\_length()** and the topology must not have been modified in the meantime.

**Note**

Flags flags are currently unused, must be 0.

The object userdata pointer is duplicated but the pointed buffer is not. However the caller may also allocate it manually in shared memory to share it as well.

**Returns**

0 on success.

\-1 with errno set to EBUSY if the virtual memory mapping defined by mmap\_address and length isn't available in the process.

\-1 with errno set to EINVAL if fileoffset, mmap\_address or length aren't page-aligned.

## Author

Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code.
