Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1132500imm; Mon, 9 Jul 2018 18:09:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdIS+1JLOjxufpZXb6adFBGBIkTkty7T8Pgu/R53JDyCwD8MlmpTQncRL1kQ9bJtXU5pNQ4 X-Received: by 2002:a63:7c18:: with SMTP id x24-v6mr20872652pgc.311.1531184987317; Mon, 09 Jul 2018 18:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531184987; cv=none; d=google.com; s=arc-20160816; b=t/cWLj+YaUi+cBK/kcmy9lCCpj2Ns3YfZcqeD5q5vQDqwpZXMAzCLYATKVu1u+QEin UWiEbYvHMomrWHbFGMBUcOuF8JB6bBp0gu8mkGx2GMAtcd2WZnGsFnNYaJfJQricp0cK Hnr1i8jzBlyvDd1r4U8W/3O1V07iLEm60BjTvtpgWFBhLlQirJRA0ZDiClc8leGD/Gkd Q/IvsQRlEVI5R0agZzspKHEec2kkM+gNE1wytMY24Q0/nu4z838QtvKxK6lCQfGEk+Xy QsZXXQAfLrzMH3ysVSb1TqWD9jCmlpctokl6zshZ+eFWdAk3G3BalBflZ75sXgRcvdqT jCNA== 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 :arc-authentication-results; bh=pWQCtHO/7lLLDKNaGK4C8H9tCx6v1k0UVBJ68zb6TA4=; b=OqZUp8OWvGyS0jzx1k8OSWiP9qvE69GM8ZNZluaS+7GRxMALrIfJ0N56e1P400KzOV b8nU0RXxiDpSZU0nCPdrYS/ybzCWeMNIY4pYNzVGwBZCN3AePZYCoweHmiIKpAeyI7ki 6yy6rHEWO+EeBkEW9jBf1winmZmHw5oC96UcYCZNLLv4qpZ2bEiokT0VyewslIr3MkNP lq/IdLNCDedQ31kVOAJkfRfwggquO1Gv2R8hzUW3ouNoOM4v2pqJIDhURDqNZa5bNId5 6i+5GkIyflO3fJpvliIE2i2mjuahmR9zMi6k6EnOu1eTPEaUnsSvMQhLmpU9VYcLuzBH 8w7w== 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 f12-v6si7288500pgg.653.2018.07.09.18.09.32; Mon, 09 Jul 2018 18:09:47 -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 S933342AbeGJBIt (ORCPT + 99 others); Mon, 9 Jul 2018 21:08:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53374 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933129AbeGJBIn (ORCPT ); Mon, 9 Jul 2018 21:08:43 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C9475D16; Tue, 10 Jul 2018 01:08:42 +0000 (UTC) Date: Mon, 9 Jul 2018 18:08:41 -0700 From: Andrew Morton To: David Rientjes Cc: Linus Torvalds , Davidlohr Bueso , Alexey Dobriyan , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch] mm, vmacache: hash addresses based on pmd Message-Id: <20180709180841.ebfb6cf70bd8dc08b269c0d9@linux-foundation.org> In-Reply-To: References: 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 Mon, 9 Jul 2018 17:50:03 -0700 (PDT) David Rientjes wrote: > When perf profiling a wide variety of different workloads, it was found > that vmacache_find() had higher than expected cost: up to 0.08% of cpu > utilization in some cases. This was found to rival other core VM > functions such as alloc_pages_vma() with thp enabled and default > mempolicy, and the conditionals in __get_vma_policy(). > > VMACACHE_HASH() determines which of the four per-task_struct slots a vma > is cached for a particular address. This currently depends on the pfn, > so pfn 5212 occupies a different vmacache slot than its neighboring > pfn 5213. > > vmacache_find() iterates through all four of current's vmacache slots > when looking up an address. Hashing based on pfn, an address has > ~1/VMACACHE_SIZE chance of being cached in the first vmacache slot, or > about 25%, *if* the vma is cached. > > This patch hashes an address by its pmd instead of pte to optimize for > workloads with good spatial locality. This results in a higher > probability of vmas being cached in the first slot that is checked: > normally ~70% on the same workloads instead of 25%. Was the improvement quantifiable? Surprised. That little array will all be in CPU cache and that loop should execute pretty quickly? If it's *that* sensitive then let's zap the no-longer-needed WARN_ON. And we could hide all the event counting behind some developer-only ifdef. Did you consider LRU-sorting the array instead?