acl: perform the ACL-as-a-service user registrations in global heap 95/20295/2
authorAndrew Yourtchenko <ayourtch@gmail.com>
Mon, 24 Jun 2019 15:13:06 +0000 (15:13 +0000)
committerDave Barach <openvpp@barachs.net>
Tue, 9 Jul 2019 21:27:59 +0000 (21:27 +0000)
Some users tend to call registration routine long before they need
that service - which triggers an immediate initialization of
the ACL heap, which is rather big. This commit defers this process
by keeping the registrations in the global heap.

Change-Id: I5825871bd836851942b55184b6ee2657c7a9cc33
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
src/plugins/acl/acl.c
src/plugins/acl/lookup_context.c

index 56a1bfa..9ebb349 100644 (file)
@@ -789,10 +789,6 @@ acl_interface_set_inout_acl_list (acl_main_t * am, u32 sw_if_index,
       u32 lc_index = (*pinout_lc_index_by_sw_if_index)[sw_if_index];
       if (~0 == lc_index)
        {
-         if (~0 == am->interface_acl_user_id)
-           am->interface_acl_user_id =
-             acl_plugin.register_user_module ("interface ACL", "sw_if_index",
-                                              "is_input");
          lc_index =
            acl_plugin.get_lookup_context_index (am->interface_acl_user_id,
                                                 sw_if_index, is_input);
@@ -3659,7 +3655,9 @@ acl_init (vlib_main_t * vm)
   /* Set the default threshold */
   am->tuple_merge_split_threshold = TM_SPLIT_THRESHOLD;
 
-  am->interface_acl_user_id = ~0;      /* defer till the first use */
+  am->interface_acl_user_id =
+    acl_plugin.register_user_module ("interface ACL", "sw_if_index",
+                                    "is_input");
 
   return error;
 }
index 904e8ad..28fa9ee 100644 (file)
@@ -77,9 +77,13 @@ static int acl_lc_index_valid(acl_main_t *am, u32 lc_index)
 static u32 acl_plugin_register_user_module (char *user_module_name, char *val1_label, char *val2_label)
 {
   acl_main_t *am = &acl_main;
-  void *oldheap = acl_plugin_set_heap();
+  /*
+   * Because folks like to call this early on,
+   * use the global heap, so as to avoid
+   * initializing the main ACL heap before
+   * they start using ACLs.
+   */
   u32 user_id = get_acl_user_id(am, user_module_name, val1_label, val2_label);
-  clib_mem_set_heap (oldheap);
   return user_id;
 }
 
@@ -99,8 +103,11 @@ static int acl_plugin_get_lookup_context_index (u32 acl_user_id, u32 val1, u32 v
   if (!acl_user_id_valid(am, acl_user_id))
     return VNET_API_ERROR_INVALID_REGISTRATION;
 
-  void *oldheap = acl_plugin_set_heap ();
-
+  /*
+   * The lookup context index allocation is
+   * an operation done within the global heap,
+   * so no heap switching necessary.
+   */
 
   pool_get(am->acl_lookup_contexts, acontext);
   acontext->acl_indices = 0;
@@ -111,7 +118,6 @@ static int acl_plugin_get_lookup_context_index (u32 acl_user_id, u32 val1, u32 v
   u32 new_context_id = acontext - am->acl_lookup_contexts;
   vec_add1(am->acl_users[acl_user_id].lookup_contexts, new_context_id);
 
-  clib_mem_set_heap (oldheap);
   return new_context_id;
 }