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 564E7C25B08 for ; Mon, 8 Aug 2022 19:34:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C95486B0075; Mon, 8 Aug 2022 15:34:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFB456B0074; Mon, 8 Aug 2022 15:34:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 829DD8E0005; Mon, 8 Aug 2022 15:34:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 10A576B0071 for ; Mon, 8 Aug 2022 15:34:50 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DB4E7A0B7B for ; Mon, 8 Aug 2022 19:34:49 +0000 (UTC) X-FDA: 79777427898.04.072E1AD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 8487E18017A for ; Mon, 8 Aug 2022 19:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=D9OxPNakbQ7dXKQCeoqgLhnSNcTIRcyWrbUHuZ9BacA=; b=NPX6uQWh6ILJI7341MGeUAJfzE 7z59gMsRaWJdTSStyg8Xj1WMPn0riCNnTiZzhYTE4uVgF9xjxhI4iUqx4pgwphxr+h46GI5pSJrm+ KydgmHP3tHKwd7PaIbx5fpgh8/DJSOoB8gpVawNVfYGCWVCI8PFfEF1TVp7+VI0/I/SviXcpZvM1O TmgvnQ0oymn1NolYAOfTpMZKk92llD4JNhZl4IBCPtz51qQKoFvKcZtQ1UVUy0ClzqyZsdhkTbepn FRrVzKWizmGk5ffAv0JL/zvinkBFYlJQ0IwD37OjS5kWeohE6wfhDcg9x4YTRWkcI9R6AB1jZm0kr BxggQb1A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oL8WU-00EAsQ-3Z; Mon, 08 Aug 2022 19:34:46 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , hughd@google.com Subject: [PATCH 05/59] mm: Add the first tail page to struct folio Date: Mon, 8 Aug 2022 20:33:33 +0100 Message-Id: <20220808193430.3378317-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808193430.3378317-1-willy@infradead.org> References: <20220808193430.3378317-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NPX6uQWh; spf=none (imf24.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=1659987289; a=rsa-sha256; cv=none; b=swZ531NxIZyE0EBeOdFp0QoJR0SCdi14jC408GO5/F8L4qb+qgSQa5I9Ea2WE4bpP1qYdt 6OiSQdC3zcPYIbv4osmlSdnSY58k5GfXKDDf1Ihs6FbKQayyLHuKo/EYvbDcn0zHW77EAA 9DastaM8gZz5udt+f/L7gDwhz3rKQt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659987289; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D9OxPNakbQ7dXKQCeoqgLhnSNcTIRcyWrbUHuZ9BacA=; b=F1EF6DWk4OtLHq9TTP1wGgXVji5yHm5xKTyIHh+3YernjFTjB3ZCeU/W+vx7IHqeU25CCN zKvR1pPG2b8uRy947/IK+/4i5Z0b+S7DAGTjab34gJJ1kCGkUruQ0Jmr8RTW5AT5DIBBR1 rvE78ouUD5XtrsSH6oLzIgbdc2eTOfs= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8487E18017A X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NPX6uQWh; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Stat-Signature: yci7y4rjursjsyyu79knznibe8o3wbq9 X-HE-Tag: 1659987289-688124 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: Some of the static checkers get confused by extracting the page from the folio and referring to fields in the first tail page. Adding these fields to struct folio lets us avoid doing that. It has the risk that people will refer to those fields without checking that the folio is actually a large folio, so prefix them with underscores and document the preferred function to use instead. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm_types.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index cf97f3884fda..8a9ee9d24973 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -244,6 +244,13 @@ struct page { * @_refcount: Do not access this member directly. Use folio_ref_count() * to find how many references there are to this folio. * @memcg_data: Memory Control Group data. + * @_flags_1: For large folios, additional page flags. + * @__head: Points to the folio. Do not use. + * @_folio_dtor: Which destructor to use for this folio. + * @_folio_order: Do not use directly, call folio_order(). + * @_total_mapcount: Do not use directly, call folio_entire_mapcount(). + * @_pincount: Do not use directly, call folio_maybe_dma_pinned(). + * @_folio_nr_pages: Do not use directly, call folio_nr_pages(). * * A folio is a physically, virtually and logically contiguous set * of bytes. It is a power-of-two in size, and it is aligned to that @@ -282,9 +289,17 @@ struct folio { }; struct page page; }; + unsigned long _flags_1; + unsigned long __head; + unsigned char _folio_dtor; + unsigned char _folio_order; + atomic_t _total_mapcount; + atomic_t _pincount; +#ifdef CONFIG_64BIT + unsigned int _folio_nr_pages; +#endif }; -static_assert(sizeof(struct page) == sizeof(struct folio)); #define FOLIO_MATCH(pg, fl) \ static_assert(offsetof(struct page, pg) == offsetof(struct folio, fl)) FOLIO_MATCH(flags, flags); @@ -299,6 +314,19 @@ FOLIO_MATCH(_refcount, _refcount); FOLIO_MATCH(memcg_data, memcg_data); #endif #undef FOLIO_MATCH +#define FOLIO_MATCH(pg, fl) \ + static_assert(offsetof(struct folio, fl) == \ + offsetof(struct page, pg) + sizeof(struct page)) +FOLIO_MATCH(flags, _flags_1); +FOLIO_MATCH(compound_head, __head); +FOLIO_MATCH(compound_dtor, _folio_dtor); +FOLIO_MATCH(compound_order, _folio_order); +FOLIO_MATCH(compound_mapcount, _total_mapcount); +FOLIO_MATCH(compound_pincount, _pincount); +#ifdef CONFIG_64BIT +FOLIO_MATCH(compound_nr, _folio_nr_pages); +#endif +#undef FOLIO_MATCH static inline atomic_t *folio_mapcount_ptr(struct folio *folio) { -- 2.35.1