From nobody Fri Oct 08 07:59:18 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B391712D9CB7; Fri, 8 Oct 2021 07:59:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HQgZG4dL2z4qYj; Fri, 8 Oct 2021 07:59:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7AA352365B; Fri, 8 Oct 2021 07:59:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1987xIm3046582; Fri, 8 Oct 2021 07:59:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1987xIrF046581; Fri, 8 Oct 2021 07:59:18 GMT (envelope-from git) Date: Fri, 8 Oct 2021 07:59:18 GMT Message-Id: <202110080759.1987xIrF046581@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 7e64580b5f47 - main - routing: Use the same index space for both nexthop and nexthop groups. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7e64580b5f477ba4523799f26d1178f611f5d6cb Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=7e64580b5f477ba4523799f26d1178f611f5d6cb commit 7e64580b5f477ba4523799f26d1178f611f5d6cb Author: Alexander V. Chernikov AuthorDate: 2021-10-06 19:07:54 +0000 Commit: Alexander V. Chernikov CommitDate: 2021-10-08 07:58:55 +0000 routing: Use the same index space for both nexthop and nexthop groups. This simplifies userland object handling along with kernel-level nexthop handling in fib algo framework. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D32342 --- sys/net/route/fib_algo.c | 6 ++---- sys/net/route/nhgrp.c | 31 +++++++------------------------ sys/net/route/nhop_var.h | 1 - 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c index 4bae9e5edd6c..54b0464711a5 100644 --- a/sys/net/route/fib_algo.c +++ b/sys/net/route/fib_algo.c @@ -1764,12 +1764,10 @@ get_nhop_idx(struct nhop_object *nh) { #ifdef ROUTE_MPATH if (NH_IS_NHGRP(nh)) - return (nhgrp_get_idx((struct nhgrp_object *)nh) * 2 - 1); + return (nhgrp_get_idx((struct nhgrp_object *)nh)); else - return (nhop_get_idx(nh) * 2); -#else - return (nhop_get_idx(nh)); #endif + return (nhop_get_idx(nh)); } uint32_t diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c index 982ff2a72f15..07abdf480101 100644 --- a/sys/net/route/nhgrp.c +++ b/sys/net/route/nhgrp.c @@ -159,9 +159,9 @@ link_nhgrp(struct nh_control *ctl, struct nhgrp_priv *grp_priv) NHOPS_WLOCK(ctl); /* Check if we need to resize hash and index */ new_num_buckets = CHT_SLIST_GET_RESIZE_BUCKETS(&ctl->gr_head); - new_num_items = bitmask_get_resize_items(&ctl->gr_idx_head); + new_num_items = bitmask_get_resize_items(&ctl->nh_idx_head); - if (bitmask_alloc_idx(&ctl->gr_idx_head, &idx) != 0) { + if (bitmask_alloc_idx(&ctl->nh_idx_head, &idx) != 0) { NHOPS_WUNLOCK(ctl); DPRINTF("Unable to allocate mpath index"); consider_resize(ctl, new_num_buckets, new_num_items); @@ -196,7 +196,7 @@ unlink_nhgrp(struct nh_control *ctl, struct nhgrp_priv *key) } idx = nhg_priv_ret->nhg_idx; - ret = bitmask_free_idx(&ctl->gr_idx_head, idx); + ret = bitmask_free_idx(&ctl->nh_idx_head, idx); nhg_priv_ret->nhg_idx = 0; nhg_priv_ret->nh_control = NULL; @@ -243,8 +243,8 @@ consider_resize(struct nh_control *ctl, uint32_t new_gr_bucket, uint32_t new_idx CHT_SLIST_RESIZE(&ctl->gr_head, mpath, gr_ptr, new_gr_bucket); } if (gr_idx_ptr != NULL) { - if (bitmask_copy(&ctl->gr_idx_head, gr_idx_ptr, new_idx_items) == 0) - bitmask_swap(&ctl->gr_idx_head, gr_idx_ptr, new_idx_items, &old_idx_ptr); + if (bitmask_copy(&ctl->nh_idx_head, gr_idx_ptr, new_idx_items) == 0) + bitmask_swap(&ctl->nh_idx_head, gr_idx_ptr, new_idx_items, &old_idx_ptr); } NHOPS_WUNLOCK(ctl); @@ -261,8 +261,8 @@ bool nhgrp_ctl_alloc_default(struct nh_control *ctl, int malloc_flags) { size_t alloc_size; - uint32_t num_buckets, num_items; - void *cht_ptr, *mask_ptr; + uint32_t num_buckets; + void *cht_ptr; malloc_flags = (malloc_flags & (M_NOWAIT | M_WAITOK)) | M_ZERO; @@ -275,29 +275,16 @@ nhgrp_ctl_alloc_default(struct nh_control *ctl, int malloc_flags) return (false); } - /* - * Allocate nexthop index bitmask. - */ - num_items = 128; - mask_ptr = malloc(bitmask_get_size(num_items), M_NHOP, malloc_flags); - if (mask_ptr == NULL) { - DPRINTF("mpath bitmask init failed"); - free(cht_ptr, M_NHOP); - return (false); - } - NHOPS_WLOCK(ctl); if (ctl->gr_head.hash_size == 0) { /* Init hash and bitmask */ CHT_SLIST_INIT(&ctl->gr_head, cht_ptr, num_buckets); - bitmask_init(&ctl->gr_idx_head, mask_ptr, num_items); NHOPS_WUNLOCK(ctl); } else { /* Other thread has already initiliazed hash/bitmask */ NHOPS_WUNLOCK(ctl); free(cht_ptr, M_NHOP); - free(mask_ptr, M_NHOP); } DPRINTF("mpath init done for fib/af %d/%d", ctl->rh->rib_fibnum, @@ -315,18 +302,14 @@ nhgrp_ctl_init(struct nh_control *ctl) * routes will not be necessarily used. */ CHT_SLIST_INIT(&ctl->gr_head, NULL, 0); - bitmask_init(&ctl->gr_idx_head, NULL, 0); return (0); } void nhgrp_ctl_free(struct nh_control *ctl) { - if (ctl->gr_head.ptr != NULL) free(ctl->gr_head.ptr, M_NHOP); - if (ctl->gr_idx_head.idx != NULL) - free(ctl->gr_idx_head.idx, M_NHOP); } void diff --git a/sys/net/route/nhop_var.h b/sys/net/route/nhop_var.h index 4ce82dd4a968..76984df0497f 100644 --- a/sys/net/route/nhop_var.h +++ b/sys/net/route/nhop_var.h @@ -57,7 +57,6 @@ struct nh_control { struct nhops_head nh_head; /* hash table head */ struct bitmask_head nh_idx_head; /* nhop index head */ struct nhgroups_head gr_head; /* nhgrp hash table head */ - struct bitmask_head gr_idx_head; /* nhgrp index head */ struct rwlock ctl_lock; /* overall ctl lock */ struct rib_head *ctl_rh; /* pointer back to rnh */ struct epoch_context ctl_epoch_ctx; /* epoch ctl helper */