linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Linux MM <linux-mm@kvack.org>, Kernel Team <Kernel-team@fb.com>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Hugh Dickins <hughd@google.com>,
	William Kucharski <william.kucharski@oracle.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH] mm/thp: flush file for !is_shmem PageDirty() case in collapse_file()
Date: Thu, 31 Oct 2019 04:55:29 +0000	[thread overview]
Message-ID: <4542F512-D964-44AD-9BAA-6683C540AF7E@fb.com> (raw)
In-Reply-To: <20191030185115.ad780e74c66b6286789559fd@linux-foundation.org>

[-- Attachment #1: Type: text/plain, Size: 4073 bytes --]



On Oct 30, 2019, at 6:51 PM, Andrew Morton <akpm@linux-foundation.org<mailto:akpm@linux-foundation.org>> wrote:

On Wed, 30 Oct 2019 13:07:36 -0700 Song Liu <songliubraving@fb.com<mailto:songliubraving@fb.com>> wrote:

For non-shmem file THPs, khugepaged only collapses read only .text mapping
(VM_DENYWRITE). These pages should not be dirty except the case where the
file hasn't been flushed since first write.

Call filemap_flush() in collapse_file() to accelerate the write back in
such cases.

Also add warning if PageDirty() triggered for pages from readahead path.

Reported-and-tested-by: syzbot+efb9e48b9fbdc49bb34a@syzkaller.appspotmail.com<mailto:syzbot+efb9e48b9fbdc49bb34a@syzkaller.appspotmail.com>

If sysbot reported something then we definitely want to be able to
review that report when reviewing the patch!  So please do include a
Link: for that sort of thing.

A bit of sleuthing leads me to
http://lkml.kernel.org/r/000000000000c50fd70595fdd5b2@google.com

which shows that this patch is in fact a fix against
mmthp-recheck-each-page-before-collapsing-file-thp.patch.  This very
important information wasn't in the changelog.

And this patch doesn't really fix the sysbot hang, does it?  The patch
restores the flush which was removed in order to fix the sysbot hang.

In general, please do try to include all this sort of information when
preparing changelogs.

Sorry for the confusion. This one is a bit tricky.

syzbot reported hang issue with filemap_flush(), which is already fixed
by previous patch which removes filemap_flush().

This patch tries to add filemap_flush() back, in a proper way. So this
patch is an improvement, not a fix. That's why I didn't include the
fixes tag.

However, I used syzbot to test this patch, by replying "#syz test: ...".
to the previous report (the one you found). I didn't cc the mail list
for those tests. syzbot did find bug with an earlier version, and gave
green light for this version. This is the reason I would like to give
syzbot credit with the tag. Maybe I should just make it "Tested-by:
syzbot"?



--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1601,6 +1601,33 @@ static void collapse_file(struct mm_struct *mm,
result = SCAN_FAIL;
goto xa_unlocked;
}
+ if (WARN_ON_ONCE(PageDirty(page))) {

I'm not understanding what guarantees this.  Can't another process
which has the file open for writing come in and dirty the page after
the readahead has completed and before this process locks the page?

For non-shmem file, khugepaged only work for VM_DENYWRITE mappings.
Therefore, the page cannot be opened for write by another process.


+ /*
+  * page from readahead should not
+  * be dirty. Show warning if this
+  * somehow happens.
+  */
+ result = SCAN_FAIL;
+ goto out_unlock;
+ }
+ } else if (PageDirty(page)) {
+ /*
+  * khugepaged only works on read-only fd,
+  * so this page is dirty because it hasn't
+  * been flushed since first write. There
+  * won't be new dirty pages.
+  *
+  * Trigger async flush here and hope the
+  * writeback is done when khugepaged
+  * revisits this page.
+  *
+  * This is a one-off situation. We are not
+  * forcing writeback in loop.
+  */
+ xas_unlock_irq(&xas);
+ filemap_flush(mapping);
+ result = SCAN_FAIL;
+ goto xa_unlocked;
} else if (trylock_page(page)) {
get_page(page);
xas_unlock_irq(&xas);

The patch mmthp-recheck-each-page-before-collapsing-file-thp.patch has
undergone quite a bit of churn so I don't think it should be mainlined
without more testing and review.  But it fixes a significant issue.  So
could the appropriate developers please take some time to recheck and
retest it all?

We are running production tests with previous version (no filemap_flush).
syzbot also gives green light to that one. Maybe we should ship the
version without filemap_flush with 5.4, and this improvement with 5.5?

This improvement also passed syzbot's test. If this looks good, we will
also add this to production tests.

Thanks,
Song

[-- Attachment #2: Type: text/html, Size: 40237 bytes --]

  reply	other threads:[~2019-10-31  4:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 20:07 Song Liu
2019-10-31  1:51 ` Andrew Morton
2019-10-31  4:55   ` Song Liu [this message]
2019-10-31 18:10   ` Song Liu
2019-11-01 18:31   ` Johannes Weiner
2019-11-01 21:48     ` Song Liu

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=4542F512-D964-44AD-9BAA-6683C540AF7E@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-mm@kvack.org \
    --cc=william.kucharski@oracle.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