Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3693252pxb; Wed, 13 Oct 2021 10:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCGklZMFS5cUG4CXcuZ2GJZvLk/x9ZtmMW3sZdFif89uZicDEOAJ7WzT9jyMUVEfbeUOK3 X-Received: by 2002:a63:7e45:: with SMTP id o5mr442636pgn.445.1634147920308; Wed, 13 Oct 2021 10:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634147920; cv=none; d=google.com; s=arc-20160816; b=ALIWSBwjWLUMrsYRDyY54oiuZXRHkxLxPiG7FE5qCIEXu/P3Ge21KOBMKh+vMzVEIS nrmHXdt8tq36VqoUNlHkvJeUUP1rihwBlc7qdY1o9HEBHB1v/ramDID/FrT+0E/NDXGA LsXmSV8RqcYDilRLTivKAPvuzjdT4Sx3SC1yGJP+u7GofzOj5QbnrHtx2pdb4PZujtvh mOpOvJLRth0WFi1XO7eNLHvn6ITCXvzAcaUPFvXrG4ZAdKrE+s8mAclO4Di1vjmeVfMY nU8xbqRaGTYOmSI1jfsTV3omKoVH1PNx4+AKt2h+nHZ3riKn8zzS6RPXEzXMQVFdT2p5 1CkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9PscKTgwema1CV/ObUGT9iiJi3NgNOjPZpZfckZDhw4=; b=zZN8+RpVlAqMijO7owGN7i+ilZ/KBE8i1NCWmGQ1hskcTLM4GqN65ILl2DeTp6cdBD 0MabUPi3H3UMyv3T/IxNAJWUnaYlq0eDGc9vITPxAjsHRrfkXcpM8dwSl0dbpmV25rgN D879u07S4RfA3bkCC73Oc5xJUzOAmjYWUyLxEu6N1Qc5lovwGZ90IzWRZ3phu/2d6w0i Zft2EMXV1rkfpWtkmMOlxf6g6z5s3+3l5jzdWJGCPTCSio955d+Uj+qhAJv3diXaQ4S2 xvDyb03NtYzXikdTn44wPSAwz4O9np6xSFxu8QULAWObi5GuAEjcO7Z0YhKaFG+7wiXV G7tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=DjiL4hwF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si430010pfu.376.2021.10.13.10.58.26; Wed, 13 Oct 2021 10:58:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=DjiL4hwF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238202AbhJMR7b (ORCPT + 99 others); Wed, 13 Oct 2021 13:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbhJMR7Y (ORCPT ); Wed, 13 Oct 2021 13:59:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD78CC061570 for ; Wed, 13 Oct 2021 10:57:20 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?