From: David Rientjes <rientjes@google.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org, Mikulas Patocka <mpatocka@redhat.com>,
Ondrej Kozina <okozina@redhat.com>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
Mel Gorman <mgorman@suse.de>, Neil Brown <neilb@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
dm-devel@redhat.com, Michal Hocko <mhocko@suse.com>
Subject: Re: [RFC PATCH 1/2] mempool: do not consume memory reserves from the reclaim path
Date: Tue, 19 Jul 2016 13:45:52 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.10.1607191315400.58064@chino.kir.corp.google.com> (raw)
In-Reply-To: <20160719135426.GA31229@cmpxchg.org>
On Tue, 19 Jul 2016, Johannes Weiner wrote:
> Mempool guarantees forward progress by having all necessary memory
> objects for the guaranteed operation in reserve. Think about it this
> way: you should be able to delete the pool->alloc() call entirely and
> still make reliable forward progress. It would kill concurrency and be
> super slow, but how could it be affected by a system OOM situation?
>
> If our mempool_alloc() is waiting for an object that an OOM victim is
> holding, where could that OOM victim get stuck before giving it back?
> As I asked in the previous thread, surely you wouldn't do a mempool
> allocation first and then rely on an unguarded page allocation to make
> forward progress, right? It would defeat the purpose of using mempools
> in the first place. And surely the OOM victim wouldn't be waiting for
> a lock that somebody doing mempool_alloc() *against the same mempool*
> is holding. That'd be an obvious ABBA deadlock.
>
> So maybe I'm just dense, but could somebody please outline the exact
> deadlock diagram? Who is doing what, and how are they getting stuck?
>
> cpu0: cpu1:
> mempool_alloc(pool0)
> mempool_alloc(pool0)
> wait for cpu1
> not allocating memory - would defeat mempool
> not taking locks held by cpu0* - would ABBA
> ???
> mempool_free(pool0)
>
> Thanks
>
> * or any other task that does mempool_alloc(pool0) before unlock
>
I'm approaching this from a perspective of any possible mempool usage, not
with any single current user in mind.
Any mempool_alloc() user that then takes a contended mutex can do this.
An example:
taskA taskB taskC
----- ----- -----
mempool_alloc(a)
mutex_lock(b)
mutex_lock(b)
mempool_alloc(a)
Imagine the mempool_alloc() done by taskA depleting all free elements so
we rely on it to do mempool_free() before any other mempool allocator can
be guaranteed.
If taskC is oom killed, or has PF_MEMALLOC set, it cannot access memory
reserves from the page allocator if __GFP_NOMEMALLOC is automatic in
mempool_alloc(). This livelocks the page allocator for all processes.
taskB in this case need only stall after taking mutex_lock() successfully;
that could be because of the oom livelock, it is contended on another
mutex held by an allocator, etc.
Obviously taskB stalling while holding a mutex that is contended by a
mempool user holding an element is not preferred, but it's possible. (A
simplified version is also possible with 0-size mempools, which are also
allowed.)
My point is that I don't think we should be forcing any behavior wrt
memory reserves as part of the mempool implementation. In the above,
taskC mempool_alloc() would succeed and not livelock unless
__GFP_NOMEMALLOC is forced. The mempool_alloc() user may construct their
set of gfp flags as appropriate just like any other memory allocator in
the kernel.
The alternative would be to ensure no mempool users ever take a lock that
another thread can hold while contending another mutex or allocating
memory itself.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-07-19 20:46 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-18 8:39 [RFC PATCH 0/2] mempool vs. page allocator interaction Michal Hocko
2016-07-18 8:41 ` [RFC PATCH 1/2] mempool: do not consume memory reserves from the reclaim path Michal Hocko
2016-07-18 8:41 ` [RFC PATCH 2/2] mm, mempool: do not throttle PF_LESS_THROTTLE tasks Michal Hocko
2016-07-19 21:50 ` Mikulas Patocka
2016-07-22 8:46 ` NeilBrown
2016-07-22 9:04 ` NeilBrown
2016-07-22 9:15 ` Michal Hocko
2016-07-23 0:12 ` NeilBrown
2016-07-25 8:32 ` Michal Hocko
2016-07-25 19:23 ` Michal Hocko
2016-07-26 7:07 ` Michal Hocko
2016-07-27 3:43 ` [dm-devel] " NeilBrown
2016-07-27 18:24 ` Michal Hocko
2016-07-27 21:33 ` NeilBrown
2016-07-28 7:17 ` Michal Hocko
2016-08-03 12:53 ` Mikulas Patocka
2016-08-03 14:34 ` Michal Hocko
2016-08-04 18:49 ` Mikulas Patocka
2016-08-12 12:32 ` Michal Hocko
2016-08-13 17:34 ` Mikulas Patocka
2016-08-14 10:34 ` Michal Hocko
2016-08-15 16:15 ` Mikulas Patocka
2016-11-23 21:11 ` Mikulas Patocka
2016-11-24 13:29 ` Michal Hocko
2016-11-24 17:10 ` Mikulas Patocka
2016-11-28 14:06 ` Michal Hocko
2016-07-25 21:52 ` Mikulas Patocka
2016-07-26 7:25 ` Michal Hocko
2016-07-27 4:02 ` [dm-devel] " NeilBrown
2016-07-27 14:28 ` Mikulas Patocka
2016-07-27 18:40 ` Michal Hocko
2016-08-03 13:59 ` Mikulas Patocka
2016-08-03 14:42 ` Michal Hocko
2016-08-04 18:46 ` Mikulas Patocka
2016-07-27 21:36 ` NeilBrown
2016-07-19 2:00 ` [RFC PATCH 1/2] mempool: do not consume memory reserves from the reclaim path David Rientjes
2016-07-19 7:49 ` Michal Hocko
2016-07-19 13:54 ` Johannes Weiner
2016-07-19 14:19 ` Michal Hocko
2016-07-19 22:01 ` Mikulas Patocka
2016-07-19 20:45 ` David Rientjes [this message]
2016-07-20 8:15 ` Michal Hocko
2016-07-20 21:06 ` David Rientjes
2016-07-21 8:52 ` Michal Hocko
2016-07-21 12:13 ` Johannes Weiner
2016-07-21 14:53 ` Michal Hocko
2016-07-21 15:26 ` Johannes Weiner
2016-07-22 1:41 ` NeilBrown
2016-07-22 6:37 ` Michal Hocko
2016-07-22 12:26 ` Vlastimil Babka
2016-07-22 19:44 ` Andrew Morton
2016-07-23 18:52 ` Vlastimil Babka
2016-07-19 21:50 ` Mikulas Patocka
2016-07-20 6:44 ` Michal Hocko
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=alpine.DEB.2.10.1607191315400.58064@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=akpm@linux-foundation.org \
--cc=dm-devel@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=mpatocka@redhat.com \
--cc=neilb@suse.de \
--cc=okozina@redhat.com \
--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