From: David Hildenbrand <david@redhat.com>
To: Barry Song <21cnbao@gmail.com>, Lance Yang <ioworker0@gmail.com>,
Vishal Moola <vishal.moola@gmail.com>
Cc: akpm@linux-foundation.org, zokeefe@google.com,
ryan.roberts@arm.com, shy828301@gmail.com, mhocko@suse.com,
fengwei.yin@intel.com, xiehuan09@gmail.com,
wangkefeng.wang@huawei.com, songmuchun@bytedance.com,
peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] mm/madvise: enhance lazyfreeing with mTHP in madvise_free
Date: Thu, 7 Mar 2024 09:32:11 +0100 [thread overview]
Message-ID: <5cc05529-eb80-410e-bc26-233b0ba0b21f@redhat.com> (raw)
In-Reply-To: <CAGsJ_4xREM-P1mFqeM-s3-cJ9czb6PXwizb-3hOhwaF6+QM5QA@mail.gmail.com>
On 07.03.24 09:10, Barry Song wrote:
> On Thu, Mar 7, 2024 at 9:00 PM Lance Yang <ioworker0@gmail.com> wrote:
>>
>> Hey Barry,
>>
>> Thanks for taking time to review!
>>
>> On Thu, Mar 7, 2024 at 3:00 PM Barry Song <21cnbao@gmail.com> wrote:
>>>
>>> On Thu, Mar 7, 2024 at 7:15 PM Lance Yang <ioworker0@gmail.com> wrote:
>>>>
>> [...]
>>>> +static inline bool can_mark_large_folio_lazyfree(unsigned long addr,
>>>> + struct folio *folio, pte_t *start_pte)
>>>> +{
>>>> + int nr_pages = folio_nr_pages(folio);
>>>> + fpb_t flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
>>>> +
>>>> + for (int i = 0; i < nr_pages; i++)
>>>> + if (page_mapcount(folio_page(folio, i)) != 1)
No new direct subpage mapcount users please if avoidable. Also, without
holding the page lock this might be racy (did not stare at the bigger code).
>>>> + return false;
>>>
>>> we have moved to folio_estimated_sharers though it is not precise, so
>>> we don't do
>>> this check with lots of loops and depending on the subpage's mapcount.
>>
>> If we don't check the subpage’s mapcount, and there is a cow folio associated
>> with this folio and the cow folio has smaller size than this folio,
>> should we still
>> mark this folio as lazyfree?
>
> I agree, this is true. However, we've somehow accepted the fact that
> folio_likely_mapped_shared
> can result in false negatives or false positives to balance the
> overhead. So I really don't know :-)
>
> Maybe David and Vishal can give some comments here.
Well, I did not accept the fact yet that folio_likely_mapped_shared()
can give false negatives :)
So I've been working on a replacement [1], also in the context of
removing the subpage mapcounts. But there is still a lot to resolve
around that, first step being to introduce the total mapcount.
But independent of that, MADV_FREE is special (compared to
MADV_DONTNEED), because we really have to make sure all page table
mappings that map the folio will be covered here.
What could work for large folios is making sure that #ptes that map the
folio here correspond to the folio_mapcount(). And folio_mapcount()
should be called under folio lock, to avoid racing with swapout/migration.
So instead of checking each page_mapcount(), see how many PTEs you could
batch, try taking the folio lock, and compare the number of batched PTEs
against folio_mapcount(). If they match, we're good. if not, there is
some other folio mapping somewhere else (other process, mremap).
folio_likely_mapped_shared() should still be used as an early exit point.
[1]
https://lore.kernel.org/all/20231124132626.235350-1-david@redhat.com/T/#u
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-03-07 8:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 6:14 Lance Yang
2024-03-07 7:00 ` Barry Song
2024-03-07 8:00 ` Lance Yang
2024-03-07 8:10 ` Barry Song
2024-03-07 8:32 ` David Hildenbrand [this message]
2024-03-07 9:07 ` Ryan Roberts
2024-03-07 9:33 ` Barry Song
2024-03-07 10:50 ` Ryan Roberts
2024-03-07 10:54 ` David Hildenbrand
2024-03-07 10:54 ` David Hildenbrand
2024-03-07 11:13 ` Ryan Roberts
2024-03-07 11:17 ` David Hildenbrand
2024-03-07 14:41 ` Lance Yang
2024-03-07 14:58 ` David Hildenbrand
2024-03-07 15:08 ` Lance Yang
2024-03-07 11:26 ` Barry Song
2024-03-07 11:31 ` David Hildenbrand
2024-03-07 11:42 ` Ryan Roberts
2024-03-07 11:45 ` David Hildenbrand
2024-03-07 12:01 ` Barry Song
2024-03-07 12:04 ` David Hildenbrand
2024-03-07 16:31 ` Ryan Roberts
2024-03-07 18:54 ` Barry Song
2024-03-07 19:48 ` David Hildenbrand
2024-03-08 13:05 ` Ryan Roberts
2024-03-08 13:27 ` David Hildenbrand
2024-03-08 13:48 ` Ryan Roberts
2024-03-08 18:01 ` Barry Song
2024-03-11 9:55 ` Ryan Roberts
2024-03-11 10:01 ` Barry Song
2024-03-11 15:07 ` Ryan Roberts
2024-03-12 10:20 ` Lance Yang
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=5cc05529-eb80-410e-bc26-233b0ba0b21f@redhat.com \
--to=david@redhat.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=fengwei.yin@intel.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=peterx@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=songmuchun@bytedance.com \
--cc=vishal.moola@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=xiehuan09@gmail.com \
--cc=zokeefe@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
all inboxes | Powered by JetHome®