Skip to content

Commit

Permalink
net/packet: introduce packet_rcv_try_clear_pressure() helper
Browse files Browse the repository at this point in the history
There are two places where we want to clear the pressure
if possible, add a helper to make it more obvious.

Signed-off-by: Eric Dumazet <[email protected]>
Suggested-by: Willem de Bruijn <[email protected]>
Acked-by: Vinicius Costa Gomes <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Jun 15, 2019
1 parent 3a2bb84 commit 9bb6cd6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,13 @@ static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb)
return ret;
}

static void packet_rcv_try_clear_pressure(struct packet_sock *po)
{
if (READ_ONCE(po->pressure) &&
__packet_rcv_has_room(po, NULL) == ROOM_NORMAL)
WRITE_ONCE(po->pressure, 0);
}

static void packet_sock_destruct(struct sock *sk)
{
skb_queue_purge(&sk->sk_error_queue);
Expand Down Expand Up @@ -3308,8 +3315,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
if (skb == NULL)
goto out;

if (READ_ONCE(pkt_sk(sk)->pressure))
packet_rcv_has_room(pkt_sk(sk), NULL);
packet_rcv_try_clear_pressure(pkt_sk(sk));

if (pkt_sk(sk)->has_vnet_hdr) {
err = packet_rcv_vnet(msg, skb, &len);
Expand Down Expand Up @@ -4127,8 +4133,7 @@ static __poll_t packet_poll(struct file *file, struct socket *sock,
TP_STATUS_KERNEL))
mask |= EPOLLIN | EPOLLRDNORM;
}
if (READ_ONCE(po->pressure) && __packet_rcv_has_room(po, NULL) == ROOM_NORMAL)
WRITE_ONCE(po->pressure, 0);
packet_rcv_try_clear_pressure(po);
spin_unlock_bh(&sk->sk_receive_queue.lock);
spin_lock_bh(&sk->sk_write_queue.lock);
if (po->tx_ring.pg_vec) {
Expand Down

0 comments on commit 9bb6cd6

Please sign in to comment.