Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp197212imm; Tue, 9 Oct 2018 16:24:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV61pXTKe9FkuTYaz0VhpIZHTG3hLh81DRMjsj91ygWNRoIk3u+Q5pOf3iD1QCD+/BET1QU4x X-Received: by 2002:a17:902:6ac4:: with SMTP id i4-v6mr30498542plt.153.1539127459277; Tue, 09 Oct 2018 16:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539127459; cv=none; d=google.com; s=arc-20160816; b=KmmoMmRgYIOw0tUvIqLD1I3e371HcKyayaYhz4tmllBv+hcxzthftgR+VG+idzalgj LNZCxiiZx0pjLoYTmBTdX9391fIxoFjfJSnRqBIacOowH2XtRgGi7TL+30zJKE/wQCUy CyHV9FgZfvG6z7g0mmFQvqccCFyenwwx81M4nODAXp3Bo4aWNvP/2cUi7FCvHNwCMQMl cafFMfa4PXCUdkxXli+XemtlWaCwdabw92kpAmCzwg1O/V/p/4wNqu1dx4YOKqQiQ2nz BTLPFJS7eYgOK2cIsyxFII4hdmNcb4mtx+6iOqD3jXXtpAZYuvwim2zk/slSuqny6cSQ 6zrw== 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; bh=ULY//GBZvi+f3kccvWtwKU1JAZlRFthAzqXIIT6GbOU=; b=iwK99eBAOvf3bQntsHv6t+DLZ6ld73j/23YbVAGL4mFuAQotXRBm78S+ItLNI1xGDO 4VR7M1tiCNDio8WjAJCosI6eUx/B2JxznUkIEuC35CCsSNiWltDk43xTVnBEX2u1cZWN adbzQ9dslBffTLX3crbqxTYj/yWzUcclIotm4zHCvTTVcI/eHdpD174DWoJEzTiktyu4 wbfqqLBaapHokAzRyLKVWE0R++/w3rq+wcFrjDN2orAwlBGENu3Uyu+mWZt08ttdClKo 0RHUjNng3vRwXD2WeYFDbH2tSyRY6ytz2H86MtfBK8xtnkNA8s5eYsEgos2EpwjGPGkn Q4Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=nifWcTpg; 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 3-v6si21843411plo.318.2018.10.09.16.24.04; Tue, 09 Oct 2018 16:24:19 -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=pass header.i=@joelfernandes.org header.s=google header.b=nifWcTpg; 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 S1726668AbeJJG1r (ORCPT + 99 others); Wed, 10 Oct 2018 02:27:47 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38427 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725748AbeJJG1q (ORCPT ); Wed, 10 Oct 2018 02:27:46 -0400 Received: by mail-pl1-f195.google.com with SMTP id b5-v6so1553669plr.5 for ; Tue, 09 Oct 2018 16:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ULY//GBZvi+f3kccvWtwKU1JAZlRFthAzqXIIT6GbOU=; b=nifWcTpgOCqb7M+dEVVMxs6w4vV69BB/kshkK+Og/jHKLgtQUvlHB381+iuJWyv4zu isNTo34VzvYbiE1mze2Dc5hfMYu4dYVj/2dfNPzoXnPl0UYLZ3nh9Aq9qZ7+cZiHCuOd MrOQcAcIsFRyM7bPx5HarB13VBIBgns/b3iA4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ULY//GBZvi+f3kccvWtwKU1JAZlRFthAzqXIIT6GbOU=; b=H/cXn/+HVslhEIspNgdWMh2lhLgM4UrULhfTxH5uCYA8cJpAj/lRv5GbJYD/kEXIt8 UyzGLcd6dSJSnVGnklyJaFx/aDktoPd4K9UxZD4RgFqmeYwJKzhTgYcUe4+jku1f/T0u RdUMC4NBVTyYii26Luy2NJd3tqU9qX59yF5Vk/i3vNzbMxH6uP4h1ZlsQ0OIAzeUKRZJ do+jdV3V6shPyDajKTwoLylpumeFR5snKVAC20IxtkbQ5z+s/hUFBLjm64p+1j4sWfWZ ztv5jT+hIQB7b5bfx/5c+XZjp9J5Vs2pxO5i6cuDTLLJttpp60t7hKRepNyXOheumBzo mYUQ== X-Gm-Message-State: ABuFfohbbcUU+NDaIPPiiSpJ+fugGV16HfCe/98A2CcK58z68Yu67Ti5 ZRv3KZ4aZBiAAqxYoD4FNao9kg== X-Received: by 2002:a17:902:bb08:: with SMTP id l8-v6mr29701939pls.252.1539126510940; Tue, 09 Oct 2018 16:08:30 -0700 (PDT) Received: from localhost ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id u62-v6sm28489522pfu.69.2018.10.09.16.08.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Oct 2018 16:08:29 -0700 (PDT) Date: Tue, 9 Oct 2018 16:08:28 -0700 From: Joel Fernandes To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, minchan@google.com, hughd@google.com, lokeshgidra@google.com, Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Thomas Gleixner Subject: Re: [PATCH] mm: Speed up mremap on large regions Message-ID: <20181009230828.GB17911@joelaf.mtv.corp.google.com> References: <20181009201400.168705-1-joel@joelfernandes.org> <20181009143859.8b9a700b1caf4e8d1e33a723@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181009143859.8b9a700b1caf4e8d1e33a723@linux-foundation.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 09, 2018 at 02:38:59PM -0700, Andrew Morton wrote: > On Tue, 9 Oct 2018 13:14:00 -0700 "Joel Fernandes (Google)" wrote: > > > Android needs to mremap large regions of memory during memory management > > related operations. The mremap system call can be really slow if THP is > > not enabled. The bottleneck is move_page_tables, which is copying each > > pte at a time, and can be really slow across a large map. Turning on THP > > may not be a viable option, and is not for us. This patch speeds up the > > performance for non-THP system by copying at the PMD level when possible. > > > > The speed up is three orders of magnitude. On a 1GB mremap, the mremap > > completion times drops from 160-250 millesconds to 380-400 microseconds. > > > > Before: > > Total mremap time for 1GB data: 242321014 nanoseconds. > > Total mremap time for 1GB data: 196842467 nanoseconds. > > Total mremap time for 1GB data: 167051162 nanoseconds. > > > > After: > > Total mremap time for 1GB data: 385781 nanoseconds. > > Total mremap time for 1GB data: 388959 nanoseconds. > > Total mremap time for 1GB data: 402813 nanoseconds. > > > > Incase THP is enabled, the optimization is skipped. I also flush the > > tlb every time we do this optimization since I couldn't find a way to > > determine if the low-level PTEs are dirty. It is seen that the cost of > > doing so is not much compared the improvement, on both x86-64 and arm64. > > Looks tasty. Thanks :) > > --- a/mm/mremap.c > > +++ b/mm/mremap.c > > @@ -191,6 +191,54 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, > > drop_rmap_locks(vma); > > } > > > > +bool move_normal_pmd(struct vm_area_struct *vma, unsigned long old_addr, > > I'll park this for now, shall plan to add a `static' in there then > merge it up after 4.20-rc1. Thanks, I will also add static to the function in my own tree just for the future in case I'm doing another revision. - Joel