From: Lennart Poettering Date: Sat, 25 Sep 2010 11:32:54 +0000 (+0200) Subject: readahead: disable on low memory machines X-Git-Tag: v11~88 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41a598e21a9f6cfe8dad7759c3c9facd55774acf;p=systemd readahead: disable on low memory machines --- diff --git a/src/readahead-collect.c b/src/readahead-collect.c index 937231ca..fe35da70 100644 --- a/src/readahead-collect.c +++ b/src/readahead-collect.c @@ -50,6 +50,12 @@ #define MINCORE_VEC_SIZE (READAHEAD_FILE_SIZE_MAX/PAGE_SIZE) +/* fixme: + * + * - detect ssd/lvm/... on btrfs + * - read ahead directories + */ + static int btrfs_defrag(int fd) { struct btrfs_ioctl_vol_args data; @@ -302,10 +308,7 @@ static int collect(const char *root) { ul = fd_first_block(m->fd); if ((k = hashmap_put(files, p, ULONG_TO_PTR(ul))) < 0) { - - if (k != -EEXIST) - log_warning("set_put() failed: %s", strerror(-k)); - + log_warning("set_put() failed: %s", strerror(-k)); free(p); } } @@ -355,7 +358,7 @@ static int collect(const char *root) { if (on_ssd || on_btrfs) { /* On SSD or on btrfs, just write things out in the - * order the files where accessed. */ + * order the files were accessed. */ HASHMAP_FOREACH_KEY(q, p, files, i) pack_file(pack, p, on_btrfs); @@ -442,6 +445,11 @@ int main(int argc, char *argv[]) { log_parse_environment(); log_open(); + if (!enough_ram()) { + log_info("Disabling readahead collector due to low memory."); + return 0; + } + if (collect(argc >= 2 ? argv[1] : "/") < 0) return 1; diff --git a/src/readahead-common.c b/src/readahead-common.c index 8533717d..88441dbe 100644 --- a/src/readahead-common.c +++ b/src/readahead-common.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "log.h" #include "readahead-common.h" @@ -105,3 +106,13 @@ finish: return b; } + +bool enough_ram(void) { + struct sysinfo si; + + assert_se(sysinfo(&si) >= 0); + + return si.totalram > 127 * 1024*1024; /* Enable readahead only + * with at least 128MB + * memory */ +} diff --git a/src/readahead-common.h b/src/readahead-common.h index 5d8f1a34..d39dd5b4 100644 --- a/src/readahead-common.h +++ b/src/readahead-common.h @@ -31,4 +31,6 @@ int file_verify(int fd, const char *fn, struct stat *st); int fs_on_ssd(const char *p); +bool enough_ram(void); + #endif diff --git a/src/readahead-replay.c b/src/readahead-replay.c index 1f1ec523..58d9468c 100644 --- a/src/readahead-replay.c +++ b/src/readahead-replay.c @@ -206,6 +206,11 @@ int main(int argc, char*argv[]) { log_parse_environment(); log_open(); + if (!enough_ram()) { + log_info("Disabling readahead replay due to low memory."); + return 0; + } + if (replay(argc >= 2 ? argv[1] : "/") < 0) return 1;