|
Zbigniew Jędrzejewski-Szmek |
d66047 |
From ab3ada57a761fde9050d7452f6bd9d897b9067ec Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
From: Lennart Poettering <lennart@poettering.net>
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
Date: Wed, 27 Nov 2013 01:44:52 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
Subject: [PATCH] journal: simplify pre-allocation logic
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
let's just do a single fallocate() as far as possible, and don't
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
distuingish between allocated space and file size.
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
This way we can save a syscall for each append, which makes quite some
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
benefits.
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
(cherry picked from commit eda4b58b50509dc8ad0428a46e20f6c5cf516d58)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
src/journal/journal-file.c | 19 ++++++++-----------
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
1 file changed, 8 insertions(+), 11 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
index e0abddf..090cf97 100644
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
--- a/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+++ b/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
@@ -315,7 +315,7 @@ static int journal_file_verify_header(JournalFile *f) {
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) {
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- uint64_t old_size, new_size, file_size;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ uint64_t old_size, new_size;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
assert(f);
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
@@ -356,6 +356,11 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ /* Increase by larger blocks at once */
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ new_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ if (f->metrics.max_size > 0 && new_size > f->metrics.max_size)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ new_size = f->metrics.max_size;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
/* Note that the glibc fallocate() fallback is very
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
inefficient, hence we try to minimize the allocation area
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
as we can. */
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
@@ -363,16 +368,8 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
if (r != 0)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
return -r;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- /* Increase the file size a bit further than this, so that we
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- * we can create larger memory maps to cache */
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- file_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- if (file_size > (uint64_t) f->last_stat.st_size) {
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- if (file_size > new_size)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- ftruncate(f->fd, file_size);
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- if (fstat(f->fd, &f->last_stat) < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
- }
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ if (fstat(f->fd, &f->last_stat) < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
+ return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
f->header->arena_size = htole64(new_size - le64toh(f->header->header_size));
|
|
Zbigniew Jędrzejewski-Szmek |
d66047 |
|