From patchwork Wed Jul 25 15:52:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10544241 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 A1C401822 for ; Wed, 25 Jul 2018 15:53:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 917222A5C1 for ; Wed, 25 Jul 2018 15:53:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FE702A65B; Wed, 25 Jul 2018 15:53:01 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE 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 401BD2A5C1 for ; Wed, 25 Jul 2018 15:53:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 190FB6B0287; Wed, 25 Jul 2018 11:53:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 141996B028B; Wed, 25 Jul 2018 11:53:00 -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 057806B028C; Wed, 25 Jul 2018 11:53:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id B4CD66B0287 for ; Wed, 25 Jul 2018 11:52:59 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id u16-v6so1000674pfm.15 for ; Wed, 25 Jul 2018 08:52:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=K/wRWZpM/AGbkrzMDg7aU9hs152pni5PDFBMxhN+AjM=; b=X7nFxPakV9eJMmFwhW8CyZ6V43ajJdua8+kKB37DM0pRU8k8xg5AAxflCTGLWkHG60 vUpdql3UhaHz7F6CSKcHhtaUd+FWbsZiNG0xKklNauVNbqY5BrP2zJj+GiHZzOQeftef h9cU4LXVbPVqg426k72rLHqweCPXf8tACD7S4wMR7hJ7pIJ5368lIQuHdeRcXmkKgIaU i4yAwtC/zvD2rxUF2fjEiYEgy6rwNxM+dIH4+LKsluyNO8Soaqp5Ud0qYz8L6eYc7And /OYRqsL5J2nNodEdQFYqXWCXYixXTVLP7EWmTic5xLVo5fDwkEq36GdvksCC4Ken9ueO 9RwQ== X-Gm-Message-State: AOUpUlFKy3aBqA/6n1uQIOpcaYj3Wg/7jv8EPrL5+sERK74m8zK5eha2 7r1eO1JdvETPfBGqcsRpwq8LIlM0Zy5JpjIjuYgaUlts0dEKdhjYiw6sy5edixdA3vNMItqFvdl OFHunAaFx3hzmCkAZappKLLbuZhOpElUGIuR2eZBeso4uLtTWxpac6bG0MuItFZ8C2eEgv9KVxf crgcvzW/ViEU0d8UpqOs3tOYeY/qPsWmwXy6dQQrrWK9rxBD43vwjWa06NVpQ1n7K7jg7yviCud /f0cOaEWDrteUnJR/JsHrukUy9EmbId4CVEK9traC+CRa/29a06kcPwZ+nnvf7xnBmb/t9S+yfh Ltn/v1cdc1YzWXE9vn7BH8oCufbjXyWaRsewBGRB6rEtCi7OSupIe7CdBLQVsXI+l++3XAnVc6C X X-Received: by 2002:a17:902:b40c:: with SMTP id x12-v6mr21911272plr.163.1532533979435; Wed, 25 Jul 2018 08:52:59 -0700 (PDT) X-Received: by 2002:a17:902:b40c:: with SMTP id x12-v6mr21911242plr.163.1532533978792; Wed, 25 Jul 2018 08:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532533978; cv=none; d=google.com; s=arc-20160816; b=mYEthgNJYj60lMU5ERDiYO+//t2jFilukiG92i/RiBHoQ9kuBiEeR8QGRe9+6H5KdD 2EggyIuusTTu4U1u4Xs9glEWZ/a0TtxwIzO6hOlfgtH2ejdkx1JimTd7LDUIj/hKxb3Q FlXRBo+WYiUjbFOHoAWlQ0qoV1R0rDHdO6onUrhTa0eyEjQU+iEheRoohXt1iF7tVOFb wRmVeotTMiqVLcAp4MwqiQ7UXHyoLgqjBOcpgYb8B81bR6/2Ly1fAnDoXwj6anwaousQ ln/qBj7AxNQFLrAmSnzQNGzgE3y9xTXqTQ54rsFYGRBL7T1609wxOMn3wsJIOpJ0a4Rg 1hVA== 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 :dkim-signature:arc-authentication-results; bh=K/wRWZpM/AGbkrzMDg7aU9hs152pni5PDFBMxhN+AjM=; b=hGFf0cQWPCd2dogSceQktx18QM3UQ4bjRKCtp4jtUkZzPTMuKfCD2QsLRj1FMdaYtY P/DRCTSgxXSp8rOE3rALgdyB8h9+g5E7kqs0YE5Phr04yoGlWX+A5YHA16IUn1ju11vv 6RLYpaNmm3/BvsQBl+VNaR6G61aWvtSqBcb433VWI/6YbQ4L7ToByCDStxVCWbkRSe4W ETFqKulxsNx6R1PR1RyBUA0qdt167b/vsMUoqkWOegfg9KsYfeFbmrYf98cluSYhDsw4 jBM+vstiXLhhunDrp6aEBFyG+VZN5fwpRhH6WiRsVLznmNzu1BjOf/c30JffrQKPV60+ xbxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ma8z2A/j"; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m125-v6sor4033155pgm.6.2018.07.25.08.52.58 for (Google Transport Security); Wed, 25 Jul 2018 08:52:58 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ma8z2A/j"; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K/wRWZpM/AGbkrzMDg7aU9hs152pni5PDFBMxhN+AjM=; b=ma8z2A/jxCaq6DwkQd+T6yi1HYjCEMWw04jtBYac+r+9P+XWO3u0CcZH6C/HHdNfdL EXfbmyrrmjcCC5dX2uTLmNXwo5NgzqVs+mgr2kbUamSCp+uj+bdE+Kbi3sRdDobhk2zz 9qEIUbu1Ga5Vou4YrU6yoQ3g8LZHqbuJMtiSsXrsw2LfBDuHnWLebxxwjz75wpRXY6VI l00aTzzGomupAFS9R6//RWoThsOfPEJ7GC1xJ6imm2NMev6EVhJFABHGbiWB3ER9DftY LEtDiwyD7NTy3V1CSlxlA5aeMDFcy2Kio0wihJMXi4QDYConhfCl4Ga+fHOSTgGmhUuU WJdg== X-Google-Smtp-Source: AAOMgpdWBIwJmQ1fXACJaTG3kCLAXCXzsiKVtGTzpi2ABhQFW42EOk+OCDOD9R0JjB81aE7aQ2/mYg== X-Received: by 2002:a63:555:: with SMTP id 82-v6mr21394995pgf.25.1532533978421; Wed, 25 Jul 2018 08:52:58 -0700 (PDT) Received: from roar.au.ibm.com ([61.69.188.107]) by smtp.gmail.com with ESMTPSA id j72-v6sm23438315pge.19.2018.07.25.08.52.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 08:52:57 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org Subject: [RFC PATCH 1/4] mm: munmap optimise single threaded page freeing Date: Thu, 26 Jul 2018 01:52:43 +1000 Message-Id: <20180725155246.1085-2-npiggin@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180725155246.1085-1-npiggin@gmail.com> References: <20180725155246.1085-1-npiggin@gmail.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 In case a single threaded process is zapping its own mappings, there should be no concurrent memory accesses through the TLBs, and so it is safe to free pages immediately rather than batch them up. --- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 135d18b31e44..773d588b371d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -296,6 +296,15 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_ VM_BUG_ON(!tlb->end); VM_WARN_ON(tlb->page_size != page_size); + /* + * When this is our mm and there are no other users, there can not be + * a concurrent memory access. + */ + if (current->mm == tlb->mm && atomic_read(&tlb->mm->mm_users) < 2) { + free_page_and_swap_cache(page); + return false; + } + batch = tlb->active; /* * Add the page and check if we are full. If so