From: Michal Hocko <mhocko@suse.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
kirill@shutemov.name, linux-mm@kvack.org,
kirill.shutemov@linux.intel.com
Subject: Re: [PATCH v2] mm: Warn on lock_page() from reclaim context.
Date: Tue, 20 Mar 2018 09:44:45 +0100 [thread overview]
Message-ID: <20180320084445.GE23100@dhcp22.suse.cz> (raw)
In-Reply-To: <20180319150824.24032e2854908b0cc5240d9f@linux-foundation.org>
On Mon 19-03-18 15:08:24, Andrew Morton wrote:
> On Sun, 18 Mar 2018 10:22:49 +0900 Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
>
> > >From f43b8ca61b76f9a19c13f6bf42b27fad9554afc0 Mon Sep 17 00:00:00 2001
> > From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> > Date: Sun, 18 Mar 2018 10:18:01 +0900
> > Subject: [PATCH v2] mm: Warn on lock_page() from reclaim context.
> >
> > Kirill A. Shutemov noticed that calling lock_page[_killable]() from
> > reclaim context might cause deadlock. In order to help finding such
> > lock_page[_killable]() users (including out of tree users), this patch
> > emits warning messages when CONFIG_PROVE_LOCKING is enabled.
> >
> > ...
> >
> > --- a/include/linux/pagemap.h
> > +++ b/include/linux/pagemap.h
> > @@ -466,6 +466,7 @@ static inline pgoff_t linear_page_index(struct vm_area_struct *vma,
> > extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
> > unsigned int flags);
> > extern void unlock_page(struct page *page);
> > +extern void __warn_lock_page_from_reclaim_context(void);
> >
> > static inline int trylock_page(struct page *page)
> > {
> > @@ -479,6 +480,9 @@ static inline int trylock_page(struct page *page)
> > static inline void lock_page(struct page *page)
> > {
> > might_sleep();
> > + if (IS_ENABLED(CONFIG_PROVE_LOCKING) &&
> > + unlikely(current->flags & PF_MEMALLOC))
> > + __warn_lock_page_from_reclaim_context();
> > if (!trylock_page(page))
> > __lock_page(page);
> > }
>
> I think it would be neater to do something like
>
> #ifdef CONFIG_PROVE_LOCKING
> static inline void lock_page_check_context(struct page *page)
> {
> if (unlikely(current->flags & PF_MEMALLOC))
> __lock_page_check_context(page);
> }
> #else
> static inline void lock_page_check_context(struct page *page)
> {
> }
> #endif
>
> and
>
> void __lock_page_check_context(struct page *page)
> {
> WARN_ONCE(...);
> dump_page(page);
> }
I would just put __lock_page_check_context in place. Or do you expect
more callers? But agreed that this looks neater than in line code.
> And I wonder if overloading CONFIG_PROVE_LOCKING is appropriate here.
> CONFIG_PROVE_LOCKING is a high-level thing under which a whole bunch of
> different debugging options may exist.
Yes but it is meant to catch locking issues in general so I think doing
this check under the same config makes sense.
> I guess we should add a new config item under PROVE_LOCKING,
I am not convinced a new config is really worth it. We have way too many
already and PROVE_LOCKING sounds like a good fit to me.
> or perhaps use CONFIG_DEBUG_VM.
Please don't. There are people running with this config and adding more
potentially performance visible changes wouldn't make them too happy.
> Also, is PF_MEMALLOC the best way of determining that we're running
> reclaim? What about using current->reclaim_state?
Yeah, reclaim_state state would rule out PF_MEMALLOC (ab)users
allocating under the page lock.
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2018-03-20 8:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-17 14:11 [PATCH] " Tetsuo Handa
2018-03-17 15:54 ` Kirill A. Shutemov
2018-03-18 1:22 ` [PATCH v2] " Tetsuo Handa
2018-03-18 8:55 ` Kirill A. Shutemov
2018-03-19 9:04 ` Michal Hocko
2018-03-19 10:14 ` Kirill A. Shutemov
2018-03-19 10:33 ` Michal Hocko
2018-03-19 10:45 ` Kirill A. Shutemov
2018-03-19 10:55 ` Michal Hocko
2018-03-19 12:04 ` Tetsuo Handa
2018-03-19 22:08 ` Andrew Morton
2018-03-20 8:44 ` Michal Hocko [this message]
2018-03-20 17:50 ` Andrew Morton
2018-03-29 7:04 ` [lkp-robot] [mm] 67ffc906f8: WARNING:at_mm/filemap.c:#__warn_lock_page_from_reclaim_context kernel test robot
2018-03-29 10:32 ` [lkp-robot] [mm] 67ffc906f8:WARNING:at_mm/filemap.c:#__warn_lock_page_from_reclaim_context Tetsuo Handa
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=20180320084445.GE23100@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=kirill@shutemov.name \
--cc=linux-mm@kvack.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
/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