linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ge Yang <yangge1116@126.com>
To: David Hildenbrand <david@redhat.com>, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, 21cnbao@gmail.com,
	baolin.wang@linux.alibaba.com, liuzixing@hygon.cn
Subject: Re: [PATCH V2] mm/gup: Clear the LRU flag of a page before adding to LRU batch
Date: Tue, 30 Jul 2024 18:01:45 +0800	[thread overview]
Message-ID: <18cdbd92-81db-42be-a290-08462759ffe6@126.com> (raw)
In-Reply-To: <d41865b4-d6fa-49ba-890a-921eefad27dd@redhat.com>



在 2024/7/30 17:58, David Hildenbrand 写道:
> On 30.07.24 11:56, Ge Yang wrote:
>>
>>
>> 在 2024/7/30 17:41, David Hildenbrand 写道:
>>> On 30.07.24 11:36, Ge Yang wrote:
>>>>
>>>>
>>>> 在 2024/7/30 15:45, David Hildenbrand 写道:
>>>>>>> Looking at this in more detail, I wonder if we can turn that to
>>>>>>>
>>>>>>> if (!folio_test_clear_lru(folio))
>>>>>>>         return;
>>>>>>> folio_get(folio);
>>>>>>>
>>>>>>> In all cases? The caller must hold a reference, so this should be
>>>>>>> fine.
>>>>>>>
>>>>>>
>>>>>> Seems the caller madvise_free_pte_range(...), calling
>>>>>> folio_mark_lazyfree(...), doesn't hold a reference on folio.
>>>>>>
>>>>>
>>>>> If that would be the case and the folio could get freed concurrently,
>>>>> the folio_get(folio) would be completely broken.
>>>>>
>>>>> In madvise_free_pte_range() we hold the PTL, so the folio cannot get
>>>>> freed concurrently.
>>>>>
>>>>
>>>> Right.
>>>>
>>>>> folio_get() is only allowed when we are sure the folio cannot get 
>>>>> freed
>>>>> concurrently, because we know there is a reference that cannot go 
>>>>> away.
>>>>>
>>>>>
>>>>
>>>> When cpu0 runs folio_activate(), and cpu1 runs folio_put() 
>>>> concurrently,
>>>> a possible bad scenario would like:
>>>>
>>>> cpu0                                           cpu1
>>>>
>>>>                                               folio_put_testzero(folio)
>>>> if (!folio_test_clear_lru(folio))// Seems folio shouldn't be accessed
>>>>
>>>>           return;
>>>> folio_get(folio);
>>>>                                                __folio_put(folio)
>>>>                                                __folio_clear_lru(folio)
>>>>
>>>>
>>>> Seems we should use folio_try_get(folio) instead of folio_get(folio).
>>>
>>> In which case is folio_activate() called without the PTL on a mapped
>>> page or without a raised refcount?
>>>
>>
>> No such case has been found. But, folio_put() can be run at anytime, so
>> folio_activate() may access a folio with a reference count of 0.
> 
> If you can't find such a case then nothing is broken and no switch to 
> folio_try_get() is required.
> 

Ok, thanks.



  reply	other threads:[~2024-07-30 10:01 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-22  6:48 yangge1116
2024-07-03  9:46 ` Barry Song
2024-07-03 11:15   ` Ge Yang
2024-07-03 12:02 ` David Hildenbrand
2024-07-04  6:24   ` Ge Yang
2024-07-27 22:33 ` Chris Li
2024-07-29  0:34   ` Ge Yang
2024-07-29  3:49   ` Ge Yang
2024-07-29 22:06     ` Chris Li
2024-08-02  1:51       ` Ge Yang
2024-08-02 20:18         ` Chris Li
2024-08-03  8:25           ` Ge Yang
2024-08-03 17:08             ` Yu Zhao
2024-08-03 20:03               ` Kairui Song
2024-08-04 12:21                 ` Kairui Song
2024-08-04 17:51                   ` Chris Li
2024-08-04 19:11                     ` Chris Li
2024-09-02 12:53                       ` Linux regression tracking (Thorsten Leemhuis)
2024-09-05  5:00                         ` Chris Li
2024-07-29 14:04 ` David Hildenbrand
2024-07-30  0:57   ` Ge Yang
2024-07-30  7:45     ` David Hildenbrand
2024-07-30  9:36       ` Ge Yang
2024-07-30  9:41         ` David Hildenbrand
2024-07-30  9:56           ` Ge Yang
2024-07-30  9:58             ` David Hildenbrand
2024-07-30 10:01               ` Ge Yang [this message]
2024-12-26  0:31 Andy amonte

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=18cdbd92-81db-42be-a290-08462759ffe6@126.com \
    --to=yangge1116@126.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuzixing@hygon.cn \
    --cc=stable@vger.kernel.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