mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-08 15:04:45 +00:00
dc680de28c
The previous commit moved from O(n) to O(1) for removal, but in the
process introduced an additional pointer member to a struct that
increased the size from 60 to 68 bytes, putting nodes in the 128-byte
slab. With deployed systems having as many as 2 million nodes, this
represents a significant doubling in memory usage (128 MiB -> 256 MiB).
Fix this by using our own kmem_cache, that's sized exactly right. This
also makes wireguard's memory usage more transparent in tools like
slabtop and /proc/slabinfo.
Fixes: e7096c131e
("net: WireGuard secure network tunnel")
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Cc: stable@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
79 lines
1.6 KiB
C
79 lines
1.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
|
*/
|
|
|
|
#include "version.h"
|
|
#include "device.h"
|
|
#include "noise.h"
|
|
#include "queueing.h"
|
|
#include "ratelimiter.h"
|
|
#include "netlink.h"
|
|
|
|
#include <uapi/linux/wireguard.h>
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/genetlink.h>
|
|
#include <net/rtnetlink.h>
|
|
|
|
static int __init mod_init(void)
|
|
{
|
|
int ret;
|
|
|
|
ret = wg_allowedips_slab_init();
|
|
if (ret < 0)
|
|
goto err_allowedips;
|
|
|
|
#ifdef DEBUG
|
|
ret = -ENOTRECOVERABLE;
|
|
if (!wg_allowedips_selftest() || !wg_packet_counter_selftest() ||
|
|
!wg_ratelimiter_selftest())
|
|
goto err_peer;
|
|
#endif
|
|
wg_noise_init();
|
|
|
|
ret = wg_peer_init();
|
|
if (ret < 0)
|
|
goto err_peer;
|
|
|
|
ret = wg_device_init();
|
|
if (ret < 0)
|
|
goto err_device;
|
|
|
|
ret = wg_genetlink_init();
|
|
if (ret < 0)
|
|
goto err_netlink;
|
|
|
|
pr_info("WireGuard " WIREGUARD_VERSION " loaded. See www.wireguard.com for information.\n");
|
|
pr_info("Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.\n");
|
|
|
|
return 0;
|
|
|
|
err_netlink:
|
|
wg_device_uninit();
|
|
err_device:
|
|
wg_peer_uninit();
|
|
err_peer:
|
|
wg_allowedips_slab_uninit();
|
|
err_allowedips:
|
|
return ret;
|
|
}
|
|
|
|
static void __exit mod_exit(void)
|
|
{
|
|
wg_genetlink_uninit();
|
|
wg_device_uninit();
|
|
wg_peer_uninit();
|
|
wg_allowedips_slab_uninit();
|
|
}
|
|
|
|
module_init(mod_init);
|
|
module_exit(mod_exit);
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_DESCRIPTION("WireGuard secure network tunnel");
|
|
MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
|
|
MODULE_VERSION(WIREGUARD_VERSION);
|
|
MODULE_ALIAS_RTNL_LINK(KBUILD_MODNAME);
|
|
MODULE_ALIAS_GENL_FAMILY(WG_GENL_NAME);
|