[ovs-dev] [PATCH 6/7] ovn-northd-ddlog: Intern nb::Logical_Switch.

Ben Pfaff blp at ovn.org
Thu Aug 12 15:53:57 UTC 2021


From: Ben Pfaff <blp at cs.stanford.edu>

With the benchmark at
https://mail.openvswitch.org/pipermail/ovs-dev/2021-July/385333.html,
this reduces memory consumption by 300 MB and elapsed time by a few
seconds.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 northd/ipam.dl       |  2 +-
 northd/lswitch.dl    | 36 ++++++++++++++++++------------------
 northd/multicast.dl  |  2 +-
 northd/ovn-nb.dlopts |  1 +
 northd/ovn_northd.dl | 16 ++++++++--------
 5 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/northd/ipam.dl b/northd/ipam.dl
index da71b2872..4665a28cb 100644
--- a/northd/ipam.dl
+++ b/northd/ipam.dl
@@ -187,7 +187,7 @@ SwitchIPv4ReservedAddresses(lswitch, addrs) :-
     var addrs = addr.group_by(lswitch).to_set().
 
 SwitchIPv4ReservedAddresses(lswitch_uuid, set_empty()) :-
-    nb::Logical_Switch(._uuid = lswitch_uuid),
+    &nb::Logical_Switch(._uuid = lswitch_uuid),
     not SwitchIPv4ReservedAddress(lswitch_uuid, _).
 
 /* Allocate dynamic IP addresses for ports that require them:
diff --git a/northd/lswitch.dl b/northd/lswitch.dl
index 7e7b62a4d..868ae115f 100644
--- a/northd/lswitch.dl
+++ b/northd/lswitch.dl
@@ -44,7 +44,7 @@ SwitchRouterPeerRef(lsp, None) :-
  * (Use LogicalSwitchPort instead, which guarantees uniqueness.) */
 relation LogicalSwitchPortCandidate(lsp_uuid: uuid, ls_uuid: uuid)
 LogicalSwitchPortCandidate(lsp_uuid, ls_uuid) :-
-    nb::Logical_Switch(._uuid = ls_uuid, .ports = ports),
+    &nb::Logical_Switch(._uuid = ls_uuid, .ports = ports),
     var lsp_uuid = FlatMap(ports).
 Warning[message] :-
     LogicalSwitchPortCandidate(lsp_uuid, ls_uuid),
@@ -74,7 +74,7 @@ LogicalSwitchPortWithUnknownAddress(ls_uuid, lsp_uuid) :-
 output relation LogicalSwitchHasUnknownPorts(ls: uuid, has_unknown: bool)
 LogicalSwitchHasUnknownPorts(ls, true) :- LogicalSwitchPortWithUnknownAddress(ls, _).
 LogicalSwitchHasUnknownPorts(ls, false) :-
-    nb::Logical_Switch(._uuid = ls),
+    &nb::Logical_Switch(._uuid = ls),
     not LogicalSwitchPortWithUnknownAddress(ls, _).
 
 /* PortStaticAddresses: static IP addresses associated with each Logical_Switch_Port */
@@ -101,11 +101,11 @@ PortInGroup(port, group) :-
 relation LogicalSwitchACL(ls: uuid, acl: uuid)
 
 LogicalSwitchACL(ls, acl) :-
-    nb::Logical_Switch(._uuid = ls, .acls = acls),
+    &nb::Logical_Switch(._uuid = ls, .acls = acls),
     var acl = FlatMap(acls).
 
 LogicalSwitchACL(ls, acl) :-
-    nb::Logical_Switch(._uuid = ls, .ports = ports),
+    &nb::Logical_Switch(._uuid = ls, .ports = ports),
     var port_id = FlatMap(ports),
     PortInGroup(port_id, group_id),
     nb::Port_Group(._uuid = group_id, .acls = acls),
@@ -125,7 +125,7 @@ LogicalSwitchHasStatefulACL(ls, true) :-
     LogicalSwitchStatefulACL(ls, _).
 
 LogicalSwitchHasStatefulACL(ls, false) :-
-    nb::Logical_Switch(._uuid = ls),
+    &nb::Logical_Switch(._uuid = ls),
     not LogicalSwitchStatefulACL(ls, _).
 
 // "Pitfalls of projections" in ddlog-new-feature.rst explains why this
