通过修改页表可以移动内存页吗? [英] Can a memory page be moved by modifying the page table?

查看:263
本文介绍了通过修改页表可以移动内存页吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能(在任何合理的操作系统,最好是Linux上)只通过修改页表而不是实际移动任何数据来交换两个内存页的内容。



动机是密集矩阵转置。如果数据被页面​​大小阻塞,则可以在页面内调换数据(适合缓存),然后交换页面以将块移动到其最终位置。一个大的矩阵会移动很多页面,所以希望刷新TLB不会造成麻烦。

解决方案

文件可以做的伎俩,但我认为我从来没有尝试过这自己。使用 mmap 与MAP_ANONYMOUS进行映射超过纯虚拟地址(无物理文件支持)。然后你可以重新映射你的'文件'到VA的各个领域获得实际的零拷贝语义。在Windows中,您可以使用 MapViewOfFile 使用CreateMapOfFile(INVALID_HANDLE_VALUE,...)创建的文件映射句柄,但是注意在NT上不能控制重映射的目标(即,新映射的VA地址是 / em>的函数调用),在Linux上,所需的地址被视为一个提示

如果这不起作用,那么你可能需要在内核中创建一个内存管理器模块,这对任何实际项目都是不可行的。


Is it possible (on any reasonable OS, preferably Linux) to swap the contents of two memory pages by only modifying the page table and not actually moving any data?

The motivation is a dense matrix transpose. If the data were blocked by page size it would be possible to transpose the data within a page (fits in cache) then swap pages to move the blocks into their final place. A large matrix would have many many pages moved, so hopefully flushing the TLB wouldn't cause trouble.

解决方案

I think memory mapped files may do the trick, but I reckon I never tried this myself. Use mmap with MAP_ANONYMOUS to map over pure virtual address (no physical file backing). Then you can remap your 'file' into various areas of the VA obtaining in effect zero-copy semantics. In Windows you'd use MapViewOfFile with a file mapping handle created using CreateMapOfFile(INVALID_HANDLE_VALUE, ...), but note than on NT you cannot control the target of your remapping (ie. the newly mapped VA address is the output of the function call), and on Linux the desired address is taken as a hint.

If this doesn't work, then you'd probably need to create a memory manager module in kernel, which is not feasible for any practical project.

这篇关于通过修改页表可以移动内存页吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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