本文介绍了如何知道指针是否在物理内存中或它将触发页面错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个指针,并且在乎内存访问性能,则可以检查对它的下一个操作是否会触发页面错误.如果可以的话,可以设计一种算法,以便对循环操作进行重新排序,以最大程度地减少页面错误.

If I have a pointer and I care about memory access performance I may check whether the next operation on it will trigger a page fault. If it will, an algorithm could be designed so that it reorders loop operations to minimize page faults.

是否有任何便携式(或linux/windows不可移植)方式来检查特定的内存地址,访问是否会触发页面错误?

Is there any portable (or linux/windows non-portable) way to check for a particular memory address whether access will trigger a page fault?

推荐答案

我写了页面信息库在Linux上执行此操作.它使用了隐藏的页面地图文件,因此不会移植到其他操作系统.

I wrote the page-info library to do this on Linux. It uses the pagemap file under the covers so won't be portable to other OSes.

某些信息仅限于root用户使用,但您无需root就可以获取有关页面状态的信息(无论它是否在RAM中).引用自述文件:

Some information is restricted to root users, but you should be able to get the information about page presence (whether it is in RAM or not) without being root. Quoting from the README:

对于大范围查询,性能并未完全优化,因为它会为每个页面进行单独读取,但是可以很好地接受PR来改善此范围.

The performance isn't exactly optimized for querying large ranges as it does a separate read for each page, but a PR to improve this would be greatfully accepted.

这篇关于如何知道指针是否在物理内存中或它将触发页面错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 15:35