summaryrefslogtreecommitdiff
path: root/lib/ovsdb-data.h
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2022-07-01 01:34:06 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-07-13 20:33:07 +0200
commit485ac63d10f8af22030c8b71de77094eee4f0672 (patch)
tree031b10b7142be06187882b40d33ddc1d0c8f9f2f /lib/ovsdb-data.h
parent02dabb21f24313cba7669d898b00d2d875eb513f (diff)
downloadopenvswitch-485ac63d10f8af22030c8b71de77094eee4f0672.tar.gz
ovsdb: Add lazy-copy support for ovsdb_datum objects.
Currently ovsdb-server is using shallow copies of some JSON objects by keeping a reference counter. JSON string objects are also used directly as ovsdb atoms in database rows to avoid extra copies. Taking this approach one step further ovsdb_datum objects can also be mostly deduplicated by postponing the copy until it actually needed. datum object itself contains a type and 2 pointers to data arrays. Adding a one more pointer to a reference counter we may create a shallow copy of the datum by simply copying type and pointers and increasing the reference counter. Before modifying the datum, special function needs to be called to perform an actual copy of the object, a.k.a. unshare it. Most of the datum modifications are performed inside the special functions in ovsdb-data.c, so that is not very hard to track. A few places like ovsdb-server.c and column mutations are accessing and changing the data directly, so a few extra unshare() calls has to be added there. This change doesn't affect the maximum memory consumption too much, because most of the copies are short-living. However, not actually performing these copies saves up to 40% of CPU time on operations with large sets. Reported-at: https://bugzilla.redhat.com/2069089 Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'lib/ovsdb-data.h')
-rw-r--r--lib/ovsdb-data.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h
index ba5d179a6..dcb620513 100644
--- a/lib/ovsdb-data.h
+++ b/lib/ovsdb-data.h
@@ -146,6 +146,8 @@ struct ovsdb_datum {
unsigned int n; /* Number of 'keys' and 'values'. */
union ovsdb_atom *keys; /* Each of the ovsdb_type's 'key_type'. */
union ovsdb_atom *values; /* Each of the ovsdb_type's 'value_type'. */
+ unsigned int *refcnt; /* Number of copies with the same
+ * 'keys' and 'values'. */
};
#define OVSDB_DATUM_INITIALIZER { 0, NULL, NULL }
@@ -155,22 +157,21 @@ void ovsdb_datum_init_default(struct ovsdb_datum *, const struct ovsdb_type *);
bool ovsdb_datum_is_default(const struct ovsdb_datum *,
const struct ovsdb_type *);
const struct ovsdb_datum *ovsdb_datum_default(const struct ovsdb_type *);
-void ovsdb_datum_clone(struct ovsdb_datum *, const struct ovsdb_datum *,
- const struct ovsdb_type *);
+void ovsdb_datum_clone(struct ovsdb_datum *, const struct ovsdb_datum *);
void ovsdb_datum_destroy(struct ovsdb_datum *, const struct ovsdb_type *);
+void ovsdb_datum_unshare(struct ovsdb_datum *, const struct ovsdb_type *);
void ovsdb_datum_swap(struct ovsdb_datum *, struct ovsdb_datum *);
/* Checking and maintaining invariants. */
struct ovsdb_error *ovsdb_datum_sort(struct ovsdb_datum *,
- enum ovsdb_atomic_type key_type)
+ const struct ovsdb_type *type)
OVS_WARN_UNUSED_RESULT;
void ovsdb_datum_sort_assert(struct ovsdb_datum *,
- enum ovsdb_atomic_type key_type);
+ const struct ovsdb_type *type);
size_t ovsdb_datum_sort_unique(struct ovsdb_datum *,
- enum ovsdb_atomic_type key_type,
- enum ovsdb_atomic_type value_type);
+ const struct ovsdb_type *type);
struct ovsdb_error *ovsdb_datum_check_constraints(
const struct ovsdb_datum *, const struct ovsdb_type *)