I’m experimenting with CXL and trying to figure out how to use it as shared memory between two different hosts/instances. The goal is to write a small C program where:
Instance A writes data into CXL memory
Instance B reads that same data from the shared CXL memory region
Ideally, I’d like to do this entirely from user space (no kernel module).
Does anyone know of sample code, libraries, or documentation on how to mmap() or otherwise access CXL memory from user space?
Could the size or alignment still be an issue? The device is in daxdev mode. Am I missing a configuration step or using the wrong flush instruction?
Thanks again,
ZO
Here is the output for cxl list -Ru
{
"region":"region1",
"resource":"0x8080000000",
"size":"128.00 GiB (137.44 GB)",
"interleave_ways":1,
"interleave_granularity":4096,
"decode_state":"commit"
}
When CXL_SHARED_SIZE is 4096: Error memory-mapping DAX device: Invalid argument. However, using 2 MiB (2 * 1024 * 1024) mmap works.
Now, making some edits to the script - clflushopt-ing before and after every access-, here are the outputs:
From host A, writer:
sudo ./w
DAX device just mapped at address 0x7f5188400000
Data before writing: -1
Data after writing completed: 4660
From host B, reader:
sudo ./r
DAX device just mapped at address 0x7f02c6400000
Data: -1