Whamcloud - gitweb
EX-4015 lipe: reduce ls3_object_attrs size
authorJohn L. Hammond <jhammond@whamcloud.com>
Thu, 17 Feb 2022 15:52:59 +0000 (09:52 -0600)
committerJohn L. Hammond <jhammond@whamcloud.com>
Thu, 10 Mar 2022 17:24:50 +0000 (17:24 +0000)
Reduce the size of struct ls3_object_attrs from 131KB to 360B by heap
allocating the link and lmv xattr buffers.

Test-Parameters: trivial testlist=sanity-lipe-scan3 facet=mds1
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: I5b210cb46eb027dbc922675deb1231a544b93d6a
Reviewed-on: https://review.whamcloud.com/46544
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lipe/src/lipe_scan3/ls3_debug.h
lipe/src/lipe_scan3/ls3_object_attrs.c
lipe/src/lipe_scan3/ls3_object_attrs.h
lipe/src/lipe_scan3/ls3_scan.c

index a018000..ac593e2 100644 (file)
@@ -106,9 +106,26 @@ static inline void *xstrdup1(const char *file, int line, const char *func, const
        return ptr;
 }
 
+static inline void *xstrndup1(const char *file, int line, const char *func,
+                             const char *s, size_t n)
+{
+       void *ptr;
+
+       if (s == NULL)
+               LS3_FATAL("NULL pointer at (%s:%d:%s)\n", file, line, func);
+
+       ptr = strndup(s, n);
+
+       if (ptr == NULL)
+               LS3_OOM_AT(file, line, func, strnlen(s, n));
+
+       return ptr;
+}
+
 #define xmalloc(size) (xmalloc1(__FILE__, __LINE__, __func__, (size)))
 #define xcalloc(nmemb, size) (xcalloc1(__FILE__, __LINE__, __func__, (nmemb), (size)))
 #define xstrdup(s) (xstrdup1(__FILE__, __LINE__, __func__, (s)))
+#define xstrndup(s, n) (xstrndup1(__FILE__, __LINE__, __func__, (s), (n)))
 
 static inline const char *xstrerror(intmax_t err)
 {
index 8c84dc8..872fbfb 100644 (file)
@@ -395,55 +395,61 @@ static void lipe_object_attrs_xattrs_fini(struct ls3_object_attrs *attrs)
        assert(lipe_list_empty(&attrs->loa_xattrs));
 }
 
-void lipe_object_attrs_reset(struct ls3_object_attrs *attrs)
+void lipe_object_attrs_reset(struct ls3_object_attrs *loa)
 {
-       struct lov_user_md *lum = attrs->loa_lum;
-       int lum_size = attrs->loa_lum_size;
-
-       lipe_object_attrs_links_fini(attrs);
-       lipe_object_attrs_paths_fini(attrs);
-       lipe_object_attrs_xattrs_fini(attrs);
-       memset(lum, 0, lum_size);
-       memset(attrs, 0, sizeof(*attrs));
-       attrs->loa_lum = lum;
-       attrs->loa_lum_size = lum_size;
-       LIPE_INIT_LIST_HEAD(&attrs->loa_links);
-       LIPE_INIT_LIST_HEAD(&attrs->loa_paths);
-       LIPE_INIT_LIST_HEAD(&attrs->loa_xattrs);
+       loa->loa_attr_bits = 0;
+       loa->loa_ino = 0;
+       memset(&loa->loa_file_fid, 0, sizeof(loa->loa_file_fid));
+       memset(&loa->loa_self_fid, 0, sizeof(loa->loa_self_fid));
+       lipe_object_attrs_links_fini(loa);
+       lipe_object_attrs_paths_fini(loa);
+       lipe_object_attrs_xattrs_fini(loa);
 }
 
