Skip to content

Commit 62803fe

Browse files
committed
Merge branch 'inuse-cleanups'
Eric Dumazet says: ==================== net: prot_inuse and sock_inuse cleanups Small series cleaning and optimizing sock_prot_inuse_add() and sock_inuse_add(). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents abc3342 + b3cb764 commit 62803fe

File tree

13 files changed

+33
-69
lines changed

13 files changed

+33
-69
lines changed

include/net/netns/core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct netns_core {
1212
int sysctl_somaxconn;
1313

1414
#ifdef CONFIG_PROC_FS
15-
int __percpu *sock_inuse;
1615
struct prot_inuse __percpu *prot_inuse;
1716
#endif
1817
};

include/net/sock.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,13 +1429,32 @@ proto_memory_pressure(struct proto *prot)
14291429

14301430

14311431
#ifdef CONFIG_PROC_FS
1432-
/* Called with local bh disabled */
1433-
void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
1432+
#define PROTO_INUSE_NR 64 /* should be enough for the first time */
1433+
struct prot_inuse {
1434+
int all;
1435+
int val[PROTO_INUSE_NR];
1436+
};
1437+
1438+
static inline void sock_prot_inuse_add(const struct net *net,
1439+
const struct proto *prot, int val)
1440+
{
1441+
this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val);
1442+
}
1443+
1444+
static inline void sock_inuse_add(const struct net *net, int val)
1445+
{
1446+
this_cpu_add(net->core.prot_inuse->all, val);
1447+
}
1448+
14341449
int sock_prot_inuse_get(struct net *net, struct proto *proto);
14351450
int sock_inuse_get(struct net *net);
14361451
#else
1437-
static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
1438-
int inc)
1452+
static inline void sock_prot_inuse_add(const struct net *net,
1453+
const struct proto *prot, int val)
1454+
{
1455+
}
1456+
1457+
static inline void sock_inuse_add(const struct net *net, int val)
14391458
{
14401459
}
14411460
#endif

net/core/sock.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@
144144
static DEFINE_MUTEX(proto_list_mutex);
145145
static LIST_HEAD(proto_list);
146146

147-
static void sock_inuse_add(struct net *net, int val);
148-
149147
/**
150148
* sk_ns_capable - General socket capability test
151149
* @sk: Socket to use a capability on or through
@@ -3536,19 +3534,8 @@ void sk_get_meminfo(const struct sock *sk, u32 *mem)
35363534
}
35373535

35383536
#ifdef CONFIG_PROC_FS
3539-
#define PROTO_INUSE_NR 64 /* should be enough for the first time */
3540-
struct prot_inuse {
3541-
int val[PROTO_INUSE_NR];
3542-
};
3543-
35443537
static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
35453538

3546-
void sock_prot_inuse_add(struct net *net, struct proto *prot, int val)
3547-
{
3548-
__this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val);
3549-
}
3550-
EXPORT_SYMBOL_GPL(sock_prot_inuse_add);
3551-
35523539
int sock_prot_inuse_get(struct net *net, struct proto *prot)
35533540
{
35543541
int cpu, idx = prot->inuse_idx;
@@ -3561,17 +3548,12 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot)
35613548
}
35623549
EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
35633550

3564-
static void sock_inuse_add(struct net *net, int val)
3565-
{
3566-
this_cpu_add(*net->core.sock_inuse, val);
3567-
}
3568-
35693551
int sock_inuse_get(struct net *net)
35703552
{
35713553
int cpu, res = 0;
35723554

35733555
for_each_possible_cpu(cpu)
3574-
res += *per_cpu_ptr(net->core.sock_inuse, cpu);
3556+
res += per_cpu_ptr(net->core.prot_inuse, cpu)->all;
35753557

35763558
return res;
35773559
}
@@ -3583,22 +3565,12 @@ static int __net_init sock_inuse_init_net(struct net *net)
35833565
net->core.prot_inuse = alloc_percpu(struct prot_inuse);
35843566
if (net->core.prot_inuse == NULL)
35853567
return -ENOMEM;
3586-
3587-
net->core.sock_inuse = alloc_percpu(int);
3588-
if (net->core.sock_inuse == NULL)
3589-
goto out;
3590-
35913568
return 0;
3592-
3593-
out:
3594-
free_percpu(net->core.prot_inuse);
3595-
return -ENOMEM;
35963569
}
35973570

35983571
static void __net_exit sock_inuse_exit_net(struct net *net)
35993572
{
36003573
free_percpu(net->core.prot_inuse);
3601-
free_percpu(net->core.sock_inuse);
36023574
}
36033575

