gpt4 book ai didi

linux - 系统调用 lseek() 在 ubuntu 2.6.32 与 2.6.24 中比较慢

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:46 26 4
gpt4 key购买 nike

我在 ubuntu 14 和 18 上运行以下代码。在相同硬件上,它在 18 上慢了 6 倍。我做错了什么吗?

main(int argc, char *argv[])
{
int fd;
off_t m;
time_t start, ed;
int i, k;

if (argc<2) exit(0);

fd = open(argv[1],O_RDWR|O_CREAT);
if (fd<0) {
printf("cannot open file %s\n", argv[1]);
exit(0);
}

start = time(0L);
for(k=0; k<100; ++k) {
for(i=0;i<500000;++i) {
m = lseek(fd, 0, 0);
if (m== -1) {
printf("lseek failed\n");
exit(0);
}
}
}
ed = time(0L);
printf("Time: %ld\n",ed-start);
}

在 ubuntu 14 上这需要 4 秒在 ubuntu 18 上需要 24 秒硬件相同

最佳答案

zx485 是对的。内核中的 Spectre 预防将其速度降低了 6 倍。在 redhat 7 上禁用以下保护将其更改为正常。

# echo 0 > /sys/kernel/debug/x86/pti_enabled
# echo 0 > /sys/kernel/debug/x86/retp_enabled
# echo 0 > /sys/kernel/debug/x86/ibrs_enabled

关于linux - 系统调用 lseek() 在 ubuntu 2.6.32 与 2.6.24 中比较慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54596931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com