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

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

问题描述

是否有一种方法可以在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".

我已经编写了这样的内存管理器, do 允许我执行此操作-但这始终是因为内核级存在一些潜在的问题,必须在内核级解决.通常是因为总线上的某些其他代理(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.

当您谈论缓存行"时,您无需担心.您可以放心,用户空间内存的每个 page 是连续的,并且每个 page 都比缓存行大得多(无论您使用的是哪种架构)关于).

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天全站免登陆