Skip to content

Commit

Permalink
sock: add net to prot->enter_memory_pressure callback
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
xemul authored and davem330 committed Jul 17, 2008
1 parent cf1100a commit 5c52ba1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ struct proto {
#endif

/* Memory pressure */
void (*enter_memory_pressure)(void);
void (*enter_memory_pressure)(struct sock *sk);
atomic_t *memory_allocated; /* Current allocated memory. */
atomic_t *sockets_allocated; /* Current number of sockets. */
/*
Expand Down Expand Up @@ -1210,7 +1210,7 @@ static inline struct page *sk_stream_alloc_page(struct sock *sk)

page = alloc_pages(sk->sk_allocation, 0);
if (!page) {
sk->sk_prot->enter_memory_pressure();
sk->sk_prot->enter_memory_pressure(sk);
sk_stream_moderate_sndbuf(sk);
}
return page;
Expand Down
2 changes: 1 addition & 1 deletion include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ static inline void tcp_openreq_init(struct request_sock *req,
ireq->rmt_port = tcp_hdr(skb)->source;
}

extern void tcp_enter_memory_pressure(void);
extern void tcp_enter_memory_pressure(struct sock *sk);

static inline int keepalive_intvl_when(const struct tcp_sock *tp)
{
Expand Down
2 changes: 1 addition & 1 deletion net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
/* Under pressure. */
if (allocated > prot->sysctl_mem[1])
if (prot->enter_memory_pressure)
prot->enter_memory_pressure();
prot->enter_memory_pressure(sk);

/* Over hard limit. */
if (allocated > prot->sysctl_mem[2])
Expand Down
2 changes: 1 addition & 1 deletion net/decnet/af_decnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static void dn_destruct(struct sock *sk)

static int dn_memory_pressure;

static void dn_enter_memory_pressure(void)
static void dn_enter_memory_pressure(struct sock *sk)
{
if (!dn_memory_pressure) {
dn_memory_pressure = 1;
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ int tcp_memory_pressure __read_mostly;

EXPORT_SYMBOL(tcp_memory_pressure);

void tcp_enter_memory_pressure(void)
void tcp_enter_memory_pressure(struct sock *sk)
{
if (!tcp_memory_pressure) {
NET_INC_STATS(LINUX_MIB_TCPMEMORYPRESSURES);
Expand Down Expand Up @@ -649,7 +649,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp)
}
__kfree_skb(skb);
} else {
sk->sk_prot->enter_memory_pressure();
sk->sk_prot->enter_memory_pressure(sk);
sk_stream_moderate_sndbuf(sk);
}
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static int sctp_memory_pressure;
static atomic_t sctp_memory_allocated;
static atomic_t sctp_sockets_allocated;

static void sctp_enter_memory_pressure(void)
static void sctp_enter_memory_pressure(struct sock *sk)
{
sctp_memory_pressure = 1;
}
Expand Down

0 comments on commit 5c52ba1

Please sign in to comment.