@@ -136,7 +136,7 @@ LogicalSwitchHasACLs(ls, true) :-
     LogicalSwitchACL(ls, _).
 
 LogicalSwitchHasACLs(ls, false) :-
-    nb::Logical_Switch(._uuid = ls),
+    &nb::Logical_Switch(._uuid = ls),
     not LogicalSwitchACL(ls, _).
 
 /*
@@ -146,7 +146,7 @@ LogicalSwitchHasACLs(ls, false) :-
  */
 relation LogicalSwitchLocalnetPort0(ls_uuid: uuid, lsp: (uuid, string))
 LogicalSwitchLocalnetPort0(ls_uuid, (lsp_uuid, lsp.name)) :-
-    ls in nb::Logical_Switch(._uuid = ls_uuid),
+    ls in &nb::Logical_Switch(._uuid = ls_uuid),
     var lsp_uuid = FlatMap(ls.ports),
     lsp in &nb::Logical_Switch_Port(._uuid = lsp_uuid),
     lsp.__type == "localnet".
@@ -156,7 +156,7 @@ LogicalSwitchLocalnetPorts(ls_uuid, localnet_ports) :-
     LogicalSwitchLocalnetPort0(ls_uuid, lsp),
     var localnet_ports = lsp.group_by(ls_uuid).to_vec().
 LogicalSwitchLocalnetPorts(ls_uuid, vec_empty()) :-
-    ls in nb::Logical_Switch(),
+    ls in &nb::Logical_Switch(),
     var ls_uuid = ls._uuid,
     not LogicalSwitchLocalnetPort0(ls_uuid, _).
 
@@ -164,7 +164,7 @@ LogicalSwitchLocalnetPorts(ls_uuid, vec_empty()) :-
 relation LogicalSwitchDNS(ls_uuid: uuid, dns_uuid: uuid)
 
 LogicalSwitchDNS(ls._uuid, dns_uuid) :-
-    nb::Logical_Switch[ls],
+    &nb::Logical_Switch[ls],
     var dns_uuid = FlatMap(ls.dns_records),
     nb::DNS(._uuid = dns_uuid).
 
@@ -183,12 +183,12 @@ LogicalSwitchHasDNSRecords(ls, true) :-
     LogicalSwitchWithDNSRecords(ls).
 
 LogicalSwitchHasDNSRecords(ls, false) :-
-    nb::Logical_Switch(._uuid = ls),
+    &nb::Logical_Switch(._uuid = ls),
     not LogicalSwitchWithDNSRecords(ls).
 
 relation LogicalSwitchHasNonRouterPort0(ls: uuid)
 LogicalSwitchHasNonRouterPort0(ls_uuid) :-
-    ls in nb::Logical_Switch(._uuid = ls_uuid),
+    ls in &nb::Logical_Switch(._uuid = ls_uuid),
     var lsp_uuid = FlatMap(ls.ports),
     lsp in &nb::Logical_Switch_Port(._uuid = lsp_uuid),
     lsp.__type != "router".
