linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-doc@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Hugh Dickins <hughd@google.com>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Yin Fengwei <fengwei.yin@intel.com>,
	Yang Shi <shy828301@gmail.com>
Subject: Re: [PATCH mm-unstable v1] mm: add a total mapcount for large folios
Date: Fri, 11 Aug 2023 11:14:39 -0400	[thread overview]
Message-ID: <9D4A9EE8-8CEF-4B08-9A32-149B6C548AB8@nvidia.com> (raw)
In-Reply-To: <ZNZNuooaFH9P4raS@x1n>

[-- Attachment #1: Type: text/plain, Size: 5250 bytes --]

On 11 Aug 2023, at 11:03, Peter Xu wrote:

> On Thu, Aug 10, 2023 at 11:59:25PM +0200, David Hildenbrand wrote:
>> On 10.08.23 23:54, Matthew Wilcox wrote:
>>> On Thu, Aug 10, 2023 at 05:48:19PM -0400, Peter Xu wrote:
>>>>> Yes, that comment from Hugh primarily discusses how we could possibly
>>>>> optimize the loop, and if relying on folio_nr_pages_mapped() to reduce the
>>>>> iterations would be racy. As far as I can see, there are cases where "it
>>>>> would be certainly a bad idea" :)
>>>>
>>>> Is the race described about mapcount being changed right after it's read?
>>>> Are you aware of anything specific that will be broken, and will be fixed
>>>> with this patch?
>>>
>>> The problem is that people check the mapcount while holding no locks;
>>> not the PTL, not the page lock.  So it's an unfixable race.
>>>
>>>> Having a total mapcount does sound helpful if partial folio is common
>>>> indeed.
>>>>
>>>> I'm curious whether that'll be so common after the large anon folio work -
>>>> isn't it be sad if partial folio will be a norm?  It sounds to me that's
>>>> the case when small page sizes should be used.. and it's prone to waste?
>>>
>>> The problem is that entire_mapcount isn't really entire_mapcount.
>>> It's pmd_mapcount.  I have had thoughts about using it as entire_mapcount,
>>> but it gets gnarly when people do partial unmaps.  So the _usual_ case
>>> ends up touching every struct page.  Which sucks.  Also it's one of the
>>> things which stands in the way of shrinking struct page.
>>
>> Right, so one current idea is to have a single total_mapcount and look into
>> removing the subpage mapcounts (which will require first removing
>> _nr_pages_mapped, because that's still one of the important users).
>>
>> Until we get there, also rmap code has to do eventually "more tracking" and
>> might, unfortunately, end up slower.
>>
>>>
>>> But it's kind of annoying to explain all of this to you individually.
>>> There have been hundreds of emails about it over the last months on
>>> this mailing list.  It would be nice if you could catch up instead of
>>> jumping in.
>>
>> To be fair, a lot of the details are not readily available and in the heads
>> of selected people :)
>>
>> Peter, if you're interested, we can discuss the current plans, issues and
>> ideas offline!
>
> Thanks for offering help, David.
>
> Personally I still am unclear yet on why entire_mapcount cannot be used as
> full-folio mapcounts, and why "partial unmap" can happen a lot (I don't
> expect), but yeah I can try to catch up to educate myself first.

Separate entire_mapcount and per-page mapcount are needed to maintain precise
NR_{ANON,FILE}_MAPPED and NR_ANON_THPS. I wrote some explanation (third paragraph)
at: https://lore.kernel.org/linux-mm/A28053D6-E158-4726-8BE1-B9F4960AD570@nvidia.com/.
Let me know if it helps.

>
> The only issue regarding an offline sync-up is that even if David will help
> Peter on catching up the bits, it'll not scale when another Peter2 had the
> same question..  So David, rather than I waste your time on helping one
> person, let me try to catch up with the public threads - I'm not sure how
> far I can go myself; otoh thread links will definitely be helpful to be
> replied here, so anyone else can reference too.  I collected a list (which
> can be enriched) of few threads that might be related, just in case helpful
> to anyone besides myself:
>
> [PATCH 0/2] don't use mapcount() to check large folio sharing
> https://lore.kernel.org/r/20230728161356.1784568-1-fengwei.yin@intel.com
>
> [PATCH v1-v2 0/3] support large folio for mlock
> https://lore.kernel.org/r/20230728070929.2487065-1-fengwei.yin@intel.com
> https://lore.kernel.org/r/20230809061105.3369958-1-fengwei.yin@intel.com
>
> [PATCH v1 0/4] Optimize mmap_exit for large folios
> https://lore.kernel.org/r/20230810103332.3062143-1-ryan.roberts@arm.com
>
> [PATCH v4-v5 0/5] variable-order, large folios for anonymous memory
> https://lore.kernel.org/linux-mm/20230726095146.2826796-1-ryan.roberts@arm.com/
> https://lore.kernel.org/r/20230810142942.3169679-1-ryan.roberts@arm.com
>
> [PATCH v3-v4 0/3] Optimize large folio interaction with deferred split
> (I assumed Ryan's this one goes into the previous set v5 finally, so just
>  the discussions as reference)
> https://lore.kernel.org/r/20230720112955.643283-1-ryan.roberts@arm.com
> https://lore.kernel.org/r/20230727141837.3386072-1-ryan.roberts@arm.com
>
> [RFC PATCH v2 0/4] fix large folio for madvise_cold_or_pageout()
> https://lore.kernel.org/r/20230721094043.2506691-1-fengwei.yin@intel.com
>
> I'm not sure how far I'll go; maybe I'll start working on something else
> before I finish all of them.  I'll see..
>
> Not allowing people to jump in will definitely cause less interactions and
> less involvement/open-ness for the mm community, as sometimes people can't
> easily judge when it's proper to jump in.
>
> IMHO the ideal solution is always keep all discussions public (either
> meetings with recordings, or shared online documents, always use on-list
> discussions, etc.), then share the links.
>
> -- 
> Peter Xu

--
Best Regards,
Yan, Zi

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]

  reply	other threads:[~2023-08-11 15:14 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09  8:32 David Hildenbrand
2023-08-09 15:45 ` Zi Yan
2023-08-09 19:07 ` Ryan Roberts
2023-08-09 19:17   ` David Hildenbrand
2023-08-10 10:40     ` Ryan Roberts
2023-08-10 11:14     ` David Hildenbrand
2023-08-10 11:27       ` David Hildenbrand
2023-08-10 11:32         ` David Hildenbrand
2023-08-10 11:35           ` Ryan Roberts
2023-08-09 19:21   ` Matthew Wilcox
2023-08-09 19:26     ` David Hildenbrand
2023-08-10  3:14       ` Yin Fengwei
2023-08-09 21:23 ` Peter Xu
2023-08-10  3:25   ` Matthew Wilcox
2023-08-10  8:37     ` David Hildenbrand
2023-08-10 21:48       ` Peter Xu
2023-08-10 21:54         ` Matthew Wilcox
2023-08-10 21:59           ` David Hildenbrand
2023-08-11 15:03             ` Peter Xu
2023-08-11 15:14               ` Zi Yan [this message]
2023-08-11 15:17               ` David Hildenbrand
2023-08-10  8:59   ` David Hildenbrand
2023-08-10 10:48     ` Ryan Roberts
2023-08-10 17:15       ` Peter Xu
2023-08-10 17:47         ` David Hildenbrand
2023-08-10 19:02           ` Ryan Roberts
2023-08-10 20:57           ` Peter Xu
2023-08-10 21:48             ` Matthew Wilcox
2023-08-10 22:27               ` David Hildenbrand
2023-08-11 15:18                 ` Peter Xu
2023-08-11 15:32                   ` David Hildenbrand
2023-08-11 15:58                     ` Peter Xu
2023-08-11 16:08                       ` David Hildenbrand
2023-08-11 16:11                         ` Zi Yan
2023-08-11 22:18                           ` Peter Xu
2023-08-10 22:16             ` David Hildenbrand
2023-08-10  3:24 ` Yin Fengwei

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=9D4A9EE8-8CEF-4B08-9A32-149B6C548AB8@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=fengwei.yin@intel.com \
    --cc=hughd@google.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=peterx@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=willy@infradead.org \
    /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