Change cork to a pointer in sockets
Subsystems (5)
cover Change cork to a pointer in sockets
This patch changes the cork field of both the inet_sock and inet6_sk structs to a pointer, reducing their size.
Oliver Crumrine (17):
Make cork in inet_sock a pointer.
Allocate and free cork in inet_create and inet_release in file
net/ipv4/af_inet.c
Change cork in ipv6_pinfo to a pointer.
Allocate and free cork in inet6_sk.
Change occurence of cork in inet_sock to pointer in include/net/ip.h
Since cork in inet_sock and inet6_sk will be a pointer, they don't
need to be referenced in this function in include/net/ipv6.h
Change occurences of cork in inet_sock to pointer in file
net/ipv4/af_inet.c Change occurence of cork to pointer in file net/ipv4/datagram.c Change instances of cork in net/ipv4/inet_connection_sock.c to
pointer.
Change instances of cork to pointer in net/ipv4/ip_output.c Update occurences of cork to pointer in net/ipv4/syncookies.c Change occurences of cork to pointer in net/ipv4/tcp_output.c Change instances of cork to a pointer in file net/ipv4/udp.c Update usages of cork in net/ipv6/ip6_output.c to pointer. Modify occurences of cork in net/ipv6/raw.c to use a pointer Change usages of cork to pointer in net/ipv6/udp.c Change instance of cork to pointer in net/ipv4/tcp_ipv4.c
include/linux/ipv6.h | 2 +- include/net/inet_sock.h | 2 +- include/net/ip.h | 2 +- include/net/ipv6.h | 4 ++-- net/ipv4/af_inet.c | 6 ++++-- net/ipv4/datagram.c | 2 +- net/ipv4/inet_connection_sock.c | 6 +++--- net/ipv4/ip_output.c | 6 +++--- net/ipv4/syncookies.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/udp.c | 8 ++++---- net/ipv6/af_inet6.c | 5 +++++ net/ipv6/ip6_output.c | 10 +++++----- net/ipv6/raw.c | 4 ++-- net/ipv6/udp.c | 4 ++-- 16 files changed, 37 insertions(+), 30 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/17 Make cork in inet_sock a pointer.
Change the cork in inet_sock to a pointer. This is the actual change to the struct itself for ipv4.
--- include/net/inet_sock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/inet_sock.h +1 -1
@@ -240,7 +240,7 @@ struct inet_sock { } local_port_range;struct ip_mc_socklist __rcu *mc_list; -struct inet_cork_full cork; +struct inet_cork_full *cork; };#define IPCORK_OPT 1/* ip-options has been held in ipcork.opt */
Signature · 1 line
2.42.0
PATCH 2/17 Allocate and free cork for ipv4 and ipv6
In reply to Oliver CrumrineThis allocates the cork for ipv4, and frees it for both ipv4 and ipv6 (ipv6 inet_cork_full is allocated in a different function)
--- net/ipv4/af_inet.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/af_inet.c +2 -0
@@ -362,6 +362,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol, inet->mc_index =0 ; inet->mc_list =NULL ; inet->rcv_tos =0 ; + inet->cork =kzalloc (sizeof (struct inet_cork_full ),GFP_KERNEL );if (inet->inet_num) {/* It assumes that any protocol which allows
@@ -431,6 +432,7 @@ int inet_release(struct socket *sock) !(current->flags & PF_EXITING)) timeout = sk->sk_lingertime; sk->sk_prot->close (sk, timeout); +kfree (inet_sk (sk)->cork); sock->sk =NULL ; }return 0 ;
Signature · 1 line
2.42.0
PATCH 3/17 Change cork in ipv6_pinfo to a pointer.
In reply to Oliver CrumrineThe actual change to make inet6_cork a pointer in the ipv6_pinfo struct itself.
--- include/linux/ipv6.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/ipv6.h +1 -1
@@ -290,7 +290,7 @@ struct ipv6_pinfo {struct ipv6_txoptions __rcu *opt;struct sk_buff *pktoptions;struct sk_buff *rxpmtu; -struct inet6_cork cork; +struct inet6_cork *cork; };/* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
Signature · 1 line
2.42.0
PATCH 4/17 Allocate and free cork in inet6_sk.
In reply to Oliver CrumrineAllocate both the inet6_cork and inet_cork_full here, and free the inet6_cork. (The inet_cork_full is freed in inet_release called at the last line of inet6_release)
--- net/ipv6/af_inet6.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ipv6/af_inet6.c +5 -0
@@ -221,6 +221,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol, np->mc_all =1 ; np->pmtudisc =IPV6_PMTUDISC_WANT ; np->repflow = net->ipv6.sysctl.flowlabel_reflect &FLOWLABEL_REFLECT_ESTABLISHED ; + np->cork =kzalloc (sizeof (struct inet6_cork ),GFP_KERNEL ); sk->sk_ipv6only = net->ipv6.sysctl.bindv6only; sk->sk_txrehash =READ_ONCE (net->core.sysctl_txrehash);
@@ -234,6 +235,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol, inet->mc_index =0 ;RCU_INIT_POINTER (inet->mc_list,NULL ); inet->rcv_tos =0 ; + inet->cork =kzalloc (sizeof (struct inet_cork_full ),GFP_KERNEL );if (READ_ONCE (net->ipv4.sysctl_ip_no_pmtu_disc)) inet->pmtudisc =IP_PMTUDISC_DONT ;
@@ -481,6 +483,9 @@ int inet6_release(struct socket *sock)/* Free ac lists */ ipv6_sock_ac_close (sk); +/* Free cork */ +kfree (inet6_sk (sk)->cork); +return inet_release (sock); }EXPORT_SYMBOL (inet6_release);
Signature · 1 line
2.42.0
PATCH 5/17 Change occurence of cork to pointer
In reply to Oliver CrumrineChange cork to pointer in accordance with the previous patches in the set.
--- include/net/ip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/ip.h +1 -1
@@ -240,7 +240,7 @@ int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);static inline struct sk_buff *ip_finish_skb (struct sock *sk,struct flowi4 *fl4) { -return __ip_make_skb (sk, fl4, &sk->sk_write_queue, &inet_sk (sk)->cork.base); +return __ip_make_skb (sk, fl4, &sk->sk_write_queue, &inet_sk (sk)->cork->base); }/* Get the route scope that should be used when sending a packet. */
Signature · 1 line
2.42.0
PATCH 6/17 Update code for cork as a pointer
In reply to Oliver CrumrineBecause the corks are pointers, they don't need to be referenced to be passed into __ip6_make_skb.
--- include/net/ipv6.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/ipv6.h +2 -2
@@ -1122,8 +1122,8 @@ struct sk_buff *ip6_make_skb(struct sock *sk,static inline struct sk_buff *ip6_finish_skb (struct sock *sk) { -return __ip6_make_skb (sk, &sk->sk_write_queue, &inet_sk (sk)->cork, - &inet6_sk (sk)->cork); +return __ip6_make_skb (sk, &sk->sk_write_queue,inet_sk (sk)->cork, +inet6_sk (sk)->cork); } int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
Signature · 1 line
2.42.0
PATCH 7/17 Change occurences of cork to pointer
In reply to Oliver CrumrineChange two occurences of cork to a pointer in both inet_sk_reselect_saddr, and inet_sk_rebuild_header.
--- net/ipv4/af_inet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/af_inet.c +2 -2
@@ -1263,7 +1263,7 @@ static int inet_sk_reselect_saddr(struct sock *sk) daddr = inet_opt->opt.faddr;/* Query new route. */ - fl4 = &inet->cork.fl.u.ip4; + fl4 = &inet->cork->fl.u.ip4; rt =ip_route_connect (fl4, daddr,0 , sk->sk_bound_dev_if, sk->sk_protocol, inet->inet_sport, inet->inet_dport, sk);
@@ -1321,7 +1321,7 @@ int inet_sk_rebuild_header(struct sock *sk)if (inet_opt && inet_opt->opt.srr) daddr = inet_opt->opt.faddr;rcu_read_unlock (); - fl4 = &inet->cork.fl.u.ip4; + fl4 = &inet->cork->fl.u.ip4; rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, inet->inet_saddr, inet->inet_dport, inet->inet_sport, sk->sk_protocol, RT_CONN_FLAGS(sk),
Signature · 1 line
2.42.0
PATCH 8/17 Update cork to pointer
In reply to Oliver CrumrineUpdates cork to a pointer in the __ip4_datagram_connect function in accordance with the previous patches.
--- net/ipv4/datagram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/datagram.c +1 -1
@@ -45,7 +45,7 @@ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len }else if (!oif) { oif = inet->uc_index; } - fl4 = &inet->cork.fl.u.ip4; + fl4 = &inet->cork->fl.u.ip4; rt =ip_route_connect (fl4, usin->sin_addr.s_addr, saddr, oif, sk->sk_protocol, inet->inet_sport, usin->sin_port, sk);
Signature · 1 line
2.42.0
PATCH 9/17 Change instances of cork to a pointer
In reply to Oliver CrumrineMake these usages of the cork a pointer in accordance with the previous patches.
--- net/ipv4/inet_connection_sock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv4/inet_connection_sock.c +3 -3
@@ -830,7 +830,7 @@ struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,struct rtable *rt; opt =rcu_dereference (ireq->ireq_opt); - fl4 = &newinet->cork.fl.u.ip4; + fl4 = &newinet->cork->fl.u.ip4; flowi4_init_output(fl4, ireq->ir_iif, ireq->ir_mark, ip_sock_rt_tos(sk), ip_sock_rt_scope(sk),
@@ -1482,7 +1482,7 @@ struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu)struct inet_sock *inet =inet_sk (sk);if (!dst) { - dst =inet_csk_rebuild_route (sk, &inet->cork.fl); + dst =inet_csk_rebuild_route (sk, &inet->cork->fl);if (!dst) goto out; }
@@ -1490,7 +1490,7 @@ struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu) dst =__sk_dst_check (sk,0 );if (!dst) - dst =inet_csk_rebuild_route (sk, &inet->cork.fl); + dst =inet_csk_rebuild_route (sk, &inet->cork->fl); out:return dst; }
Signature · 1 line
2.42.0
PATCH 11/17 Update occurences of cork to pointer
In reply to Oliver CrumrineUpdates an occurence of cork to a pointer in accordance with the previous patches in the set
--- net/ipv4/syncookies.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/syncookies.c +1 -1
@@ -450,6 +450,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)* Normal sockets get it right from inet_csk_route_child_sock() */ if (ret) -inet_sk (ret)->cork.fl.u.ip4 = fl4; +inet_sk (ret)->cork->fl.u.ip4 = fl4; out:return ret; }
Signature · 1 line
2.42.0
PATCH 12/17 Change an occurence of cork to pointer
In reply to Oliver CrumrineChanges this occurence of cork to a pointer
--- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_output.c +1 -1
@@ -1414,7 +1414,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, err =INDIRECT_CALL_INET (icsk->icsk_af_ops->queue_xmit, inet6_csk_xmit, ip_queue_xmit, - sk, skb, &inet->cork.fl); + sk, skb, &inet->cork->fl);if (unlikely (err >0 )) {tcp_enter_cwr (sk);
Signature · 1 line
2.42.0
PATCH 13/17 Change some instances of cork to a pointer
In reply to Oliver CrumrineChanges a few instances of cork to a pointer in accordance with the previous patches
--- net/ipv4/udp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv4/udp.c +4 -4
@@ -981,7 +981,7 @@ int udp_push_pending_frames(struct sock *sk) {struct udp_sock *up =udp_sk (sk);struct inet_sock *inet =inet_sk (sk); -struct flowi4 *fl4 = &inet->cork.fl.u.ip4; +struct flowi4 *fl4 = &inet->cork->fl.u.ip4;struct sk_buff *skb;int err =0 ;
@@ -989,7 +989,7 @@ int udp_push_pending_frames(struct sock *sk)if (!skb) goto out; - err =udp_send_skb (skb, fl4, &inet->cork.base); + err =udp_send_skb (skb, fl4, &inet->cork->base); out: up->len =0 ;
@@ -1068,7 +1068,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; - fl4 = &inet->cork.fl.u.ip4; + fl4 = &inet->cork->fl.u.ip4;if (up->pending) {/* * There are pending frames.
@@ -1260,7 +1260,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)/* * Now cork the socket to pend data. */ - fl4 = &inet->cork.fl.u.ip4; + fl4 = &inet->cork->fl.u.ip4; fl4->daddr = daddr; fl4->saddr = saddr; fl4->fl4_dport = dport;
Signature · 1 line
2.42.0
PATCH 14/17 Update usages of cork to a pointer
In reply to Oliver CrumrineModify a few instances of cork to be a pointer
--- net/ipv6/ip6_output.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/ipv6/ip6_output.c +5 -5
@@ -1878,12 +1878,12 @@ int ip6_append_data(struct sock *sk,* setup for corking */ dst_hold (&rt->dst); - err =ip6_setup_cork (sk, &inet->cork, &np->cork, + err =ip6_setup_cork (sk, inet->cork, np->cork, ipc6, rt);if (err)return err; - inet->cork.fl.u.ip6 = *fl6; + inet->cork->fl.u.ip6 = *fl6; exthdrlen = (ipc6->opt ? ipc6->opt->opt_flen :0 ); length += exthdrlen; transhdrlen += exthdrlen;
@@ -1891,8 +1891,8 @@ int ip6_append_data(struct sock *sk, transhdrlen =0 ; } -return __ip6_append_data (sk, &sk->sk_write_queue, &inet->cork, - &np->cork,sk_page_frag (sk), getfrag, +return __ip6_append_data (sk, &sk->sk_write_queue, inet->cork, + np->cork,sk_page_frag (sk), getfrag, from, length, transhdrlen, flags, ipc6); }EXPORT_SYMBOL_GPL (ip6_append_data);
@@ -2058,7 +2058,7 @@ static void __ip6_flush_pending_frames(struct sock *sk,void ip6_flush_pending_frames (struct sock *sk) {__ip6_flush_pending_frames (sk, &sk->sk_write_queue, - &inet_sk (sk)->cork, &inet6_sk (sk)->cork); +inet_sk (sk)->cork,inet6_sk (sk)->cork); }EXPORT_SYMBOL_GPL (ip6_flush_pending_frames);
Signature · 1 line
2.42.0
PATCH 15/17 Modify occurences of cork to make it a pointer
In reply to Oliver CrumrineUpdate an occurence of ockr to make it a pointer, just like all the previous patches
--- net/ipv6/raw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/raw.c +2 -2
@@ -520,8 +520,8 @@ static int rawv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6, goto out; offset = rp->offset; - total_len =inet_sk (sk)->cork.base.length; - opt =inet6_sk (sk)->cork.opt; + total_len =inet_sk (sk)->cork->base.length; + opt =inet6_sk (sk)->cork->opt; total_len -= opt ? opt->opt_flen :0 ;if (offset >= total_len -1 ) {
Signature · 1 line
2.42.0
PATCH 16/17 Change a usage of cork to pointer
In reply to Oliver CrumrineChange an instance of cork to a pointer in accordance with the other patches in this set
--- net/ipv6/udp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/udp.c +2 -2
@@ -1306,8 +1306,8 @@ static int udp_v6_push_pending_frames(struct sock *sk)if (!skb) goto out; - err =udp_v6_send_skb (skb, &inet_sk (sk)->cork.fl.u.ip6, - &inet_sk (sk)->cork.base); + err =udp_v6_send_skb (skb, &inet_sk (sk)->cork->fl.u.ip6, + &inet_sk (sk)->cork->base); out: up->len =0 ; up->pending =0 ;
Signature · 1 line
2.42.0
PATCH 17/17 Change the last instance of cork to pointer
In reply to Oliver CrumrineChange the last of the instances of cork to a pointer.
--- net/ipv4/tcp_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_ipv4.c +1 -1
@@ -229,7 +229,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) orig_sport = inet->inet_sport; orig_dport = usin->sin_port; - fl4 = &inet->cork.fl.u.ip4; + fl4 = &inet->cork->fl.u.ip4; rt =ip_route_connect (fl4, nexthop, inet->inet_saddr, sk->sk_bound_dev_if,IPPROTO_TCP , orig_sport, orig_dport, sk);
Signature · 1 line
2.42.0
Re: [PATCH net-next 01/17] Make cork in inet_sock a pointer.
In reply to Oliver CrumrineQuoted 13 lines · Oliver Crumrine
Change the cork in
inet_sockto a pointer. This is the actual change to the struct itself for ipv4.Signed-off-by Oliver Crumrine <[email protected]>--- include/net/inet_sock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/net/inet_sock.h +0
-0
include/net/inet_sock.h struct inet_sock { · line 246
Quoted 8 lines
include/net/inet_sock.h +1
-1@@ -240,7 +240,7 @@ struct inet_sock { } local_port_range;struct ip_mc_socklist __rcu *mc_list; -struct inet_cork_full cork; +struct inet_cork_full *cork; };#define IPCORK_OPT 1/* ip-options has been held in ipcork.opt */
Please make sure each patch in the series in buildable. This helps during a git bisect.
Signature · 2 lines
Regards, Ravi
Paolo Abeni
maintainerQuoted 35 lines · Oliver Crumrine
This patch changes the cork field of both the
inet_sockandinet6_skstructs to a pointer, reducing their size.Oliver Crumrine (17):
Make cork ininet_socka pointer.
Allocate and free cork ininet_createandinet_releasein filenet/ipv4/af_inet.c Change cork in ipv6_pinfo to a pointer. Allocate and free cork in inet6_sk. Change occurence of cork in inet_sock to pointer in include/net/ip.h Since cork in inet_sock and inet6_sk will be a pointer, they don't need to be referenced in this function in include/net/ipv6.h Change occurences of cork in inet_sock to pointer in file net/ipv4/af_inet.cChange occurence of cork to pointer in file
net/ipv4/datagram.cChange instances of cork innet/ipv4/inet_connection_sock.cto
pointer.
Change instances of cork to pointer innet/ipv4/ip_output.cUpdate occurences of cork to pointer innet/ipv4/syncookies.cChange occurences of cork to pointer innet/ipv4/tcp_output.cChange instances of cork to a pointer in filenet/ipv4/udp.cUpdate usages of cork innet/ipv6/ip6_output.cto pointer. Modify occurences of cork innet/ipv6/raw.cto use a pointer Change usages of cork to pointer innet/ipv6/udp.cChange instance of cork to pointer innet/ipv4/tcp_ipv4.cinclude/linux/ipv6.h | 2 +- include/net/inet_sock.h | 2 +- include/net/ip.h | 2 +- include/net/ipv6.h | 4 ++-- net/ipv4/af_inet.c | 6 ++++-- net/ipv4/datagram.c | 2 +- net/ipv4/inet_connection_sock.c | 6 +++--- net/ipv4/ip_output.c | 6 +++--- net/ipv4/syncookies.c | 2 +-
Quoted 8 lines
net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/udp.c | 8 ++++---- net/ipv6/af_inet6.c | 5 +++++ net/ipv6/ip6_output.c | 10 +++++----- net/ipv6/raw.c | 4 ++-- net/ipv6/udp.c | 4 ++-- 16 files changed, 37 insertions(+), 30 deletions(-)
Could you please explain the rationale behind such changes?
As the cork struct is still allocated for each inet/inet6 socket, the total memory used by the the now smaller socket struct and the cork struct will be greater then the memory used originally by such socket. And the double allocation/free will be slower then the original one.
This also adds a bunch of additional pointer de-reference in the xmit path.
Finally the above change will probably conflict with the goodies introduced by:
https://lore.kernel.org/netdev/[email protected]/
I'm sorry, but this looks really a no-go.
Before future submissions, please read thoroughly the process documentation, including the netdev specific bits in maintainer- netdev.rst: there a bit of issues with the process here (the recipients list does not include a lot of relevant ones, there are typos there, the patch series is too long, it breaks the builds ...)
Cheers,
Paolo