2014-11-26 10:36:00 +01:00
|
|
|
---
|
2015-03-09 09:20:20 +01:00
|
|
|
src/journal/catalog.c | 21 +++++++++++++++++++--
|
|
|
|
src/journal/journal-authenticate.c | 4 ++--
|
|
|
|
src/journal/journal-file.c | 2 +-
|
|
|
|
src/journal/journald-kmsg.c | 2 +-
|
|
|
|
src/journal/mmap-cache.c | 24 ++++++++++++++++++++++--
|
|
|
|
5 files changed, 45 insertions(+), 8 deletions(-)
|
2014-11-26 10:36:00 +01:00
|
|
|
|
2015-03-09 09:20:20 +01:00
|
|
|
--- src/journal/catalog.c
|
|
|
|
+++ src/journal/catalog.c 2014-10-24 11:44:59.079838065 +0000
|
|
|
|
@@ -472,9 +472,19 @@ finish:
|
2014-11-26 10:36:00 +01:00
|
|
|
|
|
|
|
static int open_mmap(const char *database, int *_fd, struct stat *_st, void **_p) {
|
|
|
|
const CatalogHeader *h;
|
2015-03-09 09:20:20 +01:00
|
|
|
- int fd;
|
|
|
|
+ static const struct {
|
|
|
|
+ const int index;
|
|
|
|
+ int advise;
|
|
|
|
+ } advises[] = {
|
|
|
|
+ {0,MADV_WILLNEED},
|
|
|
|
+ {1,MADV_SEQUENTIAL},
|
|
|
|
+ {2,MADV_DONTDUMP},
|
|
|
|
+ {3,MADV_DONTFORK}
|
|
|
|
+ };
|
|
|
|
+ int n, fd;
|
2014-11-26 10:36:00 +01:00
|
|
|
void *p;
|
|
|
|
struct stat st;
|
2015-03-09 09:20:20 +01:00
|
|
|
+ size_t psize;
|
|
|
|
|
|
|
|
assert(_fd);
|
|
|
|
assert(_st);
|
|
|
|
@@ -494,12 +504,19 @@ static int open_mmap(const char *databas
|
2014-11-26 10:36:00 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- p = mmap(NULL, PAGE_ALIGN(st.st_size), PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
+ psize = PAGE_ALIGN(st.st_size);
|
2015-03-09 09:20:20 +01:00
|
|
|
+ p = mmap(NULL, psize, PROT_READ, MAP_SHARED|MAP_POPULATE|MAP_NONBLOCK, fd, 0);
|
2014-11-26 10:36:00 +01:00
|
|
|
if (p == MAP_FAILED) {
|
2015-03-09 09:20:20 +01:00
|
|
|
close_nointr_nofail(fd);
|
2014-11-26 10:36:00 +01:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2015-03-09 09:20:20 +01:00
|
|
|
+ for (n=0; n < sizeof(advises)/sizeof(advises[0]); n++) {
|
|
|
|
+ int r = madvise(p, psize, advises[n].advise);
|
|
|
|
+ if (r < 0)
|
2014-11-26 10:36:00 +01:00
|
|
|
+ log_warning("Failed to give advice about use of memory: %m");
|
2015-03-09 09:20:20 +01:00
|
|
|
+ }
|
2014-11-26 10:36:00 +01:00
|
|
|
+
|
|
|
|
h = p;
|
|
|
|
if (memcmp(h->signature, CATALOG_SIGNATURE, sizeof(h->signature)) != 0 ||
|
|
|
|
le64toh(h->header_size) < sizeof(CatalogHeader) ||
|
2015-03-09 09:20:20 +01:00
|
|
|
--- src/journal/journal-authenticate.c
|
|
|
|
+++ src/journal/journal-authenticate.c 2014-10-24 07:41:09.271837523 +0000
|
|
|
|
@@ -355,7 +355,7 @@ int journal_file_fss_load(JournalFile *f
|
2014-11-26 10:36:00 +01:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
- m = mmap(NULL, PAGE_ALIGN(sizeof(FSSHeader)), PROT_READ, MAP_SHARED, fd, 0);
|
2015-03-09 09:20:20 +01:00
|
|
|
+ m = mmap(NULL, PAGE_ALIGN(sizeof(FSSHeader)), PROT_READ, MAP_SHARED|MAP_STACK, fd, 0);
|
2014-11-26 10:36:00 +01:00
|
|
|
if (m == MAP_FAILED) {
|
|
|
|
m = NULL;
|
|
|
|
r = -errno;
|
2015-03-09 09:20:20 +01:00
|
|
|
@@ -399,7 +399,7 @@ int journal_file_fss_load(JournalFile *f
|
2014-11-26 10:36:00 +01:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
- f->fss_file = mmap(NULL, PAGE_ALIGN(f->fss_file_size), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
2015-03-09 09:20:20 +01:00
|
|
|
+ f->fss_file = mmap(NULL, PAGE_ALIGN(f->fss_file_size), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_STACK, fd, 0);
|
2014-11-26 10:36:00 +01:00
|
|
|
if (f->fss_file == MAP_FAILED) {
|
|
|
|
f->fss_file = NULL;
|
|
|
|
r = -errno;
|
2015-03-09 09:20:20 +01:00
|
|
|
--- src/journal/journal-file.c
|
|
|
|
+++ src/journal/journal-file.c 2014-10-24 07:39:25.603837720 +0000
|
|
|
|
@@ -2554,7 +2554,7 @@ int journal_file_open(
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
- f->header = mmap(NULL, PAGE_ALIGN(sizeof(Header)), prot_from_flags(flags), MAP_SHARED, f->fd, 0);
|
|
|
|
+ f->header = mmap(NULL, PAGE_ALIGN(sizeof(Header)), prot_from_flags(flags), MAP_SHARED|MAP_STACK, f->fd, 0);
|
|
|
|
if (f->header == MAP_FAILED) {
|
|
|
|
f->header = NULL;
|
|
|
|
r = -errno;
|
|
|
|
--- src/journal/journald-kmsg.c
|
|
|
|
+++ src/journal/journald-kmsg.c 2014-10-24 07:38:01.967837989 +0000
|
|
|
|
@@ -473,7 +473,7 @@ int server_open_kernel_seqnum(Server *s)
|
2014-11-26 10:36:00 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- p = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
2015-03-09 09:20:20 +01:00
|
|
|
+ p = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_STACK, fd, 0);
|
2014-11-26 10:36:00 +01:00
|
|
|
if (p == MAP_FAILED) {
|
2015-03-09 09:20:20 +01:00
|
|
|
log_error("Failed to map sequential number file, ignoring: %m");
|
|
|
|
close_nointr_nofail(fd);
|
|
|
|
--- src/journal/mmap-cache.c
|
|
|
|
+++ src/journal/mmap-cache.c 2014-10-24 11:16:47.759837744 +0000
|
|
|
|
@@ -439,12 +439,21 @@ static int add_mmap(
|
2014-11-26 10:36:00 +01:00
|
|
|
struct stat *st,
|
|
|
|
void **ret) {
|
|
|
|
|
2015-03-09 09:20:20 +01:00
|
|
|
+ static const struct {
|
|
|
|
+ const int index;
|
|
|
|
+ int vise;
|
|
|
|
+ } ad[] = {
|
|
|
|
+ {0, MADV_WILLNEED},
|
|
|
|
+ {1, MADV_SEQUENTIAL},
|
|
|
|
+ {2, MADV_DONTDUMP},
|
|
|
|
+ {3, MADV_DONTFORK}
|
|
|
|
+ };
|
2014-11-26 10:36:00 +01:00
|
|
|
uint64_t woffset, wsize;
|
|
|
|
Context *c;
|
|
|
|
FileDescriptor *f;
|
|
|
|
Window *w;
|
|
|
|
void *d;
|
2015-03-09 09:20:20 +01:00
|
|
|
- int r;
|
|
|
|
+ int n, r;
|
2014-11-26 10:36:00 +01:00
|
|
|
|
|
|
|
assert(m);
|
2015-03-09 09:20:20 +01:00
|
|
|
assert(m->n_ref > 0);
|
|
|
|
@@ -481,7 +490,7 @@ static int add_mmap(
|
2014-11-26 10:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
- d = mmap(NULL, wsize, prot, MAP_SHARED, fd, woffset);
|
2015-03-09 09:20:20 +01:00
|
|
|
+ d = mmap(NULL, wsize, prot, MAP_SHARED|MAP_POPULATE|MAP_NONBLOCK, fd, woffset);
|
2014-11-26 10:36:00 +01:00
|
|
|
if (d != MAP_FAILED)
|
|
|
|
break;
|
|
|
|
if (errno != ENOMEM)
|
2015-03-09 09:20:20 +01:00
|
|
|
@@ -494,6 +503,17 @@ static int add_mmap(
|
2014-11-26 10:36:00 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-03-09 09:20:20 +01:00
|
|
|
+ for (n=0; n < sizeof(ad)/sizeof(ad[0]); n++) {
|
|
|
|
+ if (ad[n].vise == MADV_DONTFORK) {
|
2014-11-26 10:36:00 +01:00
|
|
|
+ int flags = fcntl(fd, F_GETFD);
|
|
|
|
+ if (flags < 0 || !(flags & FD_CLOEXEC))
|
|
|
|
+ continue;
|
|
|
|
+ }
|
2015-03-09 09:20:20 +01:00
|
|
|
+ r = madvise(d, wsize, ad[n].vise);
|
|
|
|
+ if (r < 0)
|
2014-11-26 10:36:00 +01:00
|
|
|
+ log_warning("Failed to give advice about use of memory: %m");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
c = context_add(m, context);
|
|
|
|
if (!c)
|
|
|
|
goto outofmem;
|