[ovs-dev] [PATCH] ovsdb-idl: Add memory report function.

Ilya Maximets i.maximets at ovn.org
Thu Oct 14 11:46:14 UTC 2021


Added new function to return memory usage statistics for database
objects inside IDL.  Statistics similar to what ovsdb-server reports.
Not counting _Server database as it should be small, hence doesn't
worth adding extra code to the ovsdb-cs module.  Can be added later
if needed.

ovs-vswitchd is a user in OVS, but this API will be mostly useful for
OVN daemons.

Signed-off-by: Ilya Maximets <i.maximets at ovn.org>
---
 lib/ovsdb-idl.c   | 24 ++++++++++++++++++++++++
 lib/ovsdb-idl.h   |  3 +++
 vswitchd/bridge.c |  2 ++
 3 files changed, 29 insertions(+)

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 383a601f6..b22492d5e 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -42,6 +42,7 @@
 #include "openvswitch/poll-loop.h"
 #include "openvswitch/shash.h"
 #include "skiplist.h"
+#include "simap.h"
 #include "sset.h"
 #include "svec.h"
 #include "util.h"
@@ -465,6 +466,29 @@ ovsdb_idl_wait(struct ovsdb_idl *idl)
     ovsdb_cs_wait(idl->cs);
 }
 
+/* Returns memory usage statistics. */
+void
+ovsdb_idl_get_memory_usage(struct ovsdb_idl *idl, struct simap *usage)
+{
+    unsigned int cells = 0;
+
+    if (!idl) {
+        return;
+    }
+
+    for (size_t i = 0; i < idl->class_->n_tables; i++) {
+        struct ovsdb_idl_table *table = &idl->tables[i];
+        unsigned int n_columns = shash_count(&table->columns);
+        unsigned int n_rows = hmap_count(&table->rows);
+
+        cells += n_rows * n_columns;
+    }
+
+    simap_increase(usage, "idl-cells", cells);
+    simap_increase(usage, "idl-outstanding-txns",
+                   hmap_count(&idl->outstanding_txns));
+}
+
 /* Returns a "sequence number" that represents the state of 'idl'.  When
  * ovsdb_idl_run() changes the database, the sequence number changes.  The
  * initial fetch of the entire contents of the remote database is considered to
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 16c8d5f70..d00599616 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -55,6 +55,7 @@ struct ovsdb_idl_row;
 struct ovsdb_idl_column;
 struct ovsdb_idl_table;
 struct ovsdb_idl_table_class;
+struct simap;
 struct uuid;
 
 struct ovsdb_idl *ovsdb_idl_create(const char *remote,
@@ -73,6 +74,8 @@ void ovsdb_idl_set_leader_only(struct ovsdb_idl *, bool leader_only);
 void ovsdb_idl_run(struct ovsdb_idl *);
 void ovsdb_idl_wait(struct ovsdb_idl *);
 
+void ovsdb_idl_get_memory_usage(struct ovsdb_idl *, struct simap *usage);
+
 void ovsdb_idl_set_lock(struct ovsdb_idl *, const char *lock_name);
 bool ovsdb_idl_has_lock(const struct ovsdb_idl *);
 bool ovsdb_idl_is_lock_contended(const struct ovsdb_idl *);
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index c790a56ad..5223aa897 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -3423,6 +3423,8 @@ bridge_get_memory_usage(struct simap *usage)
     HMAP_FOR_EACH (br, node, &all_bridges) {
         ofproto_get_memory_usage(br->ofproto, usage);
     }
+
+    ovsdb_idl_get_memory_usage(idl, usage);
 }
 
 /* QoS unixctl user interface functions. */
-- 
2.31.1



More information about the dev mailing list