All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
	snazy@snazy.de, Michal Hocko <mhocko@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>, Jan Kara <jack@suse.cz>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	Randy Dunlap <rdunlap@infradead.org>,
	linux-kernel@vger.kernel.org, Linux MM <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Potyra, Stefan" <Stefan.Potyra@elektrobit.com>
Subject: Re: mlockall(MCL_CURRENT) blocking infinitely
Date: Wed, 6 Nov 2019 13:03:15 +0100	[thread overview]
Message-ID: <20191106120315.GF16085@quack2.suse.cz> (raw)
In-Reply-To: <20191105182211.GA33242@cmpxchg.org>

On Tue 05-11-19 13:22:11, Johannes Weiner wrote:
> On Tue, Nov 05, 2019 at 04:28:21PM +0100, Vlastimil Babka wrote:
> > On 11/5/19 2:23 PM, Robert Stupp wrote:
> > > "git bisect" led to a result.
> > > 
> > > The offending merge commit is f91f2ee54a21404fbc633550e99d69d14c2478f2
> > > "Merge branch 'akpm' (rest of patches from Andrew)".
> > > 
> > > The first bad commit in the merged series of commits is
> > > https://github.com/torvalds/linux/commit/6b4c9f4469819a0c1a38a0a4541337e0f9bf6c11
> > > . a75d4c33377277b6034dd1e2663bce444f952c14, the commit before 6b4c9f44,
> > > is good.
> > 
> > Ah, great you could bisect this. CCing people from the commit
> > 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations")
> 
> Judging from Robert's stack captures, the task is not hung but
> busy-looping in __mm_populate(). AFAICS, the only way this can occur
> is if populate_vma_page_range() returns 0 and we don't advance the
> iteration position (if it returned an error, we wouldn't reset nend
> and move on to the next vma as ignore_errors is 1 for mlockall.)
> 
> populate_vma_page_range() returns 0 when the first page is not found
> and faultin_page() returns -EBUSY (if it were processing pages, or if
> the error from faultin_page() would be a different one, we would
> return the number of pages processed or -error).
> 
> faultin_page() returns -EBUSY when VM_FAULT_RETRY is set, i.e. we
> dropped the mmap_sem in order to initiate IO and require a retry. That
> is consistent with the bisect result (new VM_FAULT_RETRY conditions).
> 
> At this point, regular page fault would retry with FAULT_FLAG_TRIED to
> indicate that the mmap_sem cannot be dropped a second time. But this
> mlock path doesn't set that flag and we can loop repeatedly. That is
> something we probably need to fix with a FOLL_TRIED somewhere.

It seems we could use __get_user_pages_locked() for that in
populate_vma_page_range() if we were guaranteed that mm stays alive.  This
is guaranteed for current->mm cases but there seem to be some callers to
populate_vma_page_range() where mm could indeed go away once we drop
mmap_sem. These luckily pass NULL for the 'nonblocking' parameter though so
all call sites seem to be fine but it would be fragile...

> What I don't quite understand yet is why the fault path doesn't make
> progress eventually. We must drop the mmap_sem without changing the
> state in any way. How can we keep looping on the same page?

That may be a slight suboptimality with Josef's patches. If the page
is marked as PageReadahead, we always drop mmap_sem if we can and start
readahead without checking whether that makes sense or not in
do_async_mmap_readahead(). OTOH page_cache_async_readahead() then clears
PageReadahead so the only way how I can see we could loop like this is when
file->ra->ra_pages is 0. Not sure if that's what's happening through. We'd
need to find which of the paths in filemap_fault() calls
maybe_unlock_mmap_for_io() to tell more.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  parent reply	other threads:[~2019-11-06 12:03 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24  7:36 mlockall(MCL_CURRENT) blocking infinitely Robert Stupp
2019-10-24 23:34 ` Randy Dunlap
2019-10-25  9:21   ` Michal Hocko
2019-10-25 11:02     ` Robert Stupp
2019-10-25 11:02       ` Robert Stupp
2019-10-25 11:46       ` Michal Hocko
2019-10-25 11:50         ` Michal Hocko
2019-10-25 11:59           ` Robert Stupp
2019-10-25 11:59             ` Robert Stupp
2019-10-25 13:19             ` Robert Stupp
2019-10-25 13:19               ` Robert Stupp
2019-10-25 11:55         ` Robert Stupp
2019-10-25 11:55           ` Robert Stupp
2019-10-25 12:05           ` Michal Hocko
2019-10-25 12:11             ` Michal Hocko
2019-10-25 13:10               ` Robert Stupp
2019-10-25 13:10                 ` Robert Stupp
2019-10-25 13:27                 ` Michal Hocko
2019-10-25 13:45                   ` Robert Stupp
2019-10-25 13:45                     ` Robert Stupp
2019-10-25 13:57                     ` Michal Hocko
2019-10-25 14:00                       ` Michal Hocko
2019-10-25 15:58                         ` Robert Stupp
2019-10-25 15:58                           ` Robert Stupp
2019-11-05 13:23                           ` Robert Stupp
2019-11-05 13:23                             ` Robert Stupp
2019-11-05 15:28                             ` Vlastimil Babka
2019-11-05 18:22                               ` Johannes Weiner
2019-11-05 20:05                                 ` Robert Stupp
2019-11-05 20:05                                   ` Robert Stupp
2019-11-06 10:25                                   ` Robert Stupp
2019-11-06 10:25                                     ` Robert Stupp
2019-11-06 11:26                                     ` Robert Stupp
2019-11-06 11:26                                       ` Robert Stupp
2019-11-06 12:04                                       ` Jan Kara
2019-11-06 12:24                                       ` Robert Stupp
2019-11-06 12:24                                         ` Robert Stupp
2019-11-06 12:03                                 ` Jan Kara [this message]
2019-11-06 13:45                                   ` Robert Stupp
2019-11-06 13:45                                     ` Robert Stupp
2019-11-06 14:35                                     ` Jan Kara
2019-11-06 15:32                                       ` Robert Stupp
2019-11-06 15:32                                         ` Robert Stupp
2019-11-06 14:38                                     ` Jan Kara
2019-11-06 14:56                                     ` Josef Bacik
2019-11-06 15:05                                       ` Jan Kara
2019-11-06 15:14                                         ` Josef Bacik
2019-11-06 15:25                                           ` Jan Kara
2019-11-06 16:39                                           ` Robert Stupp
2019-11-06 16:39                                             ` Robert Stupp
2019-11-06 17:03                                             ` Robert Stupp
2019-11-06 17:03                                               ` Robert Stupp
2019-11-06 17:25                                               ` Jan Kara
2019-11-07  8:08                                                 ` Robert Stupp
2019-11-07  8:08                                                   ` Robert Stupp
2019-11-20 12:42                                                   ` Robert Stupp
2019-10-25 13:55                   ` Robert Stupp
2019-10-25 13:55                     ` Robert Stupp

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=20191106120315.GF16085@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=Stefan.Potyra@elektrobit.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=josef@toxicpanda.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=snazy@snazy.de \
    --cc=vbabka@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.