Received: by 10.213.65.68 with SMTP id h4csp4146079imn; Tue, 10 Apr 2018 09:55:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dC++s6bR5KuY6IccjHS5YxWIz1hz41qHLaUyEadzDKxEFnnZ8Qq969D/sKu6yOeD6pJLX X-Received: by 2002:a17:902:ab88:: with SMTP id f8-v6mr1276640plr.34.1523379326413; Tue, 10 Apr 2018 09:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523379326; cv=none; d=google.com; s=arc-20160816; b=qwxDVp8CK2Vkf/nDs8amI8vXqs5rpKMeRblhX4AegzyOMTlw/GhBk3fbAnsEduPuib tuSZksfIlQYdRWYRCk2Tlkodjrk/mEXQov1K6cnPnmbYDfCUjhE7evYAIohSlLg++z5y H7vRyd9PebVp1qSVBI8yeJ2YDfe7pjas3M4vhr/dSsfBXXHlFONoiEmVtBDR5/dRn4+o BJ1bFB8kqDqTSELFEdgqULhowbiZtSRVvmuOV+4NjyXege9+lcRi79hDKKZxSRnTdUvJ e/+9OGMaF7MfSfjkrJzv0z9B1Hn4426usjhmIwTG6uRPHJVGCeH+nMCwFPdumFfzhxli G2TA== 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:dkim-signature:arc-authentication-results; bh=EnD6dfTswChQKYfUUs/TOK+2Pw2UAM3LTdNRyxjqpfE=; b=oL3sLwF1WOVpxJ7EwiFW3nM34QOHsFVkv6gPTnk7le67COjmJ44zvqv49u3OSKapiQ K6G/oNLuUfzPZETOOyO0RI1uoxDN7qpe+hvHvTgcSOAreuUViO4uND9NRzspI+ajZ2Vr 86ZqTV2nhsYO0FjLriiiS/a6uGD570tey518PQbz7IS142pikXrfsweeaniJASE94erO +uauek/U7s80fmemjshfOvxaQ1OTmVgvUZf4yuDpO8uiXqX58tKeD8a9OUokJF9khS+B YnaSJCC2p13V5QI8jaJ0pQErPrqFKbxB/7H2ic5bO9HPKKCLljJRQmHzJdcwnWuA6W9R M/bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=RmpzlPFD; 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 a12si2372623pfd.235.2018.04.10.09.54.48; Tue, 10 Apr 2018 09:55:26 -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=neutral (body hash did not verify) header.i=@infradead.org header.s=bombadil.20170209 header.b=RmpzlPFD; 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 S1752178AbeDJQvB (ORCPT + 99 others); Tue, 10 Apr 2018 12:51:01 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:60864 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751600AbeDJQu7 (ORCPT ); Tue, 10 Apr 2018 12:50:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=sshABVTQnU8/kmrcGzi3ddFvaNHHEKV7D8JHRUPXdcM=; b=RmpzlPFDFJC2NIVWWHYZ/thvL Tu+g+9KtEaJObXFTjnZr0J2NOxsXoInAsFVETpMK4ZBtZiVB9sId3OujuSguA2XhTWgLcjpxF6OZ2 1S4tmKonaeMyCGJgYuOBaHaKUJ7tn0BM3rsNxy5OO+3CqDevIUgEkdHyEo/0zwRNXJAq41qOPhNBO ukH6tjVDGhyKENN7/kXY79jj9Q1+wu7orW/wJgBJawvjym2DsFUn3SeX3kmwcHIn9miMTWo0BlTLk bJWlAZUjuCQivueesqQSPwQ/2c48/4AYbooPaE0rub8Az877pwacEFaM41Zj9JbIBnl4lN3+P3bvW UWRYgkBTw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5wTu-0001Hd-Rk; Tue, 10 Apr 2018 16:50:54 +0000 Date: Tue, 10 Apr 2018 09:50:54 -0700 From: Matthew Wilcox To: Eric Dumazet 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: <20180410165054.GC3614@bombadil.infradead.org> References: <20180410125351.15837-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 10, 2018 at 06:53:04AM -0700, Eric Dumazet wrote: > On 04/10/2018 05:53 AM, 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 > > Since there are probably no bug to fix, what about adding the extra check > only for some DEBUG option ? > > How many caches are still using ctor these days ? That's a really good question, and strangely hard to find out. I settled on "git grep -A4 kmem_cache_alloc" and then searching the 'less' output with '[^L]);'. -- arch/powerpc/kvm/book3s_64_mmu_radix.c: kvm_pte_cache = kmem_cache_create("kvm-pte", size, size, 0, pte_ctor); -- arch/powerpc/mm/init-common.c: new = kmem_cache_create(name, table_size, align, 0, ctor); -- arch/powerpc/platforms/cell/spufs/inode.c: spufs_inode_cache = kmem_cache_create("spufs_inode_cache", arch/powerpc/platforms/cell/spufs/inode.c- sizeof(struct spufs_inode_info), 0, arch/powerpc/platforms/cell/spufs/inode.c- SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, spufs_init_once); -- arch/sh/mm/pgtable.c: pgd_cachep = kmem_cache_create("pgd_cache", arch/sh/mm/pgtable.c- PTRS_PER_PGD * (1<e_slab = kmem_cache_create(rp->slab_name, drivers/usb/mon/mon_text.c- sizeof(struct mon_event_text), sizeof(long), 0, drivers/usb/mon/mon_text.c- mon_text_ctor); -- fs/9p/v9fs.c: v9fs_inode_cache = kmem_cache_create("v9fs_inode_cache", fs/9p/v9fs.c- sizeof(struct v9fs_inode), fs/9p/v9fs.c- 0, (SLAB_RECLAIM_ACCOUNT| fs/9p/v9fs.c- SLAB_MEM_SPREAD|SLAB_ACCOUNT), fs/9p/v9fs.c- v9fs_inode_init_once); -- fs/adfs/super.c: adfs_inode_cachep = kmem_cache_create("adfs_inode_cache", fs/adfs/super.c- sizeof(struct adfs_inode_info), fs/adfs/super.c- 0, (SLAB_RECLAIM_ACCOUNT| fs/adfs/super.c- SLAB_MEM_SPREAD|SLAB_ACCOUNT), fs/adfs/super.c- init_once); ... snip a huge number of filesystems ... -- ipc/mqueue.c: mqueue_inode_cachep = kmem_cache_create("mqueue_inode_cache", ipc/mqueue.c- sizeof(struct mqueue_inode_info), 0, ipc/mqueue.c- SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT, init_once); -- kernel/fork.c: sighand_cachep = kmem_cache_create("sighand_cache", kernel/fork.c- sizeof(struct sighand_struct), 0, kernel/fork.c- SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_R CU| kernel/fork.c- SLAB_ACCOUNT, sighand_ctor); -- lib/radix-tree.c: radix_tree_node_cachep = kmem_cache_create("radix_tree_n ode", lib/radix-tree.c- sizeof(struct radix_tree_node), 0, lib/radix-tree.c- SLAB_PANIC | SLAB_RECLAIM_ACCOUNT, lib/radix-tree.c- radix_tree_node_ctor); -- mm/rmap.c: anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct an on_vma), mm/rmap.c- 0, SLAB_TYPESAFE_BY_RCU|SLAB_PANIC|SLAB_ACCOUNT, mm/rmap.c- anon_vma_ctor); -- mm/shmem.c: shmem_inode_cachep = kmem_cache_create("shmem_inode_cache", mm/shmem.c- sizeof(struct shmem_inode_info), mm/shmem.c- 0, SLAB_PANIC|SLAB_ACCOUNT, shmem_init_inode); -- net/sunrpc/rpc_pipe.c: rpc_inode_cachep = kmem_cache_create("rpc_inode_cache", net/sunrpc/rpc_pipe.c- sizeof(struct rpc_inode), net/sunrpc/rpc_pipe.c- 0, (SLAB_HWCACHE_ALIGN|SLAB_RECL AIM_ACCOUNT| net/sunrpc/rpc_pipe.c- SLAB_MEM_SPREAD| SLAB_ACCOUNT), net/sunrpc/rpc_pipe.c- init_once); -- security/integrity/iint.c: kmem_cache_create("iint_cache", sizeof(struc t integrity_iint_cache), security/integrity/iint.c- 0, SLAB_PANIC, init_once); So aside from the filesystems, about fourteen places use it in the kernel. If we want to get rid of the concept of constructors, it's doable, but somebody needs to do the work to show what the effects will be. For example, I took a quick look at the sighand_struct in kernel/fork.c. That initialises the spinlock and waitqueue head which are at the end of sighand_struct. The caller who allocates sighand_struct touches the head of the struct. So if we removed the ctor, we'd touch two cachelines on allocation instead of one ... but we could rearrange the sighand_struct to put all the initialised bits in the first cacheline (and we probably should).