来自用户空间的连续物理内存 [英] Contiguous physical memory from userspace

查看:25
本文介绍了来自用户空间的连续物理内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 linux 中从用户空间分配连续的物理内存?至少有几个保证连续的内存页面.一个巨大的页面不是答案.

Is there a way to allocate contiguous physical memory from userspace in linux? At least few guaranteed contiguous memory pages. One huge page isn't the answer.

推荐答案

没有.那没有.您确实需要从内核空间执行此操作.

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".

我编写了这样的内存管理器,确实允许我这样做 - 但它总是因为内核级别的一些潜在问题,必须在内核级别解决.通常是因为总线上的其他一些代理(PCI 卡、BIOS 或什至另一台通过 RDMA 接口的计算机)具有物理连续内存要求.同样,所有这些都必须在内核空间中解决.

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).

这篇关于来自用户空间的连续物理内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