36043576
static struct pernet_operations net_inuse_ops = {
@@ -3644,9 +3616,6 @@ static inline void release_proto_idx(struct proto *prot)
36443616
{
36453617
}
36463618

3647-
static void sock_inuse_add(struct net *net, int val)
3648-
{
3649-
}
36503619
#endif
36513620

36523621
static void tw_prot_cleanup(struct timewait_sock_ops *twsk_prot)

net/ieee802154/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ static int raw_hash(struct sock *sk)
174174
{
175175
write_lock_bh(&raw_lock);
176176
sk_add_node(sk, &raw_head);
177-
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
178177
write_unlock_bh(&raw_lock);
178+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
179179

180180
return 0;
181181
}
@@ -453,8 +453,8 @@ static int dgram_hash(struct sock *sk)
453453
{
454454
write_lock_bh(&dgram_lock);
455455
sk_add_node(sk, &dgram_head);
456-
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
457456
write_unlock_bh(&dgram_lock);
457+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
458458

459459
return 0;
460460
}

net/ipv4/raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ int raw_hash_sk(struct sock *sk)
9999

100100
write_lock_bh(&h->lock);
101101
sk_add_node(sk, head);
102-
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
103102
write_unlock_bh(&h->lock);
103+
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
104104

105105
return 0;
106106
}

net/ipv6/ipv6_sockglue.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
471471

472472
if (sk->sk_protocol == IPPROTO_TCP) {
473473
struct inet_connection_sock *icsk = inet_csk(sk);
474-
local_bh_disable();
474+
475475
sock_prot_inuse_add(net, sk->sk_prot, -1);
476476
sock_prot_inuse_add(net, &tcp_prot, 1);
477-
local_bh_enable();
477+
478478
sk->sk_prot = &tcp_prot;
479479
icsk->icsk_af_ops = &ipv4_specific;
480480
sk->sk_socket->ops = &inet_stream_ops;
@@ -485,10 +485,10 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
485485

486486
if (sk->sk_protocol == IPPROTO_UDPLITE)
487487
prot = &udplite_prot;
488-
local_bh_disable();
488+
489489
sock_prot_inuse_add(net, sk->sk_prot, -1);
490490
sock_prot_inuse_add(net, prot, 1);
491-
local_bh_enable();
491+
492492
sk->sk_prot = prot;
493493
sk->sk_socket->ops = &inet_dgram_ops;
494494
sk->sk_family = PF_INET;

net/mptcp/subflow.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,9 +1534,7 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
15341534
*/
15351535
sf->sk->sk_net_refcnt = 1;
15361536
get_net(net);
1537-
#ifdef CONFIG_PROC_FS
1538-
this_cpu_add(*net->core.sock_inuse, 1);
1539-
#endif
1537+
sock_inuse_add(net, 1);
15401538
err = tcp_set_ulp(sf->sk, "mptcp");
15411539
release_sock(sf->sk);
15421540

net/netlink/af_netlink.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol,
707707
if (err < 0)
708708
goto out_module;
709709

710-
local_bh_disable();
711710
sock_prot_inuse_add(net, &netlink_proto, 1);
712-
local_bh_enable();
713711

714712
nlk = nlk_sk(sock->sk);
715713
nlk->module = module;
@@ -809,9 +807,7 @@ static int netlink_release(struct socket *sock)
809807
netlink_table_ungrab();
810808
}
811809

812-
local_bh_disable();
813810
sock_prot_inuse_add(sock_net(sk), &netlink_proto, -1);
814-
local_bh_enable();
815811
call_rcu(&nlk->rcu, deferred_put_nlk_sk);
816812
return 0;
817813
}

net/packet/af_packet.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,9 +3102,7 @@ static int packet_release(struct socket *sock)
31023102
sk_del_node_init_rcu(sk);
31033103
mutex_unlock(&net->packet.sklist_lock);
31043104

3105-
preempt_disable();
31063105
sock_prot_inuse_add(net, sk->sk_prot, -1);
3107-
preempt_enable();
31083106

31093107
spin_lock(&po->bind_lock);
31103108
unregister_prot_hook(sk, false);
@@ -3368,9 +3366,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
33683366
sk_add_node_tail_rcu(sk, &net->packet.sklist);
33693367
mutex_unlock(&net->packet.sklist_lock);
33703368

3371-
preempt_disable();
33723369
sock_prot_inuse_add(net, &packet_proto, 1);
3373-
preempt_enable();
33743370

33753371
return 0;
33763372
out2:

net/sctp/socket.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,12 +5068,9 @@ static int sctp_init_sock(struct sock *sk)
50685068

50695069
SCTP_DBG_OBJCNT_INC(sock);
50705070

5071-
local_bh_disable();
50725071
sk_sockets_allocated_inc(sk);
50735072
sock_prot_inuse_add(net, sk->sk_prot, 1);
50745073

5075-
local_bh_enable();
5076-
50775074
return 0;
50785075
}
50795076

@@ -5099,10 +5096,8 @@ static void sctp_destroy_sock(struct sock *sk)
50995096
list_del(&sp->auto_asconf_list);
51005097
}
51015098
sctp_endpoint_free(sp->ep);
5102-
local_bh_disable();
51035099
sk_sockets_allocated_dec(sk);
51045100
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
5105-
local_bh_enable();
51065101
}
51075102

51085103
/* Triggered when there are no references on the socket anymore */

0 commit comments

Comments
 (0)