summaryrefslogtreecommitdiff
path: root/ovsdb/mutation.c
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 /ovsdb/mutation.c
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 'ovsdb/mutation.c')
-rw-r--r--ovsdb/mutation.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/ovsdb/mutation.c b/ovsdb/mutation.c
index 03d1c3499..cbc71bc49 100644
--- a/ovsdb/mutation.c
+++ b/ovsdb/mutation.c
@@ -287,6 +287,8 @@ mutate_scalar(const struct ovsdb_type *dst_type, struct ovsdb_datum *dst,
struct ovsdb_error *error;
unsigned int i;
+ ovsdb_datum_unshare(dst, dst_type);
+
if (base->type == OVSDB_TYPE_INTEGER) {
int64_t y = arg->integer;
for (i = 0; i < dst->n; i++) {
@@ -322,7 +324,7 @@ mutate_scalar(const struct ovsdb_type *dst_type, struct ovsdb_datum *dst,
}
}
- error = ovsdb_datum_sort(dst, dst_type->key.type);
+ error = ovsdb_datum_sort(dst, dst_type);
if (error) {
ovsdb_error_destroy(error);
return ovsdb_error("constraint violation",