Linux:写入分为 512K 块 [英] Linux: writes are split into 512K chunks

查看:11
本文介绍了Linux:写入分为 512K 块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成大 SCSI 写入的用户空间应用程序(详情如下).但是,当我查看到达 SCSI 目标(即由 FC 连接的存储)的 SCSI 命令时,有些东西将这些写入拆分为 512K 块.

I have a user-space application that generates big SCSI writes (details below). However, when I'm looking at the SCSI commands that reach the SCSI target (i.e. the storage, connected by the FC) something is splitting these writes into 512K chunks.

该应用程序基本上会直接向设备进行 1M 大小的直接写入:

The application basically does 1M-sized direct writes directly into the device:

fd = open("/dev/sdab", ..|O_DIRECT);
write(fd, ..., 1024 * 1024);

此代码导致发送两个 SCSI WRITE,每个 512K.

This code causes two SCSI WRITEs to be sent, 512K each.

但是,如果我发出直接 SCSI 命令,没有块层,则写入不会拆分.我从命令行发出以下命令:

However, if I issue a direct SCSI command, without the block layer, the write is not split. I issue the following command from the command line:

sg_dd bs=1M count=1 blk_sgio=1 if=/dev/urandom of=/dev/sdab oflag=direct

我可以看到一个 1M 大小的 SCSI WRITE.

I can see one single 1M-sized SCSI WRITE.

问题是,什么是拆分写入,更重要的是,它是否可配置?Linux 块层似乎是有罪的(因为 SG_IO 没有通过它)并且 512K 似乎太随意了,不能成为某种可配置的参数.

The question is, what is splitting the write and, more importantly, is it configurable? Linux block layer seems to be guilty (because SG_IO doesn't pass through it) and 512K seems too arbitrary a number not to be some sort of a configurable parameter.

推荐答案

问题确实在块层,SCSI 层本身很少考虑大小.您应该检查底层是否确实能够通过您的请求,特别是关于直接 io,因为它可能被分成许多小页面并且需要一个比硬件可以支持的更长的分散 - 收集列表,或者甚至只是驱动程序(libata 是/在某种程度上受到限制).

The blame is indeed on the block layer, the SCSI layer itself has little regard to the size. You should check though that the underlying layers are indeed able to pass your request, especially with regard to direct io since that may be split into many small pages and requires a scatter-gather list that is longer than what can be supported by the hardware or even just the drivers (libata is/was somewhat limited).

您应该查看并调整/sys/class/block/$DEV/queue 那里有各种各样的文件,最有可能与您需要的文件匹配的是 max_sectors_kb,但您可以尝试一下,看看哪些对您有用.您可能还需要调整分区变量.

You should look and tune /sys/class/block/$DEV/queue there are assorted files there and the most likely to match what you need is max_sectors_kb but you can just try it out and see what works for you. You may also need to tune the partitions variables as well.

这篇关于Linux:写入分为 512K 块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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