Whamcloud - gitweb
LU-6565 llog: Do not update the whole llog header
[fs/lustre-release.git] / lustre / obdclass / llog_osd.c
index 5d3e246..b4ef51a 100644 (file)
@@ -347,7 +347,6 @@ static int llog_osd_write_rec(const struct lu_env *env,
        struct llog_rec_tail    *lrt;
        struct dt_object        *o;
        size_t                   left;
-       bool                     header_is_updated = false;
 
        ENTRY;
 
@@ -518,14 +517,46 @@ static int llog_osd_write_rec(const struct lu_env *env,
        llh->llh_count++;
        spin_unlock(&loghandle->lgh_hdr_lock);
 
-       lgi->lgi_off = 0;
-       lgi->lgi_buf.lb_len = llh->llh_hdr.lrh_len;
-       lgi->lgi_buf.lb_buf = &llh->llh_hdr;
-       rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
-       if (rc)
-               GOTO(out, rc);
+       if (lgi->lgi_attr.la_size == 0) {
+               lgi->lgi_off = 0;
+               lgi->lgi_buf.lb_len = llh->llh_hdr.lrh_len;
+               lgi->lgi_buf.lb_buf = &llh->llh_hdr;
+               rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
+               if (rc != 0)
+                       GOTO(out, rc);
+       } else {
+               /* Note: If this is not initialization (size == 0), then do not
+                * write the whole header (8k bytes), only update header/tail
+                * and bits needs to be updated. Because this update might be
+                * part of cross-MDT operation, which needs to write these
+                * updates into the update log(32KB limit) and also pack inside
+                * the RPC (1MB limit), if we write 8K for each operation, which
+                * will cost a lot space, and keep us adding more updates to one
+                * update log.*/
+               lgi->lgi_off = offsetof(typeof(*llh), llh_count);
+               lgi->lgi_buf.lb_len = sizeof(llh->llh_count);
+               lgi->lgi_buf.lb_buf = &llh->llh_count;
+               rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
+               if (rc != 0)
+                       GOTO(out, rc);
+
+               lgi->lgi_off = offsetof(typeof(*llh),
+                       llh_bitmap[index / (sizeof(*llh->llh_bitmap) * 8)]);
+               lgi->lgi_buf.lb_len = sizeof(*llh->llh_bitmap);
+               lgi->lgi_buf.lb_buf =
+                       &llh->llh_bitmap[index/(sizeof(*llh->llh_bitmap)*8)];
+               rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
+               if (rc != 0)
+                       GOTO(out, rc);
+
+               lgi->lgi_off = offsetof(typeof(*llh), llh_tail);
+               lgi->lgi_buf.lb_len = sizeof(llh->llh_tail);
+               lgi->lgi_buf.lb_buf = &llh->llh_tail;
+               rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
+               if (rc != 0)
+                       GOTO(out, rc);
+       }
 
-       header_is_updated = true;
        rc = dt_attr_get(env, o, &lgi->lgi_attr);
        if (rc)
                GOTO(out, rc);
@@ -564,14 +595,6 @@ out:
        loghandle->lgh_last_idx--;
        llh->llh_tail.lrt_index = loghandle->lgh_last_idx;
 
-       /* restore the header on disk if it was written */
-       if (header_is_updated) {
-               lgi->lgi_off = 0;
-               lgi->lgi_buf.lb_len = llh->llh_hdr.lrh_len;
-               lgi->lgi_buf.lb_buf = &llh->llh_hdr;
-               dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
-       }
-
        RETURN(rc);
 }