psi: dont alloc memory for psi by default
Memory about struct psi_group is allocated by default for each cgroup even if psi_disabled is true, in this case, these allocated memory is waste, so alloc memory for struct psi_group only when psi_disabled is false. Signed-off-by: Chen Wandun <chenwandun@huawei.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
parent
e71e60cd74
commit
5f69a6577b
@ -475,7 +475,7 @@ struct cgroup {
|
||||
struct work_struct release_agent_work;
|
||||
|
||||
/* used to track pressure stalls */
|
||||
struct psi_group psi;
|
||||
struct psi_group *psi;
|
||||
|
||||
/* used to store eBPF programs */
|
||||
struct cgroup_bpf bpf;
|
||||
|
@ -674,7 +674,7 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp)
|
||||
|
||||
static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
|
||||
{
|
||||
return &cgrp->psi;
|
||||
return cgrp->psi;
|
||||
}
|
||||
|
||||
bool cgroup_psi_enabled(void);
|
||||
|
@ -3609,21 +3609,21 @@ static int cpu_stat_show(struct seq_file *seq, void *v)
|
||||
static int cgroup_io_pressure_show(struct seq_file *seq, void *v)
|
||||
{
|
||||
struct cgroup *cgrp = seq_css(seq)->cgroup;
|
||||
struct psi_group *psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
|
||||
struct psi_group *psi = cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
|
||||
|
||||
return psi_show(seq, psi, PSI_IO);
|
||||
}
|
||||
static int cgroup_memory_pressure_show(struct seq_file *seq, void *v)
|
||||
{
|
||||
struct cgroup *cgrp = seq_css(seq)->cgroup;
|
||||
struct psi_group *psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
|
||||
struct psi_group *psi = cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
|
||||
|
||||
return psi_show(seq, psi, PSI_MEM);
|
||||
}
|
||||
static int cgroup_cpu_pressure_show(struct seq_file *seq, void *v)
|
||||
{
|
||||
struct cgroup *cgrp = seq_css(seq)->cgroup;
|
||||
struct psi_group *psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
|
||||
struct psi_group *psi = cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
|
||||
|
||||
return psi_show(seq, psi, PSI_CPU);
|
||||
}
|
||||
@ -3649,7 +3649,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
|
||||
psi = cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
|
||||
new = psi_trigger_create(psi, buf, nbytes, res);
|
||||
if (IS_ERR(new)) {
|
||||
cgroup_put(cgrp);
|
||||
|
@ -957,10 +957,16 @@ int psi_cgroup_alloc(struct cgroup *cgroup)
|
||||
if (static_branch_likely(&psi_disabled))
|
||||
return 0;
|
||||
|
||||
cgroup->psi.pcpu = alloc_percpu(struct psi_group_cpu);
|
||||
if (!cgroup->psi.pcpu)
|
||||
cgroup->psi = kmalloc(sizeof(struct psi_group), GFP_KERNEL);
|
||||
if (!cgroup->psi)
|
||||
return -ENOMEM;
|
||||
group_init(&cgroup->psi);
|
||||
|
||||
cgroup->psi->pcpu = alloc_percpu(struct psi_group_cpu);
|
||||
if (!cgroup->psi->pcpu) {
|
||||
kfree(cgroup->psi);
|
||||
return -ENOMEM;
|
||||
}
|
||||
group_init(cgroup->psi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -969,10 +975,11 @@ void psi_cgroup_free(struct cgroup *cgroup)
|
||||
if (static_branch_likely(&psi_disabled))
|
||||
return;
|
||||
|
||||
cancel_delayed_work_sync(&cgroup->psi.avgs_work);
|
||||
free_percpu(cgroup->psi.pcpu);
|
||||
cancel_delayed_work_sync(&cgroup->psi->avgs_work);
|
||||
free_percpu(cgroup->psi->pcpu);
|
||||
/* All triggers must be removed by now */
|
||||
WARN_ONCE(cgroup->psi.poll_states, "psi: trigger leak\n");
|
||||
WARN_ONCE(cgroup->psi->poll_states, "psi: trigger leak\n");
|
||||
kfree(cgroup->psi);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user