linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Yin, Fengwei" <fengwei.yin@intel.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>,
	<linux-mm@kvack.org>, <akpm@linux-foundation.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH mm-unstable 5/5] mm/mempolicy: Convert migrate_page_add() to migrate_folio_add()
Date: Sat, 21 Jan 2023 11:41:56 +0800	[thread overview]
Message-ID: <2bcf36c4-54a1-37e4-7a0a-3d3e34ef4e56@intel.com> (raw)
In-Reply-To: <Y8rv3/GfW8XDDXj7@casper.infradead.org>



On 1/21/2023 3:47 AM, Matthew Wilcox wrote:
> On Thu, Jan 19, 2023 at 09:24:16AM +0800, Yin, Fengwei wrote:
>> On 1/19/2023 7:22 AM, Vishal Moola (Oracle) wrote:
>>> @@ -1022,27 +1022,23 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask,
>>>  }
>>>  
>>>  #ifdef CONFIG_MIGRATION
>>> -/*
>>> - * page migration, thp tail pages can be passed.
>>> - */
>>> -static int migrate_page_add(struct page *page, struct list_head *pagelist,
>>> +static int migrate_folio_add(struct folio *folio, struct list_head *foliolist,
>>>  				unsigned long flags)
>>>  {
>>> -	struct page *head = compound_head(page);
>>>  	/*
>>> -	 * Avoid migrating a page that is shared with others.
>>> +	 * Avoid migrating a folio that is shared with others.
>>>  	 */
>>> -	if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(head) == 1) {
>>> -		if (!isolate_lru_page(head)) {
>>> -			list_add_tail(&head->lru, pagelist);
>>> -			mod_node_page_state(page_pgdat(head),
>>> -				NR_ISOLATED_ANON + page_is_file_lru(head),
>>> -				thp_nr_pages(head));
>>> +	if ((flags & MPOL_MF_MOVE_ALL) || folio_mapcount(folio) == 1) {
>> One question to the page_mapcount -> folio_mapcount here.
>>
>> For a large folio with 0 entire mapcount, if the first sub-page and any
>> other sub-page are mapped, page_mapcount(head) == 1 is true while
>> folio_mapcount(folio) == 1 is not.
> 
> We had a good discussion about this in today's THP Cabal meeting [1].  I
> didn't quite check everything that I said was true, so let me summarise
> & correct it now ...
> 
>  - This is a heuristic.  We're trying to see whether this folio is
>    mapped by multiple processes (because if it is, it's probably not
>    worth migrating).  If the heuristic is wrong, it probably doesn't
>    matter _too_ much?
Agree.

>  - A proper heuristic for this would be
> 		folio_total_mapcount(folio) == folio_nr_pages(folio)
I am not sure. File folio can be partially mapped. Maybe following check?
  for each sub-pages:
     (folio_entire_mapcount(folio) + sub-pages->_mapcount) <= 1

But it's also expensive to check all sub-pages. Maybe a bit in folio
if filio mapped to only one process is really important?

>    but this would be expensive to calculate as it requires examining
>    512 cachelines for a 2MB page.
>  - For a large folio which is smaller than PMD size, we're guaranteed
>    that folio_mapcount() is 0 today.
My understanding is: for large folio, if any sub-page is mapped,
folio_mapcount() can not be 0.

>  - In the meeting I said that page_mapcount() of the head of a THP
>    page was zero; that's not true; I had forgotten that we added in
>    entire_mapcount to the individual page mapcount.
> 
> so I now think this should be:
> 
> 	page_mapcount(folio_page(folio, 0))
For file large folio, it's possible folio_page(folio, 0) mapped only
once, other sub-pages mapped multiple times.

But I think this maybe the best choice here.

> 
> with an explanation that checking every page is too heavy-weight.
> Maybe it should be its own function:
> 
> static inline int folio_estimated_mapcount(folio)
> {
> 	return page_mapcount(folio_page(folio, 0));
> }
> 
> with a nice comment explaining what's going on.
> 
> [1] https://www.youtube.com/watch?v=A3PoGQQQD3Q is the recording of
> today's meeting.
This is nice. Thanks a lot for sharing.


Regards
Yin, Fengwei



      reply	other threads:[~2023-01-21  3:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18 23:22 [PATCH mm-unstable 0/5] Vishal Moola (Oracle)
2023-01-18 23:22 ` [PATCH mm-unstable 1/5] mm/mempolicy: Convert queue_pages_pmd() to queue_folios_pmd() Vishal Moola (Oracle)
2023-01-18 23:22 ` [PATCH mm-unstable 2/5] mm/mempolicy: Convert queue_pages_pte_range() to queue_folios_pte_range() Vishal Moola (Oracle)
2023-01-18 23:22 ` [PATCH mm-unstable 3/5] mm/mempolicy: Convert queue_pages_hugetlb() to queue_folios_hugetlb() Vishal Moola (Oracle)
2023-01-18 23:22 ` [PATCH mm-unstable 4/5] mm/mempolicy: Convert queue_pages_required() to queue_folio_required() Vishal Moola (Oracle)
2023-01-18 23:22 ` [PATCH mm-unstable 5/5] mm/mempolicy: Convert migrate_page_add() to migrate_folio_add() Vishal Moola (Oracle)
2023-01-19  1:24   ` Yin, Fengwei
2023-01-20 19:41     ` Vishal Moola
2023-01-21  3:21       ` Yin, Fengwei
2023-01-20 19:47     ` Matthew Wilcox
2023-01-21  3:41       ` Yin, Fengwei [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=2bcf36c4-54a1-37e4-7a0a-3d3e34ef4e56@intel.com \
    --to=fengwei.yin@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vishal.moola@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