user_driver: use ramfs to allocate DMA buffers #537
Closed
+47
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When allocating DMA buffers for noiommu VFIO devices, we need to ensure that the kernel will not move the buffers in physical memory. In some cases, we achieve that by managing the memory entirely in user mode. In others, we allocate memory from the kernel on demand and then lock it with
mlock
.The
mlock
approach apparently does not always work--since we are locking pages allocated for an anonymous mapping, the kernel is still free to move the allocation between physical pages.mlock
's only guarantee seems to be that the kernel will not swap the page out to the swap file (which doesn't exist in the OpenHCL environment anyway). It looks like pages are indeed being moved with the ARM64 kernel for a reason that is not yet completely understood.To fix this, switch to using a temporary file in ramfs instead of using an anonymous mapping. This should guarantee the allocation does not move between physical pages since ramfs pages are allocated as immovable in the kernel.
Also, update the init process to mount ramfs. This has no resource usage effect by itself--ramfs allocates memory only as required.