From: Matthew Wilcox <willy@infradead.org>
To: netdev@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Subject: [PATCH 13/38] ppp: Convert units_idr to XArray
Date: Tue, 20 Aug 2019 15:32:34 -0700 [thread overview]
Message-ID: <20190820223259.22348-14-willy@infradead.org> (raw)
In-Reply-To: <20190820223259.22348-1-willy@infradead.org>
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Remove the unit_* wrappers around the IDR code; using the XArray API
directly is more clear. I suspect the all_ppp_mutex could probably be
removed, but it probably isn't a scalability bottleneck.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
drivers/net/ppp/ppp_generic.c | 73 ++++++++---------------------------
1 file changed, 16 insertions(+), 57 deletions(-)
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index a30e41a56085..1a12f30de30f 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -24,7 +24,6 @@
#include <linux/kmod.h>
#include <linux/init.h>
#include <linux/list.h>
-#include <linux/idr.h>
#include <linux/netdevice.h>
#include <linux/poll.h>
#include <linux/ppp_defs.h>
@@ -48,6 +47,7 @@
#include <net/slhc_vj.h>
#include <linux/atomic.h>
#include <linux/refcount.h>
+#include <linux/xarray.h>
#include <linux/nsproxy.h>
#include <net/net_namespace.h>
@@ -206,7 +206,7 @@ static atomic_t channel_count = ATOMIC_INIT(0);
static unsigned int ppp_net_id __read_mostly;
struct ppp_net {
/* units to ppp mapping */
- struct idr units_idr;
+ struct xarray units;
/*
* all_ppp_mutex protects the units_idr mapping.
@@ -283,10 +283,6 @@ static struct channel *ppp_find_channel(struct ppp_net *pn, int unit);
static int ppp_connect_channel(struct channel *pch, int unit);
static int ppp_disconnect_channel(struct channel *pch);
static void ppp_destroy_channel(struct channel *pch);
-static int unit_get(struct idr *p, void *ptr);
-static int unit_set(struct idr *p, void *ptr, int n);
-static void unit_put(struct idr *p, int n);
-static void *unit_find(struct idr *p, int n);
static void ppp_setup(struct net_device *dev);
static const struct net_device_ops ppp_netdev_ops;
@@ -904,7 +900,7 @@ static __net_init int ppp_init_net(struct net *net)
{
struct ppp_net *pn = net_generic(net, ppp_net_id);
- idr_init(&pn->units_idr);
+ xa_init_flags(&pn->units, XA_FLAGS_ALLOC);
mutex_init(&pn->all_ppp_mutex);
INIT_LIST_HEAD(&pn->all_channels);
@@ -922,7 +918,7 @@ static __net_exit void ppp_exit_net(struct net *net)
struct net_device *aux;
struct ppp *ppp;
LIST_HEAD(list);
- int id;
+ unsigned long id;
rtnl_lock();
for_each_netdev_safe(net, dev, aux) {
@@ -930,7 +926,7 @@ static __net_exit void ppp_exit_net(struct net *net)
unregister_netdevice_queue(dev, &list);
}
- idr_for_each_entry(&pn->units_idr, ppp, id)
+ xa_for_each(&pn->units, id, ppp)
/* Skip devices already unregistered by previous loop */
if (!net_eq(dev_net(ppp->dev), net))
unregister_netdevice_queue(ppp->dev, &list);
@@ -939,7 +935,6 @@ static __net_exit void ppp_exit_net(struct net *net)
rtnl_unlock();
mutex_destroy(&pn->all_ppp_mutex);
- idr_destroy(&pn->units_idr);
WARN_ON_ONCE(!list_empty(&pn->all_channels));
WARN_ON_ONCE(!list_empty(&pn->new_channels));
}
@@ -959,27 +954,25 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
mutex_lock(&pn->all_ppp_mutex);
if (unit < 0) {
- ret = unit_get(&pn->units_idr, ppp);
+ ret = xa_alloc(&pn->units, &ppp->file.index, ppp,
+ xa_limit_31b, GFP_KERNEL);
if (ret < 0)
goto err;
} else {
- /* Caller asked for a specific unit number. Fail with -EEXIST
+ /*
+ * Caller asked for a specific unit number. Fail with -EEXIST
* if unavailable. For backward compatibility, return -EEXIST
- * too if idr allocation fails; this makes pppd retry without
- * requesting a specific unit number.
+ * too if memory allocation fails; this makes pppd retry
+ * without requesting a specific unit number.
*/
- if (unit_find(&pn->units_idr, unit)) {
- ret = -EEXIST;
- goto err;
- }
- ret = unit_set(&pn->units_idr, ppp, unit);
+ ret = xa_insert(&pn->units, unit, ppp, GFP_KERNEL);
if (ret < 0) {
/* Rewrite error for backward compatibility */
ret = -EEXIST;
goto err;
}
+ ppp->file.index = unit;
}
- ppp->file.index = ret;
if (!ifname_is_set)
snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ppp->file.index);
@@ -996,7 +989,7 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
err_unit:
mutex_lock(&pn->all_ppp_mutex);
- unit_put(&pn->units_idr, ppp->file.index);
+ xa_erase(&pn->units, ppp->file.index);
err:
mutex_unlock(&pn->all_ppp_mutex);
@@ -1346,7 +1339,7 @@ static void ppp_dev_uninit(struct net_device *dev)
ppp_unlock(ppp);
mutex_lock(&pn->all_ppp_mutex);
- unit_put(&pn->units_idr, ppp->file.index);
+ xa_erase(&pn->units, ppp->file.index);
mutex_unlock(&pn->all_ppp_mutex);
ppp->owner = NULL;
@@ -3136,7 +3129,7 @@ static void ppp_destroy_interface(struct ppp *ppp)
static struct ppp *
ppp_find_unit(struct ppp_net *pn, int unit)
{
- return unit_find(&pn->units_idr, unit);
+ return xa_load(&pn->units, unit);
}
/*
@@ -3277,40 +3270,6 @@ static void __exit ppp_cleanup(void)
unregister_pernet_device(&ppp_net_ops);
}
-/*
- * Units handling. Caller must protect concurrent access
- * by holding all_ppp_mutex
- */
-
-/* associate pointer with specified number */
-static int unit_set(struct idr *p, void *ptr, int n)
-{
- int unit;
-
- unit = idr_alloc(p, ptr, n, n + 1, GFP_KERNEL);
- if (unit == -ENOSPC)
- unit = -EINVAL;
- return unit;
-}
-
-/* get new free unit number and associate pointer with it */
-static int unit_get(struct idr *p, void *ptr)
-{
- return idr_alloc(p, ptr, 0, 0, GFP_KERNEL);
-}
-
-/* put unit number back to a pool */
-static void unit_put(struct idr *p, int n)
-{
- idr_remove(p, n);
-}
-
-/* get pointer associated with the number */
-static void *unit_find(struct idr *p, int n)
-{
- return idr_find(p, n);
-}
-
/* Module/initialization stuff */
module_init(ppp_init);
--
2.23.0.rc1
next prev parent reply other threads:[~2019-08-20 22:33 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 22:32 [PATCH 00/38] Convert networking to use the XArray Matthew Wilcox
2019-08-20 22:32 ` [PATCH 01/38] mlx4: Convert cq_table->tree to XArray Matthew Wilcox
2019-08-20 22:32 ` [PATCH 02/38] mlx4: Convert srq_table->tree " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 03/38] mlx4: Convert qp_table_tree " Matthew Wilcox
2019-08-27 19:18 ` Saeed Mahameed
2019-08-20 22:32 ` [PATCH 04/38] mlx5: Convert cq_table " Matthew Wilcox
2019-08-27 19:22 ` Saeed Mahameed
2019-08-20 22:32 ` [PATCH 05/38] mlx5: Convert mlx5_qp_table " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 06/38] mlx5: Convert counters_idr " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 07/38] mlx5: Convert fpga IDRs " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 08/38] nfp: Convert " Matthew Wilcox
2019-08-21 3:59 ` Jakub Kicinski
2019-08-20 22:32 ` [PATCH 09/38] ath10k: Convert pending_tx " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 10/38] ath10k: Convert mgmt_pending_tx IDR " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 11/38] mt76: Convert token " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 12/38] mwifiex: Convert ack_status_frames " Matthew Wilcox
2019-08-20 22:32 ` Matthew Wilcox [this message]
2019-08-20 22:32 ` [PATCH 14/38] tap: Convert minor_idr " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 15/38] nfp: Convert internal ports " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 16/38] qrtr: Convert qrtr_nodes " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 17/38] qrtr: Convert qrtr_ports " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 18/38] rxrpc: Convert " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 19/38] 9p: Convert reqs IDR " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 20/38] 9p: Convert fids " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 21/38] 9p: Move lock from client to trans_fd Matthew Wilcox
2019-08-20 22:32 ` [PATCH 22/38] sctp: Convert sctp_assocs_id to XArray Matthew Wilcox
2019-08-20 22:32 ` [PATCH 23/38] cls_api: Convert tcf_net " Matthew Wilcox
2019-08-20 23:57 ` David Miller
2019-08-21 0:52 ` Matthew Wilcox
2019-08-20 22:32 ` [PATCH 24/38] cls_u32: Convert tc_u_common->handle_idr " Matthew Wilcox
2019-08-21 21:13 ` Jakub Kicinski
2019-08-21 21:25 ` Matthew Wilcox
2019-08-21 21:38 ` Jakub Kicinski
2019-08-20 22:32 ` [PATCH 25/38] cls_u32: Convert tc_u_hnode->handle_idr " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 26/38] cls_bpf: Convert handle_idr " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 27/38] cls_bpf: Remove list of programs Matthew Wilcox
2019-08-20 22:32 ` [PATCH 28/38] cls_bpf: Use XArray marks to accelerate re-offload Matthew Wilcox
2019-08-20 22:32 ` [PATCH 29/38] cls_flower: Convert handle_idr to XArray Matthew Wilcox
2019-08-20 23:58 ` David Miller
2019-08-21 0:50 ` Matthew Wilcox
2019-08-21 18:27 ` Vlad Buslov
2019-08-25 18:32 ` Cong Wang
2019-08-26 10:11 ` Vlad Buslov
2019-08-20 22:32 ` [PATCH 30/38] cls_flower: Use XArray list of filters in fl_walk Matthew Wilcox
2019-08-21 18:32 ` Vlad Buslov
2019-08-20 22:32 ` [PATCH 31/38] cls_flower: Use XArray marks instead of separate list Matthew Wilcox
2019-08-21 19:12 ` Vlad Buslov
2019-08-20 22:32 ` [PATCH 32/38] cls_basic: Convert handle_idr to XArray Matthew Wilcox
2019-08-20 22:32 ` [PATCH 33/38] act_api: Convert action_idr " Matthew Wilcox
2019-08-21 19:41 ` Vlad Buslov
2019-08-21 20:35 ` Matthew Wilcox
2019-08-20 22:32 ` [PATCH 34/38] net_namespace: Convert netns_ids " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 35/38] tipc: Convert conn_idr " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 36/38] netlink: Convert genl_fam_idr " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 37/38] mac80211: Convert ack_status_frames " Matthew Wilcox
2019-08-20 22:32 ` [PATCH 38/38] mac80211: Convert function_inst_ids " Matthew Wilcox
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=20190820223259.22348-14-willy@infradead.org \
--to=willy@infradead.org \
--cc=netdev@vger.kernel.org \
/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).