I/O请求在Linux内核中的工作方式

发布于 2025-02-04 14:02:46 字数 149 浏览 3 评论 0原文

再会!我可以关于I/O如何在低级上工作有一个疑问吗?更具体地说,我的问题是在一个I/O请求中可以处理多少个字节? 例如,如果我们逐行读取输入文档(假设包含10行的文档),则Linux内核将使用一条I/O请求提交所有10行,或者它将单独提交10个I/O请求?预先感谢您的任何评论或建议。

Good day! May I have a question about how I/O works on low-level? More specifically, my question is how many bytes can be handled in the one I/O requests?
For example, if we read an input document line by line (let's say a document containing 10 lines), the Linux kernel will submit all 10 lines using one I/O request or it will submit 10 I/O request separately? Thank you in advance for any comments or suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽梦紫曦~ 2025-02-11 14:02:46

刚刚遇到了这个问题。让我根据Linux内核概述IO层。

1. You perform a line read from application 

用户空间

2. Read/write system call moves the control to kernel

内核

3. VFS layer comes into picture and find the filesystem the file belongs to 
4. Filesystem specific read is invoked, say ext3_read 
5. Filesystem sees if the data in Page cache, if yes then returns the data 
6. If data is not in pagecache the using the file Inode, filesystem gets the sector number of the disk, this File block number is mapped to 
7. Filesystem prepares an IOVEC, a structure for performing IO from disk. It consists of vector of RAM pages and sector number fetched from the Inode map.
8. The IOVEC is converted to SCSI/NVMe command and send to Lowerlayer device driver to read from the disk.

如果执行多行读取,则对内核进行多个系统调用。内核中的文件系统可能会从页面缓存中获取数据,或者读取到磁盘的问题。

Just came across this question. Let me give an overview of the layers of IO as per Linux kernel.

1. You perform a line read from application 

Userspace

2. Read/write system call moves the control to kernel

Kernel

3. VFS layer comes into picture and find the filesystem the file belongs to 
4. Filesystem specific read is invoked, say ext3_read 
5. Filesystem sees if the data in Page cache, if yes then returns the data 
6. If data is not in pagecache the using the file Inode, filesystem gets the sector number of the disk, this File block number is mapped to 
7. Filesystem prepares an IOVEC, a structure for performing IO from disk. It consists of vector of RAM pages and sector number fetched from the Inode map.
8. The IOVEC is converted to SCSI/NVMe command and send to Lowerlayer device driver to read from the disk.

If you perform multiple lines read then you do multiple system call to kernel. The filesystem in kernel may fetch the data from page cache, or issues read to the disk.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文