Contiguous physical memory from userspace

No. There is not. You do need to do this from Kernel space.

If you say “we need to do this from User Space” – without anything going on in kernel-space it makes little sense – because a user space program has no way of controlling or even knowing if the underlying memory is contiguous or not.

The only reason where you would need to do this – is if you were working in-conjunction with a piece of hardware, or some other low-level (i.e. Kernel) service that needed this requirement. So again, you would have to deal with it at that level.

So the answer isn’t just “you can’t” – but “you should never need to”.

I have written such memory managers that do allow me to do this – but it was always because of some underlying issue at the kernel level, which had to be addressed at the kernel level. Generally because some other agent on the bus (PCI card, BIOS or even another computer over RDMA interface) had the physical contiguous memory requirement. Again, all of this had to be addressed in kernel space.

When you talk about “cache lines” – you don’t need to worry. You can be assured that each page of your user-space memory is contiguous, and each page is much larger than a cache-line (no matter what architecture you’re talking about).

Leave a Comment