[NET] Move sndmsg_page and sndmsg_off to struct sock

Yeah, the poor cousins will use this as well :-)
parent a09a8386
...@@ -129,8 +129,6 @@ struct inet_opt { ...@@ -129,8 +129,6 @@ struct inet_opt {
int mc_index; /* Multicast device index */ int mc_index; /* Multicast device index */
__u32 mc_addr; __u32 mc_addr;
struct ip_mc_socklist *mc_list; /* Group array */ struct ip_mc_socklist *mc_list; /* Group array */
struct page *sndmsg_page; /* Cached page for sendmsg */
u32 sndmsg_off; /* Cached offset for sendmsg */
/* /*
* Following members are used to retain the infomation to build * Following members are used to retain the infomation to build
* an ip header on each ip fragmentation while the socket is corked. * an ip header on each ip fragmentation while the socket is corked.
......
...@@ -167,6 +167,8 @@ struct sock_common { ...@@ -167,6 +167,8 @@ struct sock_common {
* @sk_socket - Identd and reporting IO signals * @sk_socket - Identd and reporting IO signals
* @sk_user_data - RPC layer private data * @sk_user_data - RPC layer private data
* @sk_owner - module that owns this socket * @sk_owner - module that owns this socket
* @sk_sndmsg_page - cached page for sendmsg
* @sk_sndmsg_off - cached offset for sendmsg
* @sk_send_head - front of stuff to transmit * @sk_send_head - front of stuff to transmit
* @sk_write_pending - a write to stream socket waits to start * @sk_write_pending - a write to stream socket waits to start
* @sk_queue_shrunk - write queue has been shrunk recently * @sk_queue_shrunk - write queue has been shrunk recently
...@@ -249,8 +251,10 @@ struct sock { ...@@ -249,8 +251,10 @@ struct sock {
struct timeval sk_stamp; struct timeval sk_stamp;
struct socket *sk_socket; struct socket *sk_socket;
void *sk_user_data; void *sk_user_data;
struct sk_buff *sk_send_head;
struct module *sk_owner; struct module *sk_owner;
struct page *sk_sndmsg_page;
__u32 sk_sndmsg_off;
struct sk_buff *sk_send_head;
int sk_write_pending; int sk_write_pending;
void *sk_security; void *sk_security;
__u8 sk_queue_shrunk; __u8 sk_queue_shrunk;
......
...@@ -650,6 +650,14 @@ void sk_free(struct sock *sk) ...@@ -650,6 +650,14 @@ void sk_free(struct sock *sk)
printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n", printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
__FUNCTION__, atomic_read(&sk->sk_omem_alloc)); __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
/*
* If sendmsg cached page exists, toss it.
*/
if (sk->sk_sndmsg_page) {
__free_page(sk->sk_sndmsg_page);
sk->sk_sndmsg_page = NULL;
}
security_sk_free(sk); security_sk_free(sk);
kmem_cache_free(sk->sk_slab, sk); kmem_cache_free(sk->sk_slab, sk);
module_put(owner); module_put(owner);
...@@ -1175,6 +1183,9 @@ void sock_init_data(struct socket *sock, struct sock *sk) ...@@ -1175,6 +1183,9 @@ void sock_init_data(struct socket *sock, struct sock *sk)
sk->sk_error_report = sock_def_error_report; sk->sk_error_report = sock_def_error_report;
sk->sk_destruct = sock_def_destruct; sk->sk_destruct = sock_def_destruct;
sk->sk_sndmsg_page = NULL;
sk->sk_sndmsg_off = 0;
sk->sk_peercred.pid = 0; sk->sk_peercred.pid = 0;
sk->sk_peercred.uid = -1; sk->sk_peercred.uid = -1;
sk->sk_peercred.gid = -1; sk->sk_peercred.gid = -1;
......
...@@ -766,8 +766,8 @@ int ip_append_data(struct sock *sk, ...@@ -766,8 +766,8 @@ int ip_append_data(struct sock *sk,
inet->cork.fragsize = mtu = dst_pmtu(&rt->u.dst); inet->cork.fragsize = mtu = dst_pmtu(&rt->u.dst);
inet->cork.rt = rt; inet->cork.rt = rt;
inet->cork.length = 0; inet->cork.length = 0;
inet->sndmsg_page = NULL; sk->sk_sndmsg_page = NULL;
inet->sndmsg_off = 0; sk->sk_sndmsg_off = 0;
if ((exthdrlen = rt->u.dst.header_len) != 0) { if ((exthdrlen = rt->u.dst.header_len) != 0) {
length += exthdrlen; length += exthdrlen;
transhdrlen += exthdrlen; transhdrlen += exthdrlen;
...@@ -915,8 +915,8 @@ int ip_append_data(struct sock *sk, ...@@ -915,8 +915,8 @@ int ip_append_data(struct sock *sk,
} else { } else {
int i = skb_shinfo(skb)->nr_frags; int i = skb_shinfo(skb)->nr_frags;
skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1];
struct page *page = inet->sndmsg_page; struct page *page = sk->sk_sndmsg_page;
int off = inet->sndmsg_off; int off = sk->sk_sndmsg_off;
unsigned int left; unsigned int left;
if (page && (left = PAGE_SIZE - off) > 0) { if (page && (left = PAGE_SIZE - off) > 0) {
...@@ -928,7 +928,7 @@ int ip_append_data(struct sock *sk, ...@@ -928,7 +928,7 @@ int ip_append_data(struct sock *sk,
goto error; goto error;
} }
get_page(page); get_page(page);
skb_fill_page_desc(skb, i, page, inet->sndmsg_off, 0); skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0);
frag = &skb_shinfo(skb)->frags[i]; frag = &skb_shinfo(skb)->frags[i];
} }
} else if (i < MAX_SKB_FRAGS) { } else if (i < MAX_SKB_FRAGS) {
...@@ -939,8 +939,8 @@ int ip_append_data(struct sock *sk, ...@@ -939,8 +939,8 @@ int ip_append_data(struct sock *sk,
err = -ENOMEM; err = -ENOMEM;
goto error; goto error;
} }
inet->sndmsg_page = page; sk->sk_sndmsg_page = page;
inet->sndmsg_off = 0; sk->sk_sndmsg_off = 0;
skb_fill_page_desc(skb, i, page, 0, 0); skb_fill_page_desc(skb, i, page, 0, 0);
frag = &skb_shinfo(skb)->frags[i]; frag = &skb_shinfo(skb)->frags[i];
...@@ -954,7 +954,7 @@ int ip_append_data(struct sock *sk, ...@@ -954,7 +954,7 @@ int ip_append_data(struct sock *sk,
err = -EFAULT; err = -EFAULT;
goto error; goto error;
} }
inet->sndmsg_off += copy; sk->sk_sndmsg_off += copy;
frag->size += copy; frag->size += copy;
skb->len += copy; skb->len += copy;
skb->data_len += copy; skb->data_len += copy;
......
...@@ -816,8 +816,8 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, ...@@ -816,8 +816,8 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset,
return res; return res;
} }
#define TCP_PAGE(sk) (inet_sk(sk)->sndmsg_page) #define TCP_PAGE(sk) (sk->sk_sndmsg_page)
#define TCP_OFF(sk) (inet_sk(sk)->sndmsg_off) #define TCP_OFF(sk) (sk->sk_sndmsg_off)
static inline int select_size(struct sock *sk, struct tcp_opt *tp) static inline int select_size(struct sock *sk, struct tcp_opt *tp)
{ {
......
...@@ -2113,10 +2113,6 @@ static int tcp_v4_destroy_sock(struct sock *sk) ...@@ -2113,10 +2113,6 @@ static int tcp_v4_destroy_sock(struct sock *sk)
if (tp->bind_hash) if (tp->bind_hash)
tcp_put_port(sk); tcp_put_port(sk);
/* If sendmsg cached page exists, toss it. */
if (inet_sk(sk)->sndmsg_page)
__free_page(inet_sk(sk)->sndmsg_page);
atomic_dec(&tcp_sockets_allocated); atomic_dec(&tcp_sockets_allocated);
return 0; return 0;
......
...@@ -854,8 +854,8 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse ...@@ -854,8 +854,8 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse
np->cork.hop_limit = hlimit; np->cork.hop_limit = hlimit;
inet->cork.fragsize = mtu = dst_pmtu(&rt->u.dst); inet->cork.fragsize = mtu = dst_pmtu(&rt->u.dst);
inet->cork.length = 0; inet->cork.length = 0;
inet->sndmsg_page = NULL; sk->sk_sndmsg_page = NULL;
inet->sndmsg_off = 0; sk->sk_sndmsg_off = 0;
exthdrlen = rt->u.dst.header_len + (opt ? opt->opt_flen : 0); exthdrlen = rt->u.dst.header_len + (opt ? opt->opt_flen : 0);
length += exthdrlen; length += exthdrlen;
transhdrlen += exthdrlen; transhdrlen += exthdrlen;
...@@ -971,8 +971,8 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse ...@@ -971,8 +971,8 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse
} else { } else {
int i = skb_shinfo(skb)->nr_frags; int i = skb_shinfo(skb)->nr_frags;
skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1]; skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1];
struct page *page = inet->sndmsg_page; struct page *page = sk->sk_sndmsg_page;
int off = inet->sndmsg_off; int off = sk->sk_sndmsg_off;
unsigned int left; unsigned int left;
if (page && (left = PAGE_SIZE - off) > 0) { if (page && (left = PAGE_SIZE - off) > 0) {
...@@ -984,7 +984,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse ...@@ -984,7 +984,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse
goto error; goto error;
} }
get_page(page); get_page(page);
skb_fill_page_desc(skb, i, page, inet->sndmsg_off, 0); skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0);
frag = &skb_shinfo(skb)->frags[i]; frag = &skb_shinfo(skb)->frags[i];
} }
} else if(i < MAX_SKB_FRAGS) { } else if(i < MAX_SKB_FRAGS) {
...@@ -995,8 +995,8 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse ...@@ -995,8 +995,8 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse
err = -ENOMEM; err = -ENOMEM;
goto error; goto error;
} }
inet->sndmsg_page = page; sk->sk_sndmsg_page = page;
inet->sndmsg_off = 0; sk->sk_sndmsg_off = 0;
skb_fill_page_desc(skb, i, page, 0, 0); skb_fill_page_desc(skb, i, page, 0, 0);
frag = &skb_shinfo(skb)->frags[i]; frag = &skb_shinfo(skb)->frags[i];
...@@ -1010,7 +1010,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse ...@@ -1010,7 +1010,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse
err = -EFAULT; err = -EFAULT;
goto error; goto error;
} }
inet->sndmsg_off += copy; sk->sk_sndmsg_off += copy;
frag->size += copy; frag->size += copy;
skb->len += copy; skb->len += copy;
skb->data_len += copy; skb->data_len += copy;
......
...@@ -1911,10 +1911,6 @@ static int tcp_v6_destroy_sock(struct sock *sk) ...@@ -1911,10 +1911,6 @@ static int tcp_v6_destroy_sock(struct sock *sk)
if (tcp_sk(sk)->bind_hash) if (tcp_sk(sk)->bind_hash)
tcp_put_port(sk); tcp_put_port(sk);
/* If sendmsg cached page exists, toss it. */
if (inet->sndmsg_page != NULL)
__free_page(inet->sndmsg_page);
atomic_dec(&tcp_sockets_allocated); atomic_dec(&tcp_sockets_allocated);
return inet6_destroy_sock(sk); return inet6_destroy_sock(sk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment