about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-07-13 06:41:59 +0000
committerEric Wong <normalperson@yhbt.net>2013-07-13 06:53:27 +0000
commit5666c4496facb4ad7cfa073cf1d6d849784e06b8 (patch)
treee90808fd7f513d7e016210fa6716503494c6e286
parentfe57de9a8b6b9a6f4f840ab5a2ca17c8f803ce20 (diff)
downloadcmogstored-5666c4496facb4ad7cfa073cf1d6d849784e06b8.tar.gz
The update prefix is bounded in size, so this will save us NR_DEVICES
malloc/free pairs each second from typical iostat output.
-rw-r--r--iostat.h6
-rw-r--r--mnt.c12
2 files changed, 11 insertions, 7 deletions
diff --git a/iostat.h b/iostat.h
index 6df96b6..4414ca1 100644
--- a/iostat.h
+++ b/iostat.h
@@ -5,6 +5,10 @@
 struct mog_queue;
 struct mog_fd;
 #define MOG_IOUTIL_LEN (sizeof("1666.00"))
+
+/* this is way larger than it needs to be... */
+#define MOG_IOSTAT_DEVLEN (72)
+
 struct mog_iostat {
         int cs;
         bool ready;
@@ -12,7 +16,7 @@ struct mog_iostat {
         uint8_t dev_tip;
         struct mog_queue *queue;
         char util[MOG_IOUTIL_LEN];
-        char dev[72]; /* this is way larger than it needs to be... */
+        char dev[MOG_IOSTAT_DEVLEN];
 };
 
 void mog_iostat_init(struct mog_iostat *);
diff --git a/mnt.c b/mnt.c
index 092111c..bfc972f 100644
--- a/mnt.c
+++ b/mnt.c
@@ -288,7 +288,7 @@ void mog_mnt_release(const struct mount_entry *me)
 #define MOG_DEV_T_INVAL ((dev_t)-1)
 
 struct mnt_update {
-        const char *prefix;
+        char prefix[(sizeof("/dev/") - 1) + MOG_IOSTAT_DEVLEN];
         size_t prefixlen;
         dev_t st_rdev;
         char util[MOG_IOUTIL_LEN];
@@ -340,12 +340,14 @@ static bool update_util_each(void *ent, void *upd)
  */
 void mog_mnt_update_util(struct mog_iostat *iostat)
 {
+        static const size_t pfx_len = sizeof("/dev/") - 1;
         struct mnt_update update;
+        size_t cpy_len = strlen(iostat->dev);
+        char *dst = mempcpy(update.prefix, "/dev/", pfx_len);
         struct stat st;
-        const char *devsuffix = iostat->dev;
 
-        update.prefix = xasprintf("/dev/%s", devsuffix);
-        update.prefixlen = strlen(update.prefix);
+        mempcpy(dst, iostat->dev, cpy_len + 1);
+        update.prefixlen = cpy_len + pfx_len;
 
         /*
          * st_rdev matching is necessary for cryptmount(8) on Linux, where
@@ -368,6 +370,4 @@ void mog_mnt_update_util(struct mog_iostat *iostat)
         CHECK(int, 0, pthread_mutex_lock(&by_dev_lock) );
         (void)hash_do_for_each(by_dev, update_util_each, &update);
         CHECK(int, 0, pthread_mutex_unlock(&by_dev_lock) );
-
-        mog_free(update.prefix);
 }