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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE0A4C04A94 for ; Tue, 15 Aug 2023 20:16:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AE2794002D; Tue, 15 Aug 2023 16:16:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45E728D0001; Tue, 15 Aug 2023 16:16:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34CEB94002D; Tue, 15 Aug 2023 16:16:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2749B8D0001 for ; Tue, 15 Aug 2023 16:16:55 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ECE0DA035E for ; Tue, 15 Aug 2023 20:16:54 +0000 (UTC) X-FDA: 81127447548.10.0E37D67 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 24B98C0012 for ; Tue, 15 Aug 2023 20:16:52 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Yoz8qtkL; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692130613; a=rsa-sha256; cv=none; b=FKkNQvIpVxW0gdwIqiHee/jPt7HD1AUiLTKXxPPx2Uo3eztrSJf6njK50oQ037Lq2FpQbF sJTRQGaYD7vuxqoR1quMzSindcTe1fkaNt4MZbuHyIg4ACB7n1WssES0LoZapQkBKXwzf8 nbCXff+vr0cktKFv6BkE/CjKTh+PyGg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Yoz8qtkL; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692130613; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/9YcFGMjTmXUnLrKv4QF9PTeQWEDd0deRpHi/hJXg4I=; b=u+mvAqKNICw0W6KkwLra+8WYh18+tXLgjYKcYQ6/4Aa2kDnKggEd54KfTuBYt9g1YQm3wg rSOMcX1gLnBk0aW1AXly3y1T4wDMwU4/oD1BVBD5JN1KXLUo4bZ/Ybjgk6Cxtq0G2Ocsuv uojv3B+DGF0653zLjkgZ/Us995wG4lE= 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=/9YcFGMjTmXUnLrKv4QF9PTeQWEDd0deRpHi/hJXg4I=; b=Yoz8qtkLjSkJfKTPRhC4/0t7M+ +Y+Guwp081+fK1vH++EwchRlPbELgiRaLPpC7ubO8ncrMBIAdsx39bsSaIjslrmFOSM+b1W9hiVHS acpC8OIIE7ZywjizR5J8bLHbSTGylU7NgooknTMeDgTNoaWmMkWuTWXgXhzMYmn0c8OCB4TtBdlUj prk2P5oiXiuoquTciMa1hwsdWm7UX8lVPt4u1INl1rbgkB5EyNvZ/7UHRhoOOS4UNguXv2sM9lfL0 PJzXaYeNSFyrObYMKw3YQ7mieS6GxwSHCkA6bkthnPvLlL3Hf2p50Dn2pJhgzzmaqF8C1tN8W6FUr 4G0mMMFA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qW0T9-00ADGZ-My; Tue, 15 Aug 2023 20:16:47 +0000 Date: Tue, 15 Aug 2023 21:16:47 +0100 From: Matthew Wilcox To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Kravetz , David Hildenbrand , Andrew Morton , Yu Zhao , Ryan Roberts , Yang Shi , Hugh Dickins , "Kirill A . Shutemov" Subject: Re: [PATCH RFC v2 0/3] mm: Properly document tail pages for a folio Message-ID: References: <20230814184411.330496-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 24B98C0012 X-Stat-Signature: n9kbdy6b5nrfuiyywbs5wbu4nuabpe61 X-Rspam-User: X-HE-Tag: 1692130612-767586 X-HE-Meta: U2FsdGVkX1/fb0BYbKuOmBC+KeBTbMDPqJW0ve5aOZFN+rbUGsgRrol6MWVqg1REZMSwQ82LMhPM8ZMZGnzNxS9cBgtAWvXohRNHNpaxbkrCahejWRGaMt2inl+xrwcUO4jA0Sl6uhNGYMUx5V+93HSuZUAi69IpxrZk/CJxxROm3NzcQZZW7z+3P1sQw/5FEvwCtH+gvF6UUfrf+fcdHjPtT6yncyjANe97RY91ZbJE3dBe2O8i4ZS5C+mVXbswq5lLGTOZ/rP7OWQm6TxSo8cBK6Hh8+0C+L1kf9J6OpnF1D/23h4SKooJSUCoT4yxSZbgYnAX0JOpfYPz7GPQIOjkc16KgtGgJ93D8xvVm3vgYqzkA842bJ5W4fDNZPQzbWBbyF5zr1hCOcKO8TzlbFvuN9DOmRAOdcsECTAYVRVghCafcfCJaXPjqkG4mCdKhRhQZFHr+/fhiu6R9w9KtaJcN4frJsb859ulvXZc4hXkdog+Gk6E2icTMsdz5sdcOfJwDhMpizhw4ilDh3rrUFaKNfGFp1G4EVhBznUVGoGEPuTO6ooCWz2LOj7sNudEdXJEodzQumRccBsO56P05iFz6a/VWmOg/a876DsqTkkvWk8ELN8Y451pi9yAa0SKiX1utlhcUTVuzrtXkzIyvDjsy2Ksz/P+PL23zYUpzovSKYS8nMPz0E5bmdTHQ2dAJDwvWlt8dtpmW94DYBTSNhHhgOyiepTrTlRqIf/XPkjWakY+9zF9FMiKArxup3ut59R1hE3DyNuxkV5pXF/cctFRB7rJAWeDv0YX4m+6NZVskMDbT5w7pkl4CUMzRnINFNQGCy0w117lfHQLP3BC5Ks9g9dn6hG7abVV3h4OQKC4hmhhJT7cWJfVw30OsYa7US9S7pXXgiDuSIHnPF34sfgpIEqYC1DDqXazNSo9NIg0VMwx5Up+4qN4+yo4t1hBnOBbnQH/mGl70upPYKb vwsnw7hr BizchJgdvbrGqIf67VgVkuKZaTL5g3tWfvZqssVvx7ATb+GhtkUzi081sX0HlGl1SDygYEnyKviFoqGvbfp9yhqIY3l3WzdSX0qPi9/KoMtfUOMPljSKGZJudNVfSQ9MH6A9HSHBwXIR2MXg= 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 Tue, Aug 15, 2023 at 03:37:21PM -0400, Peter Xu wrote: > On Tue, Aug 15, 2023 at 04:45:52AM +0100, Matthew Wilcox wrote: > > I always forget about THP_SWAP using tail->private. That actually needs > > to be asserted by the compiler, not just documented. Something along > > these lines. > > > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > > index 659c7b84726c..3880b3f2e321 100644 > > --- a/include/linux/mm_types.h > > +++ b/include/linux/mm_types.h > > @@ -340,8 +340,11 @@ struct folio { > > atomic_t _pincount; > > #ifdef CONFIG_64BIT > > unsigned int _folio_nr_pages; > > -#endif > > + /* 4 byte gap here */ > > /* private: the union with struct page is transitional */ > > + /* Fix THP_SWAP to not use tail->private */ > > + unsigned long _private_1; > > +#endif > > }; > > struct page __page_1; > > }; > > @@ -362,6 +365,9 @@ struct folio { > > /* public: */ > > struct list_head _deferred_list; > > /* private: the union with struct page is transitional */ > > + unsigned long _avail_2a; > > + /* Fix THP_SWAP to not use tail->private */ > > + unsigned long _private_2a; > > }; > > struct page __page_2; > > }; > > @@ -386,12 +392,18 @@ FOLIO_MATCH(memcg_data, memcg_data); > > offsetof(struct page, pg) + sizeof(struct page)) > > FOLIO_MATCH(flags, _flags_1); > > FOLIO_MATCH(compound_head, _head_1); > > +#ifdef CONFIG_64BIT > > +FOLIO_MATCH(private, _private_1); > > +#endif > > #undef FOLIO_MATCH > > #define FOLIO_MATCH(pg, fl) \ > > static_assert(offsetof(struct folio, fl) == \ > > offsetof(struct page, pg) + 2 * sizeof(struct page)) > > FOLIO_MATCH(flags, _flags_2); > > FOLIO_MATCH(compound_head, _head_2); > > +FOLIO_MATCH(flags, _flags_2a); > > +FOLIO_MATCH(compound_head, _head_2a); > > +FOLIO_MATCH(private, _private_2a); > > #undef FOLIO_MATCH > > > > /* > > > > This is against the patchset I just posted which frees up a word in the > > first tail page. > > Okay, I assume you meant to suggest leverage FOLIO_MATCH(), which I can > definitely try. But then I'd hope it covers not only private field but all > the fields that the tail pages reuses; the goal is to document everything > no matter in what form. I'll see what I can get.. Thanks. No, sometimes there are things which shouldn't be documented because they don't matter, and when changing code sometimes we forget to change the documentation, and then people read the documentation which is different from the code, and they get confused. It matters that the various 'private' members line up. It matters that folio->index matches page->index. It does not matter what offset _entire_mapcount is at. That can be moved around freely and no documentation needs to be changed. I don't want you to use FOLIO_MATCH to make any unnecessary assertions. The only assertion missing is for _private_1 and _private_2a, and that's why I wrote a patch to add them.