@@ -199,7 +199,7 @@ output relation LogicalSwitchHasNonRouterPort(ls: uuid, has_non_router_port: boo
 LogicalSwitchHasNonRouterPort(ls, true) :-
     LogicalSwitchHasNonRouterPort0(ls).
 LogicalSwitchHasNonRouterPort(ls, false) :-
-    nb::Logical_Switch(._uuid = ls),
+    &nb::Logical_Switch(._uuid = ls),
     not LogicalSwitchHasNonRouterPort0(ls).
 
 // LogicalSwitchCopp maps from each LS to its collection of Copp meters,
@@ -207,12 +207,12 @@ LogicalSwitchHasNonRouterPort(ls, false) :-
 relation LogicalSwitchCopp(ls: uuid, meters: Map<string,string>)
 LogicalSwitchCopp(ls, meters) :- LogicalSwitchCopp0(ls, meters).
 LogicalSwitchCopp(ls, map_empty()) :-
-    nb::Logical_Switch(._uuid = ls),
+    &nb::Logical_Switch(._uuid = ls),
     not LogicalSwitchCopp0(ls, _).
 
 relation LogicalSwitchCopp0(ls: uuid, meters: Map<string,string>)
 LogicalSwitchCopp0(ls, meters) :-
-    nb::Logical_Switch(._uuid = ls, .copp = Some{copp_uuid}),
+    &nb::Logical_Switch(._uuid = ls, .copp = Some{copp_uuid}),
     nb::Copp(._uuid = copp_uuid, .meters = meters),
     var entry = FlatMap(meters),
     (var copp_id, var meter_name) = entry,
@@ -280,7 +280,7 @@ Switch[Switch{
            .copp              = copp,
            .is_vlan_transparent = is_vlan_transparent
        }.intern()] :-
-    nb::Logical_Switch[ls],
+    &nb::Logical_Switch[ls],
     LogicalSwitchHasStatefulACL(ls._uuid, has_stateful_acl),
     LogicalSwitchHasACLs(ls._uuid, has_acls),
     LogicalSwitchHasLBVIP(ls._uuid, has_lb_vip),
@@ -320,7 +320,7 @@ Switch[Switch{
 /* SwitchLB: many-to-many relation between logical switches and nb::LB */
 relation SwitchLB(sw_uuid: uuid, lb: Intern<nb::Load_Balancer>)
 SwitchLB(sw_uuid, lb) :-
-    nb::Logical_Switch(._uuid = sw_uuid, .load_balancer = lb_ids),
+    &nb::Logical_Switch(._uuid = sw_uuid, .load_balancer = lb_ids),
     var lb_id = FlatMap(lb_ids),
     lb in &nb::Load_Balancer(._uuid = lb_id).
 
@@ -337,7 +337,7 @@ output relation LogicalSwitchHasLBVIP(sw_uuid: uuid, has_lb_vip: bool)
 LogicalSwitchHasLBVIP(sw_uuid, true) :-
     SwitchLBVIP(.sw_uuid = sw_uuid).
 LogicalSwitchHasLBVIP(sw_uuid, false) :-
-    nb::Logical_Switch(._uuid = sw_uuid),
+    &nb::Logical_Switch(._uuid = sw_uuid),
     not SwitchLBVIP(.sw_uuid = sw_uuid).
 
 /* Load balancer virtual IPs.
@@ -520,7 +520,7 @@ relation SwitchQoS(sw: Intern<Switch>, qos: Intern<nb::QoS>)
 
 SwitchQoS(sw, qos) :-
     sw in &Switch(),
-    nb::Logical_Switch(._uuid = sw._uuid, .qos_rules = qos_rules),
+    &nb::Logical_Switch(._uuid = sw._uuid, .qos_rules = qos_rules),
     var qos_rule = FlatMap(qos_rules),
     qos in &nb::QoS(._uuid = qos_rule).
 
diff --git a/northd/multicast.dl b/northd/multicast.dl
index dfd58f477..ef365b408 100644
--- a/northd/multicast.dl
+++ b/northd/multicast.dl
@@ -64,7 +64,7 @@ McastSwitchCfg[McastSwitchCfg {
                    .query_interval = query_interval,
                    .query_max_resp = query_max_resp
                }.intern()] :-
-    nb::Logical_Switch(._uuid        = ls_uuid,
+    &nb::Logical_Switch(._uuid        = ls_uuid,
                       .other_config = other_config),
     var idle_timeout = other_config.get_int_def("mcast_idle_timeout", mCAST_DEFAULT_IDLE_TIMEOUT_S())
                                    .clamp(mCAST_IDLE_TIMEOUT_S_RANGE()),
diff --git a/northd/ovn-nb.dlopts b/northd/ovn-nb.dlopts
index 402a44636..c22130004 100644
--- a/northd/ovn-nb.dlopts
+++ b/northd/ovn-nb.dlopts
@@ -17,6 +17,7 @@
 --intern-table ACL
 --intern-table QoS
 --intern-table Load_Balancer
+--intern-table Logical_Switch
 --intern-table Load_Balancer_Health_Check
 --intern-table Meter
 --intern-table NAT
diff --git a/northd/ovn_northd.dl b/northd/ovn_northd.dl
index 38b97aa6b..dadf33ab6 100644
--- a/northd/ovn_northd.dl
+++ b/northd/ovn_northd.dl
@@ -59,7 +59,7 @@ relation OutProxy_Datapath_Binding (
 
 /* Datapath_Binding table */
 OutProxy_Datapath_Binding(uuid, external_ids) :-
-    nb::Logical_Switch(._uuid = uuid, .name = name, .external_ids = ids,
+    &nb::Logical_Switch(._uuid = uuid, .name = name, .external_ids = ids,
                        .other_config = other_config),
     var uuid_str = uuid2str(uuid),
     var external_ids = {
@@ -1753,7 +1753,7 @@ Flow(.logical_datapath = sw._uuid,
      .io_port          = None,
      .controller_meter = None) :-
     sw in &Switch(),
-    nb::Logical_Switch(._uuid = sw._uuid, .forwarding_groups = forwarding_groups),
+    &nb::Logical_Switch(._uuid = sw._uuid, .forwarding_groups = forwarding_groups),
     var fg_uuid = FlatMap(forwarding_groups),
     fg in nb::Forwarding_Group(._uuid = fg_uuid),
     not fg.child_port.is_empty(),
@@ -1785,7 +1785,7 @@ Flow(.logical_datapath = sw._uuid,
      .io_port          = None,
      .controller_meter = None) :-
     sw in &Switch(),
-    nb::Logical_Switch(._uuid = sw._uuid, .forwarding_groups = forwarding_groups),
+    &nb::Logical_Switch(._uuid = sw._uuid, .forwarding_groups = forwarding_groups),
     var fg_uuid = FlatMap(forwarding_groups),
     fg in nb::Forwarding_Group(._uuid = fg_uuid),
     not fg.child_port.is_empty(),
@@ -3692,7 +3692,7 @@ for (SwitchPortIPv6Address(.port = &SwitchPort{.lsp = lsp, .json_name = json_nam
 
 /* Ingress table ARP_ND_RSP: ARP/ND responder, by default goto next.
  * (priority 0)*/
-for (ls in nb::Logical_Switch) {
+for (ls in &nb::Logical_Switch) {
     Flow(.logical_datapath = ls._uuid,
          .stage            = s_SWITCH_IN_ARP_ND_RSP(),
          .priority         = 0,
@@ -4074,7 +4074,7 @@ for (LogicalSwitchHasDNSRecords(ls, true))
 
  * Ingress table EXTERNAL_PORT - External port handling, by default goto next.
  * (priority 0). */
-for (ls in nb::Logical_Switch) {
+for (ls in &nb::Logical_Switch) {
     Flow(.logical_datapath = ls._uuid,
          .stage            = s_SWITCH_IN_DHCP_OPTIONS(),
          .priority         = 0,
@@ -4364,7 +4364,7 @@ Flow(.logical_datapath = sp.sw._uuid,
 
 /* Ingress table L2_LKUP: Destination lookup, broadcast and multicast handling
  * (priority 100). */
-for (ls in nb::Logical_Switch) {
+for (ls in &nb::Logical_Switch) {
     var mc_flood = json_string_escape(mC_FLOOD().0) in
     Flow(.logical_datapath = ls._uuid,
          .stage            = s_SWITCH_IN_L2_LKUP(),
@@ -8255,7 +8255,7 @@ function get_dp_tunkey(map: Map<string,string>, key: string): Option<integer> {
 // Tunnel keys requested by datapaths.
 relation RequestedTunKey(datapath: uuid, tunkey: integer)
 RequestedTunKey(uuid, tunkey) :-
-    ls in nb::Logical_Switch(._uuid = uuid),
+    ls in &nb::Logical_Switch(._uuid = uuid),
     Some{var tunkey} = get_dp_tunkey(ls.other_config, "requested-tnl-key").
 RequestedTunKey(uuid, tunkey) :-
     lr in nb::Logical_Router(._uuid = uuid),
@@ -8653,7 +8653,7 @@ sb::Out_Load_Balancer(._uuid = lb._uuid,
                       .datapaths = datapaths,
                       .external_ids = ["lb_id" -> uuid2str(lb_uuid)],
                       .options = options) :-
-    nb in nb::Logical_Switch(._uuid = ls_uuid, .load_balancer = lb_uuids),
+    nb in &nb::Logical_Switch(._uuid = ls_uuid, .load_balancer = lb_uuids),
     var lb_uuid = FlatMap(lb_uuids),
     var datapaths = ls_uuid.group_by(lb_uuid).to_set(),
     lb in &nb::Load_Balancer(._uuid = lb_uuid),
-- 
2.31.1



More information about the dev mailing list