From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: roopa@nvidia.com, dsahern@gmail.com,
Nikolay Aleksandrov <nikolay@nvidia.com>
Subject: [PATCH iproute2-next] ip: nexthop: keep cache netlink socket open
Date: Mon, 4 Oct 2021 12:03:28 +0300 [thread overview]
Message-ID: <20211004090328.2329012-1-razor@blackwall.org> (raw)
In-Reply-To: <c036dc79-0d78-df8b-343b-fa9a913bd5cf@gmail.com>
From: Nikolay Aleksandrov <nikolay@nvidia.com>
Since we use the cache netlink socket for each nexthop we can keep it open
instead of opening and closing it on every add call. The socket is opened
once, on the first add call and then reused for the rest.
Suggested-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
I actually had this in my initial patchset, but switched it with the
open/close on each call. TBH, I don't recall why, perhaps to be the same
as the link cache. I don't see a reason not to keep the socket open.
I've re-run the stress test and the selftests, all look good.
ip/ipnexthop.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index b4d44a86429c..83a5540e771c 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -35,6 +35,7 @@ enum {
NLMSG_ALIGN(sizeof(struct nhmsg))))
static struct hlist_head nh_cache[NH_CACHE_SIZE];
+static struct rtnl_handle nh_cache_rth = { .fd = -1 };
static void usage(void) __attribute__((noreturn));
@@ -563,14 +564,15 @@ static int __ipnh_cache_parse_nlmsg(const struct nlmsghdr *n,
static struct nh_entry *ipnh_cache_add(__u32 nh_id)
{
- struct rtnl_handle cache_rth = { .fd = -1 };
struct nlmsghdr *answer = NULL;
struct nh_entry *nhe = NULL;
- if (rtnl_open(&cache_rth, 0) < 0)
+ if (nh_cache_rth.fd < 0 && rtnl_open(&nh_cache_rth, 0) < 0) {
+ nh_cache_rth.fd = -1;
goto out;
+ }
- if (__ipnh_get_id(&cache_rth, nh_id, &answer) < 0)
+ if (__ipnh_get_id(&nh_cache_rth, nh_id, &answer) < 0)
goto out;
nhe = malloc(sizeof(*nhe));
@@ -585,7 +587,6 @@ static struct nh_entry *ipnh_cache_add(__u32 nh_id)
out:
if (answer)
free(answer);
- rtnl_close(&cache_rth);
return nhe;
--
2.31.1
next prev parent reply other threads:[~2021-10-04 9:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-30 11:38 [PATCH iproute2-next 00/12] ip: nexthop: cache nexthops and print routes' nh info Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 01/12] ip: print_rta_if takes ifindex as device argument instead of attribute Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 02/12] ip: export print_rta_gateway version which outputs prepared gateway string Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 03/12] ip: nexthop: add resilient group structure Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 04/12] ip: nexthop: split print_nh_res_group into parse and print parts Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 05/12] ip: nexthop: add nh entry structure Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 06/12] ip: nexthop: parse attributes into nh entry structure before printing Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 07/12] ip: nexthop: factor out print_nexthop's nh entry printing Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 08/12] ip: nexthop: factor out ipnh_get_id rtnl talk into a helper Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 09/12] ip: nexthop: add cache helpers Nikolay Aleksandrov
2021-10-04 0:33 ` David Ahern
2021-10-04 9:03 ` Nikolay Aleksandrov [this message]
2021-10-05 14:35 ` [PATCH iproute2-next] ip: nexthop: keep cache netlink socket open David Ahern
2021-09-30 11:38 ` [PATCH iproute2-next 10/12] ip: nexthop: add a helper which retrieves and prints cached nh entry Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 11/12] ip: route: print and cache detailed nexthop information when requested Nikolay Aleksandrov
2021-09-30 11:38 ` [PATCH iproute2-next 12/12] ip: nexthop: add print_cache_nexthop which prints and manages the nh cache Nikolay Aleksandrov
2021-10-04 0:40 ` [PATCH iproute2-next 00/12] ip: nexthop: cache nexthops and print routes' nh info patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211004090328.2329012-1-razor@blackwall.org \
--to=razor@blackwall.org \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@nvidia.com \
--cc=roopa@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).