linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Peter Xu <peterx@redhat.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Hugh Dickins <hughd@google.com>,
	"Kirill A . Shutemov" <kirill@shutemov.name>,
	Randy Dunlap <rdunlap@infradead.org>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Yu Zhao <yuzhao@google.com>, Ryan Roberts <ryan.roberts@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Yang Shi <shy828301@gmail.com>
Subject: Re: [PATCH RFC v3] mm: Proper document tail pages fields for folio
Date: Fri, 18 Aug 2023 16:38:05 +0200	[thread overview]
Message-ID: <6259fc1c-62e4-5ac0-33cb-0cd9a985c5f4@redhat.com> (raw)
In-Reply-To: <ZN1IH/8JxkkOU5Ec@casper.infradead.org>

On 17.08.23 00:05, Matthew Wilcox wrote:
> 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;

Probably with "/* for anon and shm pages only */

> +			};
>   			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 */
> 

Sound reasonable, but maybe we should even get rid of the getter/setter 
completely then?

-- 
Cheers,

David / dhildenb



      reply	other threads:[~2023-08-18 14:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 21:25 Peter Xu
2023-08-16 13:33 ` David Hildenbrand
2023-08-16 16:53   ` Peter Xu
2023-08-16 18:59     ` David Hildenbrand
2023-08-16 18:41   ` Matthew Wilcox
2023-08-16 18:51     ` David Hildenbrand
2023-08-16 22:05       ` Matthew Wilcox
2023-08-18 14:38         ` David Hildenbrand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6259fc1c-62e4-5ac0-33cb-0cd9a985c5f4@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=peterx@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=willy@infradead.org \
    --cc=yuzhao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox