Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932898AbcJZTIL (ORCPT ); Wed, 26 Oct 2016 15:08:11 -0400 Received: from resqmta-ch2-03v.sys.comcast.net ([69.252.207.35]:36847 "EHLO resqmta-ch2-03v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932231AbcJZTIJ (ORCPT ); Wed, 26 Oct 2016 15:08:09 -0400 Date: Wed, 26 Oct 2016 14:08:07 -0500 (CDT) From: Christoph Lameter X-X-Sender: cl@east.gentwo.org To: Thomas Garnier cc: Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, gthelen@google.com Subject: Re: [PATCH v1] memcg: Prevent caches to be both OFF_SLAB & OBJFREELIST_SLAB In-Reply-To: <1477503688-69191-1-git-send-email-thgarnie@google.com> Message-ID: References: <1477503688-69191-1-git-send-email-thgarnie@google.com> Content-Type: text/plain; charset=US-ASCII X-CMAE-Envelope: MS4wfMWOjKn82vHb7UAEdDjk3Gu2SieERJQL/rxkqE80FyFIB5Cgc8GuUn4O+/EjIr7cGAqKeFxrOun/eYc+hDysIxpB7aR+QsfjyAYc0u4G0beYQ36a0tuV EjxYqgn/1BMSN1IaELEno4ihaEbuECioIClCtcNcqm/w8nFwhcskqsDHWZ0NaMupgKWT4uV120Lcylv6SFhExIj8I0RskISYBKoaDXyi21XWUSnYq6tD8lTt oFRJfXJOD33gl+P9e+HPafzSaig1jUuMh5fn/IW7i2x24Kx44Jr3LynQtawsAsc/gm3Q/SS4xy6GHdbHhPUtNHi2j2p6kP45gUkiK/juEx0Yxr4fME2brfEF lwi6AepbuZeceBQ0LuQaQt31s4ldBzlxvrmmViwNtjyTNWl51+w= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2600 Lines: 67 Hmmm...Doesnt this belong into memcg_create_kmem_cache() or into kmem_cache_create() in mm/slab_common.h? Definitely not in an allocator specific function since this is an issue for all allocators. memcg_create_kmem_cache() simply assumes that it can pass flags from the kmem_cache structure to kmem_cache_create(). However, those flags may contain slab specific options. kmem_cache_create() could filter out flags that cannot be specified. Maybe create SLAB_FLAGS_PERMITTED in linux/mm/slab.h and mask other bits out in kmem_cache_create()? Slub also has internal flags and those also should not be passed to kmem_cache_create(). If we define the valid ones we can mask them out. The cleanest approach would be if kmem_cache_create() would reject invalid flags and fail and if memcg_create_kmem_cache() would mask out the invalid flags using SLAB_FLAGS_PERMITTED or so. On Wed, 26 Oct 2016, Thomas Garnier wrote: > While testing OBJFREELIST_SLAB integration with pagealloc, we found a > bug where kmem_cache(sys) would be created with both CFLGS_OFF_SLAB & > CFLGS_OBJFREELIST_SLAB. > > The original kmem_cache is created early making OFF_SLAB not possible. > When kmem_cache(sys) is created, OFF_SLAB is possible and if pagealloc > is enabled it will try to enable it first under certain conditions. > Given kmem_cache(sys) reuses the original flag, you can have both flags > at the same time resulting in allocation failures and odd behaviors. > > The proposed fix removes these flags by default at the entrance of > __kmem_cache_create. This way the function will define which way the > freelist should be handled at this stage for the new cache. > > Fixes: b03a017bebc4 ("mm/slab: introduce new slab management type, OBJFREELIST_SLAB") > Signed-off-by: Thomas Garnier > Signed-off-by: Greg Thelen > --- > Based on next-20161025 > --- > mm/slab.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/mm/slab.c b/mm/slab.c > index 3c83c29..efe280a 100644 > --- a/mm/slab.c > +++ b/mm/slab.c > @@ -2027,6 +2027,14 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags) > int err; > size_t size = cachep->size; > > + /* > + * memcg re-creates caches with the flags of the originals. Remove > + * the freelist related flags to ensure they are re-defined at this > + * stage. Prevent having both flags on edge cases like with pagealloc > + * if the original cache was created too early to be OFF_SLAB. > + */ > + flags &= ~(CFLGS_OBJFREELIST_SLAB|CFLGS_OFF_SLAB); > + > #if DEBUG > #if FORCED_DEBUG > /* >