Whamcloud - gitweb
LU-18576 obdclass: do not update llog's timestamp each time 10/57510/4
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 18 Dec 2024 12:24:14 +0000 (15:24 +0300)
committerOleg Drokin <green@whamcloud.com>
Thu, 2 Jan 2025 20:53:32 +0000 (20:53 +0000)
updating llog's timestamp on every record doesn't makes sense as
we save seconds and introduces performance penalty (upto 15% in
microbenchmark). it should be enough to update it every second.

the results, in msec per record inserted:

32K records into a plain llog:
mtime update: yes no
1 thread 2421 2137
4 threads 1941 1687

120K records into a catalog:
mtime update yes no
1 thread 3007 2765
4 threads 2012 1744

Fixes: e33d196b93 ("LU-17309 llog: set timestamp on llog objects at creation time")
Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I0178ba7071ce39668550b4faa5e1e86397c8a89d
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57510
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: kg.xu <squalfof@gmail.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/include/lustre_log.h
lustre/obdclass/llog.c
lustre/obdclass/llog_cat.c

index f1c5053..392564b 100644 (file)
@@ -294,6 +294,7 @@ struct llog_handle {
 
        int                     lgh_max_size;
        bool                    lgh_destroyed;
+       unsigned long           lgh_timestamp;
 };
 
 /* llog_osd.c */
index 10d7748..d6509e0 100644 (file)
@@ -1321,6 +1321,7 @@ int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
        struct llog_thread_info *lgi = llog_info(env);
        bool need_cookie;
        bool update_attr;
+       unsigned long timestamp;
        int rc;
 
        ENTRY;
@@ -1347,9 +1348,12 @@ int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
         * size/block needs to be written anyway; 2) update for catalog
         * since this doesn't happen very often
         */
-       update_attr = (idx == LLOG_NEXT_IDX ||
-                       (loghandle->lgh_hdr &&
-                        loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT));
+       timestamp = ktime_get_real_seconds();
+
+       update_attr = (timestamp != loghandle->lgh_timestamp) &&
+                      (idx == LLOG_NEXT_IDX ||
+                      (loghandle->lgh_hdr &&
+                       loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT));
        if (update_attr)
                dt_declare_attr_set(env, loghandle->lgh_obj, NULL, th);
 
@@ -1373,8 +1377,9 @@ int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
                rc = llog_write_rec(env, loghandle, rec, NULL, idx, th);
        }
        if (rc == 0 && update_attr) {
+               loghandle->lgh_timestamp = timestamp;
                lgi->lgi_attr.la_valid = LA_MTIME;
-               lgi->lgi_attr.la_mtime = ktime_get_real_seconds();
+               lgi->lgi_attr.la_mtime = timestamp;
                dt_attr_set(env, loghandle->lgh_obj, &lgi->lgi_attr, th);
        }
 
index 3f423df..bb476c5 100644 (file)
@@ -604,10 +604,13 @@ retry:
                if (rc == -ENOSPC && llog_is_full(loghandle))
                        rc = -ENOBUFS;
        } else {
-               /* no overhead since inode size needs to be written anyway */
-               lgi->lgi_attr.la_valid = LA_MTIME;
-               lgi->lgi_attr.la_mtime = ktime_get_real_seconds();
-               dt_attr_set(env, loghandle->lgh_obj, &lgi->lgi_attr, th);
+               unsigned long timestamp = ktime_get_real_seconds();
+               if (timestamp != loghandle->lgh_timestamp) {
+                       loghandle->lgh_timestamp = timestamp;
+                       lgi->lgi_attr.la_valid = LA_MTIME;
+                       lgi->lgi_attr.la_mtime = timestamp;
+                       dt_attr_set(env, loghandle->lgh_obj, &lgi->lgi_attr, th);
+               }
        }
 
        up_write(&loghandle->lgh_lock);