From patchwork Thu Oct 14 11:46:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1540870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVSKd63Z3z9sP7 for ; Thu, 14 Oct 2021 22:46:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 42B8160EA8; Thu, 14 Oct 2021 11:46:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HoX6e_q4iByu; Thu, 14 Oct 2021 11:46:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 69588606A6; Thu, 14 Oct 2021 11:46:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 44C7FC000F; Thu, 14 Oct 2021 11:46:23 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0F34DC000D for ; Thu, 14 Oct 2021 11:46:22 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id E3D2A4065A for ; Thu, 14 Oct 2021 11:46:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R9zGe5vT3cvA for ; Thu, 14 Oct 2021 11:46:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp4.osuosl.org (Postfix) with ESMTPS id E029040658 for ; Thu, 14 Oct 2021 11:46:20 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 6D7D7E0006; Thu, 14 Oct 2021 11:46:17 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Thu, 14 Oct 2021 13:46:14 +0200 Message-Id: <20211014114614.829400-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Cc: Ilya Maximets , Dumitru Ceara Subject: [ovs-dev] [PATCH] ovsdb-idl: Add memory report function. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 Acked-by: Han Zhou Acked-by: Dumitru Ceara --- 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. */