readahead-collect.c revision 4826f0b7b5c0aefa08b8cc7ef64d69027f84da2c
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek This file is part of systemd.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Copyright 2010 Lennart Poettering
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek (at your option) any later version.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek * - detect ssd on btrfs/lvm...
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek * - read ahead directories
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * - handle files where nothing is in mincore
8847551bcbfa8265bae04f567bb1aadc7b480325Zbigniew Jędrzejewski-Szmek * - does ioprio_set work with fadvise()?
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic ReadaheadShared *shared = NULL;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek/* Avoid collisions with the NULL pointer */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek#define SECTOR_TO_PTR(s) ULONG_TO_PTR((s)+1)
8847551bcbfa8265bae04f567bb1aadc7b480325Zbigniew Jędrzejewski-Szmek#define PTR_TO_SECTOR(p) (PTR_TO_ULONG(p)-1)
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int btrfs_defrag(int fd) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek struct btrfs_ioctl_vol_args data = { .fd = fd };
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek return ioctl(fd, BTRFS_IOC_DEFRAG, &data);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW);
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek if (errno == EPERM || errno == EACCES)
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek log_warning("open(%s) failed: %m", fn);
d71839afd88589247d8dd42b2b09d024f521749dZbigniew Jędrzejewski-Szmek k = file_verify(fd, fn, arg_file_size_max, &st);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek start = mmap(NULL, l, PROT_READ, MAP_SHARED, fd, 0);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek log_warning("mmap(%s) failed: %m", fn);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek log_warning("mincore(%s) failed: %m", fn);
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering /* Store the inode, so that we notice when the file is deleted */
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek for (c = 0; c < pages; c++) {
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek bool new_mapped = !!(vec[c] & 1);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek log_debug("%s: page %u to %u", fn, b, c);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek /* We don't write any range data if we should read the entire file */
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek log_debug("%s: page %u to %u", fn, b, c);
36d4739a68c3edafe4d145d525a26de4ef0b8e5aZbigniew Jędrzejewski-Szmek /* End marker */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic unsigned long fd_first_block(int fd) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (ioctl(fd, FS_IOC_FIEMAP, &data) < 0)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (data.fiemap.fm_mapped_extents <= 0)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (data.fiemap.fm_extents[0].fe_flags & FIEMAP_EXTENT_UNKNOWN)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek return (unsigned long) data.fiemap.fm_extents[0].fe_physical;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic int qsort_compare(const void *a, const void *b) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek const struct item *i, *j;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* sort by bin first */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* then sort by sector */
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek return strcmp(i->path, j->path);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int collect(const char *root) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek FD_FANOTIFY, /* Get the actual fs events */
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek FD_INOTIFY, /* We get notifications to quit early via this fd */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek struct pollfd pollfd[_FD_MAX] = {};
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek int fanotify_fd = -1, signal_fd = -1, inotify_fd = -1, r = 0;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek char *pack_fn_new = NULL, *pack_fn = NULL;
5dabb1e04e4521abf040e77a8322b70e7acdc7b0Zbigniew Jędrzejewski-Szmek uint64_t previous_block_readahead;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek bool previous_block_readahead_set = false;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek starttime = now(CLOCK_MONOTONIC);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek /* If there's no pack file yet we lower the kernel readahead
8847551bcbfa8265bae04f567bb1aadc7b480325Zbigniew Jędrzejewski-Szmek * so that mincore() is accurate. If there is a pack file
8847551bcbfa8265bae04f567bb1aadc7b480325Zbigniew Jędrzejewski-Szmek * already we assume it is accurate enough so that kernel
8847551bcbfa8265bae04f567bb1aadc7b480325Zbigniew Jędrzejewski-Szmek * readahead is never triggered. */
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek block_get_readahead(root, &previous_block_readahead) >= 0 &&
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek block_set_readahead(root, 8*1024) >= 0;
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek if (ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) < 0)
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek log_warning("Failed to set IDLE IO priority class: %m");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek assert_se(sigemptyset(&mask) == 0);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek sigset_add_many(&mask, SIGINT, SIGTERM, -1);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if ((signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC)) < 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek files = hashmap_new(string_hash_func, string_compare_func);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Failed to allocate set.");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek fanotify_fd = fanotify_init(FAN_CLOEXEC|FAN_NONBLOCK, O_RDONLY|O_LARGEFILE|O_CLOEXEC|O_NOATIME);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Failed to create fanotify object: %m");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (fanotify_mark(fanotify_fd, FAN_MARK_ADD|FAN_MARK_MOUNT, FAN_OPEN, AT_FDCWD, root) < 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Failed to mark %s: %m", root);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek not_after = now(CLOCK_MONOTONIC) + arg_timeout;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek pollfd[FD_FANOTIFY].fd = fanotify_fd;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek pollfd[FD_FANOTIFY].events = POLLIN;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek pollfd[FD_SIGNAL].fd = signal_fd;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek pollfd[FD_SIGNAL].events = POLLIN;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek pollfd[FD_INOTIFY].fd = inotify_fd;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "STATUS=Collecting readahead data");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (access("/run/systemd/readahead/cancel", F_OK) >= 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_debug("Collection canceled");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (access("/run/systemd/readahead/done", F_OK) >= 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_debug("Got termination request");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek struct fanotify_event_metadata metadata;
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek struct fanotify_event_metadata *m;
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek if (hashmap_size(files) > arg_files_max) {
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek log_debug("Reached maximum number of read ahead files, ending collection.");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_debug("Reached maximum collection time, ending collection.");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if ((h = poll(pollfd, _FD_MAX, (int) ((not_after - t) / USEC_PER_MSEC))) < 0) {
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt if (h == 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_debug("Reached maximum collection time, ending collection.");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (pollfd[FD_SIGNAL].revents) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek uint8_t inotify_buffer[sizeof(struct inotify_event) + FILENAME_MAX];
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if ((n = read(inotify_fd, &inotify_buffer, sizeof(inotify_buffer))) < 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (errno == EINTR || errno == EAGAIN)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Failed to read inotify event: %m");
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek e = (struct inotify_event*) inotify_buffer;
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if ((e->mask & IN_CREATE) && streq(e->name, "cancel")) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek log_debug("Collection canceled");
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if ((e->mask & IN_CREATE) && streq(e->name, "done")) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek log_debug("Got termination request");
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek step = sizeof(struct inotify_event) + e->len;
72c0a2c255b172ebbb2a2b7dab7c9aec4c9582d9Lennart Poettering e = (struct inotify_event*) ((uint8_t*) e + step);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if ((n = read(fanotify_fd, &data, sizeof(data))) < 0) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if (errno == EINTR || errno == EAGAIN)
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek /* fanotify sometimes returns EACCES on read()
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek * where it shouldn't. For now let's just
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek * ignore it here (which is safe), but
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek * eventually this should be
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * dropped when the kernel is fixed.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * https://bugzilla.redhat.com/show_bug.cgi?id=707577 */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Failed to read event: %m");
50a0b0717563d08c027a16a896bff8d7754eab9eZbigniew Jędrzejewski-Szmek for (m = &data.metadata; FAN_EVENT_OK(m, n); m = FAN_EVENT_NEXT(m, n)) {
50a0b0717563d08c027a16a896bff8d7754eab9eZbigniew Jędrzejewski-Szmek snprintf(fn, sizeof(fn), "/proc/self/fd/%i", m->fd);
5bc891206dd8eb4e4df58f502b0184b8426caf22Zbigniew Jędrzejewski-Szmek if ((k = readlink_malloc(fn, &p)) >= 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* Not interesting, or
eb56eb9b40950f1edcffdb7313f8de4f8572a6d5Michal Schmidt * already read */
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek entrytime = now(CLOCK_MONOTONIC);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek entry->bin = (entrytime - starttime) / 2000000;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if ((k = hashmap_put(files, p, entry)) < 0) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek log_warning("set_put() failed: %s", strerror(-k));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_warning("readlink(%s) failed: %s", fn, strerror(-k));
30776485c5bc2d9c356e875f2aee874d22c393b7Zbigniew Jędrzejewski-Szmek close_nointr_nofail(fanotify_fd);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_debug("Writing Pack File...");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_debug("On SSD: %s", yes_no(on_ssd));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek on_btrfs = statfs(root, &sfs) >= 0 && sfs.f_type == (__SWORD_TYPE) BTRFS_SUPER_MAGIC;
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_debug("On btrfs: %s", yes_no(on_btrfs));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek pack = fopen(pack_fn_new, "we");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error("Failed to open pack file: %m");
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek fputs(CANONICAL_HOST READAHEAD_PACK_FILE_VERSION, pack);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek /* On SSD or on btrfs, just write things out in the
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek * order the files were accessed. */
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek HASHMAP_FOREACH_KEY(q, p, files, i)
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek /* On rotating media, order things by the block
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek if (!(ordered = new(struct item, n))) {
50a0b0717563d08c027a16a896bff8d7754eab9eZbigniew Jędrzejewski-Szmek memcpy(j, q, sizeof(struct item));
1af719edc5958c01c19204fb68d6fc45c9eea85cZbigniew Jędrzejewski-Szmek qsort(ordered, n, sizeof(struct item), qsort_compare);
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering for (k = 0; k < n; k++)
dad29dff1925a114e20d4eb7b47fca23c4f25fd7Lennart Poettering pack_file(pack, ordered[k].path, on_btrfs);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (rename(pack_fn_new, pack_fn) < 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Failed to rename readahead file: %m");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek close_nointr_nofail(fanotify_fd);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek close_nointr_nofail(inotify_fd);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek while ((p = hashmap_steal_first_key(files)))
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (previous_block_readahead_set) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* Restore the original kernel readahead setting if we
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * changed it, and nobody has overwritten it since
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (block_get_readahead(root, &bytes) >= 0 && bytes == 8*1024)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek block_set_readahead(root, previous_block_readahead);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekint main_collect(const char *root) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* Skip this step on read-only media. Note that we check the
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * underlying block device here, not he read-only flag of the
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * file system on top, since that one is most likely mounted
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * read-only anyway at boot, even if the underlying block
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek * device is theoretically writable. */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (fs_on_read_only(root) > 0) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_info("Disabling readahead collector due to read-only media.");
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek log_info("Disabling readahead collector due to low memory.");