diff mbox series

[ovs-dev,2/5] ovsdb: transaction: Avoid diffs for different type references.

Message ID 20231218020249.3447973-3-i.maximets@ovn.org
State Accepted
Commit 6f11d9daad526bf51ee1538c7451a04572dc7a12
Delegated to: Ilya Maximets
Headers show
Series ovsdb: transaction: Bug Fixes + Reuse of column diffs. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Ilya Maximets Dec. 18, 2023, 2:02 a.m. UTC
While counting strong references current code first generates a
difference between old and new datums and only after it checks
the types of the atoms to be strong references.

Similar thing happens while assessing weak references.  First
the added/removed are generated and then we check for atoms
to be weak references.

Check the type first to avoid unnecessary work.  This change
doubles the performance of transactions that modify large sets
of references.

For example, with this change applied, initial read of OVSDB
file containing 136K transactions of large OVN port groups
and address sets on my laptop takes 24 seconds vs 43 seconds
without.

Fixes: 4dbff9f0a685 ("ovsdb: transaction: Incremental reassessment of weak refs.")
Fixes: b2712d026eae ("ovsdb: transaction: Use diffs for strong reference counting.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 lib/ovsdb-types.h   | 12 ++++++++++++
 ovsdb/transaction.c |  7 ++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Mike Pattrick Dec. 29, 2023, 2:36 p.m. UTC | #1
On Sun, Dec 17, 2023 at 9:03 PM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> While counting strong references current code first generates a
> difference between old and new datums and only after it checks
> the types of the atoms to be strong references.
>
> Similar thing happens while assessing weak references.  First
> the added/removed are generated and then we check for atoms
> to be weak references.
>
> Check the type first to avoid unnecessary work.  This change
> doubles the performance of transactions that modify large sets
> of references.
>
> For example, with this change applied, initial read of OVSDB
> file containing 136K transactions of large OVN port groups
> and address sets on my laptop takes 24 seconds vs 43 seconds
> without.
>
> Fixes: 4dbff9f0a685 ("ovsdb: transaction: Incremental reassessment of weak refs.")
> Fixes: b2712d026eae ("ovsdb: transaction: Use diffs for strong reference counting.")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Acked-by: Mike Pattrick <mkp@redhat.com>
diff mbox series

Patch

diff --git a/lib/ovsdb-types.h b/lib/ovsdb-types.h
index 9777efea3..688fe5633 100644
--- a/lib/ovsdb-types.h
+++ b/lib/ovsdb-types.h
@@ -238,6 +238,18 @@  static inline bool ovsdb_type_is_map(const struct ovsdb_type *type)
     return type->value.type != OVSDB_TYPE_VOID;
 }
 
+static inline bool ovsdb_type_has_strong_refs(const struct ovsdb_type *type)
+{
+    return ovsdb_base_type_is_strong_ref(&type->key)
+           || ovsdb_base_type_is_strong_ref(&type->value);
+}
+
+static inline bool ovsdb_type_has_weak_refs(const struct ovsdb_type *type)
+{
+    return ovsdb_base_type_is_weak_ref(&type->key)
+           || ovsdb_base_type_is_weak_ref(&type->value);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c
index f43533a8c..bbe4cddc1 100644
--- a/ovsdb/transaction.c
+++ b/ovsdb/transaction.c
@@ -322,7 +322,8 @@  update_row_ref_count(struct ovsdb_txn *txn, struct ovsdb_txn_row *r)
         const struct ovsdb_column *column = node->data;
         struct ovsdb_error *error;
 
-        if (bitmap_is_set(r->changed, column->index)) {
+        if (bitmap_is_set(r->changed, column->index)
+            && ovsdb_type_has_strong_refs(&column->type)) {
             if (r->old && !r->new) {
                 error = ovsdb_txn_adjust_row_refs(
                             txn, r->old, column,
@@ -718,6 +719,10 @@  assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row)
         unsigned int orig_n;
         bool zero = false;
 
+        if (!ovsdb_type_has_weak_refs(&column->type)) {
+            continue;
+        }
+
         orig_n = datum->n;
 
         /* Collecting all key-value pairs that references deleted rows. */