Skip to content

Commit 07f6c4b

Browse files
ying-xuedavem330
authored andcommitted
tipc: convert tipc reference table to use generic rhashtable
As tipc reference table is statically allocated, its memory size requested on stack initialization stage is quite big even if the maximum port number is just restricted to 8191 currently, however, the number already becomes insufficient in practice. But if the maximum ports is allowed to its theory value - 2^32, its consumed memory size will reach a ridiculously unacceptable value. Apart from this, heavy tipc users spend a considerable amount of time in tipc_sk_get() due to the read-lock on ref_table_lock. If tipc reference table is converted with generic rhashtable, above mentioned both disadvantages would be resolved respectively: making use of the new resizable hash table can avoid locking on the lookup; smaller memory size is required at initial stage, for example, 256 hash bucket slots are requested at the beginning phase instead of allocating the entire 8191 slots in old mode. The hash table will grow if entries exceeds 75% of table size up to a total table size of 1M, and it will automatically shrink if usage falls below 30%, but the minimum table size is allowed down to 256. Also converts ref_table_lock to a separate mutex to protect hash table mutations on write side. Lastly defers the release of the socket reference using call_rcu() to allow using an RCU read-side protected call to rhashtable_lookup(). Signed-off-by: Ying Xue <[email protected]> Acked-by: Jon Maloy <[email protected]> Acked-by: Erik Hugne <[email protected]> Cc: Thomas Graf <[email protected]> Acked-by: Thomas Graf <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 545a148 commit 07f6c4b

File tree

6 files changed

+180
-353
lines changed

6 files changed

+180
-353
lines changed

net/tipc/Kconfig

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ menuconfig TIPC
2020

2121
If in doubt, say N.
2222

23-
config TIPC_PORTS
24-
int "Maximum number of ports in a node"
25-
depends on TIPC
26-
range 127 65535
27-
default "8191"
28-
help
29-
Specifies how many ports can be supported by a node.
30-
Can range from 127 to 65535 ports; default is 8191.
31-
32-
Setting this to a smaller value saves some memory,
33-
setting it to higher allows for more ports.
34-
3523
config TIPC_MEDIA_IB
3624
bool "InfiniBand media type support"
3725
depends on TIPC && INFINIBAND_IPOIB

net/tipc/config.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,6 @@ static struct sk_buff *cfg_set_own_addr(void)
183183
return tipc_cfg_reply_error_string("cannot change to network mode");
184184
}
185185

186-
static struct sk_buff *cfg_set_max_ports(void)
187-
{
188-
u32 value;
189-
190-
if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
191-
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
192-
value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
193-
if (value == tipc_max_ports)
194-
return tipc_cfg_reply_none();
195-
if (value < 127 || value > 65535)
196-
return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
197-
" (max ports must be 127-65535)");
198-
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
199-
" (cannot change max ports while TIPC is active)");
200-
}
201-
202186
static struct sk_buff *cfg_set_netid(void)
203187
{
204188
u32 value;
@@ -285,15 +269,9 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
285269
case TIPC_CMD_SET_NODE_ADDR:
286270
rep_tlv_buf = cfg_set_own_addr();
287271
break;
288-
case TIPC_CMD_SET_MAX_PORTS:
289-
rep_tlv_buf = cfg_set_max_ports();
290-
break;
291272
case TIPC_CMD_SET_NETID:
292273
rep_tlv_buf = cfg_set_netid();
293274
break;
294-
case TIPC_CMD_GET_MAX_PORTS:
295-
rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
296-
break;
297275
case TIPC_CMD_GET_NETID:
298276
rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
299277
break;
@@ -317,6 +295,8 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
317295
case TIPC_CMD_SET_REMOTE_MNG:
318296
case TIPC_CMD_GET_REMOTE_MNG:
319297
case TIPC_CMD_DUMP_LOG:
298+
case TIPC_CMD_SET_MAX_PORTS:
299+
case TIPC_CMD_GET_MAX_PORTS:
320300
rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
321301
" (obsolete command)");
322302
break;

net/tipc/core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* POSSIBILITY OF SUCH DAMAGE.
3535
*/
3636

37+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38+
3739
#include "core.h"
3840
#include "name_table.h"
3941
#include "subscr.h"
@@ -47,7 +49,6 @@ int tipc_random __read_mostly;
4749

4850
/* configurable TIPC parameters */
4951
u32 tipc_own_addr __read_mostly;
50-
int tipc_max_ports __read_mostly;
5152
int tipc_net_id __read_mostly;
5253
int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */
5354

@@ -84,9 +85,9 @@ static void tipc_core_stop(void)
8485
tipc_netlink_stop();
8586
tipc_subscr_stop();
8687
tipc_nametbl_stop();
87-
tipc_sk_ref_table_stop();
8888
tipc_socket_stop();
8989
tipc_unregister_sysctl();
90+
tipc_sk_rht_destroy();
9091
}
9192

9293
/**
@@ -98,7 +99,7 @@ static int tipc_core_start(void)
9899

99100
get_random_bytes(&tipc_random, sizeof(tipc_random));
100101

101-
err = tipc_sk_ref_table_init(tipc_max_ports, tipc_random);
102+
err = tipc_sk_rht_init();
102103
if (err)
103104
goto out_reftbl;
104105

@@ -138,7 +139,7 @@ static int tipc_core_start(void)
138139
out_netlink:
139140
tipc_nametbl_stop();
140141
out_nametbl:
141-
tipc_sk_ref_table_stop();
142+
tipc_sk_rht_destroy();
142143
out_reftbl:
143144
return err;
144145
}
@@ -150,7 +151,6 @@ static int __init tipc_init(void)
150151
pr_info("Activated (version " TIPC_MOD_VER ")\n");
151152

152153
tipc_own_addr = 0;
153-
tipc_max_ports = CONFIG_TIPC_PORTS;
154154
tipc_net_id = 4711;
155155

156156
sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<

net/tipc/core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#ifndef _TIPC_CORE_H
3838
#define _TIPC_CORE_H
3939

40-
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
41-
4240
#include <linux/tipc.h>
4341
#include <linux/tipc_config.h>
4442
#include <linux/tipc_netlink.h>
@@ -79,7 +77,6 @@ int tipc_snprintf(char *buf, int len, const char *fmt, ...);
7977
* Global configuration variables
8078
*/
8179
extern u32 tipc_own_addr __read_mostly;
82-
extern int tipc_max_ports __read_mostly;
8380
extern int tipc_net_id __read_mostly;
8481
extern int sysctl_tipc_rmem[3] __read_mostly;
8582
extern int sysctl_tipc_named_timeout __read_mostly;

0 commit comments

Comments
 (0)