net: tcp_memcontrol: simplify the per-memcg limit access
tcp_memcontrol replicates the global sysctl_mem limit array per cgroup, but it only ever sets these entries to the value of the memory_allocated page_counter limit. Use the latter directly. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
af95d7df40
commit
80f23124f5
@ -89,7 +89,6 @@ struct cg_proto {
|
|||||||
struct page_counter memory_allocated; /* Current allocated memory. */
|
struct page_counter memory_allocated; /* Current allocated memory. */
|
||||||
int memory_pressure;
|
int memory_pressure;
|
||||||
bool active;
|
bool active;
|
||||||
long sysctl_mem[3];
|
|
||||||
/*
|
/*
|
||||||
* memcg field is used to find which memcg we belong directly
|
* memcg field is used to find which memcg we belong directly
|
||||||
* Each memcg struct can hold more than one cg_proto, so container_of
|
* Each memcg struct can hold more than one cg_proto, so container_of
|
||||||
|
@ -1162,10 +1162,12 @@ static inline void sk_enter_memory_pressure(struct sock *sk)
|
|||||||
|
|
||||||
static inline long sk_prot_mem_limits(const struct sock *sk, int index)
|
static inline long sk_prot_mem_limits(const struct sock *sk, int index)
|
||||||
{
|
{
|
||||||
long *prot = sk->sk_prot->sysctl_mem;
|
long limit = sk->sk_prot->sysctl_mem[index];
|
||||||
|
|
||||||
if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
|
if (mem_cgroup_sockets_enabled && sk->sk_cgrp)
|
||||||
prot = sk->sk_cgrp->sysctl_mem;
|
limit = min_t(long, limit, sk->sk_cgrp->memory_allocated.limit);
|
||||||
return prot[index];
|
|
||||||
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void memcg_memory_allocated_add(struct cg_proto *prot,
|
static inline void memcg_memory_allocated_add(struct cg_proto *prot,
|
||||||
|
@ -21,9 +21,6 @@ int tcp_init_cgroup(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
|
|||||||
if (!cg_proto)
|
if (!cg_proto)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cg_proto->sysctl_mem[0] = sysctl_tcp_mem[0];
|
|
||||||
cg_proto->sysctl_mem[1] = sysctl_tcp_mem[1];
|
|
||||||
cg_proto->sysctl_mem[2] = sysctl_tcp_mem[2];
|
|
||||||
cg_proto->memory_pressure = 0;
|
cg_proto->memory_pressure = 0;
|
||||||
cg_proto->memcg = memcg;
|
cg_proto->memcg = memcg;
|
||||||
|
|
||||||
@ -54,7 +51,6 @@ EXPORT_SYMBOL(tcp_destroy_cgroup);
|
|||||||
static int tcp_update_limit(struct mem_cgroup *memcg, unsigned long nr_pages)
|
static int tcp_update_limit(struct mem_cgroup *memcg, unsigned long nr_pages)
|
||||||
{
|
{
|
||||||
struct cg_proto *cg_proto;
|
struct cg_proto *cg_proto;
|
||||||
int i;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cg_proto = tcp_prot.proto_cgroup(memcg);
|
cg_proto = tcp_prot.proto_cgroup(memcg);
|
||||||
@ -65,10 +61,6 @@ static int tcp_update_limit(struct mem_cgroup *memcg, unsigned long nr_pages)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
cg_proto->sysctl_mem[i] = min_t(long, nr_pages,
|
|
||||||
sysctl_tcp_mem[i]);
|
|
||||||
|
|
||||||
if (!cg_proto->active) {
|
if (!cg_proto->active) {
|
||||||
/*
|
/*
|
||||||
* The active flag needs to be written after the static_key
|
* The active flag needs to be written after the static_key
|
||||||
|
Reference in New Issue
Block a user