summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-10-26 21:28:39 +0200
committerLennart Poettering <lennart@poettering.net>2010-10-26 21:28:39 +0200
commitde58283f71162d3e6522b67e044f8f9ee9fdf066 (patch)
tree3ae6fa8dba1d47f9382c039402b32ec468e98f9b /src
parent415dbd2e542e7a0f6b15350e1c5fd00dca54b91d (diff)
readahead: bump a device's request_nr when enabling readahead
Diffstat (limited to 'src')
-rw-r--r--src/readahead-common.c77
-rw-r--r--src/readahead-common.h2
-rw-r--r--src/readahead-replay.c1
3 files changed, 79 insertions, 1 deletions
diff --git a/src/readahead-common.c b/src/readahead-common.c
index d76188b71f..85e3227f6e 100644
--- a/src/readahead-common.c
+++ b/src/readahead-common.c
@@ -20,7 +20,6 @@
***/
#include <errno.h>
-#include <libudev.h>
#include <stdlib.h>
#include <string.h>
#include <sys/sysinfo.h>
@@ -28,6 +27,7 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
+#include <libudev.h>
#include "log.h"
#include "readahead-common.h"
@@ -68,6 +68,9 @@ int fs_on_ssd(const char *p) {
if (stat(p, &st) < 0)
return -errno;
+ if (major(st.st_dev) == 0)
+ return false;
+
if (!(udev = udev_new()))
return -ENOMEM;
@@ -170,3 +173,75 @@ finish:
return m;
}
+
+
+#define BUMP_REQUEST_NR (16*1024)
+
+int bump_request_nr(const char *p) {
+ struct stat st;
+ struct udev *udev = NULL;
+ struct udev_device *udev_device = NULL, *look_at = NULL;
+ const char *nr_requests;
+ uint64_t u;
+ char nr[64], *ap = NULL;
+ int r;
+
+ assert(p);
+
+ if (stat(p, &st) < 0)
+ return -errno;
+
+ if (major(st.st_dev) == 0)
+ return 0;
+
+ if (!(udev = udev_new()))
+ return -ENOMEM;
+
+ if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev))) {
+ r = -ENOENT;
+ goto finish;
+ }
+
+ look_at = udev_device;
+ if (!(nr_requests = udev_device_get_sysattr_value(look_at, "queue/nr_requests"))) {
+
+ /* Hmm, if the block device doesn't have a queue
+ * subdir, the let's look in the parent */
+ look_at = udev_device_get_parent(udev_device);
+ nr_requests = udev_device_get_sysattr_value(look_at, "queue/nr_requests");
+ }
+
+ if (!nr_requests) {
+ r = -ENOENT;
+ goto finish;
+ }
+
+ if (safe_atou64(nr_requests, &u) >= 0 && u >= BUMP_REQUEST_NR) {
+ r = 0;
+ goto finish;
+ }
+
+ if (asprintf(&ap, "%s/queue/nr_requests", udev_device_get_syspath(look_at)) < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ snprintf(nr, sizeof(nr), "%lu", (unsigned long) BUMP_REQUEST_NR);
+
+ if ((r = write_one_line_file(ap, nr)) < 0)
+ goto finish;
+
+ log_info("Bumped block_nr parameter of %s to %lu. This is a temporary hack and should be removed one day.", udev_device_get_devnode(look_at), (unsigned long) BUMP_REQUEST_NR);
+ r = 1;
+
+finish:
+ if (udev_device)
+ udev_device_unref(udev_device);
+
+ if (udev)
+ udev_unref(udev);
+
+ free(ap);
+
+ return r;
+}
diff --git a/src/readahead-common.h b/src/readahead-common.h
index 7add62613f..964ca1f2fa 100644
--- a/src/readahead-common.h
+++ b/src/readahead-common.h
@@ -44,4 +44,6 @@ typedef struct ReadaheadShared {
ReadaheadShared *shared_get(void);
+int bump_request_nr(const char *p);
+
#endif
diff --git a/src/readahead-replay.c b/src/readahead-replay.c
index cb93fae806..ab0c8084c8 100644
--- a/src/readahead-replay.c
+++ b/src/readahead-replay.c
@@ -127,6 +127,7 @@ static int replay(const char *root) {
assert(root);
write_one_line_file("/proc/self/oom_score_adj", "1000");
+ bump_request_nr(root);
if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
log_error("Out of memory");