AltraMayor / AltraMayor/f3

f3read requires O_DIRECT on Cygwin to avoid reading cached data

Đang mở
#232 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C
Star
3.4k
Fork
177
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
2

Mô tả

The method used to avoid that `f3read` reads previously cached data does not work on Cygwin. This may result in false positive tests. Here is the local patch used for the new Cygwin package [f3-8.0-2](https://cygwin.com/packages/summary/f3.html):

```patch
From c85e6f20d1de2c5cab358929e490d760e50e41d1 Mon Sep 17 00:00:00 2001
From: Christian Franke
Date: Mon, 27 Jan 2025 12:04:17 +0100
Subject: [PATCH] f3read: ensure unbuffered reads also on Cygwin

Use O_DIRECT because POSIX_FADV_DONTNEED etc. have not the desired
effect.
---
f3read.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/f3read.c b/f3read.c
index 7537b2e..fd670c5 100644
--- a/f3read.c
+++ b/f3read.c
@@ -1,5 +1,8 @@
#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600
+#ifdef __CYGWIN__
+#define _BSD_SOURCE /* required for O_DIRECT */
+#endif

#include
#include
@@ -243,16 +246,18 @@ static void validate_file(const char *path, int number, struct flow *fw,
printf("Validating file %s ... ", filename);
fflush(stdout);
#ifdef __CYGWIN__
- /* We don't need write access, but some kernels require that
- * the file descriptor passed to fdatasync(2) to be writable.
+ /* On Cygwin, the fdatasync() and posix_fadvise() calls below do
+ * not have the desired effect. Use O_DIRECT instead to avoid
+ * read caching.
*/
- fd = open(full_fn, O_RDWR);
+ fd = open(full_fn, O_RDONLY | O_DIRECT);
#else
fd = open(full_fn, O_RDONLY);
#endif
if (fd < 0)
err(errno, "Can't open file %s", full_fn);

+#ifndef __CYGWIN__
/* If the kernel follows our advice, f3read won't ever read from cache
* even when testing small memory cards without a remount, and
* we should have a better reading-speed measurement.
@@ -262,6 +267,7 @@ static void validate_file(const char *path, int number, struct flow *fw,

/* Help the kernel to help us. */
assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL));
+#endif

saved_errno = 0;
expected_offset = (uint64_t)number * GIGABYTES;
--
2.45.1
```

BTW: It may make sense to use the (non-POSIX) flag O_DIRECT on all platforms supporting it (Linux, *BSD, ...).

[POSIX 2024](https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_fadvise.html) says about `posix_fadvise()`: _The implementation **may** use this information to optimize handling of the specified data._

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.