Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp105992imm; Tue, 9 Oct 2018 14:39:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV60a9ODhJYSfh++oq3npVjoxcwix3vNfvXAT21myF6UQgXkRlmHLqVdK5fJ3j2+eJfwbxzt7 X-Received: by 2002:a62:2982:: with SMTP id p124-v6mr31456882pfp.128.1539121194318; Tue, 09 Oct 2018 14:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539121194; cv=none; d=google.com; s=arc-20160816; b=mMvrzA+z5IhmbyoTw5+FIqieZrk4SvTXET2X+Iot/hQujJauRJpPPw3KCKfeBh3TNC tLrDGxvyLz0VrbafdweaYo5UHkf2h5iCcOd3AcbpbSql6s5+wxR9sgjEZY7vPzDel27A +B4kc4UJ9wlAiDLwYx7Nhp1swZGyODzw9RHrutEyPEIqgfwI3GpWTJkv4+vGZkiRe+DV bbjDwwYe6hNdB8fMSdY6wCIR7QoCPd5QbXnabmc2FvlE7sBGiukmuF+Go27RVCbmcSuR I56EKt6cOFmDWTfU7FU/iGCSGB6iPDVWA7Sac9HVhOj4dA9pmNpbjQLTrK2LHkK70Ech i7jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=PlxiDaebKL7H6CtFvQ7qjKz9m4QhHvPfgdDr6pbZsac=; b=fov+w1HkcCqzy4/iaD0BtHz/r1N3oTqpORhKr9srxJGOoaG9pwQZNOPDZxT+NpFHnF C76HmHh2asxNQVbMHIzAMbkdKH92DJy1pNMf5orxRnymqKVDv6FRUE90qRt2IjcNFpgU FLO/OToo5iGUpxico2waIDkbmazWH4JST4JUh/GCev6Mm8qOjIESoK2/43U2+2eG1iHI v+txrl4vN+oBzRIhigdPWonT6TVzlzT804Js9DnQdiqR5+oCTvyATXSK1JhTQw4TJ+6B XstvcIoEcxVGHgr1/cOKIg+/rN/3sIO/9Yjp2SWqUi2RbGStQODJhyF6ZELVcp6wU/HK aemA== ARC-Authentication-Results: i=1; mx.google.com; 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.14.39.39; Tue, 09 Oct 2018 14:39:54 -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; 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 S1727529AbeJJE55 (ORCPT + 99 others); Wed, 10 Oct 2018 00:57:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50330 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbeJJE55 (ORCPT ); Wed, 10 Oct 2018 00:57:57 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 602068E2; Tue, 9 Oct 2018 21:39:00 +0000 (UTC) Date: Tue, 9 Oct 2018 14:38:59 -0700 From: Andrew Morton 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, Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Thomas Gleixner Subject: Re: [PATCH] mm: Speed up mremap on large regions Message-Id: <20181009143859.8b9a700b1caf4e8d1e33a723@linux-foundation.org> In-Reply-To: <20181009201400.168705-1-joel@joelfernandes.org> References: <20181009201400.168705-1-joel@joelfernandes.org> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > --- 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.