Received: by 10.213.65.68 with SMTP id h4csp940949imn; Thu, 22 Mar 2018 11:49:26 -0700 (PDT) X-Google-Smtp-Source: AG47ELu1+r00dPE8JMkbcnv0t3pNzzHZ2fRhLXYK6O4LQ7vfrDafrVIvBb/dkgXDa4p/1wTrcaCd X-Received: by 2002:a17:902:a610:: with SMTP id u16-v6mr25837657plq.293.1521744566175; Thu, 22 Mar 2018 11:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521744566; cv=none; d=google.com; s=arc-20160816; b=ARnnyi9+HD972yWZe2QdkVVJ6RGJkkxijC07ANPenLO8jbEjaj6pv85zeCjzu2leEw 1/eCkwIA5rZcA1UNUK4/tbZbobKs8uCARSXSYThkqFSH9D8e/RWnhkX7/r19H+g1udVN s8/e/OJ53tKyY8O2Qnsu8ZXd2NojMQSTJvFN3/FW3GlL6oo+UNEYzbhtjsWbAl4V5LjI EW1kYpQmSlyCQ5tePrROCr5GUibplWQs7E9qp3YhVJLEj+L1qWji7tMy0JGf4V6IAgnE HKtN7fzwhZrNmgYDX6WJEsEIubaRrWbMt743++DRaEfbYRuhK2s3u69xYA6LTEf6PSds r3+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=t0e+Lu2LWTZPSxVxVCXe1zqNOzKkRgvjHWVGMLjpA20=; b=Xut5gOrxxFKdu5B2X5XzhrevntP5RDV/P0/78EP4+4Ot0aKaAaCoQ/8I3kfjQfyKDI naxOoDYKjk+wTz/yAwKWPjL3etkyfrGZTK92oYl5ZZdyF9Wv9wB6J7bL/xLI3GF390xO BB48bGftIRG0rhsW3ccEYuC2HDJDpFF0ha/mbCRw9Jtb/F8wZPkRbreZDBbFh6lmo6g7 GEk7/XdXYPP8ysfLaoJF19EIMkAFF8oYJXwhbdcciKKU5bPkf9A2jIVr2LWdb4/HNo5w pkXE2mpsy+pVi9+JTSnv+b++Tz99sTRz39NhkfoNMymBEh3M2IzdeHhylae/ntNHuruG ANdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=VVdQMwEe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3-v6si6959079plb.593.2018.03.22.11.49.11; Thu, 22 Mar 2018 11:49:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=VVdQMwEe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751888AbeCVSsJ (ORCPT + 99 others); Thu, 22 Mar 2018 14:48:09 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:54620 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751609AbeCVSsI (ORCPT ); Thu, 22 Mar 2018 14:48:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=t0e+Lu2LWTZPSxVxVCXe1zqNOzKkRgvjHWVGMLjpA20=; b=VVdQMwEeURxdEIHMxX4ARCz3I 9Sx708834UwY6OcrFBS9O9IYGJlEYa1gaZCSFg1jTl4eDs1Y9Pl5cbAViNykWbtYqMc3tB5eu4fFs Ddt59KHJfsdn/AefAgZi+GNR0fg5fsEI/Bs/tyhjBNbqu2g/PUFWjQBx2yO0/Evpt6qtFpQu4t/1G OlYmm8wtQD9l7yzI6pJ6J/jY2Dmwi6mFUARPKnWmzsMPGBNaRRsLNQKZZEtCgXk7ScjNydZoi06c4 cQ3FthjkklW/n4mwhP/xJQf5ww2OAzt67F2B3yjIQGvnP8/lagQopuadnR4Q7DrVRJqw3GqbDdPQj /7byRiS6w==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1ez5Fu-00021L-2g; Thu, 22 Mar 2018 18:48:06 +0000 Date: Thu, 22 Mar 2018 11:48:05 -0700 From: Matthew Wilcox To: Yang Shi Cc: Michal Hocko , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/8] mm: mmap: unmap large mapping by section Message-ID: <20180322184805.GJ28468@bombadil.infradead.org> References: <1521581486-99134-1-git-send-email-yang.shi@linux.alibaba.com> <1521581486-99134-2-git-send-email-yang.shi@linux.alibaba.com> <20180321130833.GM23100@dhcp22.suse.cz> <20180321172932.GE4780@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 22, 2018 at 10:34:08AM -0700, Yang Shi wrote: > On 3/21/18 10:29 AM, Matthew Wilcox wrote: > > Take the mmap_sem for write > > Find the VMA > > If the VMA is large(*) > > Mark the VMA as deleted > > Drop the mmap_sem > > zap all of the entries > > Take the mmap_sem > > Else > > zap all of the entries > > Continue finding VMAs > > Drop the mmap_sem > > > > Now we need to change everywhere which looks up a VMA to see if it needs > > to care the the VMA is deleted (page faults, eg will need to SIGBUS; mmap > > does not care; munmap will need to wait for the existing munmap operation > > The other question is why munmap need wait? If the other parallel munmap > finds the vma has been marked as "deleted", it just need return 0 as it > doesn't find vma. > > Currently do_munmap() does the below logic: > vma = find_vma(mm, start); > if (!vma) > return 0; At the point a munmap() returns, the area should be available for reuse. If another thread is still unmapping, it won't actually be available yet. We should wait for the other thread to finish before returning. There may be some other corner cases; like what to do if there's a partial unmap of a VMA, or a MAP_FIXED over part of an existing VMA. It's going to be safer to just wait for any conflicts to die down. It's not like real programs call munmap() on conflicting areas at the same time.