From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DF13C433F5 for ; Wed, 13 Oct 2021 17:56:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D06AC60E0C for ; Wed, 13 Oct 2021 17:56:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D06AC60E0C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 698B06B006C; Wed, 13 Oct 2021 13:56:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 648426B0071; Wed, 13 Oct 2021 13:56:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55E3C6B0072; Wed, 13 Oct 2021 13:56:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id 4635F6B006C for ; Wed, 13 Oct 2021 13:56:34 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F193518391D78 for ; Wed, 13 Oct 2021 17:56:33 +0000 (UTC) X-FDA: 78692169066.32.D1BB001 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id 49019F000090 for ; Wed, 13 Oct 2021 17:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=9PscKTgwema1CV/ObUGT9iiJi3NgNOjPZpZfckZDhw4=; b=DjiL4hwFLfNH2TSKj9qCCUziRr sJAQmyZOK6wZgoOO47bdfa7TlqFwe7//KKCDk7ArR+vemIcoZEplslecn+/I9cu9/uh5HXIqYBvuj GRNq5QZXum+iyzf2fKCL63aFm+vUIng7nhVAEA8cIo5iOK+7BRoxlvFMRRVdLFROPs+0fBobqhbGd Ubal0wGlPZQlSk5W4qMf4Kx8bdCDrUeo2IaHYwgDjobOktxgL5X9fIr1IntLCSh78zP3uSX7M4tje ixt2cew3EQtksAnK1TF1w7ME6G0It/xRNo3gpcEcsbogeMO0FR0uZd9IwgeH2V9Kk4w/x4og2yegY ZyP3Piig==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1maiTi-007gC2-Fm; Wed, 13 Oct 2021 17:55:58 +0000 Date: Wed, 13 Oct 2021 18:55:46 +0100 From: Matthew Wilcox To: Johannes Weiner Cc: linux-mm@kvack.org, Kent Overstreet , "Kirill A. Shutemov" , Vlastimil Babka , Michal Hocko , Roman Gushchin , linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 00/11] PageSlab: eliminate unnecessary compound_head() calls Message-ID: References: <20211012180148.1669685-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 49019F000090 X-Stat-Signature: xyp9n4narhd57ziuktk3f6sm6wweipgf Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DjiL4hwF; dmarc=none; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1634147793-7274 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 13, 2021 at 09:49:31AM -0400, Johannes Weiner wrote: > On Wed, Oct 13, 2021 at 04:19:18AM +0100, Matthew Wilcox wrote: > > For today, testing PageSlab on the tail page helps the test proceed > > in parallel with the action. Looking at slub's kfree() for an example: > > > > page = virt_to_head_page(x); > > if (unlikely(!PageSlab(page))) { > > free_nonslab_page(page, object); > > return; > > } > > slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_); > > > > Your proposal is certainly an improvement (since gcc doesn't know > > that compound_head(compound_head(x)) == compound_head(x)), but I > > think checking on the tail page is even better: > > > > page = virt_to_page(x); > > if (unlikely(!PageSlab(page))) { > > free_nonslab_page(compound_head(page), object); > > return; > > } > > slab = page_slab(page); > > slab_free(slab->slab_cache, slab, object, NULL, 1, _RET_IP_); > > > > The compound_head() parts can proceed in parallel with the check of > > PageSlab(). > > > > As far as the cost of setting PageSlab, those cachelines are already > > dirty because we set compound_head on each of those pages already > > (or in the case of freeing, we're about to clear compound_head on > > each of those pages). > > ... but this is not. I think the performance gains from this would > have to be significant to justify complicating page flags further. My argument isn't really "this is more efficient", because I think the performance gains are pretty minimal. More that I would like to be able to write code in the style which we'll want to use when we're using dynamically allocated memory descriptors. It's all just code, and we can change it at any time, but better to change it to something that continues to work well in the future. I don't think we end up with "virt_to_head_page()" in a dynamically allocated memory descriptor world. The head page contains no different information from the tail pages, and indeed the tail pages don't know that they're tail pages, or where the head page is. Or maybe they're all tail pages. I could see a world where we had a virt_to_memdesc() which returned a generic memory descriptor that could be cast to a struct slab if the flags within that memdesc said it was a slab. But I think it works out better to tag the memory descriptor pointer with a discriminator that defines what the pointer is. Plus it saves a page flag. Maybe that's the best way to approach it -- how would you want to write this part of kfree() when memory descriptors are dynamically allocated?