linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "yueyang.pan@epfl.ch" <yueyang.pan@epfl.ch>
Cc: linux-mm@kvack.org
Subject: Re: Some questions about shrink_folio_list
Date: Thu, 4 Apr 2024 16:35:03 +0100	[thread overview]
Message-ID: <Zg7Ip6RIkgHjdniV@casper.infradead.org> (raw)
In-Reply-To: <AS8P189MB165601127DEE02A7FA9C2D11F53D2@AS8P189MB1656.EURP189.PROD.OUTLOOK.COM>

On Wed, Apr 03, 2024 at 10:06:16PM +0000, yueyang.pan@epfl.ch wrote:
> Dear Matthew,
>     I am Yueyang Pan a PhD student from EPFL, and I am currently
> checking the swap code in the kernel. Sorry to bother you because this
> email should go to Mel Gorman. He did not reply to me so I turned to
> you for some help.

Hi Yueyang,

You'd probably have more luck if you cc'd the mailing list.  Somebody
other than Mel might have answered you.  Added it now.

> 1)  I have some questions about `try_to_unmap_flush_dirty`. I
> wonder why this is necessary in shrink_folio_list because in
> the folio_check_references, we have already checked that the PTEs
> pointing to this page does not have any access bit set. The current
> shrink_folio_list then unmaps the page, clears the dirty bit, issues
> the TLB flush if the dirty bit was set previously and then starts
> to write the page to the swap. I wonder why here we cannot take an
> opportunistic approach. My understanding is that if we don’t unmap the
> page and perform flush, when there is a concurrent write to the page,
> both the access bit and dirty bit will be set (because the dirty bit
> is cleared) so we can simply check the access bit again after pageout
> to see whether we can free this page or not.
>    I checked the git blame and saw Mel's commit in 2015 where he
> mentioned that it was better to assume a writeable entry exist
> in TLB but I wonder why this can be true if we have already use
> folio_check_references to check the PTE access bit. Does this imply
> even if the folio_check_references gives no reference there can be
> still entries in the TLB?

This is far outside my realm of expertise.  I suspect it's
possible that there can be stale entries in the TLB if
ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH.

> 2) I have some questions at the end of shrink_folio_list before the
> ref_folios are spliced again back to folio_list. What if at the same
> time, there is another function trying to free the page or mlock
> the page? Will this page be circulated again in the inactive LRU
> list and being double freed since the page lock was released at the
> list_splice? Because from what I understood, the mlock will take the
> page directly from the inactive/active list the page is in and move
> the page to the mlock list but at this moment the page does not reside
> in either of the list.

I think the answer is that these folios have their LRU flag cleared
throughout shrink_folio_list() so they cannot be mlocked?

static struct lruvec *__mlock_folio(struct folio *folio, struct lruvec *lruvec)
{
        /* There is nothing more we can do while it's off LRU */
        if (!folio_test_clear_lru(folio))
                return lruvec;



       reply	other threads:[~2024-04-04 15:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AS8P189MB165601127DEE02A7FA9C2D11F53D2@AS8P189MB1656.EURP189.PROD.OUTLOOK.COM>
2024-04-04 15:35 ` Matthew Wilcox [this message]
2024-04-04 21:32   ` yueyang.pan

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=Zg7Ip6RIkgHjdniV@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=yueyang.pan@epfl.ch \
    /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