linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chuanhua Han <hanchuanhua@oppo.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
	Barry Song <21cnbao@gmail.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org
Cc: chengming.zhou@linux.dev, chrisl@kernel.org, david@redhat.com,
	hannes@cmpxchg.org, kasong@tencent.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, mhocko@suse.com, nphamcs@gmail.com,
	shy828301@gmail.com, steven.price@arm.com, surenb@google.com,
	wangkefeng.wang@huawei.com, willy@infradead.org,
	xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com,
	yuzhao@google.com, Barry Song <v-songbaohua@oppo.com>
Subject: Re: [RFC PATCH v3 3/5] mm: swap: make should_try_to_free_swap() support large-folio
Date: Wed, 13 Mar 2024 10:21:42 +0800	[thread overview]
Message-ID: <24dc6251-8582-790f-bbd3-465deed946f5@oppo.com> (raw)
In-Reply-To: <e73c12ff-5234-44d5-a2b3-99cdc61a9c37@arm.com>

hi, Ryan Roberts

在 2024/3/12 20:34, Ryan Roberts 写道:
> On 04/03/2024 08:13, Barry Song wrote:
>> From: Chuanhua Han <hanchuanhua@oppo.com>
>>
>> should_try_to_free_swap() works with an assumption that swap-in is always done
>> at normal page granularity, aka, folio_nr_pages = 1. To support large folio
>> swap-in, this patch removes the assumption.
>>
>> Signed-off-by: Chuanhua Han <hanchuanhua@oppo.com>
>> Co-developed-by: Barry Song <v-songbaohua@oppo.com>
>> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
>> Acked-by: Chris Li <chrisl@kernel.org>
>> ---
>>  mm/memory.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/memory.c b/mm/memory.c
>> index abd4f33d62c9..e0d34d705e07 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -3837,7 +3837,7 @@ static inline bool should_try_to_free_swap(struct folio *folio,
>>  	 * reference only in case it's likely that we'll be the exlusive user.
>>  	 */
>>  	return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) &&
>> -		folio_ref_count(folio) == 2;
>> +		folio_ref_count(folio) == (1 + folio_nr_pages(folio));
> I don't think this is correct; one reference has just been added to the folio in
> do_swap_page(), either by getting from swapcache (swap_cache_get_folio()) or by
> allocating. If it came from the swapcache, it could be a large folio, because we
> swapped out a large folio and never removed it from swapcache. But in that case,
> others may have partially mapped it, so the refcount could legitimately equal
> the number of pages while still not being exclusively mapped.
>
> I'm guessing this logic is trying to estimate when we are likely exclusive so
> that we remove from swapcache (release ref) and can then reuse rather than CoW
> the folio? The main CoW path currently CoWs page-by-page even for large folios,
> and with Barry's recent patch, even the last page gets copied. So not sure what
> this change is really trying to achieve?
>
First, if it is a large folio in the swap cache, then its refcont is at
least folio_nr_pages(folio) :  


For example, in add_to_swap_cache path:

int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
                        gfp_t gfp, void **shadowp)
{
        struct address_space *address_space = swap_address_space(entry);
        pgoff_t idx = swp_offset(entry);
        XA_STATE_ORDER(xas, &address_space->i_pages, idx,
folio_order(folio));
        unsigned long i, nr = folio_nr_pages(folio); <---
        void *old;
        ...
        folio_ref_add(folio, nr); <---
        folio_set_swapcache(folio);
        ...
}


  *

    Then in the do_swap_page path:

  * if (should_try_to_free_swap(folio, vma, vmf->flags))
            folio_free_swap(folio);
  *

  * It also indicates that only folio in the swap cache will call
    folio_free_swap
  * to delete it from the swap cache, So I feel like this patch is
    necessary!? 😁

>>  }
>>  
>>  static vm_fault_t pte_marker_clear(struct vm_fault *vmf)

Thanks,

