Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp859738imm; Wed, 6 Jun 2018 07:03:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIB2yzzV8cl3J5A5nrCyn2qvZ5AW0cUId7YUEl3lClL2uK15vaZQd2eaVUTnSNJmQoHpluV X-Received: by 2002:a63:7b1e:: with SMTP id w30-v6mr2673239pgc.249.1528293817551; Wed, 06 Jun 2018 07:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528293817; cv=none; d=google.com; s=arc-20160816; b=hrnKUdSajt5P1GVp0WqWvv+hWKPAg8v83KmALVhL88+hgmrs3ja1sIToMKq5+PkUW/ itTyaVPq/Lb+eScXMAl484Bt5pgnXn6VQF3MfytRW9Z+ml/GTZfihEVPStQF2SFRtBWL oq+J5oJnk/vcNPlkU/jCNLQiz4KMSCQBKYMQ3gwC0cEz7OojCxj5g6IiezvNYablQvSI f1r9I8w5LCKBoFrYfWaJ8UPl4HVi7TVScLtv0p56HkyLWkjenQiorAHm50mglAC4MFDq oYv5QpMZ0cOOG7OzfMva+nHVlnDcbYR+EsSq92xD++eYcmQhHdixDfUcBPNafn9qor4+ cf9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=EwwIS+ktha9qhWt2vYuRPgc4uO8MCgXeUOKXGQnsuxI=; b=Vimal7lvcEvjWJicZGBqmH/zlk9uV5AQU1Vk3Q4/EvFPX1cXivdsYl16kWxzYsjQ3w 7vfZQ2OFy8ole2YeXTbVjbEuH5AYRKmD7MMa23lqIyJ2l5RFolyKHVfVvaZ51CbzLi4Q 9n4Z6Ps7uhB/PefrneF622RBqYNFpHE6IVOSbiDo9pI6UmJ5RCtLY657PWW7ZZo4l7Z3 bPLRAGYGYk8ScRCbBzOEOp33qLeDh1O2DCiNA2Nr8Fnng0/D5Xj/IfCRqICNldLBbSAT 04zOGOKTovn86XSlBAKEU+fyJxlCpPvAhwje0ftyJxpjZbZhCM4hRUkZd30jv4boGCKt XaDw== 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 j4-v6si41204123pgs.544.2018.06.06.07.03.21; Wed, 06 Jun 2018 07:03:37 -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 S1752230AbeFFOC7 (ORCPT + 99 others); Wed, 6 Jun 2018 10:02:59 -0400 Received: from outbound-smtp12.blacknight.com ([46.22.139.17]:52022 "EHLO outbound-smtp12.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751973AbeFFOC6 (ORCPT ); Wed, 6 Jun 2018 10:02:58 -0400 Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp12.blacknight.com (Postfix) with ESMTPS id DFCAE1C2511 for ; Wed, 6 Jun 2018 15:02:56 +0100 (IST) Received: (qmail 7866 invoked from network); 6 Jun 2018 14:02:56 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[37.228.237.73]) by 81.17.254.9 with ESMTPSA (DHE-RSA-AES256-SHA encrypted, authenticated); 6 Jun 2018 14:02:56 -0000 Date: Wed, 6 Jun 2018 15:02:55 +0100 From: Mel Gorman To: Andrew Morton Cc: Dave Hansen , mhocko@kernel.org, vbabka@suse.cz, Aaron Lu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mremap: Increase LATENCY_LIMIT of mremap to reduce the number of TLB shootdowns Message-ID: <20180606140255.br5ztpeqdmwfto47@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 5d1904204c99 ("mremap: fix race between mremap() and page cleanning") fixed races between mremap and other operations for both file-backed and anonymous mappings. The file-backed was the most critical as it allowed the possibility that data could be changed on a physical page after page_mkclean returned which could trigger data loss or data integrity issues. A customer reported that the cost of the TLBs for anonymous regressions was excessive and resulting in a 30-50% drop in performance overall since this commit on a microbenchmark. Unfortunately I neither have access to the test-case nor can I describe what it does other than saying that mremap operations dominate heavily. This patch increases the LATENCY_LIMIT to handle TLB flushes on a PMD boundary instead of every 64 pages. This reduces the number of TLB shootdowns by a factor of 8 which is not reported to completely restore performance but gets it within an acceptable percentage. The given metric here is simply described as "higher is better". Baseline that was known good 002: Metric: 91.05 004: Metric: 109.45 008: Metric: 73.08 016: Metric: 58.14 032: Metric: 61.09 064: Metric: 57.76 128: Metric: 55.43 Current 001: Metric: 54.98 002: Metric: 56.56 004: Metric: 41.22 008: Metric: 35.96 016: Metric: 36.45 032: Metric: 35.71 064: Metric: 35.73 128: Metric: 34.96 With patch 001: Metric: 61.43 002: Metric: 81.64 004: Metric: 67.92 008: Metric: 51.67 016: Metric: 50.47 032: Metric: 52.29 064: Metric: 50.01 128: Metric: 49.04 So for low threads, it's not restored but for larger number of threads, it's closer to the "known good" baseline. The downside is that PTL lock hold times will be slightly higher but it's unlikely that an mremap and another operation will contend on the same PMD. This is the first time I encountered a realistic workload that was mremap intensive (thousands of calls per second with small ranges dominating). Using a different mremap-intensive workload that is not representative of the real workload there is little difference observed outside of noise in the headline metrics However, the TLB shootdowns are reduced by 11% on average and at the peak, TLB shootdowns were reduced by 21%. Interrupts were sampled every second while the workload ran to get those figures. It's known that the figures will vary as the non-representative load is non-deterministic. An alternative patch was posted that should have significantly reduced the TLB flushes but unfortunately it does not perform as well as this version on the customer test case. If revisited, the two patches can stack on top of each other. Signed-off-by: Mel Gorman --- mm/mremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 049470aa1e3e..b5017cb2e1e9 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -191,7 +191,7 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, drop_rmap_locks(vma); } -#define LATENCY_LIMIT (64 * PAGE_SIZE) +#define LATENCY_LIMIT (PMD_SIZE) unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long old_addr, struct vm_area_struct *new_vma,