Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp182956imm; Tue, 9 Oct 2018 16:06:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV62UsxV59WuL90ElD2aAKOMdz7og1tg81wHIBYPV1oRrEBx8tUyjSBgoI+dk1AE9r6gBPiJj X-Received: by 2002:a63:dd58:: with SMTP id g24-v6mr26868409pgj.86.1539126410903; Tue, 09 Oct 2018 16:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539126410; cv=none; d=google.com; s=arc-20160816; b=gPQEc9OS8ArllS7xl/EvIO4bP4JrxEBa8kzWDvZcf1uXPPLp6tUI1PrcMG9PZOBeGO OT5OWTpy3umTEoj598T9f8M6n4LCj4k1W7CdOtGLECeiLTDjvQmaOirjm19PY5tN0OVl 7XGpwufklv2b5g03aiEgJWMX4ppAfqt1d+HQJ0HEdnwC4eNZ9qhBNfkVeDNpFLSbP90y lwkV0WztNRm2YKMlQhlKD0yl/R65rAfAAztyiT7T7zUINVMVRPqfFnfbOCmy8knlR/lg HKSsCggX3TkSRT8IAFAW55A+ai862tQJwnj4HMtip4NVY7oNN0V9hoT+E13lE/C/cwR+ kPDA== 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=FewfyTptfb0s5WSxMs5n7Qg+lzyT+gQ20EJBgZ1FVkE=; b=FTuDX3fiACF9rpp7mXXhMHD0zciVNCaxixpYi7JSBdvFS+yqm9RTSEKArtQc7ybrX2 QqX+7009cl8ftlRLyV+dvdP7HSrQVfhoktVwJaUiipzcpCO/1J3feXQ5hEbpD8YZJ47M 8gaiJHSAY2fvW7wWmugDHcF6sj6d36CCLMvWiX6MrVNHBTeWWbEPoYRKWuXJbJvh9xSO oYonvW1VOvKTUnAqd/N1qOVJF7JooRHlGSvffMzaLok8a+b1LDX7rrDwteSZHhM2CAWN eTvSGkZsw0bxeUL4NzGzsC2EwGgY6zsWuPk7pTDohpNjh8JVOaQQpUIdGMOeMEGbftYy RWEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=G8cCCh5h; 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 u27-v6si23227699pfk.82.2018.10.09.16.06.35; Tue, 09 Oct 2018 16:06:50 -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=G8cCCh5h; 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 S1726794AbeJJGYG (ORCPT + 99 others); Wed, 10 Oct 2018 02:24:06 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41790 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725827AbeJJGYF (ORCPT ); Wed, 10 Oct 2018 02:24:05 -0400 Received: by mail-pf1-f193.google.com with SMTP id m77-v6so1600051pfi.8 for ; Tue, 09 Oct 2018 16:04:51 -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=FewfyTptfb0s5WSxMs5n7Qg+lzyT+gQ20EJBgZ1FVkE=; b=G8cCCh5hWze45vvuvbeGbJa0fUcjUbW4JHg6w2ONchlbArSZM3b5Y/PYE5fXdeZCSi m5gNwXFfzh6JW1yUcM+d60p90DFzazhjzuGJzuVQ2leGDgKJ0mKTDwbqnnalDQjBw4QZ yqC0Pi5H9Jc/6U+C3f7/UAZPoA10Ae3cCbjsc= 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=FewfyTptfb0s5WSxMs5n7Qg+lzyT+gQ20EJBgZ1FVkE=; b=G9OPuOMTvWsh8RvyIKALjdMcN+ez19XK9Ha77h9Tf4gqaQbbJLjZgWacHC9G0TrCPh bhHO75m3GVuelMVHl/WSWkPyrW6fVE6GSFHn0GrisSwqCYgu0EpZvAQqNA/QiQBccwWY OD6RvbG7GkrhOtObtt0MZiiHXDACtwPtz2u632Cl9vorkUU/SO8Uhauv5bt/pFEa9xQB I2+lEfDiLwx+6BeID18TPqBsuLD65RtcMXi3XogelwDqnlmeOYF6hpUnU1Y6CyJFIFSF 3g3S7vUmymiqOIZOcPFgmiUSWNAMkMlSAmlRSD1mw/CMKRKtHiYeYbrqnEXWHh2ZBLwR 0tOw== X-Gm-Message-State: ABuFfogIEXl2+F9Uh5bGGTIPMduAX5qVaIYlMvVHgID3SFgXmaI1i78v elZ4fERKsyRDToOUPbUSUN9Hbw== X-Received: by 2002:a63:a012:: with SMTP id r18-v6mr28021289pge.282.1539126290226; Tue, 09 Oct 2018 16:04:50 -0700 (PDT) Received: from localhost ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id h19-v6sm34439934pfk.71.2018.10.09.16.04.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Oct 2018 16:04:48 -0700 (PDT) Date: Tue, 9 Oct 2018 16:04:47 -0700 From: Joel Fernandes To: "Kirill A. Shutemov" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, minchan@google.com, hughd@google.com, lokeshgidra@google.com, Andrew Morton , Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Thomas Gleixner Subject: Re: [PATCH] mm: Speed up mremap on large regions Message-ID: <20181009230447.GA17911@joelaf.mtv.corp.google.com> References: <20181009201400.168705-1-joel@joelfernandes.org> <20181009220222.26nzajhpsbt7syvv@kshutemo-mobl1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181009220222.26nzajhpsbt7syvv@kshutemo-mobl1> 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 Wed, Oct 10, 2018 at 01:02:22AM +0300, Kirill A. Shutemov wrote: > On Tue, Oct 09, 2018 at 01:14:00PM -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. > > Okay. That's interesting. > > It makes me wounder why do we pass virtual address to pte_alloc() (and > pte_alloc_one() inside). > > If an arch has real requirement to tight a page table to a virtual address > than the optimization cannot be used as it is. Per-arch should be fine > for this case, I guess. > > If nobody uses the address we should just drop the argument as a > preparation to the patch. I couldn't find any use of the address. But I am wondering why you feel passing the address is something that can't be done with the optimization. The pte_alloc only happens if the optimization is not triggered. Also the clean up of the argument that you're proposing is a bit out of scope of this patch but yeah we could clean it up in a separate patch if needed. I don't feel too strongly about that. It seems cosmetic and in the future if the address that's passed in is needed, then the architecture can use it. > Anyway, I think the optimization requires some groundwork before it can be > accepted. At least some explanation why it is safe to move page table from > one spot in virtual address space to another. So I did go through several scenarios and its fine to my eyes. I tested it too and couldn't find any issue. Could you describe your concern a bit more? The mm->mmap_sem lock is held through out the mremap. Further we are acquiring needed rmap locks if needed and the ptl locks of the old new page-table pages. And this same path is already copying pmds for hugepages. thanks, - Joel