清除 numpy.memmap
给定一个使用 mode='r'
创建的 numpy.memmap
对象(即只读),有没有办法强制它从物理 RAM 中清除所有加载的页面,而不删除对象本身?
换句话说,我希望对 memmap 实例的引用保持有效,但用于缓存磁盘数据的所有物理内存都未提交。对 memmap
数组的任何视图也必须保持有效。
我希望将其用作诊断工具,以帮助将脚本的“真实”内存需求与使用 memmap
引起的“瞬态”需求分开。
我在 RedHat 上使用 Python 2.7。
Given a numpy.memmap
object created with mode='r'
(i.e. read-only), is there a way to force it to purge all loaded pages out of physical RAM, without deleting the object itself?
In other words, I'd like the reference to the memmap
instance to remain valid, but all physical memory that's being used to cache the on-disk data to be uncommitted. Any views onto to the memmap
array must also remain valid.
I am hoping to use this as a diagnostic tool, to help separate "real" memory requirements of a script from "transient" requirements induced by the use of memmap
.
I'm using Python 2.7 on RedHat.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果运行“pmap SCRIPT-PID”,“真实”内存将显示为“[ anon ]”块,并且所有内存映射文件都会在最后一列中显示文件名。
如果您设法获取指向映射开头的指针并对其调用 madvise(ptr, length, MADV_DONTNEED) ,则可以在 C 级别清除页面,但这会很麻烦。
If you run "pmap SCRIPT-PID", the "real" memory shows as "[ anon ]" blocks, and all memory-mapped files show up with the file name in the last column.
Purging the pages is possible at C level, if you manage to get ahold of the pointer to the beginning of the mapping and call madvise(ptr, length, MADV_DONTNEED) on it, but it's going to be cludgy.