PhysicalMemory::PhysicalMemory(const string& _name,
const vector<AbstractMemory*>& _memories,
- bool mmap_using_noreserve) :
- _name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve)
+ bool mmap_using_noreserve,
+ const std::string& shared_backstore) :
+ _name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve),
+ sharedBackstore(shared_backstore)
{
if (mmap_using_noreserve)
warn("Not reserving swap space. May cause SIGSEGV on actual usage\n");
// perform the actual mmap
DPRINTF(AddrRanges, "Creating backing store for range %s with size %d\n",
range.to_string(), range.size());
- int map_flags = MAP_ANON | MAP_PRIVATE;
+
+ int shm_fd;
+ int map_flags;
+
+ if (sharedBackstore.empty()) {
+ shm_fd = -1;
+ map_flags = MAP_ANON | MAP_PRIVATE;
+ } else {
+ DPRINTF(AddrRanges, "Sharing backing store as %s\n",
+ sharedBackstore.c_str());
+ shm_fd = shm_open(sharedBackstore.c_str(), O_CREAT | O_RDWR, 0666);
+ if (shm_fd == -1)
+ panic("Shared memory failed");
+ if (ftruncate(shm_fd, range.size()))
+ panic("Setting size of shared memory failed");
+ map_flags = MAP_SHARED;
+ }
// to be able to simulate very large memories, the user can opt to
// pass noreserve to mmap
uint8_t* pmem = (uint8_t*) mmap(NULL, range.size(),
PROT_READ | PROT_WRITE,
- map_flags, -1, 0);
+ map_flags, shm_fd, 0);
if (pmem == (uint8_t*) MAP_FAILED) {
perror("mmap");
// Let the user choose if we reserve swap space when calling mmap
const bool mmapUsingNoReserve;
+ const std::string sharedBackstore;
+
// The physical memory used to provide the memory in the simulated
// system
std::vector<BackingStoreEntry> backingStore;
*/
PhysicalMemory(const std::string& _name,
const std::vector<AbstractMemory*>& _memories,
- bool mmap_using_noreserve);
+ bool mmap_using_noreserve,
+ const std::string& shared_backstore);
/**
* Unmap all the backing store we have used.
# I/O bridge or cache
mem_ranges = VectorParam.AddrRange([], "Ranges that constitute main memory")
+ shared_backstore = Param.String("", "backstore's shmem segment filename, "
+ "use to directly address the backstore from another host-OS process. "
+ "Leave this empty to unset the MAP_SHARED flag.")
+
cache_line_size = Param.Unsigned(64, "Cache line size in bytes")
redirect_paths = VectorParam.RedirectPath([], "Path redirections")
#else
kvmVM(nullptr),
#endif
- physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
+ physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve,
+ p->shared_backstore),
memoryMode(p->mem_mode),
_cacheLineSize(p->cache_line_size),
workItemsBegin(0),