From patchwork Wed Sep 19 17:03:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10606111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D9986CB for ; Wed, 19 Sep 2018 17:04:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F1A2BB51 for ; Wed, 19 Sep 2018 17:04:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D18B2BB1E; Wed, 19 Sep 2018 17:04:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 371A32B9F7 for ; Wed, 19 Sep 2018 17:04:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE23A8E0004; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E91C28E0001; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7FE48E0004; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 9B9B68E0001 for ; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id v9-v6so3066762pff.4 for ; Wed, 19 Sep 2018 10:04:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=qPNaq86h8ybepqRKMGj/SlFYr1hZJ82zLAVGKC7DASM=; b=alNKvEBy7r1vdH0SOGtFn6Cerff6jOLIEsvEjdhmjiWlJX5VCIqDTYhqVYFJLEZCyt 5fpPUjGilo8ptgE9gtHYqZpHWyBskLZUcnrcMljKg+0bA/uInNJrww62X5SZI7FxtnRn tgnJo1GBIDyzFSg2yQojKlf09ZUsSITmQicgKGUdmrDDXDEVjvVNEwblNUQGuex0xsC7 6MYtb5Ogqwnp3ED4DMIelxoIlqcdHTg9cDQ/JcFbcVPTs4i9y5DrHG730m3zr7tAPdkc ZrBNVz5upGWO/5F4S617MZ7dnlyb76C1eZOpvDw/JY04Am3bDvcNGrQ8X0Zoq3EeOrtd ONug== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APzg51BMHaJAoM4p0yuh0pqEGDoIbAR6NDbzBxNhWeqst06zXvnxmH0k ewWacTGv+uRaCVtdjR3I9NqOjxhdeFRbF5HT/1hewuM4neMjT6eMa91R3awTL+ASR6/T+ldLRwh TfczWQEfrWTFpBWaZFzJkIiicgVjLljNQK25qFXZoMIMY2L9kz4kEEQoj6TXVpJaI6A== X-Received: by 2002:a17:902:598d:: with SMTP id p13-v6mr34891922pli.171.1537376651249; Wed, 19 Sep 2018 10:04:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbY+PNHrU+ohu7gEGFffqhb6j14xu6dN9JKgAmGNXTD6pGlGermgELCj67wE3sOpAmrI6uM X-Received: by 2002:a17:902:598d:: with SMTP id p13-v6mr34891843pli.171.1537376649866; Wed, 19 Sep 2018 10:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537376649; cv=none; d=google.com; s=arc-20160816; b=Yf+52lpP8ilKTBWNrwIi1b0VkgkfdXzmSmT/uklX14Ujh3LdZXAAm5Fb+jMWfe9DqS gBmtNCjxaU7oJSYQBUx1L4vysATHVvdAhM+sNqvPxzBDe9kRYX565iNf74AFDN7TrVja ki6t4Gj4WODqJWRVpgPPuuN8rBLdeECDkGp3hoCnr+t5lZV9qJSu5NxLwWZxDyMqq0NE U/9SvikV4i7IqNHEkMaMXW0mptrqvd12EhUr54oX1uVUtt2+G//pYwJ4E8Mrc24crArT k2YjDmXlh55TeRFuiWRZVyWEH5xCqBuE9AulHZCfPivPawtIWasgA/32bz+7y3M/5qIt WCAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=qPNaq86h8ybepqRKMGj/SlFYr1hZJ82zLAVGKC7DASM=; b=flQd3BQh9E55lfNsfkJy0y3cBEQWY59h9eqokUsvQqWU4VQBTEfF0BK6KJUqDctIwv SrYuYrdgeOeXDA0ntm6v1/FQP+6XjdU8Ok/9PD36tZGTcRdTow/5WxR+qZmdvKeupmgH /ioJq4EK3q0JKAWfrqEK4jisbpmKe3S4snyrznCYtHWs5MzdKeqR0qfX3Bp14rU1OyHw TVT8vG9+tDnwobkKafp/ogTtjwmC6OOYoj6Z0lR1tbpzNu5RTzCBnYLNbneHs0mnYqRH sM2wfQU1dqGaLYVBSF8Vxn3iOQ06ysoJEZY9keDT0IwJBlUypF4gmBM0PpWUA66Et8Om ko0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com. [115.124.30.133]) by mx.google.com with ESMTPS id 5-v6si22253504plt.342.2018.09.19.10.04.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 10:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 as permitted sender) client-ip=115.124.30.133; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R301e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04455;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0T91h4Va_1537376628; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T91h4Va_1537376628) by smtp.aliyun-inc.com(127.0.0.1); Thu, 20 Sep 2018 01:03:55 +0800 From: Yang Shi To: mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, vbabka@suse.cz, kirill@shutemov.name, akpm@linux-foundation.org Cc: dave.hansen@intel.com, oleg@redhat.com, srikar@linux.vnet.ibm.com, yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v11 PATCH 1/3] mm: mmap: zap pages with read mmap_sem in munmap Date: Thu, 20 Sep 2018 01:03:39 +0800 Message-Id: <1537376621-51150-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537376621-51150-1-git-send-email-yang.shi@linux.alibaba.com> References: <1537376621-51150-1-git-send-email-yang.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When running some mmap/munmap scalability tests with large memory (i.e. > 300GB), the below hung task issue may happen occasionally. INFO: task ps:14018 blocked for more than 120 seconds. Tainted: G E 4.9.79-009.ali3000.alios7.x86_64 #1 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. ps D 0 14018 1 0x00000004 ffff885582f84000 ffff885e8682f000 ffff880972943000 ffff885ebf499bc0 ffff8828ee120000 ffffc900349bfca8 ffffffff817154d0 0000000000000040 00ffffff812f872a ffff885ebf499bc0 024000d000948300 ffff880972943000 Call Trace: [] ? __schedule+0x250/0x730 [] schedule+0x36/0x80 [] rwsem_down_read_failed+0xf0/0x150 [] call_rwsem_down_read_failed+0x18/0x30 [] down_read+0x20/0x40 [] proc_pid_cmdline_read+0xd9/0x4e0 [] ? do_filp_open+0xa5/0x100 [] __vfs_read+0x37/0x150 [] ? security_file_permission+0x9b/0xc0 [] vfs_read+0x96/0x130 [] SyS_read+0x55/0xc0 [] entry_SYSCALL_64_fastpath+0x1a/0xc5 It is because munmap holds mmap_sem exclusively from very beginning to all the way down to the end, and doesn't release it in the middle. When unmapping large mapping, it may take long time (take ~18 seconds to unmap 320GB mapping with every single page mapped on an idle machine). 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, 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) deal with special mappings detach vmas downgrade_write zap pages free page tables release mmap_sem The vm events with read mmap_sem may come in during page zapping, but since vmas have been detached before, they, i.e. page fault, gup, etc, will not be able to find valid vma, then just return SIGSEGV or -EFAULT as expected. If the vma has VM_HUGETLB | VM_PFNMAP, they are considered as special mappings. They will be handled by without downgrading mmap_sem in this patch since they may update vm flags. But, with the "detach vmas first" approach, the vmas have been detached when vm flags are updated, so it sounds safe to update vm flags with read mmap_sem for this specific case. So, VM_HUGETLB and VM_PFNMAP will be handled by using the optimized path in the following separate patches for bisectable sake. Unmapping uprobe areas may need update mm flags (MMF_RECALC_UPROBES). However it is fine to have false-positive MMF_RECALC_UPROBES according to uprobes developer. With the "detach vmas first" approach we don't have to re-acquire mmap_sem again to clean up vmas to avoid race window which might get the address space changed since downgrade_write() doesn't release the lock to lead regression, which simply downgrades to read lock. And, since the lock acquire/release cost is managed to the minimum and almost as same as before, the optimization could be extended to any size of mapping without incurring significant penalty to small mappings. For the time being, just do this in munmap syscall path. Other vm_munmap() or do_munmap() call sites (i.e mmap, mremap, etc) remain intact due to some implementation difficulties since they acquire write mmap_sem from very beginning and hold it until the end, do_munmap() might be called in the middle. But, the optimized do_munmap would like to be called without mmap_sem held so that we can do the optimization. So, if we want to do the similar optimization for mmap/mremap path, I'm afraid we would have to redesign them. mremap might be called on very large area depending on the usecases, the optimization to it will be considered in the future. With the patches, exclusive mmap_sem hold time when munmap a 80GB address space on a machine with 32 cores of E5-2680 @ 2.70GHz dropped to us level from second. munmap_test-15002 [008] 594.380138: funcgraph_entry: | __vm_munmap() { munmap_test-15002 [008] 594.380146: funcgraph_entry: !2485684 us | unmap_region(); munmap_test-15002 [008] 596.865836: funcgraph_exit: !2485692 us | } Here the excution time of unmap_region() is used to evaluate the time of holding read mmap_sem, then the remaining time is used with holding exclusive lock. [1] https://lwn.net/Articles/753269/ Suggested-by: Michal Hocko Suggested-by: Kirill A. Shutemov Suggested-by: Matthew Wilcox Reviewed-by: Matthew Wilcox Cc: Laurent Dufour Cc: Vlastimil Babka Cc: Andrew Morton Signed-off-by: Yang Shi Acked-by: Vlastimil Babka --- mm/mmap.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 5f2b2b1..982dd00 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2687,8 +2687,8 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma, * work. This now handles partial unmappings. * Jeremy Fitzhardinge */ -int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, - struct list_head *uf) +static int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len, + struct list_head *uf, bool downgrade) { unsigned long end; struct vm_area_struct *vma, *prev, *last; @@ -2770,25 +2770,47 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, mm->locked_vm -= vma_pages(tmp); munlock_vma_pages_all(tmp); } + + /* + * Unmapping vmas, which have VM_HUGETLB or VM_PFNMAP, + * need get done with write mmap_sem held since they may + * update vm_flags. + */ + if (downgrade && + (tmp->vm_flags & (VM_HUGETLB | VM_PFNMAP))) + downgrade = false; + tmp = tmp->vm_next; } } - /* - * Remove the vma's, and unmap the actual pages - */ + /* Detach vmas from rbtree */ detach_vmas_to_be_unmapped(mm, vma, prev, end); - unmap_region(mm, vma, prev, start, end); + /* + * mpx unmap needs to be called with mmap_sem held for write. + * It is safe to call it before unmap_region(). + */ arch_unmap(mm, vma, start, end); + if (downgrade) + downgrade_write(&mm->mmap_sem); + + unmap_region(mm, vma, prev, start, end); + /* Fix up all other VM information */ remove_vma_list(mm, vma); - return 0; + return downgrade ? 1 : 0; } -int vm_munmap(unsigned long start, size_t len) +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, + struct list_head *uf) +{ + return __do_munmap(mm, start, len, uf, false); +} + +static int __vm_munmap(unsigned long start, size_t len, bool downgrade) { int ret; struct mm_struct *mm = current->mm; @@ -2797,17 +2819,32 @@ int vm_munmap(unsigned long start, size_t len) if (down_write_killable(&mm->mmap_sem)) return -EINTR; - ret = do_munmap(mm, start, len, &uf); - up_write(&mm->mmap_sem); + ret = __do_munmap(mm, start, len, &uf, downgrade); + /* + * Returning 1 indicates mmap_sem is downgraded. + * But 1 is not legal return value of vm_munmap() and munmap(), reset + * it to 0 before return. + */ + if (ret == 1) { + up_read(&mm->mmap_sem); + ret = 0; + } else + up_write(&mm->mmap_sem); + userfaultfd_unmap_complete(mm, &uf); return ret; } + +int vm_munmap(unsigned long start, size_t len) +{ + return __vm_munmap(start, len, false); +} EXPORT_SYMBOL(vm_munmap); SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) { profile_munmap(addr); - return vm_munmap(addr, len); + return __vm_munmap(addr, len, true); } From patchwork Wed Sep 19 17:03:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10606107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5EC86CB for ; Wed, 19 Sep 2018 17:04:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C316D2B9F7 for ; Wed, 19 Sep 2018 17:04:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B72272BB1E; Wed, 19 Sep 2018 17:04:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD4852B9F7 for ; Wed, 19 Sep 2018 17:04:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82BD88E0003; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 801C78E0001; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 717558E0003; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 577178E0001 for ; Wed, 19 Sep 2018 13:04:11 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id d132-v6so2639189pgc.22 for ; Wed, 19 Sep 2018 10:04:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=xdnos7vRlVVKJr+Ky5LsaNLAjZ61PdbGqKs7xXS0Qa8=; b=E5UlpizN6LstGVwaBWFK+xUP9D/4UKiTUZC32viHOfZg+02FZkyausYiL/2KtwFuOW V62sNOj3m4QJvNpFK8Kb109uiEiiApUxn+ugAKMk0bo05hSo/DP2uTGKt1NVn2gsTv1Q HMST52soYdikETFS66sqlYw16qcFfiJtMuHQdP19TtcT6YvlwJiw6FmmtlpRu3tlU1O/ FKTYbPMj/+R62PwFBVS2dXpxd6uPehc45AR9ms2hntl7IJrH1AcxHei7Cp1P19DqkZUY 3a7xw8mpj6nMmY/WQGtan3pNmxxz7M6SIeNDMPVaubD3ML05z9AaIe9QgbiXtZzqgHb3 jU7w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APzg51BkNWatw8PnNA7ipWSqSr8BRgxU+iNrVJ9+9eACjjszfqtSH0Se 7YvWTfW7F318+nGqilZT+gSexWaZcU1mW5QRsiJP5PESD4aGIS5iLgJxHSlU5TI05RpXsif/RgP z+ltTruTOKC+9SGqqRTJNONN0iKmMYN8BQc9Fae4hFXhvvNV1/Kyyx67SeW4YIgm9yw== X-Received: by 2002:a63:e647:: with SMTP id p7-v6mr31980783pgj.218.1537376651047; Wed, 19 Sep 2018 10:04:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbRUkzM/s0cCBbMO660AvFfwrdyNuaYAjbAfZDmmfOBzoV8qWulOFx9UrMvFugufJE9vSm5 X-Received: by 2002:a63:e647:: with SMTP id p7-v6mr31980724pgj.218.1537376649806; Wed, 19 Sep 2018 10:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537376649; cv=none; d=google.com; s=arc-20160816; b=cF3sN5/HTTFx/WKT+J2pk1tUWtlX5SdF1UOWQyXyL55L+vbGVTSxV2fphJkO8o4brn a5VOGNi11gEJh6pcSH2tbZVrRBt0xkykQ0dQYBivkVQ6lGQ9KH55W2RolCxpJYz0HzaI X8c27mFouo72v9DSWle2vcGAaaGTjlI93XpFLRVcv86ZVzrTHaEfxFld7aq9d4soe3r2 buwfh1nqCDUOuaP+sIxSNLLyqHDIZev1z7XLjU1BLcE0Ul3ZrXr8Pw36efyKbpR54jaW FPfP+ro44dbU4bHyPnSkOXIoi+/NiDe+AbYSpFEILaBLkqVRD5Wg44M2tDVS9lt/n4jY IaoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=xdnos7vRlVVKJr+Ky5LsaNLAjZ61PdbGqKs7xXS0Qa8=; b=BA6tf+tQtIdwh6/BtjnnnvXGaiShtvqBh3POBMSj+RfaVl0fQxSef/rDIC8/DakWNI jSAjpZXJbqZpPg1ERtmAI43PmBCDgq1P0yqE0YTZcHOvte2hy3ioY17/46f8L5hErd2E iTIOJXjbggGHPRRwsadggOgQb4Yy0U+lMIbQ3IDnDt+YlHt6/nenJGX3keU9U4DG+SAQ yk4c9ka5XXCynTeuV3kbET2hHKJbFIVrHeT5Pv79uiQAd1zPCPGkUdSzOEQAJENgYYZF jpD4B85k99uCjMl2MR6XrGDUn8Cca21+eKsjh676doLGwvP2JFCzTDPP+S4C2njO29jV Fsvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com. [115.124.30.131]) by mx.google.com with ESMTPS id x3-v6si21452649pgo.542.2018.09.19.10.04.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 10:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.131 as permitted sender) client-ip=115.124.30.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07488;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0T91h4Va_1537376628; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T91h4Va_1537376628) by smtp.aliyun-inc.com(127.0.0.1); Thu, 20 Sep 2018 01:03:55 +0800 From: Yang Shi To: mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, vbabka@suse.cz, kirill@shutemov.name, akpm@linux-foundation.org Cc: dave.hansen@intel.com, oleg@redhat.com, srikar@linux.vnet.ibm.com, yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v11 PATCH 2/3] mm: unmap VM_HUGETLB mappings with optimized path Date: Thu, 20 Sep 2018 01:03:40 +0800 Message-Id: <1537376621-51150-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537376621-51150-1-git-send-email-yang.shi@linux.alibaba.com> References: <1537376621-51150-1-git-send-email-yang.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When unmapping VM_HUGETLB mappings, vm flags need to be updated. Since the vmas have been detached, so it sounds safe to update vm flags with read mmap_sem. Cc: Michal Hocko Cc: Vlastimil Babka Reviewed-by: Matthew Wilcox Signed-off-by: Yang Shi Acked-by: Vlastimil Babka --- mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index 982dd00..490340e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2777,7 +2777,7 @@ static int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len, * update vm_flags. */ if (downgrade && - (tmp->vm_flags & (VM_HUGETLB | VM_PFNMAP))) + (tmp->vm_flags & VM_PFNMAP)) downgrade = false; tmp = tmp->vm_next; From patchwork Wed Sep 19 17:03:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10606113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3914D6CB for ; Wed, 19 Sep 2018 17:05:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 255FC2BB51 for ; Wed, 19 Sep 2018 17:05:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19B2A2BBD5; Wed, 19 Sep 2018 17:05:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7D762BB51 for ; Wed, 19 Sep 2018 17:05:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCFE98E0006; Wed, 19 Sep 2018 13:05:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA6398E0001; Wed, 19 Sep 2018 13:05:24 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBD308E0006; Wed, 19 Sep 2018 13:05:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 8F9568E0001 for ; Wed, 19 Sep 2018 13:05:24 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id c5-v6so2795429plo.2 for ; Wed, 19 Sep 2018 10:05:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=2u/MD29Te+7XiVvlLdtEOudsBEpoda7U6+oRUts+HsE=; b=f/QIszqCdoTxNz37dR18Fv+q30SMh4rEM39+tZpZ2N2w+nz4jrGLRRdcH8Z/P9t78U a41d9P1amrotYr4fMq71xHp5FnyBGHDyw6mYK4QiMnOU96t504oF4ZPw6xMQEcHlqhAi Wsqg0TYTOPur9mwNecpsErQVOG4ogf1FwUAte58Pq3+IZ9Qs2eQU7buLqmMz6R4JPH9+ UGPvcfAAaEoQ3jBCoF8jlX9/gX3rb3kWenbCt1j6JUkq3yf2yWbDF7PfyaZGajbX4biD hjKEwsMhneNiqb1rXM4EFk9UW/1TSg9yoBYWwCbRxb44sebdY6bZgvok7glNsLMOfUJ1 aT4Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APzg51BAOVx4b68Xdibt8mmhp3peJ0B1YcagLfwRL5TOu41qTPzMrCal 7wdJPqrsJXzjoYnsyf39U5GxNUnzr8lfZF7BuoWyz4l39ZwYKbVmhb4xoQ/ac3TyF5xqa5wYcF2 eXY2Conbx/R8dp6eR4mym0EksWx6/5dIUoAqTrc8lD7wM/6BV5RPpfUD7DF+gUFQAKw== X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr33757871pgu.259.1537376724247; Wed, 19 Sep 2018 10:05:24 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda5Ht+1oMys2f/tK9O/VNjDGQcT6oRp7kiYBgOdwUGsE+ZTowl7bOCdO6mQB4gCc5OYIzm/ X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr33757812pgu.259.1537376723173; Wed, 19 Sep 2018 10:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537376723; cv=none; d=google.com; s=arc-20160816; b=gHkCSbTUTvjVR1s/NCxyrV4BXxNd43LoPfMMorom9/zw1IKF5QK1u0cwggu2Oc2ijY ALp+zDsZORs6HeyzXwVM8XuH4MQpp7Uw/ABvxoWC1B15nGKczQgOV62hKxMBKpq8E/2M lt+uHTulw1j+BuQZ2xMOmx2f1Lzh+uUYKt2vfPuti20Odr96o8NAuo5DcTxjzCs2hiJN HdBsQ/s/+DxkD8RK6qkhfWniW4m7fCKTDSe8CdizHnspO/ZAN0XZtOSXB7qy8/s9vPng pW9Ek3NiKuevIq2YScAMidqch7P9IADFScIWyY/vWgFxZjm7RIUdrINgKkGHZ7gok88C vBEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=2u/MD29Te+7XiVvlLdtEOudsBEpoda7U6+oRUts+HsE=; b=YgTawc2Tb551CA9VBpao4+SBhMTLJXAzqUuJRsNYzX+zOgJyJy0jzT5g6BYx/ZyKmO kg/oA5ddgr70BHy+eUzSBDrE5VpKwulk30f3yzgqmg8h3mHSTDESZLsFWA2BXKu1qPtt HPDAEMcvWZB7cthNnxQtX+s8s2ZD8dUaagYbDw7BRmE+QPdfFCHdyXK3Mla/oecq2Pkb NQjpB9oaN+FHy5f+r40RR94FXP6Jk/ks6CJqECAVNAF9DCXhZbzmBVoiW8uucZp5FMYT etHdTBso12yzJDdhZex+sWBWRgSZoPDZT72++2B1Md4Z8JeYdHhHnKN2V5i1eV+TAPlJ NE5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id 59-v6si20957573plp.87.2018.09.19.10.05.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 10:05:23 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0T91h4Va_1537376628; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T91h4Va_1537376628) by smtp.aliyun-inc.com(127.0.0.1); Thu, 20 Sep 2018 01:03:55 +0800 From: Yang Shi To: mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, vbabka@suse.cz, kirill@shutemov.name, akpm@linux-foundation.org Cc: dave.hansen@intel.com, oleg@redhat.com, srikar@linux.vnet.ibm.com, yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v11 PATCH 3/3] mm: unmap VM_PFNMAP mappings with optimized path Date: Thu, 20 Sep 2018 01:03:41 +0800 Message-Id: <1537376621-51150-4-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537376621-51150-1-git-send-email-yang.shi@linux.alibaba.com> References: <1537376621-51150-1-git-send-email-yang.shi@linux.alibaba.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When unmapping VM_PFNMAP mappings, vm flags need to be updated. Since the vmas have been detached, so it sounds safe to update vm flags with read mmap_sem. Cc: Michal Hocko Cc: Vlastimil Babka Reviewed-by: Matthew Wilcox Signed-off-by: Yang Shi Acked-by: Vlastimil Babka --- mm/mmap.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 490340e..847a17d 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2771,15 +2771,6 @@ static int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len, munlock_vma_pages_all(tmp); } - /* - * Unmapping vmas, which have VM_HUGETLB or VM_PFNMAP, - * need get done with write mmap_sem held since they may - * update vm_flags. - */ - if (downgrade && - (tmp->vm_flags & VM_PFNMAP)) - downgrade = false; - tmp = tmp->vm_next; } }