Skip to content

Commit 5c52ba1

Browse files
xemuldavem330
authored andcommitted
sock: add net to prot->enter_memory_pressure callback
The tcp_enter_memory_pressure calls NET_INC_STATS, but doesn't have where to get the net from. I decided to add a sk argument, not the net itself, only to factor all the required sock_net(sk) calls inside the enter_memory_pressure callback itself. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cf1100a commit 5c52ba1

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

include/net/sock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ struct proto {
565565
#endif
566566

567567
/* Memory pressure */
568-
void (*enter_memory_pressure)(void);
568+
void (*enter_memory_pressure)(struct sock *sk);
569569
atomic_t *memory_allocated; /* Current allocated memory. */
570570
atomic_t *sockets_allocated; /* Current number of sockets. */
571571
/*
@@ -1210,7 +1210,7 @@ static inline struct page *sk_stream_alloc_page(struct sock *sk)
12101210

12111211
page = alloc_pages(sk->sk_allocation, 0);
12121212
if (!page) {
1213-
sk->sk_prot->enter_memory_pressure();
1213+
sk->sk_prot->enter_memory_pressure(sk);
12141214
sk_stream_moderate_sndbuf(sk);
12151215
}
12161216
return page;

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static inline void tcp_openreq_init(struct request_sock *req,
975975
ireq->rmt_port = tcp_hdr(skb)->source;
976976
}
977977

978-
extern void tcp_enter_memory_pressure(void);
978+
extern void tcp_enter_memory_pressure(struct sock *sk);
979979

980980
static inline int keepalive_intvl_when(const struct tcp_sock *tp)
981981
{

net/core/sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
14421442
/* Under pressure. */
14431443
if (allocated > prot->sysctl_mem[1])
14441444
if (prot->enter_memory_pressure)
1445-
prot->enter_memory_pressure();
1445+
prot->enter_memory_pressure(sk);
14461446

14471447
/* Over hard limit. */
14481448
if (allocated > prot->sysctl_mem[2])

net/decnet/af_decnet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static void dn_destruct(struct sock *sk)
451451

452452
static int dn_memory_pressure;
453453

454-
static void dn_enter_memory_pressure(void)
454+
static void dn_enter_memory_pressure(struct sock *sk)
455455
{
456456
if (!dn_memory_pressure) {
457457
dn_memory_pressure = 1;

net/ipv4/tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ int tcp_memory_pressure __read_mostly;
316316

317317
EXPORT_SYMBOL(tcp_memory_pressure);
318318

319-
void tcp_enter_memory_pressure(void)
319+
void tcp_enter_memory_pressure(struct sock *sk)
320320
{
321321
if (!tcp_memory_pressure) {
322322
NET_INC_STATS(LINUX_MIB_TCPMEMORYPRESSURES);
@@ -649,7 +649,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp)
649649
}
650650
__kfree_skb(skb);
651651
} else {
652-
sk->sk_prot->enter_memory_pressure();
652+
sk->sk_prot->enter_memory_pressure(sk);
653653
sk_stream_moderate_sndbuf(sk);
654654
}
655655
return NULL;

net/sctp/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int sctp_memory_pressure;
116116
static atomic_t sctp_memory_allocated;
117117
static atomic_t sctp_sockets_allocated;
118118

119-
static void sctp_enter_memory_pressure(void)
119+
static void sctp_enter_memory_pressure(struct sock *sk)
120120
{
121121
sctp_memory_pressure = 1;
122122
}

0 commit comments

Comments
 (0)