Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1204870imm; Wed, 11 Jul 2018 20:05:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcWJr7yT2wkRWoFpcoHTlvN0TynSKwA6s7uW1ujYaCUAZCQsu+ywaRvr7UsMcUKcdml3dg4 X-Received: by 2002:a62:1815:: with SMTP id 21-v6mr478563pfy.227.1531364751568; Wed, 11 Jul 2018 20:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531364751; cv=none; d=google.com; s=arc-20160816; b=sRicaAGF85Yffvacxk+24/rJGQxCpx6QZwdUgs1reJL3LOkt/kAT+0IytY7XxIbkDH csPoRYAImurR3M4YVVY5sCn9BNgB2Mt5rF5m85VPT45ELeFzoGlKdzuF14sUmIbPNQhV k3mEf1/riNl9GST5J5DZJiNgD6pVB/GFeIk0NhwtbQlGuOQMb3Oj4Is6sAmTwCO1asxH NjHFKxAs1iYCiVyTi3xO718t6K/jSAh86gMynzPTJP2JtK/eX0MCOA841LbVtMWukLcg hT6G5nYO3NBGkwrKIqyAOGL1e7jT00DwPvJNFgKdkGfyO753O0ZyTSiDXCP4XHCxF4oo WZAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=wf0GSaau/FonDnaRqSCZ0F/n9UQ08k45HSngN1T6fDE=; b=zuvSTNbEd9yQVkYgPpFvILzBrAe+LXmTnAYJ1ht4CCIAblTKEZ3KDtML0Rx0ZB8Dr2 wA+0/2ItQlEU+t6MmXgF3c689sLnvwmXYCrIBlV5l67kydPAyZ+ulD1hyjZ1iAfYi73O UxPrmJLI6cXMGC0oHNiltJXf4iVt3fNnVJOTGg9u97qbV9n+RFaBlRhiLxwdeUFlpPmi odDYcwPHyqVhG0hWWVRW8R/xtTTlOwyP/VfX47EykxHVckGogMUTrE8zJW+4YGKpwDiv WOYZ5w/jJW4MVsbigQx/1lum/A+EKPg/Hjn590fD9kEsKH06GtsvEjRn0iFMpo1VldGv aYMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AFNVx705; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n70-v6si17239188pfa.320.2018.07.11.20.05.36; Wed, 11 Jul 2018 20:05:51 -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=@google.com header.s=20161025 header.b=AFNVx705; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388446AbeGKXuj (ORCPT + 99 others); Wed, 11 Jul 2018 19:50:39 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43033 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388049AbeGKXuj (ORCPT ); Wed, 11 Jul 2018 19:50:39 -0400 Received: by mail-pl0-f65.google.com with SMTP id c41-v6so9830491plj.10 for ; Wed, 11 Jul 2018 16:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=wf0GSaau/FonDnaRqSCZ0F/n9UQ08k45HSngN1T6fDE=; b=AFNVx705ar4ZPUBR7/kxgAhOTwEbCKEPfebc64zq7bx5iOotJODfGbvr2OfZUwbBnG G08VHcxcCQc6ZvRkHCXpwbyYe3+LL8RYTTEz/dyWZ7atBguuxSRrZxGxyCn6Hp9DwLr6 7acxL78w22F1mTLg49qbomNWaNVrH2cLdjMn/xbzpEDrfW0cxiAqIIq27F2clBprDu5r aGcAeOMfRJGazN2iTdTObc1RJUACnkMcaz7EvR38GK7lVcvyvuUN4iLI2FBXNAZTs7Vl HDYbC+yHu+pxPBfcMxRkxQqMWuDAQj207zbvONvIGMiP1skDyWcFb2MY6ExvH0XcbACP +FHw== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=wf0GSaau/FonDnaRqSCZ0F/n9UQ08k45HSngN1T6fDE=; b=flR41P3zgRp4CITqwODtg6/VBTFr0M5D6ZfnZq+6LnFjqvmMwCaUMeicrE+99aBCci 7xt3fOTfKCqRakMDGoQl6/TFn/jS3/XGKBIPkDInY9u3NLRDNuD+LASRehcudyJGR33D 52qwjLsPYrksyR0HV1lYGvzbGVe8njXQY/79Ft6E/H4u7XZFmwthkAG13v/bK9SOGvWk tgZAYqmK/Ivvmmmgh5CPvqTXL1MCXX/kc8pSXJWKbew4vOlOqlCdvJuXrjhasvs2G9/Z q2WwAvLgclYC30/fTEp860beSNGTkIZyiUjUhCmT1zUy8nud1qUd6buhA1DtxXDSAsL5 HUwQ== X-Gm-Message-State: AOUpUlEOVf1WDDk9qAWac/EeUX+0+9If1CdXubtmkYVdSuOJwZN5AnyQ gdQqTgrdQKiuqPCrHTpD9cwTBg== X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr595007pln.11.1531352635852; Wed, 11 Jul 2018 16:43:55 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id y69-v6sm45684669pfd.36.2018.07.11.16.43.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Jul 2018 16:43:55 -0700 (PDT) Date: Wed, 11 Jul 2018 16:43:54 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton 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 In-Reply-To: <20180711161030.b5ae2f5b1210150c13b1a832@linux-foundation.org> Message-ID: References: <20180709180841.ebfb6cf70bd8dc08b269c0d9@linux-foundation.org> <20180711161030.b5ae2f5b1210150c13b1a832@linux-foundation.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Jul 2018, Andrew Morton wrote: > > > Did you consider LRU-sorting the array instead? > > > > > > > It adds 40 bytes to struct task_struct, > > What does? LRU sort? It's a 4-entry array, just do it in place, like > bh_lru_install(). Confused. > I was imagining an optimized sort rather than adding an iteration to vmacache_update() of the same form that causes vmacache_find() to show up on my perf reports in the first place. > > but I'm not sure the least > > recently used is the first preferred check. If I do > > madvise(MADV_DONTNEED) from a malloc implementation where I don't control > > what is free()'d and I'm constantly freeing back to the same hugepages, > > for example, I may always get first slot cache hits with this patch as > > opposed to the 25% chance that the current implementation has (and perhaps > > an lru would as well). > > > > I'm sure that I could construct a workload where LRU would be better and > > could show that the added footprint were worthwhile, but I could also > > construct a workload where the current implementation based on pfn would > > outperform all of these. It simply turns out that on the user-controlled > > workloads that I was profiling that hashing based on pmd was the win. > > That leaves us nowhere to go. Zapping the WARN_ON seems a no-brainer > though? > I would suggest it goes under CONFIG_DEBUG_VM_VMACACHE. My implementation for the optimized vmacache_find() is based on the premise that spatial locality matters, and in practice on random user-controlled workloads this yields a faster lookup than the current implementation. Of course, any caching technique can be defeated by workloads, artifical or otherwise, but I suggest that as a general principle caching based on PMD_SHIFT rather than pfn has a greater likelihood of avoiding the iteration in vmacache_find() because of spatial locality for anything that iterates over a range of memory.