Date: Sat, 23 May 2020 12:15:47 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361415 - in head/sys/net: . route Message-ID: <202005231215.04NCFlRN035787@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Sat May 23 12:15:47 2020 New Revision: 361415 URL: https://svnweb.freebsd.org/changeset/base/361415 Log: Remove refcounting from rtentry. After making rtentry reclamation backed by epoch(9) in r361409, there is no reason in keeping reference counting code. Differential Revision: https://reviews.freebsd.org/D24867 Modified: head/sys/net/route.c head/sys/net/route/route_var.h Modified: head/sys/net/route.c ============================================================================== --- head/sys/net/route.c Sat May 23 12:00:46 2020 (r361414) +++ head/sys/net/route.c Sat May 23 12:15:47 2020 (r361415) @@ -439,39 +439,8 @@ rtfree(struct rtentry *rt) RT_LOCK_ASSERT(rt); - /* - * The callers should use RTFREE_LOCKED() or RTFREE(), so - * we should come here exactly with the last reference. - */ - RT_REMREF(rt); - if (rt->rt_refcnt > 0) { - log(LOG_DEBUG, "%s: %p has %d refs\n", __func__, rt, rt->rt_refcnt); - goto done; - } - - /* - * If we are no longer "up" (and ref == 0) - * then we can free the resources associated - * with the route. - */ - if ((rt->rt_flags & RTF_UP) == 0) { - if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT)) - panic("rtfree 2"); -#ifdef DIAGNOSTIC - if (rt->rt_refcnt < 0) { - printf("rtfree: %p not freed (neg refs)\n", rt); - goto done; - } -#endif - epoch_call(net_epoch_preempt, destroy_rtentry_epoch, - &rt->rt_epoch_ctx); - - /* - * FALLTHROUGH to RT_UNLOCK() so the reporting functions - * have consistent behaviour of operating on unlocked entry. - */ - } -done: + epoch_call(net_epoch_preempt, destroy_rtentry_epoch, + &rt->rt_epoch_ctx); RT_UNLOCK(rt); } @@ -958,7 +927,7 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t * if (report) rt_routemsg(RTM_DELETE, rt, rt->rt_nhop->nh_ifp, 0, fibnum); - RTFREE_LOCKED(rt); + rtfree(rt); } } @@ -1114,7 +1083,6 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo rt = RNTORT(rn); RT_LOCK(rt); - RT_ADDREF(rt); rt->rt_flags &= ~RTF_UP; *perror = 0; @@ -1569,8 +1537,10 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in } RIB_WUNLOCK(rnh); - if (rt_old != NULL) - RT_UNLOCK(rt_old); + if (rt_old != NULL) { + rt_notifydelete(rt_old, info); + rtfree(rt_old); + } /* * If it still failed to go into the tree, @@ -1582,11 +1552,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in return (EEXIST); } - if (rt_old != NULL) { - rt_notifydelete(rt_old, info); - RTFREE(rt_old); - } - /* * If this protocol has something to add to this then * allow it to do that as well. @@ -1639,7 +1604,7 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in if (ret_nrt) *ret_nrt = rt; - RTFREE_LOCKED(rt); + rtfree(rt); return (0); } Modified: head/sys/net/route/route_var.h ============================================================================== --- head/sys/net/route/route_var.h Sat May 23 12:00:46 2020 (r361414) +++ head/sys/net/route/route_var.h Sat May 23 12:15:47 2020 (r361415) @@ -143,7 +143,6 @@ struct rtentry { }; int rt_flags; /* up/down?, host/net */ - int rt_refcnt; /* # held references */ u_long rt_weight; /* absolute weight */ u_long rt_expire; /* lifetime for route, e.g. redirect */ #define rt_endzero rt_mtx @@ -161,36 +160,6 @@ struct rtentry { #define RT_UNLOCK_COND(_rt) do { \ if (mtx_owned(&(_rt)->rt_mtx)) \ mtx_unlock(&(_rt)->rt_mtx); \ -} while (0) - -#define RT_ADDREF(_rt) do { \ - RT_LOCK_ASSERT(_rt); \ - KASSERT((_rt)->rt_refcnt >= 0, \ - ("negative refcnt %d", (_rt)->rt_refcnt)); \ - (_rt)->rt_refcnt++; \ -} while (0) - -#define RT_REMREF(_rt) do { \ - RT_LOCK_ASSERT(_rt); \ - KASSERT((_rt)->rt_refcnt > 0, \ - ("bogus refcnt %d", (_rt)->rt_refcnt)); \ - (_rt)->rt_refcnt--; \ -} while (0) - -#define RTFREE_LOCKED(_rt) do { \ - if ((_rt)->rt_refcnt <= 1) \ - rtfree(_rt); \ - else { \ - RT_REMREF(_rt); \ - RT_UNLOCK(_rt); \ - } \ - /* guard against invalid refs */ \ - _rt = 0; \ -} while (0) - -#define RTFREE(_rt) do { \ - RT_LOCK(_rt); \ - RTFREE_LOCKED(_rt); \ } while (0) /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005231215.04NCFlRN035787>