From: Michal Hocko <mhocko@kernel.org>
To: Yang Shi <yang.shi@linux.alibaba.com>
Cc: willy@infradead.org, ldufour@linux.vnet.ibm.com,
kirill@shutemov.name, akpm@linux-foundation.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC v4 0/3] mm: zap pages with read mmap_sem in munmap for large mapping
Date: Wed, 11 Jul 2018 12:33:12 +0200 [thread overview]
Message-ID: <20180711103312.GH20050@dhcp22.suse.cz> (raw)
In-Reply-To: <1531265649-93433-1-git-send-email-yang.shi@linux.alibaba.com>
On Wed 11-07-18 07:34:06, Yang Shi wrote:
>
> Background:
> Recently, when we ran some vm scalability tests on machines with large memory,
> we ran into a couple of mmap_sem scalability issues when unmapping large memory
> space, please refer to https://lkml.org/lkml/2017/12/14/733 and
> https://lkml.org/lkml/2018/2/20/576.
>
>
> History:
> Then akpm suggested to unmap large mapping section by section and drop mmap_sem
> at a time to mitigate it (see https://lkml.org/lkml/2018/3/6/784).
>
> V1 patch series was submitted to the mailing list per Andrew's suggestion
> (see https://lkml.org/lkml/2018/3/20/786). Then I received a lot great feedback
> and suggestions.
>
> Then this topic was discussed on LSFMM summit 2018. In the summit, Michal Hocko
> suggested (also in the v1 patches review) to try "two phases" approach. Zapping
> pages with read mmap_sem, then doing via cleanup with write mmap_sem (for
> discussion detail, see https://lwn.net/Articles/753269/)
>
>
> Approach:
> Zapping pages is the most time consuming part, according to the suggestion from
> Michal Hocko [1], zapping pages can be done with holding read mmap_sem, like
> what MADV_DONTNEED does. Then re-acquire write mmap_sem to cleanup vmas.
>
> But, we can't call MADV_DONTNEED directly, since there are two major drawbacks:
> * The unexpected state from PF if it wins the race in the middle of munmap.
> It may return zero page, instead of the content or SIGSEGV.
> * Cana??t handle VM_LOCKED | VM_HUGETLB | VM_PFNMAP and uprobe mappings, which
> is a showstopper from akpm
I do not really understand why this is a showstopper. This is a mere
optimization. VM_LOCKED ranges are usually not that large. VM_HUGETLB
can be quite large alright but this should be doable on top. Is there
any reason to block any "cover most mappings first" patch?
> And, some part may need write mmap_sem, for example, vma splitting. So, the
> design is as follows:
> acquire write mmap_sem
> lookup vmas (find and split vmas)
> set VM_DEAD flags
> deal with special mappings
> downgrade_write
>
> zap pages
> release mmap_sem
>
> retake mmap_sem exclusively
> cleanup vmas
> release mmap_sem
Please explain why dropping the lock and then ratake it to cleanup vmas
is OK. This is really important because parallel thread could have
changed the underlying address space range.
Moreover
> include/linux/mm.h | 8 +++
> include/linux/oom.h | 20 -------
> mm/huge_memory.c | 4 +-
> mm/hugetlb.c | 5 ++
> mm/memory.c | 57 ++++++++++++++++---
> mm/mmap.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
> mm/shmem.c | 9 ++-
> 7 files changed, 255 insertions(+), 69 deletions(-)
this is not a small change for something that could be achieved
from the userspace trivially (just call madvise before munmap - library
can hide this). Most workloads will even not care about races because
they simply do not play tricks with mmaps and userspace MM. So why do we
want to put the additional complexity into the kernel?
Note that I am _not_ saying this is a wrong idea, we just need some
pretty sounds arguments to justify the additional complexity which is
mostly based on our fear that somebody might be doing something
(half)insane or dubious at best.
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2018-07-11 10:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-10 23:34 [RFC v4 0/3] mm: zap pages with read mmap_sem in munmap for large mapping Yang Shi
2018-07-10 23:34 ` [RFC v4 PATCH 1/3] mm: introduce VM_DEAD flag and extend check_stable_address_space to check it Yang Shi
2018-07-10 23:34 ` [RFC v4 PATCH 2/3] mm: refactor do_munmap() to extract the common part Yang Shi
2018-07-10 23:34 ` [RFC v4 PATCH 3/3] mm: mmap: zap pages with read mmap_sem for large mapping Yang Shi
2018-07-11 10:33 ` Michal Hocko [this message]
2018-07-11 11:13 ` [RFC v4 0/3] mm: zap pages with read mmap_sem in munmap " Kirill A. Shutemov
2018-07-11 11:53 ` Michal Hocko
2018-07-11 17:08 ` Yang Shi
2018-07-11 16:57 ` Yang Shi
2018-07-11 22:49 ` Andrew Morton
2018-07-12 8:15 ` Michal Hocko
2018-07-11 11:10 ` Kirill A. Shutemov
2018-07-11 11:58 ` Michal Hocko
2018-07-11 17:04 ` Yang Shi
2018-07-12 8:04 ` Michal Hocko
2018-07-12 23:45 ` Yang Shi
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=20180711103312.GH20050@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=kirill@shutemov.name \
--cc=ldufour@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
--cc=yang.shi@linux.alibaba.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).