Support native advise modes in buffered streams
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-09-09 20:39:33 +02:00
parent c72c01aff1
commit 14b1967990
4 changed files with 80 additions and 54 deletions

View file

@ -32,6 +32,18 @@
#define HAVE_MT_VERIFY 1
#endif
/*
* Start content-file writeback in bounded windows to avoid dirty-page
* throttling; the subsequent fsync() remains responsible for durability.
*
* Best test-rewrite serialization/write times with four 4 GB content files:
* ADVISE_SEQUENTIAL: 128s
* ADVISE_FLUSH: 86s
* ADVISE_DISCARD_WINDOW: 73s
* ADVISE_FLUSH_WINDOW: 61s
*/
#define CONTENT_WRITE_ADVISE ADVISE_FLUSH_WINDOW
const char* lev_name(unsigned l)
{
switch (l) {
@ -4661,7 +4673,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc)
}
}
f = sopen_write(tmp, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC);
f = sopen_write(tmp, CONTENT_WRITE_ADVISE | STREAM_FLAGS_CRC);
if (f == 0) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error opening the temporary content file '%s'. %s.\n", tmp, strerror(errno));
@ -4819,7 +4831,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc)
}
/* open all the content files */
f = sopen_multi_write(count_content, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC);
f = sopen_multi_write(count_content, CONTENT_WRITE_ADVISE | STREAM_FLAGS_CRC);
if (!f) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error opening the content files.\n");
@ -5021,7 +5033,7 @@ void state_read(struct snapraid_state* state)
msg_progress("Loading state from %s...\n", path);
f = sopen_read(path, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC);
f = sopen_read(path, ADVISE_SEQUENTIAL | STREAM_FLAGS_CRC);
if (f != 0) {
/* if found stop the search */
break;
@ -5234,7 +5246,7 @@ static void state_verify_content(struct snapraid_state* state, uint32_t crc)
STREAM* f;
pathprint(tmp, sizeof(tmp), "%s.tmp", content->content);
f = sopen_read(tmp, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC);
f = sopen_read(tmp, ADVISE_SEQUENTIAL | STREAM_FLAGS_CRC);
if (f == 0) {
/* LCOV_EXCL_START */
log_fatal(errno, "Error reopening the temporary content file '%s'. %s.\n", tmp, strerror(errno));