diff --git a/common/include/villas/memory.hpp b/common/include/villas/memory.hpp index 75311fb2f..2494754e4 100644 --- a/common/include/villas/memory.hpp +++ b/common/include/villas/memory.hpp @@ -85,6 +85,8 @@ public: MemoryAccessor(const MemoryBlock& mem) : translation(MemoryManager::get().getTranslationFromProcess(mem.getAddrSpaceId())) {} + MemoryAccessor(const MemoryTranslation& translation) : + translation(translation) {} T& operator*() const { return *reinterpret_cast(translation.getLocalAddr(0)); @@ -144,6 +146,12 @@ public: }; } + BaseAllocator(std::unique_ptr mem) : + BaseAllocator(mem->getAddrSpaceId()) + { + memoryBlock = std::move(mem); + } + virtual std::unique_ptr allocateBlock(size_t size) = 0; @@ -151,6 +159,12 @@ public: MemoryAccessor allocate(size_t num) { + if(num == 0) { + // doesn't make sense to allocate an empty block + logger->error("Trying to allocate empty memory"); + throw std::bad_alloc(); + } + const size_t size = num * sizeof(T); auto mem = allocateBlock(size); @@ -195,6 +209,9 @@ protected: MemoryBlock::deallocator_fn free; SpdLogger logger; + // optional, if allocator should own the memory block + std::unique_ptr memoryBlock; + private: MemoryManager::AddressSpaceId memoryAddrSpaceId; DerivedAllocator* derivedAlloc; @@ -216,6 +233,12 @@ public: size_t memorySize, size_t internalOffset = 0); + LinearAllocator(std::unique_ptr mem) : + LinearAllocator(mem->getAddrSpaceId(), mem->getSize()) + { + memoryBlock = std::move(mem); + } + size_t getAvailableMemory() const { return memorySize - nextFreeAddress; } diff --git a/common/lib/kernel/vfio.cpp b/common/lib/kernel/vfio.cpp index 822cf4b6c..805bacb71 100644 --- a/common/lib/kernel/vfio.cpp +++ b/common/lib/kernel/vfio.cpp @@ -754,6 +754,7 @@ VfioGroup::attach(VfioContainer& container, int groupIndex) << (container.isIommuEnabled() ? "" : "noiommu-") << groupIndex; + logger->debug("path: {}", groupPath.str().c_str()); group->fd = open(groupPath.str().c_str(), O_RDWR); if (group->fd < 0) { logger->error("Failed to open VFIO group {}", group->index);