aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/sock.h29
-rw-r--r--net/ipv4/tcp.c27
2 files changed, 29 insertions, 27 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index e329d05f7995..7d500a825e4e 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1192,33 +1192,8 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
1192 } 1192 }
1193} 1193}
1194 1194
1195static inline struct sk_buff *sk_stream_alloc_pskb(struct sock *sk, 1195struct sk_buff *sk_stream_alloc_pskb(struct sock *sk,
1196 int size, int mem, 1196 int size, int mem, gfp_t gfp);
1197 gfp_t gfp)
1198{
1199 struct sk_buff *skb;
1200
1201 /* The TCP header must be at least 32-bit aligned. */
1202 size = ALIGN(size, 4);
1203
1204 skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp);
1205 if (skb) {
1206 skb->truesize += mem;
1207 if (sk_stream_wmem_schedule(sk, skb->truesize)) {
1208 /*
1209 * Make sure that we have exactly size bytes
1210 * available to the caller, no more, no less.
1211 */
1212 skb_reserve(skb, skb_tailroom(skb) - size);
1213 return skb;
1214 }
1215 __kfree_skb(skb);
1216 } else {
1217 sk->sk_prot->enter_memory_pressure();
1218 sk_stream_moderate_sndbuf(sk);
1219 }
1220 return NULL;
1221}
1222 1197
1223static inline struct sk_buff *sk_stream_alloc_skb(struct sock *sk, 1198static inline struct sk_buff *sk_stream_alloc_skb(struct sock *sk,
1224 int size, 1199 int size,
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e055f25876df..6b35ab841db2 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -629,6 +629,33 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
629 return ret; 629 return ret;
630} 630}
631 631
632struct sk_buff *sk_stream_alloc_pskb(struct sock *sk,
633 int size, int mem, gfp_t gfp)
634{
635 struct sk_buff *skb;
636
637 /* The TCP header must be at least 32-bit aligned. */
638 size = ALIGN(size, 4);
639
640 skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp);
641 if (skb) {
642 skb->truesize += mem;
643 if (sk_stream_wmem_schedule(sk, skb->truesize)) {
644 /*
645 * Make sure that we have exactly size bytes
646 * available to the caller, no more, no less.
647 */
648 skb_reserve(skb, skb_tailroom(skb) - size);
649 return skb;
650 }
651 __kfree_skb(skb);
652 } else {
653 sk->sk_prot->enter_memory_pressure();
654 sk_stream_moderate_sndbuf(sk);
655 }
656 return NULL;
657}
658
632static ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, 659static ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset,
633 size_t psize, int flags) 660 size_t psize, int flags)
634{ 661{