forked from pool/systemd
147 lines
5.4 KiB
Diff
147 lines
5.4 KiB
Diff
---
|
|
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(-)
|
|
|
|
--- src/journal/catalog.c
|
|
+++ src/journal/catalog.c 2014-10-24 11:44:59.079838065 +0000
|
|
@@ -472,9 +472,19 @@ finish:
|
|
|
|
static int open_mmap(const char *database, int *_fd, struct stat *_st, void **_p) {
|
|
const CatalogHeader *h;
|
|
- 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;
|
|
void *p;
|
|
struct stat st;
|
|
+ size_t psize;
|
|
|
|
assert(_fd);
|
|
assert(_st);
|
|
@@ -494,12 +504,19 @@ static int open_mmap(const char *databas
|
|
return -EINVAL;
|
|
}
|
|
|
|
- p = mmap(NULL, PAGE_ALIGN(st.st_size), PROT_READ, MAP_SHARED, fd, 0);
|
|
+ psize = PAGE_ALIGN(st.st_size);
|
|
+ p = mmap(NULL, psize, PROT_READ, MAP_SHARED|MAP_POPULATE|MAP_NONBLOCK, fd, 0);
|
|
if (p == MAP_FAILED) {
|
|
close_nointr_nofail(fd);
|
|
return -errno;
|
|
}
|
|
|
|
+ for (n=0; n < sizeof(advises)/sizeof(advises[0]); n++) {
|
|
+ int r = madvise(p, psize, advises[n].advise);
|
|
+ if (r < 0)
|
|
+ log_warning("Failed to give advice about use of memory: %m");
|
|
+ }
|
|
+
|
|
h = p;
|
|
if (memcmp(h->signature, CATALOG_SIGNATURE, sizeof(h->signature)) != 0 ||
|
|
le64toh(h->header_size) < sizeof(CatalogHeader) ||
|
|
--- 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
|
|
goto finish;
|
|
}
|
|
|
|
- m = mmap(NULL, PAGE_ALIGN(sizeof(FSSHeader)), PROT_READ, MAP_SHARED, fd, 0);
|
|
+ m = mmap(NULL, PAGE_ALIGN(sizeof(FSSHeader)), PROT_READ, MAP_SHARED|MAP_STACK, fd, 0);
|
|
if (m == MAP_FAILED) {
|
|
m = NULL;
|
|
r = -errno;
|
|
@@ -399,7 +399,7 @@ int journal_file_fss_load(JournalFile *f
|
|
goto finish;
|
|
}
|
|
|
|
- f->fss_file = mmap(NULL, PAGE_ALIGN(f->fss_file_size), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
|
+ f->fss_file = mmap(NULL, PAGE_ALIGN(f->fss_file_size), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_STACK, fd, 0);
|
|
if (f->fss_file == MAP_FAILED) {
|
|
f->fss_file = NULL;
|
|
r = -errno;
|
|
--- 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)
|
|
return 0;
|
|
}
|
|
|
|
- p = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
|
+ p = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_STACK, fd, 0);
|
|
if (p == MAP_FAILED) {
|
|
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(
|
|
struct stat *st,
|
|
void **ret) {
|
|
|
|
+ static const struct {
|
|
+ const int index;
|
|
+ int vise;
|
|
+ } ad[] = {
|
|
+ {0, MADV_WILLNEED},
|
|
+ {1, MADV_SEQUENTIAL},
|
|
+ {2, MADV_DONTDUMP},
|
|
+ {3, MADV_DONTFORK}
|
|
+ };
|
|
uint64_t woffset, wsize;
|
|
Context *c;
|
|
FileDescriptor *f;
|
|
Window *w;
|
|
void *d;
|
|
- int r;
|
|
+ int n, r;
|
|
|
|
assert(m);
|
|
assert(m->n_ref > 0);
|
|
@@ -481,7 +490,7 @@ static int add_mmap(
|
|
}
|
|
|
|
for (;;) {
|
|
- d = mmap(NULL, wsize, prot, MAP_SHARED, fd, woffset);
|
|
+ d = mmap(NULL, wsize, prot, MAP_SHARED|MAP_POPULATE|MAP_NONBLOCK, fd, woffset);
|
|
if (d != MAP_FAILED)
|
|
break;
|
|
if (errno != ENOMEM)
|
|
@@ -494,6 +503,17 @@ static int add_mmap(
|
|
return -ENOMEM;
|
|
}
|
|
|
|
+ for (n=0; n < sizeof(ad)/sizeof(ad[0]); n++) {
|
|
+ if (ad[n].vise == MADV_DONTFORK) {
|
|
+ int flags = fcntl(fd, F_GETFD);
|
|
+ if (flags < 0 || !(flags & FD_CLOEXEC))
|
|
+ continue;
|
|
+ }
|
|
+ r = madvise(d, wsize, ad[n].vise);
|
|
+ if (r < 0)
|
|
+ log_warning("Failed to give advice about use of memory: %m");
|
|
+ }
|
|
+
|
|
c = context_add(m, context);
|
|
if (!c)
|
|
goto outofmem;
|