mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
net: remove SK_MEM_QUANTUM and SK_MEM_QUANTUM_SHIFT
Due to memcg interface, SK_MEM_QUANTUM is effectively PAGE_SIZE. This might change in the future, but it seems better to avoid the confusion. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
e70f3c7012
commit
100fdd1faf
@ -1532,8 +1532,6 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind);
|
|||||||
void __sk_mem_reduce_allocated(struct sock *sk, int amount);
|
void __sk_mem_reduce_allocated(struct sock *sk, int amount);
|
||||||
void __sk_mem_reclaim(struct sock *sk, int amount);
|
void __sk_mem_reclaim(struct sock *sk, int amount);
|
||||||
|
|
||||||
#define SK_MEM_QUANTUM ((int)PAGE_SIZE)
|
|
||||||
#define SK_MEM_QUANTUM_SHIFT ilog2(SK_MEM_QUANTUM)
|
|
||||||
#define SK_MEM_SEND 0
|
#define SK_MEM_SEND 0
|
||||||
#define SK_MEM_RECV 1
|
#define SK_MEM_RECV 1
|
||||||
|
|
||||||
@ -1545,7 +1543,7 @@ static inline long sk_prot_mem_limits(const struct sock *sk, int index)
|
|||||||
|
|
||||||
static inline int sk_mem_pages(int amt)
|
static inline int sk_mem_pages(int amt)
|
||||||
{
|
{
|
||||||
return (amt + SK_MEM_QUANTUM - 1) >> SK_MEM_QUANTUM_SHIFT;
|
return (amt + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool sk_has_account(struct sock *sk)
|
static inline bool sk_has_account(struct sock *sk)
|
||||||
@ -1594,7 +1592,7 @@ static inline void sk_mem_reclaim(struct sock *sk)
|
|||||||
|
|
||||||
reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk);
|
reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk);
|
||||||
|
|
||||||
if (reclaimable >= SK_MEM_QUANTUM)
|
if (reclaimable >= (int)PAGE_SIZE)
|
||||||
__sk_mem_reclaim(sk, reclaimable);
|
__sk_mem_reclaim(sk, reclaimable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1613,7 +1611,7 @@ static inline void sk_mem_reclaim_partial(struct sock *sk)
|
|||||||
|
|
||||||
reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk);
|
reclaimable = sk->sk_forward_alloc - sk_unused_reserved_mem(sk);
|
||||||
|
|
||||||
if (reclaimable > SK_MEM_QUANTUM)
|
if (reclaimable > (int)PAGE_SIZE)
|
||||||
__sk_mem_reclaim(sk, reclaimable - 1);
|
__sk_mem_reclaim(sk, reclaimable - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,7 +991,7 @@ EXPORT_SYMBOL(sock_set_mark);
|
|||||||
static void sock_release_reserved_memory(struct sock *sk, int bytes)
|
static void sock_release_reserved_memory(struct sock *sk, int bytes)
|
||||||
{
|
{
|
||||||
/* Round down bytes to multiple of pages */
|
/* Round down bytes to multiple of pages */
|
||||||
bytes &= ~(SK_MEM_QUANTUM - 1);
|
bytes = round_down(bytes, PAGE_SIZE);
|
||||||
|
|
||||||
WARN_ON(bytes > sk->sk_reserved_mem);
|
WARN_ON(bytes > sk->sk_reserved_mem);
|
||||||
sk->sk_reserved_mem -= bytes;
|
sk->sk_reserved_mem -= bytes;
|
||||||
@ -1028,9 +1028,9 @@ static int sock_reserve_memory(struct sock *sk, int bytes)
|
|||||||
mem_cgroup_uncharge_skmem(sk->sk_memcg, pages);
|
mem_cgroup_uncharge_skmem(sk->sk_memcg, pages);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
sk->sk_forward_alloc += pages << SK_MEM_QUANTUM_SHIFT;
|
sk->sk_forward_alloc += pages << PAGE_SHIFT;
|
||||||
|
|
||||||
sk->sk_reserved_mem += pages << SK_MEM_QUANTUM_SHIFT;
|
sk->sk_reserved_mem += pages << PAGE_SHIFT;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3003,10 +3003,10 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)
|
|||||||
{
|
{
|
||||||
int ret, amt = sk_mem_pages(size);
|
int ret, amt = sk_mem_pages(size);
|
||||||
|
|
||||||
sk->sk_forward_alloc += amt << SK_MEM_QUANTUM_SHIFT;
|
sk->sk_forward_alloc += amt << PAGE_SHIFT;
|
||||||
ret = __sk_mem_raise_allocated(sk, size, amt, kind);
|
ret = __sk_mem_raise_allocated(sk, size, amt, kind);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
sk->sk_forward_alloc -= amt << SK_MEM_QUANTUM_SHIFT;
|
sk->sk_forward_alloc -= amt << PAGE_SHIFT;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__sk_mem_schedule);
|
EXPORT_SYMBOL(__sk_mem_schedule);
|
||||||
@ -3034,12 +3034,12 @@ EXPORT_SYMBOL(__sk_mem_reduce_allocated);
|
|||||||
/**
|
/**
|
||||||
* __sk_mem_reclaim - reclaim sk_forward_alloc and memory_allocated
|
* __sk_mem_reclaim - reclaim sk_forward_alloc and memory_allocated
|
||||||
* @sk: socket
|
* @sk: socket
|
||||||
* @amount: number of bytes (rounded down to a SK_MEM_QUANTUM multiple)
|
* @amount: number of bytes (rounded down to a PAGE_SIZE multiple)
|
||||||
*/
|
*/
|
||||||
void __sk_mem_reclaim(struct sock *sk, int amount)
|
void __sk_mem_reclaim(struct sock *sk, int amount)
|
||||||
{
|
{
|
||||||
amount >>= SK_MEM_QUANTUM_SHIFT;
|
amount >>= PAGE_SHIFT;
|
||||||
sk->sk_forward_alloc -= amount << SK_MEM_QUANTUM_SHIFT;
|
sk->sk_forward_alloc -= amount << PAGE_SHIFT;
|
||||||
__sk_mem_reduce_allocated(sk, amount);
|
__sk_mem_reduce_allocated(sk, amount);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__sk_mem_reclaim);
|
EXPORT_SYMBOL(__sk_mem_reclaim);
|
||||||
|
@ -4661,11 +4661,11 @@ void __init tcp_init(void)
|
|||||||
max_wshare = min(4UL*1024*1024, limit);
|
max_wshare = min(4UL*1024*1024, limit);
|
||||||
max_rshare = min(6UL*1024*1024, limit);
|
max_rshare = min(6UL*1024*1024, limit);
|
||||||
|
|
||||||
init_net.ipv4.sysctl_tcp_wmem[0] = SK_MEM_QUANTUM;
|
init_net.ipv4.sysctl_tcp_wmem[0] = PAGE_SIZE;
|
||||||
init_net.ipv4.sysctl_tcp_wmem[1] = 16*1024;
|
init_net.ipv4.sysctl_tcp_wmem[1] = 16*1024;
|
||||||
init_net.ipv4.sysctl_tcp_wmem[2] = max(64*1024, max_wshare);
|
init_net.ipv4.sysctl_tcp_wmem[2] = max(64*1024, max_wshare);
|
||||||
|
|
||||||
init_net.ipv4.sysctl_tcp_rmem[0] = SK_MEM_QUANTUM;
|
init_net.ipv4.sysctl_tcp_rmem[0] = PAGE_SIZE;
|
||||||
init_net.ipv4.sysctl_tcp_rmem[1] = 131072;
|
init_net.ipv4.sysctl_tcp_rmem[1] = 131072;
|
||||||
init_net.ipv4.sysctl_tcp_rmem[2] = max(131072, max_rshare);
|
init_net.ipv4.sysctl_tcp_rmem[2] = max(131072, max_rshare);
|
||||||
|
|
||||||
|
@ -5287,7 +5287,7 @@ new_range:
|
|||||||
before(TCP_SKB_CB(skb)->end_seq, start)) {
|
before(TCP_SKB_CB(skb)->end_seq, start)) {
|
||||||
/* Do not attempt collapsing tiny skbs */
|
/* Do not attempt collapsing tiny skbs */
|
||||||
if (range_truesize != head->truesize ||
|
if (range_truesize != head->truesize ||
|
||||||
end - start >= SKB_WITH_OVERHEAD(SK_MEM_QUANTUM)) {
|
end - start >= SKB_WITH_OVERHEAD(PAGE_SIZE)) {
|
||||||
tcp_collapse(sk, NULL, &tp->out_of_order_queue,
|
tcp_collapse(sk, NULL, &tp->out_of_order_queue,
|
||||||
head, skb, start, end);
|
head, skb, start, end);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3367,7 +3367,7 @@ void sk_forced_mem_schedule(struct sock *sk, int size)
|
|||||||
if (size <= sk->sk_forward_alloc)
|
if (size <= sk->sk_forward_alloc)
|
||||||
return;
|
return;
|
||||||
amt = sk_mem_pages(size);
|
amt = sk_mem_pages(size);
|
||||||
sk->sk_forward_alloc += amt * SK_MEM_QUANTUM;
|
sk->sk_forward_alloc += amt << PAGE_SHIFT;
|
||||||
sk_memory_allocated_add(sk, amt);
|
sk_memory_allocated_add(sk, amt);
|
||||||
|
|
||||||
if (mem_cgroup_sockets_enabled && sk->sk_memcg)
|
if (mem_cgroup_sockets_enabled && sk->sk_memcg)
|
||||||
|
@ -1461,11 +1461,11 @@ static void udp_rmem_release(struct sock *sk, int size, int partial,
|
|||||||
|
|
||||||
|
|
||||||
sk->sk_forward_alloc += size;
|
sk->sk_forward_alloc += size;
|
||||||
amt = (sk->sk_forward_alloc - partial) & ~(SK_MEM_QUANTUM - 1);
|
amt = (sk->sk_forward_alloc - partial) & ~(PAGE_SIZE - 1);
|
||||||
sk->sk_forward_alloc -= amt;
|
sk->sk_forward_alloc -= amt;
|
||||||
|
|
||||||
if (amt)
|
if (amt)
|
||||||
__sk_mem_reduce_allocated(sk, amt >> SK_MEM_QUANTUM_SHIFT);
|
__sk_mem_reduce_allocated(sk, amt >> PAGE_SHIFT);
|
||||||
|
|
||||||
atomic_sub(size, &sk->sk_rmem_alloc);
|
atomic_sub(size, &sk->sk_rmem_alloc);
|
||||||
|
|
||||||
@ -1558,7 +1558,7 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
|
|||||||
spin_lock(&list->lock);
|
spin_lock(&list->lock);
|
||||||
if (size >= sk->sk_forward_alloc) {
|
if (size >= sk->sk_forward_alloc) {
|
||||||
amt = sk_mem_pages(size);
|
amt = sk_mem_pages(size);
|
||||||
delta = amt << SK_MEM_QUANTUM_SHIFT;
|
delta = amt << PAGE_SHIFT;
|
||||||
if (!__sk_mem_raise_allocated(sk, delta, amt, SK_MEM_RECV)) {
|
if (!__sk_mem_raise_allocated(sk, delta, amt, SK_MEM_RECV)) {
|
||||||
err = -ENOBUFS;
|
err = -ENOBUFS;
|
||||||
spin_unlock(&list->lock);
|
spin_unlock(&list->lock);
|
||||||
@ -3263,8 +3263,8 @@ EXPORT_SYMBOL(udp_flow_hashrnd);
|
|||||||
|
|
||||||
static void __udp_sysctl_init(struct net *net)
|
static void __udp_sysctl_init(struct net *net)
|
||||||
{
|
{
|
||||||
net->ipv4.sysctl_udp_rmem_min = SK_MEM_QUANTUM;
|
net->ipv4.sysctl_udp_rmem_min = PAGE_SIZE;
|
||||||
net->ipv4.sysctl_udp_wmem_min = SK_MEM_QUANTUM;
|
net->ipv4.sysctl_udp_wmem_min = PAGE_SIZE;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L3_MASTER_DEV
|
#ifdef CONFIG_NET_L3_MASTER_DEV
|
||||||
net->ipv4.sysctl_udp_l3mdev_accept = 0;
|
net->ipv4.sysctl_udp_l3mdev_accept = 0;
|
||||||
|
@ -167,8 +167,8 @@ static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
|
|||||||
|
|
||||||
static void __mptcp_rmem_reclaim(struct sock *sk, int amount)
|
static void __mptcp_rmem_reclaim(struct sock *sk, int amount)
|
||||||
{
|
{
|
||||||
amount >>= SK_MEM_QUANTUM_SHIFT;
|
amount >>= PAGE_SHIFT;
|
||||||
mptcp_sk(sk)->rmem_fwd_alloc -= amount << SK_MEM_QUANTUM_SHIFT;
|
mptcp_sk(sk)->rmem_fwd_alloc -= amount << PAGE_SHIFT;
|
||||||
__sk_mem_reduce_allocated(sk, amount);
|
__sk_mem_reduce_allocated(sk, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ static bool mptcp_rmem_schedule(struct sock *sk, struct sock *ssk, int size)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
amt = sk_mem_pages(size);
|
amt = sk_mem_pages(size);
|
||||||
amount = amt << SK_MEM_QUANTUM_SHIFT;
|
amount = amt << PAGE_SHIFT;
|
||||||
msk->rmem_fwd_alloc += amount;
|
msk->rmem_fwd_alloc += amount;
|
||||||
if (!__sk_mem_raise_allocated(sk, size, amt, SK_MEM_RECV)) {
|
if (!__sk_mem_raise_allocated(sk, size, amt, SK_MEM_RECV)) {
|
||||||
if (ssk->sk_forward_alloc < amount) {
|
if (ssk->sk_forward_alloc < amount) {
|
||||||
@ -972,7 +972,7 @@ static void __mptcp_mem_reclaim_partial(struct sock *sk)
|
|||||||
|
|
||||||
lockdep_assert_held_once(&sk->sk_lock.slock);
|
lockdep_assert_held_once(&sk->sk_lock.slock);
|
||||||
|
|
||||||
if (reclaimable > SK_MEM_QUANTUM)
|
if (reclaimable > (int)PAGE_SIZE)
|
||||||
__mptcp_rmem_reclaim(sk, reclaimable - 1);
|
__mptcp_rmem_reclaim(sk, reclaimable - 1);
|
||||||
|
|
||||||
sk_mem_reclaim_partial(sk);
|
sk_mem_reclaim_partial(sk);
|
||||||
|
@ -1523,11 +1523,11 @@ static __init int sctp_init(void)
|
|||||||
limit = (sysctl_sctp_mem[1]) << (PAGE_SHIFT - 7);
|
limit = (sysctl_sctp_mem[1]) << (PAGE_SHIFT - 7);
|
||||||
max_share = min(4UL*1024*1024, limit);
|
max_share = min(4UL*1024*1024, limit);
|
||||||
|
|
||||||
sysctl_sctp_rmem[0] = SK_MEM_QUANTUM; /* give each asoc 1 page min */
|
sysctl_sctp_rmem[0] = PAGE_SIZE; /* give each asoc 1 page min */
|
||||||
sysctl_sctp_rmem[1] = 1500 * SKB_TRUESIZE(1);
|
sysctl_sctp_rmem[1] = 1500 * SKB_TRUESIZE(1);
|
||||||
sysctl_sctp_rmem[2] = max(sysctl_sctp_rmem[1], max_share);
|
sysctl_sctp_rmem[2] = max(sysctl_sctp_rmem[1], max_share);
|
||||||
|
|
||||||
sysctl_sctp_wmem[0] = SK_MEM_QUANTUM;
|
sysctl_sctp_wmem[0] = PAGE_SIZE;
|
||||||
sysctl_sctp_wmem[1] = 16*1024;
|
sysctl_sctp_wmem[1] = 16*1024;
|
||||||
sysctl_sctp_wmem[2] = max(64*1024, max_share);
|
sysctl_sctp_wmem[2] = max(64*1024, max_share);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user