-int lipe_object_attrs_init(struct ls3_object_attrs *attrs)
+int lipe_object_attrs_init(struct ls3_object_attrs *loa)
 {
-       memset(attrs, 0, sizeof(*attrs));
-       attrs->loa_lum_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT,
-                                              LOV_USER_MAGIC_V3);
+       memset(loa, 0, sizeof(*loa));
+       loa->loa_lum_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT,
+                                            LOV_USER_MAGIC_V3);
+       loa->loa_lum = xmalloc(loa->loa_lum_size);
 
-       attrs->loa_lum = xcalloc(1, attrs->loa_lum_size);
+       loa->loa_link_buf_size = XATTR_SIZE_MAX;
+       loa->loa_link_buf = xmalloc(loa->loa_link_buf_size);
 
-       LIPE_INIT_LIST_HEAD(&attrs->loa_links);
-       LIPE_INIT_LIST_HEAD(&attrs->loa_paths);
-       LIPE_INIT_LIST_HEAD(&attrs->loa_xattrs);
+       loa->loa_lmv_buf_size = XATTR_SIZE_MAX;
+       loa->loa_lmv_buf = xmalloc(loa->loa_lmv_buf_size);
+
+       LIPE_INIT_LIST_HEAD(&loa->loa_links);
+       LIPE_INIT_LIST_HEAD(&loa->loa_paths);
+       LIPE_INIT_LIST_HEAD(&loa->loa_xattrs);
 
        return 0;
 }
 
-void lipe_object_attrs_fini(struct ls3_object_attrs *attrs)
+void lipe_object_attrs_fini(struct ls3_object_attrs *loa)
 {
-       lipe_object_attrs_links_fini(attrs);
-       lipe_object_attrs_paths_fini(attrs);
-       lipe_object_attrs_xattrs_fini(attrs);
-       free(attrs->loa_lum);
+       lipe_object_attrs_links_fini(loa);
+       lipe_object_attrs_paths_fini(loa);
+       lipe_object_attrs_xattrs_fini(loa);
+       free(loa->loa_lum);
+       free(loa->loa_link_buf);
+       free(loa->loa_lmv_buf);
 }
 
