Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp126081imm; Tue, 9 Oct 2018 15:03:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Yfij1cVBXZoNW68yeU+hmmPga/iEgJcLzvZUUbRzchzAN0g0A3S7RNPYQ5XtyuRCUhK4X X-Received: by 2002:a63:fb09:: with SMTP id o9-v6mr27330531pgh.333.1539122587834; Tue, 09 Oct 2018 15:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539122587; cv=none; d=google.com; s=arc-20160816; b=Kpb2ToAm2hfVVkETzv0mHkDITE2AIjne4z9EzygFNZ/FBrccSEUDyPCCzxcsBJruyF PsuyS5HW13KFjl9TCr+i3y8LVzLBzDYicIC+5pZuUL8+BYFltorsnSywg1RuZWWqhlvW Z1WxVx3Hm+PUyw0lIjJLeVydW9D3b+H7tMFQHPSsaVjpyanxBrwvKLQDv5EqI4xjw8XB bGBbFBaaSEfiEcAFrdtUYfYR88jvx19iQBQXORBXQLAO9nyLdvFSTAxaGMDTjHnPJ+f8 N50TVI85+uMaxMIFSdPh6A60tbuHGVnb51TU6kLtpn5AEczyjIF4CfBJO5W6rFPGFW/s 6Akw== 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=RY/1y0qF+ooxTkI2Ud710WZXEykzGF+8FFJR/0EVVlM=; b=tMhU9Blhc9fOJ80zuhieFlMk63x51cqNhLvYD1rvQOBTdmZiyFwjoQY/HOVCad+ren DigCkFQBYadCmfSUdRbNzPic5CddG6Id5NFfyDRxAxC4qH9CGbRRgG45j54GjCD1JZY8 jweCg6VPm1lFmS2e66qTGV7DsL3IPJVhNG21LR5HR41UvHLzxLuW0xp2o/RpMc7FTWFP vWKD1Fd0vrHBs9kNoKowRp494hBfoRgJVOKBRnvRur39cma9jmdyaP0yW98SFgtdmWGc uV9rVPi/24NF9PMhK7VWvU4qOP7Upno62ri4k4acXUTuAkBpEpZZNJlDoIrPXSoWHDn9 25Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=riVlM849; 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 n10-v6si22305685pgr.291.2018.10.09.15.02.52; Tue, 09 Oct 2018 15:03:07 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=riVlM849; 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 S1727503AbeJJFVa (ORCPT + 99 others); Wed, 10 Oct 2018 01:21:30 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46317 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbeJJFVa (ORCPT ); Wed, 10 Oct 2018 01:21:30 -0400 Received: by mail-pg1-f193.google.com with SMTP id a5-v6so1463763pgv.13 for ; Tue, 09 Oct 2018 15:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RY/1y0qF+ooxTkI2Ud710WZXEykzGF+8FFJR/0EVVlM=; b=riVlM849tHJ9aNkwmC/STFRvvd28hrwDuvDiPNAPCEdivVNe0cfhMonVUWrTjMiOfh 00QMj7knctpBm1knrX8dxRrpR9lwcHWAHVM3h8n6yBQR+hsLn1p8QGGGQ/2sRbnNlh5D wZL/FcnuGpmYMT2tjYESDTeu4KvWEJL+9FGLj5NgeBkgCpTxsfAxeYokOlj+8pabLb1g QygnJyVbYVH+7QUTDsfUM/Tk6GcdwD9x1CP7iKS9v6xgJKUO4To+6jbgqZeFnvClYjQx 63idfcSA9oOinBhH/OzbdxePe0FxTSIsr7DiB1Vq2lxU0AuFGiJ4Eq+zSeXkPdQffhYD 0m7g== 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=RY/1y0qF+ooxTkI2Ud710WZXEykzGF+8FFJR/0EVVlM=; b=qsl222uw7+HwjGksqWUIYQBJX83t5zKMj5LpacgaNqcg0URqFU7QpQeJiEBPo7rBWl QlUJmj6Btw2PEUVHW4gsD2GGdiewW1LaM6rrHJKf7C+8EIc40gIXxG9RWmvvjoP0cfwr WyE1XkP3VGP7iZWM6Oro1oIu3nx1q7QVU78QJat62flqf8fFRDS4dPyrkHngMONvULit LSTIHyH5l07459DX3SErVfpH4fNuU0hnOkU3siXMUNAqduAylBF563cx4i6ILSRKoKW7 uM97fAgIKvGbHbE4c8elsh2Gcc2gDlRy0reU+MCO7+Jdv/NT6SK/mumOutdn/1oHC/YX 3Fsw== X-Gm-Message-State: ABuFfogsO7zS6HX30UY5Np0OG8lSWbZ/orGWT+yxHnD1v6VucN26rhx3 eqfgaAxH5iGSA0UEDYNs2PEwHw== X-Received: by 2002:a63:b04f:: with SMTP id z15-v6mr25639953pgo.442.1539122548516; Tue, 09 Oct 2018 15:02:28 -0700 (PDT) Received: from kshutemo-mobl1.localdomain ([134.134.139.82]) by smtp.gmail.com with ESMTPSA id s13-v6sm29358232pfj.105.2018.10.09.15.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 15:02:27 -0700 (PDT) Received: by kshutemo-mobl1.localdomain (Postfix, from userid 1000) id 8EF8030002C; Wed, 10 Oct 2018 01:02:22 +0300 (+03) Date: Wed, 10 Oct 2018 01:02:22 +0300 From: "Kirill A. Shutemov" To: "Joel Fernandes (Google)" 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: <20181009220222.26nzajhpsbt7syvv@kshutemo-mobl1> References: <20181009201400.168705-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181009201400.168705-1-joel@joelfernandes.org> User-Agent: NeoMutt/20180716 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 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. 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. -- Kirill A. Shutemov