如何修改XFS预分配块的数量?
我编写了一个简单的程序并在 ext4 和 xfs 上运行该程序。
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
int
main(int argc, char *argv[])
{
int fd;
char *file_name = argv[1];
struct stat buf;
fd = open (file_name, O_RDWR|O_CREAT);
if (fd == -1) {
printf ("Error: %s\n", strerror(errno));
return -1;
}
write (fd, "hello", sizeof ("hello"));
fstat (fd, &buf);
printf ("st_blocks: %lu\n", buf.st_blocks);
stat (file_name, &buf);
printf ("st_blocks: %lu\n", buf.st_blocks);
close (fd);
stat (file_name, &buf);
printf ("st_blocks: %lu\n", buf.st_blocks);
return 0;
}
ext4 上的输出:
st_blocks:8 st_blocks:8 st_blocks:
xfs 上的 8 个输出:
st_blocks:128 圣块:128 st_blocks: 8
然后我探索了 xfs,发现了一个在运行 mkfs.xfs 时更改范围大小的选项。
例如: mkfs.xfs -r extsize=4096 /dev/sda1
但我仍然在 XFS 上得到相同的输出。任何人都可以提供有关如何更改 st_blocks 的更多见解吗?提前致谢。
I wrote a simple program and ran the program on ext4 and xfs.
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
int
main(int argc, char *argv[])
{
int fd;
char *file_name = argv[1];
struct stat buf;
fd = open (file_name, O_RDWR|O_CREAT);
if (fd == -1) {
printf ("Error: %s\n", strerror(errno));
return -1;
}
write (fd, "hello", sizeof ("hello"));
fstat (fd, &buf);
printf ("st_blocks: %lu\n", buf.st_blocks);
stat (file_name, &buf);
printf ("st_blocks: %lu\n", buf.st_blocks);
close (fd);
stat (file_name, &buf);
printf ("st_blocks: %lu\n", buf.st_blocks);
return 0;
}
output on ext4:
st_blocks: 8
st_blocks: 8
st_blocks: 8
output on xfs:
st_blocks: 128
st_blocks: 128
st_blocks: 8
Then I explored about xfs and found an option for changing the extent size while running mkfs.xfs.
example: mkfs.xfs -r extsize=4096 /dev/sda1
But still I get the same output on XFS. Can anyone provide more insight on how to change the st_blocks. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您看到的是 xfs 推测性预分配,这是一种启发式方法,用于避免文件增长时出现碎片。
有关详细信息,请参阅此常见问题解答条目。
您是正确的,“-o allocsize=XXX”选项禁用该启发式。您尝试使用“-r extsize = XXX”失败,因为该选项仅适用于实时子卷,而您几乎肯定没有使用它。
What you are seeing is xfs speculative preallocation, which is a heuristic which is used to avoid fragmentation of files as they grow.
For more info, see this FAQ entry.
You are correct that the "-o allocsize=XXX" option disables that heuristic. Your attempt at using "-r extsize=XXX" failed because that option is only for the realtime subvolume, which you are almost certainly not using.
我找到了答案,将答案发布在这里,以便其他遇到问题的人可以参考。
allocsize 选项用于调整缓冲区大小。
I found the answer, posting the answer here so that others facing the problem can refer it.
The allocsize option is used to tune the buffer size.