-int lipe_object_attrs_add_link(struct ls3_object_attrs *attrs,
-                              const struct lu_fid *parent_fid,
-                              const char *name)
+static int lipe_object_attrs_add_link(struct ls3_object_attrs *attrs,
+                                     const struct lu_fid *parent_fid,
+                                     const char *name, int namelen)
 {
        struct lipe_link_entry *lle = NULL;
 
+       if (namelen <= 0) {
+               LS3_ERROR("invalid link xattr: namelen = %d\n", namelen);
+               return -EOVERFLOW; /* ? */
+       }
+
        lle = xcalloc(1, sizeof(*lle));
        lle->lle_parent_fid = *parent_fid;
-       lle->lle_name = xstrdup(name);
+       lle->lle_name = xstrndup(name, namelen);
 
        lipe_list_add_tail(&lle->lle_linkage, &attrs->loa_links);
 
@@ -486,6 +492,7 @@ int lipe_object_attrs_set_links(struct ls3_object_attrs *attrs,
        for (i = 0; i < reccount; i++) {
                unsigned int reclen = (lee->lee_reclen[0] << 8) | lee->lee_reclen[1];
                struct lu_fid parent_fid;
+               int namelen;
 
                pos += reclen;
                if (pos > len) {
@@ -496,7 +503,8 @@ int lipe_object_attrs_set_links(struct ls3_object_attrs *attrs,
 
                fid_be_to_cpu(&parent_fid, (const struct lu_fid *)&lee->lee_parent_fid);
 
-               rc = lipe_object_attrs_add_link(attrs, &parent_fid, lee->lee_name);
+               namelen = reclen - offsetof(struct link_ea_entry, lee_name[0]);
+               rc = lipe_object_attrs_add_link(attrs, &parent_fid, lee->lee_name, namelen);
                if (rc < 0)
                        return rc;
 
index c86147c..73bea61 100644 (file)
@@ -163,8 +163,10 @@ struct ls3_object_attrs {
        struct lu_fid            loa_self_fid;
        uint32_t                 loa_lma_compat;
        uint32_t                 loa_lma_incompat;
-       char                     loa_leh_buf[XATTR_SIZE_MAX];
-       char                     loa_lmv_buf[XATTR_SIZE_MAX];
+       void                    *loa_link_buf;
+       size_t                   loa_link_buf_size;
+       void                    *loa_lmv_buf;
+       size_t                   loa_lmv_buf_size;
        struct lov_user_md      *loa_lum;
        int                      loa_lum_size;
        struct hsm_user_state    loa_hsm_state;
@@ -208,9 +210,6 @@ ls3_object_attrs_to_json(struct ls3_instance *li,
 int lipe_object_attrs_init(struct ls3_object_attrs *attrs);
 void lipe_object_attrs_fini(struct ls3_object_attrs *attrs);
 void lipe_object_attrs_reset(struct ls3_object_attrs *attrs);
-int lipe_object_attrs_add_link(struct ls3_object_attrs *attrs,
-                              const struct lu_fid *parent_fid,
-                              const char *name);
 int lipe_object_attrs_set_links(struct ls3_object_attrs *attrs,
                                const void *link_xattr,
                                size_t link_xattr_size);
index b4fc411..dfa3abb 100644 (file)
@@ -113,6 +113,8 @@ static int ldiskfs_trusted_xattr_get(struct lipe_object *lo,
                return -EINVAL;
        }
 
+       assert(0 <= *value_size && *value_size <= buf_size);
+
        return 0;
 }
 
@@ -225,14 +227,17 @@ ldiskfs_read_attr_links(struct ls3_instance *li,
        if (rc < 0)
                return rc;
 
-       if (loa->loa_lma_incompat & LMAI_ORPHAN)
+       if (loa->loa_lma_incompat & LMAI_ORPHAN) {
+               /* Then no links and loa_links is empty so good. */
                goto out_ok;
+       }
 
-       rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LINK, loa->loa_leh_buf, sizeof(loa->loa_leh_buf), &size);
+       rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LINK,
+                                      loa->loa_link_buf, loa->loa_link_buf_size, &size);
        if (rc < 0)
                return rc;
 
-       rc = lipe_object_attrs_set_links(loa, loa->loa_leh_buf, size);
+       rc = lipe_object_attrs_set_links(loa, loa->loa_link_buf, size);
        if (rc) {
                LS3_ERROR_OBJ(lo, "cannot decode link xattr: rc = %d\n", rc);
                return rc;
@@ -407,12 +412,13 @@ static int ldiskfs_read_attr_lmv(struct ls3_instance *li,
        if (loa->loa_attr_bits & LS3_OBJECT_ATTR_LMV)
                return 0;
 
-       memset(loa->loa_lmv_buf, 0, sizeof(loa->loa_lmv_buf));
-
-       rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LMV, loa->loa_lmv_buf, sizeof(loa->loa_lmv_buf), &size);
+       rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LMV,
+                                      loa->loa_lmv_buf, loa->loa_lmv_buf_size, &size);
        if (rc < 0)
                return rc;
 
+       /* TODO Store and check size. */
+
        loa->loa_attr_bits |= LS3_OBJECT_ATTR_LMV;
 
        return 0;
@@ -430,10 +436,8 @@ static bool lo_is_dir_stripe(struct ls3_instance *li,
                return false;
 
        lmm = (union lmv_mds_md *)loa->loa_lmv_buf;
-       if (lmm->lmv_magic == LMV_MAGIC_STRIPE)
-               return true;
 
-       return false;
+       return lmm->lmv_magic == LMV_MAGIC_STRIPE;
 }
 
 static int ldiskfs_read_attr_hsm(struct ls3_instance *li,