Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4570716ybe; Mon, 16 Sep 2019 14:40:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsTe4siHVTrqFgLSFg7jLOERnDpsqAki4T66b5izukeLR6Nsd8LrOcDAyc6TBHYVBfWWJR X-Received: by 2002:a17:906:4a58:: with SMTP id a24mr1915695ejv.142.1568670012659; Mon, 16 Sep 2019 14:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568670012; cv=none; d=google.com; s=arc-20160816; b=0hl36hkXpA0Bm8IXXF3kr2d/kYnhhgHQTiANy4kbSl6//nZVyj/NtWR64Yc9+XwxC5 XljHMT1w7oMDT1/672BDePRTE8b6RTJRxAYlZsFFBlW+EVg5AsyfbmE2qZ2ZzsOIj28x iMAsrhNL9YZ+Yj5woWoqeX1nvSfLmGqNXaKY5Ckcwbqof3eFJfIy1wzLaTko8ObahcD6 iskwDMib1gKmT4wzY/AMsdy8suqe3//lOJi6jQMYHlQE+7JG8XbW+wPtFomCSwD0GOF9 OJ26xXSQJT0aedKnedImZMCQ0alhLrgKaKrzfYHBConPJvDKBgu/v6THw8biXfQO3NEf 6vgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=DfC+q6n84zbhMpsDUftY8nxKWK1YxhqqrQVWMmDQ1iE=; b=ePhoGnDtFRXCG4B8gK+oH/VKzbezv9P8M+mgcrW8Y/9zj/4oPg9hZp0tg4dkbwCBO+ aO5o2LN45GGZRki/iFRkraNs332KP658R7CqLootfWnUEdysyd4HWHxFNSAjdME2gX5e 6cnGU+0eFJ76mWC8NXy29af03u92oaPIInXhKP7BcytizToi3eX+ONEBO5A4w+/E2afj EpZr0huW+4i9PJXwhAPLkMk1cHHQg8HrzvN6SWF1rjUq6eCX1DKO8Zx0qG3RTdY2W/sh fbhYXwzX4sCFXwwiygZbW3RQe2+GnC77Xa+e8SuYe/XrYHVlYsz3c7BO112O8oixl0Bg Klyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iOe1j1jF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oa24si93524ejb.41.2019.09.16.14.39.49; Mon, 16 Sep 2019 14:40:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iOe1j1jF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390383AbfIPScb (ORCPT + 99 others); Mon, 16 Sep 2019 14:32:31 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42025 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729331AbfIPScb (ORCPT ); Mon, 16 Sep 2019 14:32:31 -0400 Received: by mail-pg1-f196.google.com with SMTP id z12so468357pgp.9 for ; Mon, 16 Sep 2019 11:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=DfC+q6n84zbhMpsDUftY8nxKWK1YxhqqrQVWMmDQ1iE=; b=iOe1j1jFBJLIr9wC3amj30A7BR8L42Sepf+99X8Xw+0aQFxFpVXVoAxma3Oij5vac7 kXvSwwsp4qasO2wuU1dZWyGYSZBrelQF+cuWdZLWR5SUXroXVUh/cmCWTBx1yI9i9b23 /VHzN5ia0Ww/wPdChU+2n6abo1xVMd7vweUZIMu2mOCkdX6FJKhViR46dYKvG+c9wNCu 4608Z2uj/T2ndpqN1ADEVhcLJLlaarv8wgpltM0OoLdZFkoNoP/eEX+OA9N3Qx3Ll6Wg OSQcpsegLSfKnKbYNB/fVQSEzlYc+oLHd1c2LkLXYZxmsX1Qs5E/5fOF49ehIn+dhC0H Mf2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=DfC+q6n84zbhMpsDUftY8nxKWK1YxhqqrQVWMmDQ1iE=; b=hYQU6jnmtnldVlMCRJDbtz35+2hXXx3xclo+ok2ovSBkm2GSc+blwpgSrZAqmxmgM5 eIGwZzx8Vmk6unNs2qHlUJChG5o5GEY37CXUgQUU/GgqJ4O86VcsgOAT/YPbNh8vE8HX V29ip9KKgkF60xl7mDrfu8k1U7DALRXzAwmj5NhAlNxUlOzR/Oo/RPM0vzJeZspBGsK5 mNk7FdSGmkijeTTlodjo4ALKKpUvg9lGnJAlc1cuKeGOJ5HZ6KPmetdC7SnNmmEXRvez Hc7Ynbz/04R9dQOgGRHA9QtVo1nE8Htk4IWXXm2r/5h+D2f+wqveYi7IC0apbBiksyd1 n8cQ== X-Gm-Message-State: APjAAAVDKU/B6zfRBtZvC7e/DJPxDIlasADTXuZB/+Hs+Y78HdQW0IJm uasDji2gEE9tkeIvW2m5OsncOA== X-Received: by 2002:a65:4002:: with SMTP id f2mr440594pgp.447.1568658748539; Mon, 16 Sep 2019 11:32:28 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id v4sm842126pff.181.2019.09.16.11.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 11:32:27 -0700 (PDT) Date: Mon, 16 Sep 2019 11:32:27 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Qian Cai , Pengfei Li cc: cl@linux.com, penberg@kernel.org, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] mm/slub: remove left-over debugging code In-Reply-To: <1568650294-8579-1-git-send-email-cai@lca.pw> Message-ID: References: <1568650294-8579-1-git-send-email-cai@lca.pw> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 16 Sep 2019, Qian Cai wrote: > SLUB_RESILIENCY_TEST and SLUB_DEBUG_CMPXCHG look like some left-over > debugging code during the internal development that probably nobody uses > it anymore. Remove them to make the world greener. Adding Pengfei Li who has been working on a patchset for modified handling of kmalloc cache initialization and touches the resiliency test. I still find the resiliency test to be helpful/instructional for handling unexpected conditions in these caches, so I'd suggest against removing it: the only downside is that it's additional source code. But it's helpful source code for reference. The cmpxchg failures could likely be more generalized beyond SLUB since there will be other dependencies in the kernel than just this allocator. (I assume you didn't send a Signed-off-by line because this is an RFC.) > --- > mm/slub.c | 110 -------------------------------------------------------------- > 1 file changed, 110 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 8834563cdb4b..f97155ba097d 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -150,12 +150,6 @@ static inline bool kmem_cache_has_cpu_partial(struct kmem_cache *s) > * - Variable sizing of the per node arrays > */ > > -/* Enable to test recovery from slab corruption on boot */ > -#undef SLUB_RESILIENCY_TEST > - > -/* Enable to log cmpxchg failures */ > -#undef SLUB_DEBUG_CMPXCHG > - > /* > * Mininum number of partial slabs. These will be left on the partial > * lists even if they are empty. kmem_cache_shrink may reclaim them. > @@ -392,10 +386,6 @@ static inline bool __cmpxchg_double_slab(struct kmem_cache *s, struct page *page > cpu_relax(); > stat(s, CMPXCHG_DOUBLE_FAIL); > > -#ifdef SLUB_DEBUG_CMPXCHG > - pr_info("%s %s: cmpxchg double redo ", n, s->name); > -#endif > - > return false; > } > > @@ -433,10 +423,6 @@ static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page, > cpu_relax(); > stat(s, CMPXCHG_DOUBLE_FAIL); > > -#ifdef SLUB_DEBUG_CMPXCHG > - pr_info("%s %s: cmpxchg double redo ", n, s->name); > -#endif > - > return false; > } > > @@ -2004,45 +1990,11 @@ static inline unsigned long next_tid(unsigned long tid) > return tid + TID_STEP; > } > > -static inline unsigned int tid_to_cpu(unsigned long tid) > -{ > - return tid % TID_STEP; > -} > - > -static inline unsigned long tid_to_event(unsigned long tid) > -{ > - return tid / TID_STEP; > -} > - > static inline unsigned int init_tid(int cpu) > { > return cpu; > } > > -static inline void note_cmpxchg_failure(const char *n, > - const struct kmem_cache *s, unsigned long tid) > -{ > -#ifdef SLUB_DEBUG_CMPXCHG > - unsigned long actual_tid = __this_cpu_read(s->cpu_slab->tid); > - > - pr_info("%s %s: cmpxchg redo ", n, s->name); > - > -#ifdef CONFIG_PREEMPT > - if (tid_to_cpu(tid) != tid_to_cpu(actual_tid)) > - pr_warn("due to cpu change %d -> %d\n", > - tid_to_cpu(tid), tid_to_cpu(actual_tid)); > - else > -#endif > - if (tid_to_event(tid) != tid_to_event(actual_tid)) > - pr_warn("due to cpu running other code. Event %ld->%ld\n", > - tid_to_event(tid), tid_to_event(actual_tid)); > - else > - pr_warn("for unknown reason: actual=%lx was=%lx target=%lx\n", > - actual_tid, tid, next_tid(tid)); > -#endif > - stat(s, CMPXCHG_DOUBLE_CPU_FAIL); > -} > - > static void init_kmem_cache_cpus(struct kmem_cache *s) > { > int cpu; > @@ -2751,7 +2703,6 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, > object, tid, > next_object, next_tid(tid)))) { > > - note_cmpxchg_failure("slab_alloc", s, tid); > goto redo; > } > prefetch_freepointer(s, next_object); > @@ -4694,66 +4645,6 @@ static int list_locations(struct kmem_cache *s, char *buf, > } > #endif /* CONFIG_SLUB_DEBUG */ > > -#ifdef SLUB_RESILIENCY_TEST > -static void __init resiliency_test(void) > -{ > - u8 *p; > - int type = KMALLOC_NORMAL; > - > - BUILD_BUG_ON(KMALLOC_MIN_SIZE > 16 || KMALLOC_SHIFT_HIGH < 10); > - > - pr_err("SLUB resiliency testing\n"); > - pr_err("-----------------------\n"); > - pr_err("A. Corruption after allocation\n"); > - > - p = kzalloc(16, GFP_KERNEL); > - p[16] = 0x12; > - pr_err("\n1. kmalloc-16: Clobber Redzone/next pointer 0x12->0x%p\n\n", > - p + 16); > - > - validate_slab_cache(kmalloc_caches[type][4]); > - > - /* Hmmm... The next two are dangerous */ > - p = kzalloc(32, GFP_KERNEL); > - p[32 + sizeof(void *)] = 0x34; > - pr_err("\n2. kmalloc-32: Clobber next pointer/next slab 0x34 -> -0x%p\n", > - p); > - pr_err("If allocated object is overwritten then not detectable\n\n"); > - > - validate_slab_cache(kmalloc_caches[type][5]); > - p = kzalloc(64, GFP_KERNEL); > - p += 64 + (get_cycles() & 0xff) * sizeof(void *); > - *p = 0x56; > - pr_err("\n3. kmalloc-64: corrupting random byte 0x56->0x%p\n", > - p); > - pr_err("If allocated object is overwritten then not detectable\n\n"); > - validate_slab_cache(kmalloc_caches[type][6]); > - > - pr_err("\nB. Corruption after free\n"); > - p = kzalloc(128, GFP_KERNEL); > - kfree(p); > - *p = 0x78; > - pr_err("1. kmalloc-128: Clobber first word 0x78->0x%p\n\n", p); > - validate_slab_cache(kmalloc_caches[type][7]); > - > - p = kzalloc(256, GFP_KERNEL); > - kfree(p); > - p[50] = 0x9a; > - pr_err("\n2. kmalloc-256: Clobber 50th byte 0x9a->0x%p\n\n", p); > - validate_slab_cache(kmalloc_caches[type][8]); > - > - p = kzalloc(512, GFP_KERNEL); > - kfree(p); > - p[512] = 0xab; > - pr_err("\n3. kmalloc-512: Clobber redzone 0xab->0x%p\n\n", p); > - validate_slab_cache(kmalloc_caches[type][9]); > -} > -#else > -#ifdef CONFIG_SYSFS > -static void resiliency_test(void) {}; > -#endif > -#endif /* SLUB_RESILIENCY_TEST */ > - > #ifdef CONFIG_SYSFS > enum slab_stat_type { > SL_ALL, /* All slabs */ > @@ -5875,7 +5766,6 @@ static int __init slab_sysfs_init(void) > } > > mutex_unlock(&slab_mutex); > - resiliency_test(); > return 0; > } > > -- > 1.8.3.1 > >