From: Andrew Morton <akpm@linux-foundation.org>
To: Robert Love <rlove@google.com>
Cc: Raul Xiong <raulxiong@gmail.com>,
Neil Zhang <glacier1980@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Shankar Brahadeeswaran <shankoo77@gmail.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
LKML <linux-kernel@vger.kernel.org>,
Bjorn Bringert <bringert@google.com>,
devel <devel@driverdev.osuosl.org>,
Hugh Dickins <hughd@google.com>,
Anjana V Kumar <anjanavk12@gmail.com>,
linux-next <linux-next@vger.kernel.org>
Subject: Re: [PATCH -next] ashmem: Fix ashmem_shrink deadlock.
Date: Thu, 16 May 2013 09:45:59 -0700 [thread overview]
Message-ID: <20130516094559.4d2c9212.akpm@linux-foundation.org> (raw)
In-Reply-To: <CAG6tG3zaU=gkJZzNezOX=s5WWDrc2x7SHiDy3UxVzDvKkw2foA@mail.gmail.com>
On Thu, 16 May 2013 09:44:49 -0400 Robert Love <rlove@google.com> wrote:
> On Thu, May 16, 2013 at 4:15 AM, Raul Xiong <raulxiong@gmail.com> wrote:
> > The issue happens in such sequence:
> > ashmem_mmap acquired ashmem_mutex --> ashmem_mutex:shmem_file_setup
> > called kmem_cache_alloc --> shrink due to low memory --> ashmem_shrink
> > tries to acquire the same ashmem_mutex -- it blocks here.
> >
> > I think this reports the bug clearly. Please have a look.
>
> There is no debate about the nature of the bug. Only the fix.
>
> My mutex_trylock patch fixes the problem. I prefer that solution.
>
> Andrew's suggestion of GFP_ATOMIC won't work as we'd have to propagate
> that down into shmem and elsewhere.
s/won't work/impractical/
A better approach would be to add a new __GFP_NOSHRINKERS, but it's all
variations on a theme.
> Using PF_MEMALLOC will work. You'd want to define something like:
>
> static int set_memalloc(void)
> {
> if (current->flags & PF_MEMALLOC)
> return 0;
> current->flags |= PF_MEMALLOC;
> return 1;
> }
>
> static void clear_memalloc(int memalloc)
> {
> if (memalloc)
> current->flags &= ~PF_MEMALLOC;
> }
>
> and then set/clear PF_MEMALLOC around every memory allocation and
> function that descends into a memory allocation. As said I prefer my
> solution but if someone wants to put together a patch with this
> approach, fine by me.
The mutex_trylock(ashmem_mutex) will actually have the best
performance, because it skips the least amount of memory reclaim
opportunities.
But it still sucks! The real problem is that there exists a lock
called "ashmem_mutex", taken by both the high-level mmap() and by the
low-level shrinker. And taken by everything else too! The ashmem
locking is pretty crude...
What is the mutex_lock() in ashmem_mmap() actually protecting? I don't
see much, apart from perhaps some incidental races around the contents
of the file's ashmem_area, and those could/should be protected by a
per-object lock, not a global one?
next prev parent reply other threads:[~2013-05-16 16:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-01 13:56 [PATCH -next] ashmem: Fix ashmem_shrink deadlock Robert Love
2013-05-01 15:54 ` David Rientjes
2013-05-02 18:22 ` David Rientjes
2013-05-02 20:39 ` Greg Kroah-Hartman
2013-05-07 20:52 ` Andrew Morton
2013-05-13 21:42 ` Greg Kroah-Hartman
2013-05-14 3:29 ` Neil Zhang
2013-05-14 3:37 ` Raul Xiong
2013-05-16 8:15 ` Raul Xiong
2013-05-16 13:44 ` Robert Love
2013-05-16 16:45 ` Andrew Morton [this message]
2013-05-16 17:08 ` Robert Love
2013-05-16 17:19 ` Andrew Morton
2013-05-16 17:28 ` Robert Love
2013-09-17 5:05 ` Raul Xiong
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=20130516094559.4d2c9212.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=anjanavk12@gmail.com \
--cc=bringert@google.com \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=glacier1980@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=raulxiong@gmail.com \
--cc=rlove@google.com \
--cc=shankoo77@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).