[systemd-commits] 2 commits - TODO src/readahead units/systemd-readahead-collect.service.in units/systemd-readahead-replay.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Thu May 3 15:35:24 PDT 2012


 TODO                                       |    2 --
 src/readahead/readahead-collect.c          |   22 ++++++++++++++--------
 src/readahead/readahead-replay.c           |   24 ++++++++++++++++++++----
 units/systemd-readahead-collect.service.in |    1 +
 units/systemd-readahead-replay.service.in  |    1 +
 5 files changed, 36 insertions(+), 14 deletions(-)

New commits:
commit 189455ab08a70f0c80a11847b65ce38563b9332a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 4 00:34:12 2012 +0200

    readahead: store inode numbers in pack file
    
    If the inode nr for each file is available in the pack file we can
    easily detect replaced files (like they result from package upgrades)
    which we can then skip to readahead.

diff --git a/TODO b/TODO
index f2c5dd6..db422c0 100644
--- a/TODO
+++ b/TODO
@@ -254,8 +254,6 @@ Features:
 
 * drop /.readahead on bigger upgrades with yum
 
-* add inode nr check to readahead to suppress preloading changed files
-
 * add support for /bin/mount -s
 
 * GC unreferenced jobs (such as .device jobs)
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index a88e7f2..359b97b 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -86,6 +86,7 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
         void *start = MAP_FAILED;
         uint8_t *vec;
         uint32_t b, c;
+        uint64_t inode;
         size_t l, pages;
         bool mapped;
         int r = 0, fd = -1, k;
@@ -93,7 +94,8 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
         assert(pack);
         assert(fn);
 
-        if ((fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW)) < 0) {
+        fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW);
+        if (fd < 0) {
 
                 if (errno == ENOENT)
                         return 0;
@@ -106,7 +108,8 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
                 goto finish;
         }
 
-        if ((k = file_verify(fd, fn, arg_file_size_max, &st)) <= 0) {
+        k = file_verify(fd, fn, arg_file_size_max, &st);
+        if (k <= 0) {
                 r = k;
                 goto finish;
         }
@@ -115,14 +118,14 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
                 btrfs_defrag(fd);
 
         l = PAGE_ALIGN(st.st_size);
-        if ((start = mmap(NULL, l, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+        start = mmap(NULL, l, PROT_READ, MAP_SHARED, fd, 0);
+        if (start == MAP_FAILED) {
                 log_warning("mmap(%s) failed: %m", fn);
                 r = -errno;
                 goto finish;
         }
 
         pages = l / page_size();
-
         vec = alloca(pages);
         memset(vec, 0, pages);
         if (mincore(start, l, vec) < 0) {
@@ -134,6 +137,10 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
         fputs(fn, pack);
         fputc('\n', pack);
 
+        /* Store the inode, so that we notice when the file is deleted */
+        inode = (uint64_t) st.st_ino;
+        fwrite(&inode, sizeof(inode), 1, pack);
+
         mapped = false;
         for (c = 0; c < pages; c++) {
                 bool new_mapped = !!(vec[c] & 1);
@@ -479,13 +486,14 @@ done:
                 goto finish;
         }
 
-        if (!(pack = fopen(pack_fn_new, "we"))) {
+        pack = fopen(pack_fn_new, "we");
+        if (!pack) {
                 log_error("Failed to open pack file: %m");
                 r = -errno;
                 goto finish;
         }
 
-        fputs(CANONICAL_HOST "\n", pack);
+        fputs(CANONICAL_HOST ";VERSION=2\n", pack);
         putc(on_ssd ? 'S' : 'R', pack);
 
         if (on_ssd || on_btrfs) {
diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c
index a6529f8..886e16f 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -53,6 +53,7 @@ static int unpack_file(FILE *pack) {
         int r = 0, fd = -1;
         bool any = false;
         struct stat st;
+        uint64_t inode;
 
         assert(pack);
 
@@ -62,7 +63,8 @@ static int unpack_file(FILE *pack) {
         char_array_0(fn);
         truncate_nl(fn);
 
-        if ((fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW)) < 0) {
+        fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW);
+        if (fd < 0) {
 
                 if (errno != ENOENT && errno != EPERM && errno != EACCES)
                         log_warning("open(%s) failed: %m", fn);
@@ -72,6 +74,21 @@ static int unpack_file(FILE *pack) {
                 fd = -1;
         }
 
+        if (fread(&inode, sizeof(inode), 1, pack) != 1) {
+                log_error("Premature end of pack file.");
+                r = -EIO;
+                goto finish;
+        }
+
+        if (fd >= 0) {
+                /* If the inode changed the file got deleted, so just
+                 * ignore this entry */
+                if (st.st_ino != (uint64_t) inode) {
+                        close_nointr_nofail(fd);
+                        fd = -1;
+                }
+        }
+
         for (;;) {
                 uint32_t b, c;
 
@@ -166,8 +183,8 @@ static int replay(const char *root) {
 
         char_array_0(line);
 
-        if (!streq(line, CANONICAL_HOST "\n")) {
-                log_debug("Pack file host type mismatch.");
+        if (!streq(line, CANONICAL_HOST ";VERSION=2\n")) {
+                log_debug("Pack file host or version type mismatch.");
                 goto finish;
         }
 

commit 4019a16d5b65633e5f6d671c16d3215d7f7f29fc
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 4 00:15:21 2012 +0200

    units: use OOMScoreAdjust= in the unit files to set OOM score adjust

diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 70e0f66..a88e7f2 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -253,8 +253,6 @@ static int collect(const char *root) {
                 block_get_readahead(root, &previous_block_readahead) >= 0 &&
                 block_set_readahead(root, 8*1024) >= 0;
 
-        write_one_line_file("/proc/self/oom_score_adj", "1000");
-
         if (ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) < 0)
                 log_warning("Failed to set IDLE IO priority class: %m");
 
diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c
index 0b7e6df..a6529f8 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -132,7 +132,6 @@ static int replay(const char *root) {
 
         assert(root);
 
-        write_one_line_file("/proc/self/oom_score_adj", "1000");
         block_bump_request_nr(root);
 
         if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
diff --git a/units/systemd-readahead-collect.service.in b/units/systemd-readahead-collect.service.in
index c5e1d52..887339c 100644
--- a/units/systemd-readahead-collect.service.in
+++ b/units/systemd-readahead-collect.service.in
@@ -18,6 +18,7 @@ Type=notify
 ExecStart=@rootlibexecdir@/systemd-readahead-collect
 RemainAfterExit=yes
 StandardOutput=null
+OOMScoreAdjust=1000
 
 [Install]
 WantedBy=default.target
diff --git a/units/systemd-readahead-replay.service.in b/units/systemd-readahead-replay.service.in
index 7387eba..6a10167 100644
--- a/units/systemd-readahead-replay.service.in
+++ b/units/systemd-readahead-replay.service.in
@@ -18,6 +18,7 @@ Type=notify
 ExecStart=@rootlibexecdir@/systemd-readahead-replay
 RemainAfterExit=yes
 StandardOutput=null
+OOMScoreAdjust=1000
 
 [Install]
 WantedBy=default.target



More information about the systemd-commits mailing list