Received: by 10.213.65.68 with SMTP id h4csp3882510imn; Tue, 10 Apr 2018 06:11:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/chYQQnlHziPRLx74COB5HSt7X1LGRc8JOaMOzUR+2FQVdm94gy3V48SfobdBJzVU7lAn+ X-Received: by 2002:a17:902:728f:: with SMTP id d15-v6mr382081pll.119.1523365872479; Tue, 10 Apr 2018 06:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523365872; cv=none; d=google.com; s=arc-20160816; b=pPEzDT0d6lsljc+zSu6H5SC9W7lsPE022Yc5jQiHxbPzSZAMj5YH68T6ZnCw9ggyql Ui/nHlan7/FKKK4HlALU/As/+54jbZ+eLMwTBAZOiKeM5bNPEYDyNduT7GFjXfy7rqot JSr4wgx4N3a1gXGQtKqr7ngBDY+rth3C+4RFpzHOEb/WhzfIyNwXMkX7hLN+VojR81JY i4FUOWgEcdarmYE6MI58ZM1d98ElkGbYroZeRZk9WnPVvpG3cxrOc7DX9/SecgA9JsXC A77X3WvLVOR4MSSBHv33fAVdeDmptlcc3Pbdky/z5fnTWaehxR4m/tjm5QR3gbZFlhpg AsiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=vQyNRLSKY52aRp5d5gtAc50dF/i6KyDl1a6zi7R360I=; b=oivV2rq98SwurKj3tzLygjQaHW3IvNbHtvztarM4I2CiOuleHuIj01fCTmi652TSQw CezsgfexPEOXfbC0kKOM4kdzlnH1iiEqnlJYPrwlqulGyc/KmgEKJHz5aksQLLtGc+g9 ix0N6Q1tTy3D0Xr5uqOgUp93+kikxO2P1+s1Ds8RU8O8ap7seOtCnfoogyqr6lw1ijiY TmzWsiBozPWt1LWGm6KKQBbC+rryiyAoph6aMcqquKb4VnVjBjHWt/3AtlrNrBz4scCm wGzxAdVA/EReeq38jzPwlMKrw3NraW/6Xzm3ojWT8H2vaLXqo6uL29gYd18zEEwJVBhN 5aIQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2-v6si2594780plo.434.2018.04.10.06.10.35; Tue, 10 Apr 2018 06:11: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753638AbeDJNHs (ORCPT + 99 others); Tue, 10 Apr 2018 09:07:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:46983 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752752AbeDJNHr (ORCPT ); Tue, 10 Apr 2018 09:07:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8EB36AF94; Tue, 10 Apr 2018 13:07:45 +0000 (UTC) Date: Tue, 10 Apr 2018 15:07:42 +0200 From: Michal Hocko To: Matthew Wilcox Cc: linux-mm@kvack.org, Matthew Wilcox , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-kernel@vger.kernel.org, Jan Kara , Jeff Layton , Mel Gorman , stable@vger.kernel.org Subject: Re: [PATCH 1/2] slab: __GFP_ZERO is incompatible with a constructor Message-ID: <20180410130742.GM21835@dhcp22.suse.cz> References: <20180410125351.15837-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180410125351.15837-1-willy@infradead.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 10-04-18 05:53:50, Matthew Wilcox wrote: > From: Matthew Wilcox > > __GFP_ZERO requests that the object be initialised to all-zeroes, > while the purpose of a constructor is to initialise an object to a > particular pattern. We cannot do both. Add a warning to catch any > users who mistakenly pass a __GFP_ZERO flag when allocating a slab with > a constructor. > > Fixes: d07dbea46405 ("Slab allocators: support __GFP_ZERO in all allocators") > Signed-off-by: Matthew Wilcox > Cc: stable@vger.kernel.org > --- > mm/slab.c | 6 ++++-- > mm/slob.c | 4 +++- > mm/slub.c | 6 ++++-- > 3 files changed, 11 insertions(+), 5 deletions(-) > > diff --git a/mm/slab.c b/mm/slab.c > index 38d3f4fd17d7..8b2cb7db85db 100644 > --- a/mm/slab.c > +++ b/mm/slab.c > @@ -3313,8 +3313,10 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, > local_irq_restore(save_flags); > ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); > > - if (unlikely(flags & __GFP_ZERO) && ptr) > - memset(ptr, 0, cachep->object_size); > + if (unlikely(flags & __GFP_ZERO) && ptr) { > + if (!WARN_ON_ONCE(cachep->ctor)) > + memset(ptr, 0, cachep->object_size); > + } > > slab_post_alloc_hook(cachep, flags, 1, &ptr); > return ptr; Why don't we need to cover this in slab_alloc and kmem_cache_alloc_bulk as well? Other than that this patch makes sense to me. -- Michal Hocko SUSE Labs