From: Andrew Morton <akpm@linux-foundation.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Sasha Levin <sasha.levin@oracle.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@redhat.com>,
joern@logfs.org, Michel Lespinasse <walken@google.com>,
stable@kernel.org
Subject: Re: [PATCH 2/3] mm: munlock: fix deadlock in __munlock_pagevec()
Date: Mon, 16 Dec 2013 16:31:20 -0800 [thread overview]
Message-ID: <20131216163120.28218456e2c870c4c1bfce1e@linux-foundation.org> (raw)
In-Reply-To: <1387188856-21027-3-git-send-email-vbabka@suse.cz>
On Mon, 16 Dec 2013 11:14:15 +0100 Vlastimil Babka <vbabka@suse.cz> wrote:
> Commit 7225522bb ("mm: munlock: batch non-THP page isolation and
> munlock+putback using pagevec" introduced __munlock_pagevec() to speed up
> munlock by holding lru_lock over multiple isolated pages. Pages that fail to
> be isolated are put_back() immediately, also within the lock.
>
> This can lead to deadlock when __munlock_pagevec() becomes the holder of the
> last page pin and put_back() leads to __page_cache_release() which also locks
> lru_lock. The deadlock has been observed by Sasha Levin using trinity.
>
> This patch avoids the deadlock by deferring put_back() operations until
> lru_lock is released. Another pagevec (which is also used by later phases
> of the function is reused to gather the pages for put_back() operation.
>
> ...
>
Thanks for fixing this one. I'll cross it off the rather large list of
recent MM regressions :(
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -295,10 +295,12 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone)
> {
> int i;
> int nr = pagevec_count(pvec);
> - int delta_munlocked = -nr;
> + int delta_munlocked;
> struct pagevec pvec_putback;
> int pgrescued = 0;
>
> + pagevec_init(&pvec_putback, 0);
> +
> /* Phase 1: page isolation */
> spin_lock_irq(&zone->lru_lock);
> for (i = 0; i < nr; i++) {
> @@ -327,16 +329,22 @@ skip_munlock:
> /*
> * We won't be munlocking this page in the next phase
> * but we still need to release the follow_page_mask()
> - * pin.
> + * pin. We cannot do it under lru_lock however. If it's
> + * the last pin, __page_cache_release would deadlock.
> */
> + pagevec_add(&pvec_putback, pvec->pages[i]);
> pvec->pages[i] = NULL;
> - put_page(page);
> - delta_munlocked++;
> }
> }
> + delta_munlocked = -nr + pagevec_count(&pvec_putback);
> __mod_zone_page_state(zone, NR_MLOCK, delta_munlocked);
> spin_unlock_irq(&zone->lru_lock);
>
> + /* Now we can release pins of pages that we are not munlocking */
> + for (i = 0; i < pagevec_count(&pvec_putback); i++) {
> + put_page(pvec_putback.pages[i]);
> + }
> +
We could just do
--- a/mm/mlock.c~mm-munlock-fix-deadlock-in-__munlock_pagevec-fix
+++ a/mm/mlock.c
@@ -341,12 +341,9 @@ skip_munlock:
spin_unlock_irq(&zone->lru_lock);
/* Now we can release pins of pages that we are not munlocking */
- for (i = 0; i < pagevec_count(&pvec_putback); i++) {
- put_page(pvec_putback.pages[i]);
- }
+ pagevec_release(&pvec_putback);
/* Phase 2: page munlock */
- pagevec_init(&pvec_putback, 0);
for (i = 0; i < nr; i++) {
struct page *page = pvec->pages[i];
The lru_add_drain() is unnecessary overhead here. What do you think?
--
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:[~2013-12-17 0:31 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-08 1:52 kernel BUG in munlock_vma_pages_range Sasha Levin
2013-12-09 9:34 ` Vlastimil Babka
2013-12-09 17:05 ` Sasha Levin
2013-12-09 17:12 ` Vlastimil Babka
2013-12-09 17:15 ` Sasha Levin
2013-12-09 20:26 ` Sasha Levin
2013-12-11 22:59 ` Vlastimil Babka
2013-12-12 3:16 ` Sasha Levin
2013-12-12 5:03 ` Bob Liu
2013-12-12 12:41 ` Vlastimil Babka
2013-12-12 21:05 ` Sasha Levin
2013-12-13 8:49 ` Bob Liu
2013-12-13 9:08 ` Vlastimil Babka
2013-12-15 19:49 ` Sasha Levin
2013-12-16 10:14 ` [PATCH 0/3] Fix bugs in munlock Vlastimil Babka
2013-12-16 10:14 ` [PATCH 1/3] mm: munlock: fix a bug where THP tail page is encountered Vlastimil Babka
2013-12-17 1:26 ` Bob Liu
2013-12-17 13:00 ` Vlastimil Babka
2013-12-18 0:48 ` Bob Liu
2014-03-14 23:55 ` Sasha Levin
2014-03-15 3:06 ` Sasha Levin
2014-03-17 12:38 ` Vlastimil Babka
2014-03-17 21:08 ` Sasha Levin
2014-03-17 22:20 ` Vlastimil Babka
2014-03-17 22:58 ` Sasha Levin
2014-03-17 23:30 ` Vlastimil Babka
2014-03-18 10:41 ` Vlastimil Babka
2013-12-16 10:14 ` [PATCH 2/3] mm: munlock: fix deadlock in __munlock_pagevec() Vlastimil Babka
2013-12-17 0:31 ` Andrew Morton [this message]
2013-12-17 13:08 ` Vlastimil Babka
2013-12-16 10:14 ` [RFC PATCH 3/3] mm: munlock: fix potential race with THP page split Vlastimil Babka
2014-03-21 1:53 ` kernel BUG in munlock_vma_pages_range Sasha Levin
2014-03-21 9:02 ` Vlastimil Babka
2013-12-09 21:16 ` Jiri Kosina
2013-12-11 15:55 ` Sasha Levin
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=20131216163120.28218456e2c870c4c1bfce1e@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=joern@logfs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=riel@redhat.com \
--cc=sasha.levin@oracle.com \
--cc=stable@kernel.org \
--cc=vbabka@suse.cz \
--cc=walken@google.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