Chuanhua



  reply	other threads:[~2024-03-13  2:21 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04  8:13 [RFC PATCH v3 0/5] mm: support large folios swap-in Barry Song
2024-03-04  8:13 ` [RFC PATCH v3 1/5] arm64: mm: swap: support THP_SWAP on hardware with MTE Barry Song
2024-03-11 16:55   ` Ryan Roberts
2024-03-21  8:42     ` Barry Song
2024-03-21 10:31       ` Ryan Roberts
2024-03-21 10:43         ` Barry Song
2024-03-22  2:51         ` Barry Song
2024-03-22  7:41           ` Barry Song
2024-03-22 10:19             ` Ryan Roberts
2024-03-23  2:15               ` Chris Li
2024-03-23  3:50                 ` Barry Song
2024-03-04  8:13 ` [RFC PATCH v3 2/5] mm: swap: introduce swap_nr_free() for batched swap_free() Barry Song
2024-03-11 18:51   ` Ryan Roberts
2024-03-14 13:12     ` Chuanhua Han
2024-03-14 13:43       ` Ryan Roberts
2024-03-15  8:34         ` Chuanhua Han
2024-03-15 10:57           ` Ryan Roberts
2024-03-18  1:28             ` Chuanhua Han
2024-03-04  8:13 ` [RFC PATCH v3 3/5] mm: swap: make should_try_to_free_swap() support large-folio Barry Song
2024-03-12 12:34   ` Ryan Roberts
2024-03-13  2:21     ` Chuanhua Han [this message]
2024-03-13  9:09       ` Ryan Roberts
2024-03-13  9:24         ` Chuanhua Han
2024-03-04  8:13 ` [RFC PATCH v3 4/5] mm: swap: introduce swapcache_prepare_nr and swapcache_clear_nr for large folios swap-in Barry Song
2024-03-12 15:35   ` Ryan Roberts
2024-03-18 22:35     ` Barry Song
2024-03-04  8:13 ` [RFC PATCH v3 5/5] mm: support large folios swapin as a whole Barry Song
2024-03-12 16:33   ` Ryan Roberts
2024-03-14 12:56     ` Chuanhua Han
2024-03-14 13:57       ` Ryan Roberts
2024-03-14 20:43         ` Barry Song
2024-03-15 10:59           ` Ryan Roberts
2024-03-15  1:16         ` Chuanhua Han
2024-06-10 20:43       ` Shakeel Butt
2024-06-11  0:23         ` Barry Song
2024-06-11 17:24           ` Shakeel Butt
2024-06-11 22:13             ` Barry Song
2024-03-15  8:41   ` Huang, Ying
2024-03-15  8:54     ` Barry Song
2024-03-15  9:15       ` Huang, Ying
2024-03-15 10:01         ` Barry Song
2024-03-15 12:06           ` Ryan Roberts
2024-03-17  6:11             ` Barry Song
2024-03-18  1:52           ` Huang, Ying
2024-03-18  2:41             ` Barry Song
2024-03-18 16:45               ` Ryan Roberts
2024-03-19  6:27                 ` Barry Song
2024-03-19  9:05                   ` Ryan Roberts
2024-03-21  9:22                     ` Barry Song
2024-03-21 11:13                       ` Ryan Roberts
2024-03-19  9:20                 ` Huang, Ying
2024-03-19 12:19                   ` Ryan Roberts
2024-03-20  2:18                     ` Huang, Ying
2024-03-20  2:47                       ` Barry Song
2024-03-20  6:20                         ` Huang, Ying
2024-03-20 18:38                           ` Barry Song
2024-03-21  4:23                             ` Huang, Ying
2024-03-21  5:12                               ` Barry Song
2024-03-21 10:20                     ` Barry Song

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=24dc6251-8582-790f-bbd3-465deed946f5@oppo.com \
    --to=hanchuanhua@oppo.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=nphamcs@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=steven.price@arm.com \
    --cc=surenb@google.com \
    --cc=v-songbaohua@oppo.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    --cc=xiang@kernel.org \
    --cc=ying.huang@intel.com \
    --cc=yosryahmed@google.com \
    --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