Re: [BUG] Bad page states

From: Vladimir Davydov
Date: Mon Aug 08 2016 - 14:38:10 EST


On Mon, Aug 08, 2016 at 10:48:45AM -0700, Linus Torvalds wrote:
...
> > [ 43.477693] BUG: Bad page state in process S05containers pfn:1ff02a3
> > [ 43.484417] page:ffffea007fc0a8c0 count:0 mapcount:-511 mapping: (null) index:0x0
> > [ 43.492737] flags: 0x1000000000000000()
> > [ 43.496602] page dumped because: nonzero mapcount
>
> Hmm. The _mapcount field is a union with other fields, but that number
> doesn't make sense for any of the other fields.
>
> So it's almost certainly related to "PAGE_KMEMCG_MAPCOUNT_VALUE". So

Yes, it is - my bad. The thing is I set/clear PAGE_KMEMCG_MAPCOUNT_VALUE
for pages allocated with __GFP_ACCOUNT iff memcg_kmem_enabled() is true
(see __alloc_pages_nodemask and free_pages_prepare), while the latter
gets disabled when the last cgroup gets destroyed. So if you do

mkdir /sys/fs/cgroup/memory/test
# run something in the root cgroup that allocates pages with
# __GFP_ACCOUNT, e.g. a program using pipe
rmdir /sys/fs/cgroup/memory/test

Then, if there are no other memory cgroups, you'll see the bug.

Sorry about that :-(

Obviously, the PageKmemcg flag should only be set for pages that are
actually accounted to a non-root kmemcg and hence pin memcg_kmem_enabled
static key. I'll fix that.

Thanks,
Vladimir