Skip to content

Commit 99a1dec

Browse files
Mel Gormantorvalds
authored andcommitted
net: introduce sk_gfp_atomic() to allow addition of GFP flags depending on the individual socket
Introduce sk_gfp_atomic(), this function allows to inject sock specific flags to each sock related allocation. It is only used on allocation paths that may be required for writing pages back to network storage. [davem@davemloft.net: Use sk_gfp_atomic only when necessary] Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Mel Gorman <mgorman@suse.de> Acked-by: David S. Miller <davem@davemloft.net> Cc: Neil Brown <neilb@suse.de> Cc: Mike Christie <michaelc@cs.wisc.edu> Cc: Eric B Munson <emunson@mgebm.net> Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> Cc: Mel Gorman <mgorman@suse.de> Cc: Christoph Lameter <cl@linux.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 183f637 commit 99a1dec

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎include/net/sock.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ static inline bool sock_flag(const struct sock *sk, enum sock_flags flag)
658658
return test_bit(flag, &sk->sk_flags);
659659
}
660660

661+
static inline gfp_t sk_gfp_atomic(struct sock *sk, gfp_t gfp_mask)
662+
{
663+
return GFP_ATOMIC;
664+
}
665+
661666
static inline void sk_acceptq_removed(struct sock *sk)
662667
{
663668
sk->sk_ack_backlog--;

‎net/ipv4/tcp_output.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,8 @@ void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
20452045
if (unlikely(sk->sk_state == TCP_CLOSE))
20462046
return;
20472047

2048-
if (tcp_write_xmit(sk, cur_mss, nonagle, 0, GFP_ATOMIC))
2048+
if (tcp_write_xmit(sk, cur_mss, nonagle, 0,
2049+
sk_gfp_atomic(sk, GFP_ATOMIC)))
20492050
tcp_check_probe_timer(sk);
20502051
}
20512052

@@ -2666,7 +2667,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
26662667

26672668
if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
26682669
s_data_desired = cvp->s_data_desired;
2669-
skb = alloc_skb(MAX_TCP_HEADER + 15 + s_data_desired, GFP_ATOMIC);
2670+
skb = alloc_skb(MAX_TCP_HEADER + 15 + s_data_desired,
2671+
sk_gfp_atomic(sk, GFP_ATOMIC));
26702672
if (unlikely(!skb)) {
26712673
dst_release(dst);
26722674
return NULL;
@@ -3064,7 +3066,7 @@ void tcp_send_ack(struct sock *sk)
30643066
* tcp_transmit_skb() will set the ownership to this
30653067
* sock.
30663068
*/
3067-
buff = alloc_skb(MAX_TCP_HEADER, GFP_ATOMIC);
3069+
buff = alloc_skb(MAX_TCP_HEADER, sk_gfp_atomic(sk, GFP_ATOMIC));
30683070
if (buff == NULL) {
30693071
inet_csk_schedule_ack(sk);
30703072
inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
@@ -3079,7 +3081,7 @@ void tcp_send_ack(struct sock *sk)
30793081

30803082
/* Send it off, this clears delayed acks for us. */
30813083
TCP_SKB_CB(buff)->when = tcp_time_stamp;
3082-
tcp_transmit_skb(sk, buff, 0, GFP_ATOMIC);
3084+
tcp_transmit_skb(sk, buff, 0, sk_gfp_atomic(sk, GFP_ATOMIC));
30833085
}
30843086

30853087
/* This routine sends a packet with an out of date sequence
@@ -3099,7 +3101,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
30993101
struct sk_buff *skb;
31003102

31013103
/* We don't queue it, tcp_transmit_skb() sets ownership. */
3102-
skb = alloc_skb(MAX_TCP_HEADER, GFP_ATOMIC);
3104+
skb = alloc_skb(MAX_TCP_HEADER, sk_gfp_atomic(sk, GFP_ATOMIC));
31033105
if (skb == NULL)
31043106
return -1;
31053107

‎net/ipv6/tcp_ipv6.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,8 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
12991299
/* Clone pktoptions received with SYN */
13001300
newnp->pktoptions = NULL;
13011301
if (treq->pktopts != NULL) {
1302-
newnp->pktoptions = skb_clone(treq->pktopts, GFP_ATOMIC);
1302+
newnp->pktoptions = skb_clone(treq->pktopts,
1303+
sk_gfp_atomic(sk, GFP_ATOMIC));
13031304
consume_skb(treq->pktopts);
13041305
treq->pktopts = NULL;
13051306
if (newnp->pktoptions)
@@ -1349,7 +1350,8 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
13491350
* across. Shucks.
13501351
*/
13511352
tcp_md5_do_add(newsk, (union tcp_md5_addr *)&newnp->daddr,
1352-
AF_INET6, key->key, key->keylen, GFP_ATOMIC);
1353+
AF_INET6, key->key, key->keylen,
1354+
sk_gfp_atomic(sk, GFP_ATOMIC));
13531355
}
13541356
#endif
13551357

@@ -1442,7 +1444,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
14421444
--ANK (980728)
14431445
*/
14441446
if (np->rxopt.all)
1445-
opt_skb = skb_clone(skb, GFP_ATOMIC);
1447+
opt_skb = skb_clone(skb, sk_gfp_atomic(sk, GFP_ATOMIC));
14461448

14471449
if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */
14481450
sock_rps_save_rxhash(sk, skb);

0 commit comments

Comments
 (0)