forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch introduces memory pressure controls for the tcp protocol. It uses the generic socket memory pressure code introduced in earlier patches, and fills in the necessary data in cg_proto struct. Signed-off-by: Glauber Costa <[email protected]> Reviewed-by: KAMEZAWA Hiroyuki <[email protected]> CC: Eric W. Biederman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
- Loading branch information
Showing
10 changed files
with
189 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef _TCP_MEMCG_H | ||
#define _TCP_MEMCG_H | ||
|
||
struct tcp_memcontrol { | ||
struct cg_proto cg_proto; | ||
/* per-cgroup tcp memory pressure knobs */ | ||
struct res_counter tcp_memory_allocated; | ||
struct percpu_counter tcp_sockets_allocated; | ||
/* those two are read-mostly, leave them at the end */ | ||
long tcp_prot_mem[3]; | ||
int tcp_memory_pressure; | ||
}; | ||
|
||
struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg); | ||
int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss); | ||
void tcp_destroy_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss); | ||
#endif /* _TCP_MEMCG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <net/tcp.h> | ||
#include <net/tcp_memcontrol.h> | ||
#include <net/sock.h> | ||
#include <linux/memcontrol.h> | ||
#include <linux/module.h> | ||
|
||
static inline struct tcp_memcontrol *tcp_from_cgproto(struct cg_proto *cg_proto) | ||
{ | ||
return container_of(cg_proto, struct tcp_memcontrol, cg_proto); | ||
} | ||
|
||
static void memcg_tcp_enter_memory_pressure(struct sock *sk) | ||
{ | ||
if (!sk->sk_cgrp->memory_pressure) | ||
*sk->sk_cgrp->memory_pressure = 1; | ||
} | ||
EXPORT_SYMBOL(memcg_tcp_enter_memory_pressure); | ||
|
||
int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss) | ||
{ | ||
/* | ||
* The root cgroup does not use res_counters, but rather, | ||
* rely on the data already collected by the network | ||
* subsystem | ||
*/ | ||
struct res_counter *res_parent = NULL; | ||
struct cg_proto *cg_proto, *parent_cg; | ||
struct tcp_memcontrol *tcp; | ||
struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); | ||
struct mem_cgroup *parent = parent_mem_cgroup(memcg); | ||
|
||
cg_proto = tcp_prot.proto_cgroup(memcg); | ||
if (!cg_proto) | ||
return 0; | ||
|
||
tcp = tcp_from_cgproto(cg_proto); | ||
|
||
tcp->tcp_prot_mem[0] = sysctl_tcp_mem[0]; | ||
tcp->tcp_prot_mem[1] = sysctl_tcp_mem[1]; | ||
tcp->tcp_prot_mem[2] = sysctl_tcp_mem[2]; | ||
tcp->tcp_memory_pressure = 0; | ||
|
||
parent_cg = tcp_prot.proto_cgroup(parent); | ||
if (parent_cg) | ||
res_parent = parent_cg->memory_allocated; | ||
|
||
res_counter_init(&tcp->tcp_memory_allocated, res_parent); | ||
percpu_counter_init(&tcp->tcp_sockets_allocated, 0); | ||
|
||
cg_proto->enter_memory_pressure = memcg_tcp_enter_memory_pressure; | ||
cg_proto->memory_pressure = &tcp->tcp_memory_pressure; | ||
cg_proto->sysctl_mem = tcp->tcp_prot_mem; | ||
cg_proto->memory_allocated = &tcp->tcp_memory_allocated; | ||
cg_proto->sockets_allocated = &tcp->tcp_sockets_allocated; | ||
cg_proto->memcg = memcg; | ||
|
||
return 0; | ||
} | ||
EXPORT_SYMBOL(tcp_init_cgroup); | ||
|
||
void tcp_destroy_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss) | ||
{ | ||
struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); | ||
struct cg_proto *cg_proto; | ||
struct tcp_memcontrol *tcp; | ||
|
||
cg_proto = tcp_prot.proto_cgroup(memcg); | ||
if (!cg_proto) | ||
return; | ||
|
||
tcp = tcp_from_cgproto(cg_proto); | ||
percpu_counter_destroy(&tcp->tcp_sockets_allocated); | ||
} | ||
EXPORT_SYMBOL(tcp_destroy_cgroup); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters