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 66B81C27C52 for ; Wed, 16 Aug 2023 22:05:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9E3E280029; Wed, 16 Aug 2023 18:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4D8D280024; Wed, 16 Aug 2023 18:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1569280029; Wed, 16 Aug 2023 18:05:31 -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 A3E27280024 for ; Wed, 16 Aug 2023 18:05:31 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7AF1780CF1 for ; Wed, 16 Aug 2023 22:05:31 +0000 (UTC) X-FDA: 81131350062.17.ED96337 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 2E344120039 for ; Wed, 16 Aug 2023 22:05:28 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XOhFJl2t; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692223529; 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=UyMlVsySCN0Jx6lE67WHs7khNsl6mnl5e8ThdgyztOo=; b=MaUNxHQswfJrPVQzp3z3hmFGbcUQdL481cnI6o846NjkcWlBRgw7mGH0WD5jF+0TiVmkUG h0IN36ECmu8lgtqNk+LRlyO8Ifj9V9XY8/S3JF/ePvyeVFTgrJ1ZMs3oaYEEk7MyFAuSkN 8Gmet2pzFY66L7mWuD4qD0sod9UQVbk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XOhFJl2t; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692223529; a=rsa-sha256; cv=none; b=fGELtkOfYhthojSG7gLfhPEOYbFhse0582Ff502X10WEueMtNLm2m/R0ZiTeNHX6oEN4Kz oG8WLxOyu555BEEGoozyfw5qCsU1KJnazLND5wtgHITaUUPV7gWnlDuEAudn55nQTpTvis pzddRxZknfwGthLeGhJq5Oh6Q7fztbk= 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=UyMlVsySCN0Jx6lE67WHs7khNsl6mnl5e8ThdgyztOo=; b=XOhFJl2tl49bvGiQbffIoFYh5+ f8d7k5GtYOyYGA7dQO3uQKmJO8PqBNhRsZ/yEIUfdVRS793BMTxduCnkdTsU6BqHxwXTdMvQ8Nl+J +1KbxsgGvxlxTHvk+tmv64CZ7U0PpP/8qL4gXp96p0bA2rfCWRcFwK30Pfl/J4lBG45Egno/FmJ+Q LxX249DsWmItd9LcUYCXNEpBfIl2J5WH9M/vg7Thr/SAg2M+h4BUoI1N9YN6HDs9Vxo/TNf9EKEAK 9zmKL5bYbmhp2ZLUu/CzuMF6D2SmLvIU2F69FKrsm1Sm8EwGlJAztn7rfA/mKn4AZqqh5ZGRFqpwC j54F1cbw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qWOdj-00H9lF-Cu; Wed, 16 Aug 2023 22:05:19 +0000 Date: Wed, 16 Aug 2023 23:05:19 +0100 From: Matthew Wilcox To: David Hildenbrand Cc: Peter Xu , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hugh Dickins , "Kirill A . Shutemov" , Randy Dunlap , Mike Kravetz , Yu Zhao , Ryan Roberts , Andrew Morton , Yang Shi Subject: Re: [PATCH RFC v3] mm: Proper document tail pages fields for folio Message-ID: References: <20230815212547.431693-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 2E344120039 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 9twhyxdh4dy6woky78xxe9wemexzhxgr X-HE-Tag: 1692223528-340639 X-HE-Meta: U2FsdGVkX18f4q62WrOaEEx3IWxD8Cu1D2UMJKy1SMrSTpdtc9s/WC5wYIJWzbjEuO+7sQkuvear9iBAINS6ioWD2eZKqT0nNsm7bBmyOdXRusU2ChLmGv8I+tRBc1kk1Lrr/u3zue0meL+tpjL21mrVFUzIxqnBgXRBuat5KTo05GHdR0AQDcm8916bw/PkbcgVVGRxTckoIlVcsD+siuN8up2GYsjtAsRuFvAZwFVj2nT1KuHucQyuJXqGPqVTeNwiZLYCxczPxeldGgQh9TkWX9TNJRK/5r6gz4bxMU+vsWbrfWe6QcW0VF7eN/ZQQi75NL/6mRGcP0ujBP5HRV7nX9J8jUQ6XDkfrnEr9lY+QyFbeQwDKGL6yZRxurfWpfPBOD64INif7z4zTD6dayT57h+O/y8PNj/EnE/kzjFSDdNUdvtlCNqRG4xDQNSt62FliTdWD27wBvbztvCrbF3kEeNfKL9UJyuCFsmJh9bk7bb86LeV+2CQPWRqw28PkyQSaTTfbjqpw1XcRHqF9aodsaobHa2CTa+zNazKOiS8aEo/9zjjjUMbZuRU0bKIsOdG2EAmbp2eY/+iJEqlZ0xu375+WyFIvoUomaP3v6tgdLXQ4V5I4dyS1+B9/IgeRkHWi07kQyEp8yisHQdu51me7z3VIveklG2MKnbSR8cP85RiyvvU29aLOd+W+4HJOC29PV5SrZM5kbkc8d2WhLszJav8XRoddeopYyrCsqRLQke55agXFMEQ6M89H+ayHUDLgry8twQgI3MsZk1y8/F4ezgWXCjnQZTDe5I7uY7gai5QgN0I+b4Gd6OwDp1n54NTiY3JvF56knSagkHPzUBjj5iimM7hoSZfCrr14mQOoR4eDH/3fCwieNvB+jYUwDHYyGrOEmpZbiiWxRHgBoZHKJuUm6QvUez1zsHPkhpWWjOHV38w4RgwxnGom35jILvlw6+tSPz4qjLRivW +XmCOpj3 7tCRhB3+W++vbhx1+gYyO6OVB1fkTm2V4b9FZWBljDIl5rc0o9e4ycI5OBJ/xCNDbouHQ3R1+1JWdi6PSZcxLwsDLMiFtCoCnANhfTLhIS2SFM7/8hnDI1pg6GJdVbbdd2qNKDbCTkfzPh2Q= 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, Aug 16, 2023 at 08:51:49PM +0200, David Hildenbrand wrote: > On 16.08.23 20:41, Matthew Wilcox wrote: > > On Wed, Aug 16, 2023 at 03:33:30PM +0200, David Hildenbrand wrote: > > > My simple tests passed so far. If there isn't something obvious missing, > > > I can do more testing and send this as an official patch. > > > > I think you missed one: > > > > +++ b/mm/swapfile.c > > @@ -1490,7 +1490,7 @@ int swp_swapcount(swp_entry_t entry) > > > > page = vmalloc_to_page(p->swap_map + offset); > > offset &= ~PAGE_MASK; > > - VM_BUG_ON(page_private(page) != SWP_CONTINUED); > > + VM_BUG_ON(page_swap_entry(page).val != SWP_CONTINUED); > > That falls under the "weird handling of SWP_CONTINUED using vmalloced > pages". So different user of page_private(). > > Note that we don't even store swap entries in there but extended swap > counts. Ah, right. I see now. Not necessarily as part of this patch, but it got me wondering ... should we do this? And then maybe we could remove folio_swap_entry() and folio_set_swap_entry() and just use folio->swap directly. diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3880b3f2e321..e23d1356e504 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -266,6 +266,14 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page) return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page); } +/* + * A swap entry has to fit into a "unsigned long", as the entry is hidden + * in the "index" field of the swapper address space. + */ +typedef struct { + unsigned long val; +} swp_entry_t; + /** * struct folio - Represents a contiguous set of bytes. * @flags: Identical to the page flags. @@ -276,7 +284,7 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page) * @index: Offset within the file, in units of pages. For anonymous memory, * this is the index from the beginning of the mmap. * @private: Filesystem per-folio data (see folio_attach_private()). - * Used for swp_entry_t if folio_test_swapcache(). + * @swap: Used for swp_entry_t if folio_test_swapcache(). * @_mapcount: Do not access this member directly. Use folio_mapcount() to * find out how many times this folio is mapped by userspace. * @_refcount: Do not access this member directly. Use folio_ref_count() @@ -319,7 +327,10 @@ struct folio { }; struct address_space *mapping; pgoff_t index; - void *private; + union { + void *private; + swp_entry_t swap; + }; atomic_t _mapcount; atomic_t _refcount; #ifdef CONFIG_MEMCG @@ -1158,14 +1169,6 @@ enum tlb_flush_reason { NR_TLB_FLUSH_REASONS, }; - /* - * A swap entry has to fit into a "unsigned long", as the entry is hidden - * in the "index" field of the swapper address space. - */ -typedef struct { - unsigned long val; -} swp_entry_t; - /** * enum fault_flag - Fault flag definitions. * @FAULT_FLAG_WRITE: Fault was a write fault. diff --git a/include/linux/swap.h b/include/linux/swap.h index bb5adc604144..59b0f37eae5b 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -335,13 +335,12 @@ struct swap_info_struct { static inline swp_entry_t folio_swap_entry(struct folio *folio) { - swp_entry_t entry = { .val = page_private(&folio->page) }; - return entry; + return folio->swap; } static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry) { - folio->private = (void *)entry.val; + folio->swap = entry; } /* linux/mm/workingset.c */