Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <davem@davemloft.net>

+33 -69
-1
include/net/netns/core.h
··· 12 12 int sysctl_somaxconn; 13 13 14 14 #ifdef CONFIG_PROC_FS 15 - int __percpu *sock_inuse; 16 15 struct prot_inuse __percpu *prot_inuse; 17 16 #endif 18 17 };
+23 -4
include/net/sock.h
··· 1429 1429 1430 1430 1431 1431 #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 + 1434 1449 int sock_prot_inuse_get(struct net *net, struct proto *proto); 1435 1450 int sock_inuse_get(struct net *net); 1436 1451 #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) 1439 1458 { 1440 1459 } 1441 1460 #endif
+1 -32
net/core/sock.c
··· 144 144 static DEFINE_MUTEX(proto_list_mutex); 145 145 static LIST_HEAD(proto_list); 146 146 147 - static void sock_inuse_add(struct net *net, int val); 148 - 149 147 /** 150 148 * sk_ns_capable - General socket capability test 151 149 * @sk: Socket to use a capability on or through ··· 3534 3536 } 3535 3537 3536 3538 #ifdef CONFIG_PROC_FS 3537 - #define PROTO_INUSE_NR 64 /* should be enough for the first time */ 3538 - struct prot_inuse { 3539 - int val[PROTO_INUSE_NR]; 3540 - }; 3541 - 3542 3539 static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR); 3543 - 3544 - void sock_prot_inuse_add(struct net *net, struct proto *prot, int val) 3545 - { 3546 - __this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); 3547 - } 3548 - EXPORT_SYMBOL_GPL(sock_prot_inuse_add); 3549 3540 3550 3541 int sock_prot_inuse_get(struct net *net, struct proto *prot) 3551 3542 { ··· 3548 3561 } 3549 3562 EXPORT_SYMBOL_GPL(sock_prot_inuse_get); 3550 3563 3551 - static void sock_inuse_add(struct net *net, int val) 3552 - { 3553 - this_cpu_add(*net->core.sock_inuse, val); 3554 - } 3555 - 3556 3564 int sock_inuse_get(struct net *net) 3557 3565 { 3558 3566 int cpu, res = 0; 3559 3567 3560 3568 for_each_possible_cpu(cpu) 3561 - res += *per_cpu_ptr(net->core.sock_inuse, cpu); 3569 + res += per_cpu_ptr(net->core.prot_inuse, cpu)->all; 3562 3570 3563 3571 return res; 3564 3572 } ··· 3565 3583 net->core.prot_inuse = alloc_percpu(struct prot_inuse); 3566 3584 if (net->core.prot_inuse == NULL) 3567 3585 return -ENOMEM; 3568 - 3569 - net->core.sock_inuse = alloc_percpu(int); 3570 - if (net->core.sock_inuse == NULL) 3571 - goto out; 3572 - 3573 3586 return 0; 3574 - 3575 - out: 3576 - free_percpu(net->core.prot_inuse); 3577 - return -ENOMEM; 3578 3587 } 3579 3588 3580 3589 static void __net_exit sock_inuse_exit_net(struct net *net) 3581 3590 { 3582 3591 free_percpu(net->core.prot_inuse); 3583 - free_percpu(net->core.sock_inuse); 3584 3592 } 3585 3593 3586 3594 static struct pernet_operations net_inuse_ops = { ··· 3616 3644 { 3617 3645 } 3618 3646 3619 - static void sock_inuse_add(struct net *net, int val) 3620 - { 3621 - } 3622 3647 #endif 3623 3648 3624 3649 static void tw_prot_cleanup(struct timewait_sock_ops *twsk_prot)
+2 -2
net/ieee802154/socket.c
··· 174 174 { 175 175 write_lock_bh(&raw_lock); 176 176 sk_add_node(sk, &raw_head); 177 - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 178 177 write_unlock_bh(&raw_lock); 178 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 179 179 180 180 return 0; 181 181 } ··· 453 453 { 454 454 write_lock_bh(&dgram_lock); 455 455 sk_add_node(sk, &dgram_head); 456 - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 457 456 write_unlock_bh(&dgram_lock); 457 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 458 458 459 459 return 0; 460 460 }
+1 -1
net/ipv4/raw.c
··· 99 99 100 100 write_lock_bh(&h->lock); 101 101 sk_add_node(sk, head); 102 - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 103 102 write_unlock_bh(&h->lock); 103 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 104 104 105 105 return 0; 106 106 }
+4 -4
net/ipv6/ipv6_sockglue.c
··· 471 471 472 472 if (sk->sk_protocol == IPPROTO_TCP) { 473 473 struct inet_connection_sock *icsk = inet_csk(sk); 474 - local_bh_disable(); 474 + 475 475 sock_prot_inuse_add(net, sk->sk_prot, -1); 476 476 sock_prot_inuse_add(net, &tcp_prot, 1); 477 - local_bh_enable(); 477 + 478 478 sk->sk_prot = &tcp_prot; 479 479 icsk->icsk_af_ops = &ipv4_specific; 480 480 sk->sk_socket->ops = &inet_stream_ops; ··· 485 485 486 486 if (sk->sk_protocol == IPPROTO_UDPLITE) 487 487 prot = &udplite_prot; 488 - local_bh_disable(); 488 + 489 489 sock_prot_inuse_add(net, sk->sk_prot, -1); 490 490 sock_prot_inuse_add(net, prot, 1); 491 - local_bh_enable(); 491 + 492 492 sk->sk_prot = prot; 493 493 sk->sk_socket->ops = &inet_dgram_ops; 494 494 sk->sk_family = PF_INET;
+1 -3
net/mptcp/subflow.c
··· 1534 1534 */ 1535 1535 sf->sk->sk_net_refcnt = 1; 1536 1536 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); 1540 1538 err = tcp_set_ulp(sf->sk, "mptcp"); 1541 1539 release_sock(sf->sk); 1542 1540
-4
net/netlink/af_netlink.c
··· 707 707 if (err < 0) 708 708 goto out_module; 709 709 710 - local_bh_disable(); 711 710 sock_prot_inuse_add(net, &netlink_proto, 1); 712 - local_bh_enable(); 713 711 714 712 nlk = nlk_sk(sock->sk); 715 713 nlk->module = module; ··· 807 809 netlink_table_ungrab(); 808 810 } 809 811 810 - local_bh_disable(); 811 812 sock_prot_inuse_add(sock_net(sk), &netlink_proto, -1); 812 - local_bh_enable(); 813 813 call_rcu(&nlk->rcu, deferred_put_nlk_sk); 814 814 return 0; 815 815 }
-4
net/packet/af_packet.c
··· 3102 3102 sk_del_node_init_rcu(sk); 3103 3103 mutex_unlock(&net->packet.sklist_lock); 3104 3104 3105 - preempt_disable(); 3106 3105 sock_prot_inuse_add(net, sk->sk_prot, -1); 3107 - preempt_enable(); 3108 3106 3109 3107 spin_lock(&po->bind_lock); 3110 3108 unregister_prot_hook(sk, false); ··· 3366 3368 sk_add_node_tail_rcu(sk, &net->packet.sklist); 3367 3369 mutex_unlock(&net->packet.sklist_lock); 3368 3370 3369 - preempt_disable(); 3370 3371 sock_prot_inuse_add(net, &packet_proto, 1); 3371 - preempt_enable(); 3372 3372 3373 3373 return 0; 3374 3374 out2:
-5
net/sctp/socket.c
··· 5068 5068 5069 5069 SCTP_DBG_OBJCNT_INC(sock); 5070 5070 5071 - local_bh_disable(); 5072 5071 sk_sockets_allocated_inc(sk); 5073 5072 sock_prot_inuse_add(net, sk->sk_prot, 1); 5074 - 5075 - local_bh_enable(); 5076 5073 5077 5074 return 0; 5078 5075 } ··· 5096 5099 list_del(&sp->auto_asconf_list); 5097 5100 } 5098 5101 sctp_endpoint_free(sp->ep); 5099 - local_bh_disable(); 5100 5102 sk_sockets_allocated_dec(sk); 5101 5103 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 5102 - local_bh_enable(); 5103 5104 } 5104 5105 5105 5106 /* Triggered when there are no references on the socket anymore */
+1 -1
net/smc/af_smc.c
··· 89 89 90 90 write_lock_bh(&h->lock); 91 91 sk_add_node(sk, head); 92 - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 93 92 write_unlock_bh(&h->lock); 93 + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 94 94 95 95 return 0; 96 96 }
-4
net/unix/af_unix.c
··· 522 522 unix_release_addr(u->addr); 523 523 524 524 atomic_long_dec(&unix_nr_socks); 525 - local_bh_disable(); 526 525 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 527 - local_bh_enable(); 528 526 #ifdef UNIX_REFCNT_DEBUG 529 527 pr_debug("UNIX %p is destroyed, %ld are still alive.\n", sk, 530 528 atomic_long_read(&unix_nr_socks)); ··· 887 889 memset(&u->scm_stat, 0, sizeof(struct scm_stat)); 888 890 unix_insert_socket(unix_sockets_unbound(sk), sk); 889 891 890 - local_bh_disable(); 891 892 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 892 - local_bh_enable(); 893 893 894 894 return sk; 895 895
-4
net/xdp/xsk.c
··· 794 794 sk_del_node_init_rcu(sk); 795 795 mutex_unlock(&net->xdp.lock); 796 796 797 - local_bh_disable(); 798 797 sock_prot_inuse_add(net, sk->sk_prot, -1); 799 - local_bh_enable(); 800 798 801 799 xsk_delete_from_maps(xs); 802 800 mutex_lock(&xs->mutex); ··· 1394 1396 sk_add_node_rcu(sk, &net->xdp.list); 1395 1397 mutex_unlock(&net->xdp.lock); 1396 1398 1397 - local_bh_disable(); 1398 1399 sock_prot_inuse_add(net, &xsk_proto, 1); 1399 - local_bh_enable(); 1400 1400 1401 1401 return 0; 1402 1402 }