如何修改XFS预分配块的数量?

发布于 2024-12-13 20:06:05 字数 1173 浏览 7 评论 0原文

我编写了一个简单的程序并在 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 技术交流群。

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

发布评论

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

评论(2

情何以堪。 2024-12-20 20:06:06

您看到的是 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.

香草可樂 2024-12-20 20:06:05

我找到了答案,将答案发布在这里,以便其他遇到问题的人可以参考。

mount -t xfs -o allocsize=4096 设备挂载点

allocsize 选项用于调整缓冲区大小。

I found the answer, posting the answer here so that others facing the problem can refer it.

mount -t xfs -o allocsize=4096 device mount-point

The allocsize option is used to tune the buffer size.

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