From: Matthew Wilcox Subject: Misuse of constructors Date: Wed, 1 Aug 2018 08:51:36 -0700 Message-ID: <20180801155136.GB4039@bombadil.infradead.org> References: <01000164f169bc6b-c73a8353-d7d9-47ec-a782-90aadcb86bfb-000000@email.amazonses.com> <30ee6c72-dc90-275a-8e23-54221f393cb0@virtuozzo.com> <01000164f60f3f12-b1253c6e-ee57-49fc-aed8-0944ab4fd7a2-000000@email.amazonses.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Christoph Lameter , Dmitry Vyukov , Eric Dumazet , Andrey Ryabinin , Linus Torvalds , Theodore Ts'o , jack@suse.com, linux-ext4@vger.kernel.org, Greg Kroah-Hartman , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , David Miller , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev , Gerrit Renker , dccp@vger.kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, airlied@linux.ie, intel-gfx@lists.freedesktop To: Eric Dumazet Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-ext4.vger.kernel.org On Wed, Aug 01, 2018 at 08:37:07AM -0700, Eric Dumazet wrote: > The idea of having a ctor() would only be a win if all the fields that > can be initialized in the ctor are contiguous and fill an integral > number of cache lines. Let's state it more generally: Having a ctor is only a win if it allows the user to avoid reading or writing a significant number of cachelines. For example, the radix tree node occupies nine cachelines (576 bytes). The typical user will touch two of those cacheliens (the header and the cacheline which contains the slot of interest). That's seven cachelines which don't even need to be read, let alone written. I think filesystems are particularly prone to this antipattern of initialising some of their inode with a ctor and the remainder at alloc_inode() time (compare the locations of the struct members touched by inode_init_always() and inode_init_once()).