Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp765405pxf; Thu, 18 Mar 2021 11:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVrmVZuQ25WxjrD3e1nxzNrtYEw9b0hJCusk5mxSMbZ5oUY7Z4CUBxG78TCBLkM4WPYTs1 X-Received: by 2002:a17:906:2404:: with SMTP id z4mr41637366eja.14.1616090417429; Thu, 18 Mar 2021 11:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616090417; cv=none; d=google.com; s=arc-20160816; b=GR8UCZBwrs7rGSrLyJPEbEyvjKb/JKxH0NB2hQboW93hvq2TL007GpQwdsduruAbZs kmwlRyy96K6jwrku9Lm7KHcTzAYvNx2mi2Xc9buSkIYHS7IzpWLM5Tmzn0DIjyCE48k6 Utuk5FgLijeTWnjfgnfqZnNiGPSNjakchMTbNH79VStFMKwfqE+EmkJhQK11jneCWE+2 toIID512x3FzwBcnQ4uT0jHIo+dxrF0IJ6kanuVBwtUyZTRWkggPuBxkHR/V6SQyX3S2 SEni/3WWzKMBPfk2HggimdzIW/k6IU6My0k5l/UJM6OyQQ7bsWKs67NlRP6yvlZDaAnd gPNw== 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=vZm4w+si9uU9aQrNJ3zwhuKonm9Y0JsStk/oRatNIc4=; b=RlrRJ9oUEDoiCctk5apBJ3i/DIkYaDrorB42/R9rvn7OCo3ACj/Ap9dt74S1XppVQH f6XI/LHurzw+sLTyb3XgPEI1UTorzVGoYKrdnn8O7dN1agxTg3f4sypsI4OXuxbbKDRy Rub3cNpJA7T7xv0rx4ST6pULOvdMG4S8tUa1IlMPLT+QeVc24EJXmsqKasgYm/2GwvcS 6QXrR9mrEJq3chXVVDey8DKFPK4fj4CxywtzAnSEouYftyPTIHrjxO+TcD0L13fkLxXD UaEEJowkwKv9jKceH9DNveU3/tNB2DEMTfzUSAOYBFEBv0hffNCFfhXrAKPYYE6IEPn5 UBpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=QJVS2QBi; 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 v5si2098613edr.596.2021.03.18.10.59.53; Thu, 18 Mar 2021 11:00:17 -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=QJVS2QBi; 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 S232426AbhCRR6e (ORCPT + 99 others); Thu, 18 Mar 2021 13:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbhCRR6X (ORCPT ); Thu, 18 Mar 2021 13:58:23 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C589C06174A; Thu, 18 Mar 2021 10:58:23 -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=vZm4w+si9uU9aQrNJ3zwhuKonm9Y0JsStk/oRatNIc4=; b=QJVS2QBikxM65SlYiOHVDHGTvn jr2tWC5lD4nNxv30RZK00MhCdXvYT+rEuQa7l7tjRO0zyWCJb6VTWFL78QDlmm+eLHhEnyws/SA4r iAkbV3kr/ZNOnFDEXxSxFlI+QTnuDGb9m7pPWmHvk7AG+ZiV8DGhFom5aW4kg7PnAaVRU7uCV6XfQ 7/ronkKeYKGdpsSRDemEQnvpSjyslzK/7Mb8ThUxwyCrGbwx1gNg6befAQ54piW2Za17/yuUnj4bz xh/H8F0UyfdZ5auGs9f8wXp1yhjmomXf1BHaIdgFgZPory6Iydt6tM8AF9gl5j+nqeNmphr6CxpK6 uc5Oasyw==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lMwu7-003Jkp-S5; Thu, 18 Mar 2021 17:57:58 +0000 Date: Thu, 18 Mar 2021 17:57:51 +0000 From: Matthew Wilcox To: Christoph Hellwig Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v4 08/25] mm: Handle per-folio private data Message-ID: <20210318175751.GS3420@casper.infradead.org> References: <20210305041901.2396498-1-willy@infradead.org> <20210305041901.2396498-9-willy@infradead.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, Mar 17, 2021 at 06:20:32PM +0100, Christoph Hellwig wrote: > > +static inline void attach_page_private(struct page *page, void *data) > > +{ > > + attach_folio_private((struct folio *)page, data); > > +} > > + > > +static inline void *detach_page_private(struct page *page) > > +{ > > + return detach_folio_private((struct folio *)page); > > +} > > I hate these open code casts. Can't we have a single central > page_to_folio helper, which could also grow a debug check (maybe > under a new config option) to check that it really is called on a > head page? Some of that is already there. We have page_folio() which is the page_to_folio() helper you're asking for. And folio_flags() (which is called *all the time*) contains VM_BUG_ON_PGFLAGS(PageTail(page), page); Someone passing around a tail pointer cast to a folio is not going to get very far, assuming CONFIG_DEBUG_VM_PGFLAGS is enabled (most distros don't, but I do when I'm testing anything THPish). These helpers aren't going to live for very long ... I expect to have all filesystems which use attach/detach page private converted to folios pretty soon. Certainly before any of them _use_ multi-page folios. Anyway, the simple thing to do is just to use page_folio() here and eat the cost of calling compound_head() on something we're certain is an order-0 page. It only defers the win of removing the compound_head() call; it doesn't preclude it. And it means we're not setting a bad example here (there really shouldn't be any casts from pages to folios, except in the folio allocator, which uses the page allocator and then casts what _must be_ a non-tail page to a folio).