From 463fb4a722d6dd7ad9b30481972210abd0317c97 Mon Sep 17 00:00:00 2001 From: Matt Dunwoodie Date: Sun, 4 Apr 2021 17:56:55 +1000 Subject: Use malloc instead of pool_* for infrequent allocations We can get rid of the pool overhead by using the malloc family of functions. This does lose us the ability to see directly how much each allocation is using, but it if we really want that, maybe we add new malloc types? Either way, not something we need at the moment. --- sys/net/if_wg.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/sys/net/if_wg.c b/sys/net/if_wg.c index dddce93f54f..0f09d8170bf 100644 --- a/sys/net/if_wg.c +++ b/sys/net/if_wg.c @@ -341,9 +341,6 @@ int wg_clone_destroy(struct ifnet *); void wgattach(int); uint64_t peer_counter = 0; -uint64_t keypair_counter = 0; -struct pool wg_aip_pool; -struct pool wg_peer_pool; struct pool wg_packet_pool; struct pool wg_ratelimit_pool; struct timeval underload_interval = { UNDERLOAD_TIMEOUT, 0 }; @@ -363,7 +360,7 @@ wg_peer_create(struct wg_softc *sc, uint8_t public[WG_KEY_SIZE], rw_assert_wrlock(&sc->sc_lock); - if ((peer = pool_get(&wg_peer_pool, PR_NOWAIT)) == NULL) + if ((peer = malloc(sizeof(*peer), M_DEVBUF, M_NOWAIT)) == NULL) return NULL; peer->p_id = peer_counter++; @@ -394,7 +391,7 @@ wg_peer_create(struct wg_softc *sc, uint8_t public[WG_KEY_SIZE], peer->p_start_onlist = 0; if ((peer->p_remote = noise_remote_alloc(sc->sc_local, peer, public, psk)) == NULL) { - pool_put(&wg_peer_pool, peer); + free(peer, M_DEVBUF, sizeof(*peer)); return NULL; } @@ -410,7 +407,7 @@ wg_peer_free(struct noise_remote *r) { struct wg_peer *peer; peer = noise_remote_arg(r); - pool_put(&wg_peer_pool, peer); + free(peer, M_DEVBUF, sizeof(*peer)); } void @@ -510,7 +507,7 @@ wg_aip_add(struct wg_softc *sc, struct wg_peer *peer, struct wg_aip_io *d) default: return EAFNOSUPPORT; } - if ((aip = pool_get(&wg_aip_pool, PR_NOWAIT)) == NULL) + if ((aip = malloc(sizeof(*aip), M_DEVBUF, M_NOWAIT)) == NULL) return ENOBUFS; bzero(aip, sizeof(*aip)); @@ -523,7 +520,7 @@ wg_aip_add(struct wg_softc *sc, struct wg_peer *peer, struct wg_aip_io *d) LIST_INSERT_HEAD(&peer->p_aip, aip, a_entry); sc->sc_aip_num++; } else { - pool_put(&wg_aip_pool, aip); + free(aip, M_DEVBUF, sizeof(*aip)); aip = (struct wg_aip *) node; if (aip->a_peer != peer) { LIST_REMOVE(aip, a_entry); @@ -576,7 +573,7 @@ wg_aip_remove(struct wg_softc *sc, struct wg_peer *peer, struct wg_aip_io *d) sc->sc_aip_num--; LIST_REMOVE(aip, a_entry); - pool_put(&wg_aip_pool, aip); + free(aip, M_DEVBUF, sizeof(*aip)); } srp_leave(&sr); @@ -2518,10 +2515,6 @@ wgattach(int nwg) #endif if_clone_attach(&wg_cloner); - pool_init(&wg_aip_pool, sizeof(struct wg_aip), 0, - IPL_NET, 0, "wgaip", NULL); - pool_init(&wg_peer_pool, sizeof(struct wg_peer), 0, - IPL_NET, 0, "wgpeer", NULL); pool_init(&wg_packet_pool, sizeof(struct wg_packet), 0, IPL_NET, 0, "wgpacket", NULL); pool_init(&wg_ratelimit_pool, sizeof(struct ratelimit_entry), 0, -- cgit v1.2.3-59-g8ed1b