linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm: memcg/slab: Fix objcg pointer array handling problem
@ 2021-05-04 13:23 Waiman Long
  2021-05-04 13:23 ` [PATCH v2 1/2] mm: memcg/slab: Properly set up gfp flags for objcg pointer array Waiman Long
  2021-05-04 13:23 ` [PATCH v2 2/2] mm: memcg/slab: Create a new set of kmalloc-cg-<n> caches Waiman Long
  0 siblings, 2 replies; 9+ messages in thread
From: Waiman Long @ 2021-05-04 13:23 UTC (permalink / raw)
  To: Johannes Weiner, Michal Hocko, Vladimir Davydov, Andrew Morton,
	Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Vlastimil Babka, Roman Gushchin, Shakeel Butt
  Cc: linux-kernel, cgroups, linux-mm, Waiman Long

 v2:
  - Take suggestion from Vlastimil to use a new set of kmalloc-cg-* to
    handle the objcg pointer array allocation and freeing problems.

Since the merging of the new slab memory controller in v5.9,
the page structure stores a pointer to objcg pointer array for
slab pages. When the slab has no used objects, it can be freed in
free_slab() which will call kfree() to free the objcg pointer array in
memcg_alloc_page_obj_cgroups(). If it happens that the objcg pointer
array is the last used object in its slab, that slab may then be freed
which may caused kfree() to be called again.

With the right workload, the slab cache may be set up in a way that
allows the recursive kfree() calling loop to nest deep enough to
cause a kernel stack overflow and panic the system. In fact, we have
a reproducer that can cause kernel stack overflow on a s390 system
involving kmalloc-rcl-256 and kmalloc-rcl-128 slabs with the following
kfree() loop recursively called 74 times:

  [  285.520739]  [<000000000ec432fc>] kfree+0x4bc/0x560
  [  285.520740]  [<000000000ec43466>] __free_slab+0xc6/0x228
  [  285.520741]  [<000000000ec41fc2>] __slab_free+0x3c2/0x3e0
  [  285.520742]  [<000000000ec432fc>] kfree+0x4bc/0x560
					:
While investigating this issue, I also found an issue on the allocation
side. If the objcg pointer array happen to come from the same slab or
a circular dependency linkage is formed with multiple slabs, those
affected slabs can never be freed again.

This patch series addresses these two issues by introducing a new
set of kmalloc-cg-<n> caches split from kmalloc-<n> caches. The new
set will only contain non-reclaimable and non-dma objects that are
accounted in memory cgroups whereas the old set are now for unaccounted
objects only. By making this split, all the objcg pointer arrays will
come from the kmalloc-<n> caches, but those caches will never hold any
objcg pointer array. As a result, deeply nested kfree() call and the
unfreeable slab problems are now gone.

Waiman Long (2):
  mm: memcg/slab: Properly set up gfp flags for objcg pointer array
  mm: memcg/slab: Create a new set of kmalloc-cg-<n> caches

 include/linux/slab.h | 15 +++++++++++++++
 mm/memcontrol.c      |  8 ++++++++
 mm/slab.h            |  1 -
 mm/slab_common.c     | 23 +++++++++++++++--------
 4 files changed, 38 insertions(+), 9 deletions(-)

-- 
2.18.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-05 11:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04 13:23 [PATCH v2 0/2] mm: memcg/slab: Fix objcg pointer array handling problem Waiman Long
2021-05-04 13:23 ` [PATCH v2 1/2] mm: memcg/slab: Properly set up gfp flags for objcg pointer array Waiman Long
2021-05-04 19:37   ` Shakeel Butt
2021-05-04 20:02     ` Waiman Long
2021-05-04 20:06       ` Shakeel Butt
2021-05-05 11:32         ` Vlastimil Babka
2021-05-04 13:23 ` [PATCH v2 2/2] mm: memcg/slab: Create a new set of kmalloc-cg-<n> caches Waiman Long
2021-05-04 16:01   ` Vlastimil Babka
2021-05-05  1:55     ` Waiman Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).