Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1455152
| From | Johannes Weiner <hannes@cmpxchg.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup |
| Date | 2016-08-02 19:40 +0200 |
| Message-ID | <s1LPA-7DB-33@gated-at.bofh.it> (permalink) |
| References | <s1KAb-6OZ-47@gated-at.bofh.it> <s1KAb-6OZ-61@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, Aug 02, 2016 at 06:00:26PM +0200, Michal Hocko wrote:
> On Tue 02-08-16 18:00:48, Vladimir Davydov wrote:
> > @@ -5767,15 +5785,20 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
> > if (!memcg)
> > return;
> >
> > - mem_cgroup_id_get(memcg);
> > - oldid = swap_cgroup_record(entry, mem_cgroup_id(memcg));
> > + swap_memcg = mem_cgroup_id_get_active(memcg);
> > + oldid = swap_cgroup_record(entry, mem_cgroup_id(swap_memcg));
> > VM_BUG_ON_PAGE(oldid, page);
> > - mem_cgroup_swap_statistics(memcg, true);
> > + mem_cgroup_swap_statistics(swap_memcg, true);
> >
> > page->mem_cgroup = NULL;
> >
> > if (!mem_cgroup_is_root(memcg))
> > page_counter_uncharge(&memcg->memory, 1);
> > + if (memcg != swap_memcg) {
> > + if (!mem_cgroup_is_root(swap_memcg))
> > + page_counter_charge(&swap_memcg->memsw, 1);
> > + page_counter_uncharge(&memcg->memsw, 1);
> > + }
> >
> > /*
> > * Interrupts should be disabled here because the caller holds the
>
> The resulting code is a weird mixture of memcg and swap_memcg usage
> which is really confusing and error prone. Do we really have to do
> uncharge on an already offline memcg?
The charge is recursive and includes swap_memcg, i.e. live groups, so
the uncharge is necessary. I don't think the code is too bad, though?
swap_memcg is the target that is being charged for swap, memcg is the
origin group from which we swap out. Seems pretty straightforward...?
But maybe a comment above the memcg != swap_memcg check would be nice:
/*
* In case the memcg owning these pages has been offlined and doesn't
* have an ID allocated to it anymore, charge the closest online
* ancestor for the swap instead and transfer the memory+swap charge.
*/
Thinking about it, mem_cgroup_id_get_active() is a little strange; the
term we use throughout the cgroup code is "online". It might be good
to rename this mem_cgroup_id_get_online().
Thanks
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Michal Hocko <mhocko@kernel.org> - 2016-08-02 18:20 +0200
Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Johannes Weiner <hannes@cmpxchg.org> - 2016-08-02 19:40 +0200
Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Michal Hocko <mhocko@kernel.org> - 2016-08-02 22:50 +0200
Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Michal Hocko <mhocko@kernel.org> - 2016-08-03 13:30 +0200
Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Michal Hocko <mhocko@kernel.org> - 2016-08-03 14:10 +0200
Re: [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Johannes Weiner <hannes@cmpxchg.org> - 2016-08-03 16:20 +0200
csiph-web