提交 1a24e04e 编写于 作者: E Eric Dumazet 提交者: David S. Miller

net: fix sk_mem_reclaim_partial()

sk_mem_reclaim_partial() goal is to ensure each socket has
one SK_MEM_QUANTUM forward allocation. This is needed both for
performance and better handling of memory pressure situations in
follow up patches.

SK_MEM_QUANTUM is currently a page, but might be reduced to 4096 bytes
as some arches have 64KB pages.
Signed-off-by: NEric Dumazet <edumazet@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 4633c9e0
...@@ -1368,7 +1368,7 @@ static inline struct inode *SOCK_INODE(struct socket *socket) ...@@ -1368,7 +1368,7 @@ static inline struct inode *SOCK_INODE(struct socket *socket)
* Functions for memory accounting * Functions for memory accounting
*/ */
int __sk_mem_schedule(struct sock *sk, int size, int kind); int __sk_mem_schedule(struct sock *sk, int size, int kind);
void __sk_mem_reclaim(struct sock *sk); void __sk_mem_reclaim(struct sock *sk, int amount);
#define SK_MEM_QUANTUM ((int)PAGE_SIZE) #define SK_MEM_QUANTUM ((int)PAGE_SIZE)
#define SK_MEM_QUANTUM_SHIFT ilog2(SK_MEM_QUANTUM) #define SK_MEM_QUANTUM_SHIFT ilog2(SK_MEM_QUANTUM)
...@@ -1409,7 +1409,7 @@ static inline void sk_mem_reclaim(struct sock *sk) ...@@ -1409,7 +1409,7 @@ static inline void sk_mem_reclaim(struct sock *sk)
if (!sk_has_account(sk)) if (!sk_has_account(sk))
return; return;
if (sk->sk_forward_alloc >= SK_MEM_QUANTUM) if (sk->sk_forward_alloc >= SK_MEM_QUANTUM)
__sk_mem_reclaim(sk); __sk_mem_reclaim(sk, sk->sk_forward_alloc);
} }
static inline void sk_mem_reclaim_partial(struct sock *sk) static inline void sk_mem_reclaim_partial(struct sock *sk)
...@@ -1417,7 +1417,7 @@ static inline void sk_mem_reclaim_partial(struct sock *sk) ...@@ -1417,7 +1417,7 @@ static inline void sk_mem_reclaim_partial(struct sock *sk)
if (!sk_has_account(sk)) if (!sk_has_account(sk))
return; return;
if (sk->sk_forward_alloc > SK_MEM_QUANTUM) if (sk->sk_forward_alloc > SK_MEM_QUANTUM)
__sk_mem_reclaim(sk); __sk_mem_reclaim(sk, sk->sk_forward_alloc - 1);
} }
static inline void sk_mem_charge(struct sock *sk, int size) static inline void sk_mem_charge(struct sock *sk, int size)
......
...@@ -2069,12 +2069,13 @@ EXPORT_SYMBOL(__sk_mem_schedule); ...@@ -2069,12 +2069,13 @@ EXPORT_SYMBOL(__sk_mem_schedule);
/** /**
* __sk_reclaim - reclaim memory_allocated * __sk_reclaim - reclaim memory_allocated
* @sk: socket * @sk: socket
* @amount: number of bytes (rounded down to a SK_MEM_QUANTUM multiple)
*/ */
void __sk_mem_reclaim(struct sock *sk) void __sk_mem_reclaim(struct sock *sk, int amount)
{ {
sk_memory_allocated_sub(sk, amount >>= SK_MEM_QUANTUM_SHIFT;
sk->sk_forward_alloc >> SK_MEM_QUANTUM_SHIFT); sk_memory_allocated_sub(sk, amount);
sk->sk_forward_alloc &= SK_MEM_QUANTUM - 1; sk->sk_forward_alloc -= amount << SK_MEM_QUANTUM_SHIFT;
if (sk_under_memory_pressure(sk) && if (sk_under_memory_pressure(sk) &&
(sk_memory_allocated(sk) < sk_prot_mem_limits(sk, 0))) (sk_memory_allocated(sk) < sk_prot_mem_limits(sk, 0)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册