如何将mmap输入存储器写入O_DIRECT输出文件? [英] How to write mmap input memory to O_DIRECT output file?

查看:321
本文介绍了如何将mmap输入存储器写入O_DIRECT输出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不遵循伪代码的工作(O_DIRECT结果为EFAULT)

why doesn't following pseudo-code work (O_DIRECT results in EFAULT)

in_fd = open("/dev/mem");
in_mmap = mmap(in_fd);
out_fd = open("/tmp/file", O_DIRECT);
write(out_fd, in_mmap, PAGE_SIZE);

在跟随时(没有O_DIRECT)

while following does (no O_DIRECT)

in_fd = open("/dev/mem");
in_mmap = mmap(in_fd);
out_fd = open("/tmp/file");
write(out_fd, in_mmap, PAGE_SIZE);

我想这是从虚拟内核页面到虚拟用户页面的问题,无法在写调用中转换?

I guess it's something with virtual kernel pages to virtual user pages, which cannot be translated in the write call?

最诚挚的问候,

弗里德里希

推荐答案

将mmap()与O_DIRECT一起使用非常棘手.有一些限制.文件的输出应按块对齐.例如,如果将mmap()中的offset设置为0,则代码将起作用.您必须检查文件系统的块大小才能正确设置该值.

Using mmap() with O_DIRECT is tricky. There are some restrictions. The output to the file should be block aligned. For example, if you set offset in mmap() to 0 your code will work. You have to check the block size of your filesystem to set that value properly.

这篇关于如何将mmap输入存储器写入O_DIRECT输出文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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