Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp930994lqb; Wed, 29 May 2024 15:22:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNL9nxTKOLEMc6IF8zOvePlmiDr6gCSSZPPHehOGNZoavf8dAm56pkDAj2bMsCx5yrwkWKZUyki1l50sD6nKO0vCbFOfpJkdo/dDYAXw== X-Google-Smtp-Source: AGHT+IGTjN2dxZUhrE0Y97zZ2W5aVMAS4q7HYGc81l2htCVhQDPScqZt9oQLHZQBI2J2ZJZzGrUV X-Received: by 2002:a05:6e02:1a46:b0:374:60b5:8e2e with SMTP id e9e14a558f8ab-3747dfb6230mr2967025ab.22.1717021367780; Wed, 29 May 2024 15:22:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717021367; cv=pass; d=google.com; s=arc-20160816; b=oP9SxMCFiX82RsnI4IMhTK+AAytjibsuJ4pT8K7zahmM+GHBxhlXC3NB4bL1qb/zZS mT7cpuiekUfCqhcDPItBpT7Zg6eYDesHsgaRZqnnUT94FRJgWCwmhuU9Oni/DWe9kVxN YaiqE4skDmhY6tkf5O/8Cb9u9RHifHjt1rjk1mBx2SNxCMunKdsvgv/80UlXItDeA/IW de2z8Uj8IYJWu/YMp9NmcOdA/+Fa7jxoXvVDuWOnMq2VaJhyt6U+HdR1zsVPmwOBxoq2 s5oNHMF5lc3qmTbxVxf7cdWCZ6PsClrdr6vELWIwOFn0V/mL18XaTpJ81NohL/qHxFbb zP0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=dXNFpCWaiUyGAgeRu6GIx1Hrfse/W7At5lQK/blkjT8=; fh=mXrE48KahSdTYs60u7d3olDxcy4B9hjh4Vl7vhJPYF0=; b=Tb502iKbm4DLm77Ax5GtnkbsfscI43xtWbKw6iWn6cTtw1Xvbrhx0Ep3g9Vk+dzPiW Gq7UJcWV5EdjwWxx4zJhUPYCqD1efwtFXZPc0FK3LlAgc5VFvJXh8TOXxbTlkbN1kvOH 1YFfaBRkEAD2NJY1Ba2l/l15N6UoeXngqlqVU2/1l9cmPv1NWeBX0AO/sc3REMDwdHQj er1I7mRm2ZsUlXZZrIukSBR8pxEbquaELJDdq5nPKurNIfzSe0kaXsrg/2Kj06glao7G 2hmVhyv9FcMsmhE890g5VwGasLTkQdB/3sBYbBqouzN+z5QhuOKgbV+i3BV4vh2d4wYc 7Jyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eo2WH33G; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-194743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-68229937468si10977580a12.620.2024.05.29.15.22.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 15:22:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eo2WH33G; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-194743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8BEB1B24036 for ; Wed, 29 May 2024 22:22:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A40715D5A8; Wed, 29 May 2024 22:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eo2WH33G" Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDAE3169AC6 for ; Wed, 29 May 2024 22:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717021326; cv=none; b=LTgP93BolLa3CdpZNQmzZaYb0OlUG8flAJcDHk+yirLfa3asRgztAHahs8IdRzCEuommTQh4cCGWJhml+Gh51PziiV0X7nRj3fvfCajuKLXehB8KkpI2T+Zg6s5rCiOUohcmOJntyAG+mw1RWcuVxmWpl3gXvlGpe8qmuYM6kts= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717021326; c=relaxed/simple; bh=dXNFpCWaiUyGAgeRu6GIx1Hrfse/W7At5lQK/blkjT8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=BEAMsalCluP0IexO9M2zkx7kQZudaP7br2qndz3tcA+Md3Y5zx+61uu6mWVUdyffopQRj6aeUlIMOr7VgsJU3AmRXT/9VrUMC0jGqmbUBKBQgDw08QwwGJXo17jc1ucBTpkZXZpSRQE2MhIwh5nq4RUceN/Ba/zOFsPkFnmhLXQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eo2WH33G; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-42012c85e61so30035e9.0 for ; Wed, 29 May 2024 15:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717021323; x=1717626123; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dXNFpCWaiUyGAgeRu6GIx1Hrfse/W7At5lQK/blkjT8=; b=eo2WH33Gh4Xey0KAQtQsFLagivyKGY886T+eAtZyc6J6KZ2kZ0E3dHLrtaLGSJxYk8 vYNbd2sYr8d0KuqCnABQ62vr0fRCgRHf4XsEt0s1ClTN3pnYtfRQg7A61o6lFehkRLgy EPzNYNEwqNS0jHQm+XO4RnNw62Ld8nNoY/OLjUdrqFmdYzA+FHzyMXbgaJ901J/MP7sK txBcz10NU8PYH4RcSvH6rao/vvu9JKmjFYSEqm4AAOf+5VJuA9lC5nEFwuj58gh7wXp7 XpdLM4jgGxkTZjL7MGBa7Xw0lRqKxC4YlDkaXEnl8mN8ve5aKUYbH1Hd8zwfO0NFHDeN d6qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717021323; x=1717626123; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dXNFpCWaiUyGAgeRu6GIx1Hrfse/W7At5lQK/blkjT8=; b=ERXngQk+Pu1SwKdLYHVEvCp+gBUYTN+yrqfB0P2tSSFsuD5Ey6gx7VgRoE7RyKveGA BHQDPwsNRnbPJTWTOHCmXQIw64C1npQv7MvTal2LSER/bs46aCpd5Cbjdm5h0WBJM37F eJIt4AntCq9rRtnM+o/h4agHl3lizaL82AR9TvZJGZUgSn2ZtbLS7MT0StM3zRMgWeIF CoXB0KOeYZDTQbFqxu8LH/998sNcvmSekGzfZMnHn2exQoGwW/hZSt0LViNXjRy4v2Hj BVIS6CUu8XgZRt15TVrlaLtcoNdpvosVlA/KjswQswVUAnDCLjKdNzoHQfHT0ZzDXM4C ntww== X-Forwarded-Encrypted: i=1; AJvYcCXZyeyBeI8FX/bGrIBz+fXDz5SCsfl0pvY7HCav5dutY6w2++sO+J/vUZcN48qSggTc5H9tuYeq7oClb+avS2JJCTezO9S6Ti3kQq/8 X-Gm-Message-State: AOJu0Ywoed2LqclYyXX47SvFXQzCtdtLDlS7vZq4uyn7iJ7AVKfPaefo 0+C1YHCdqXs3zU7AHmcCpknvnvCBZFmZaPMjUWdOOCSS8940ba3JZ2xGC0jYw4WqDebJj5nb3u6 e8zDhKzFYFvUqVNJAj/LZZ2CnGbodT7EE5n3G X-Received: by 2002:a05:600c:2146:b0:41b:8715:1158 with SMTP id 5b1f17b1804b1-4212761becfmr670735e9.6.1717021322997; Wed, 29 May 2024 15:22:02 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240529180510.2295118-1-jthoughton@google.com> <20240529180510.2295118-3-jthoughton@google.com> In-Reply-To: From: Yu Zhao Date: Wed, 29 May 2024 16:21:24 -0600 Message-ID: Subject: Re: [PATCH v4 2/7] mm: multi-gen LRU: Have secondary MMUs participate in aging To: Sean Christopherson Cc: James Houghton , Andrew Morton , Paolo Bonzini , Albert Ou , Ankit Agrawal , Anup Patel , Atish Patra , Axel Rasmussen , Bibo Mao , Catalin Marinas , David Matlack , David Rientjes , Huacai Chen , James Morse , Jonathan Corbet , Marc Zyngier , Michael Ellerman , Nicholas Piggin , Oliver Upton , Palmer Dabbelt , Paul Walmsley , Raghavendra Rao Ananta , Ryan Roberts , Shaoqin Huang , Shuah Khan , Suzuki K Poulose , Tianrui Zhao , Will Deacon , Zenghui Yu , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 29, 2024 at 3:59=E2=80=AFPM Sean Christopherson wrote: > > On Wed, May 29, 2024, Yu Zhao wrote: > > On Wed, May 29, 2024 at 12:05=E2=80=AFPM James Houghton wrote: > > > > > > Secondary MMUs are currently consulted for access/age information at > > > eviction time, but before then, we don't get accurate age information= . > > > That is, pages that are mostly accessed through a secondary MMU (like > > > guest memory, used by KVM) will always just proceed down to the oldes= t > > > generation, and then at eviction time, if KVM reports the page to be > > > young, the page will be activated/promoted back to the youngest > > > generation. > > > > Correct, and as I explained offline, this is the only reasonable > > behavior if we can't locklessly walk secondary MMUs. > > > > Just for the record, the (crude) analogy I used was: > > Imagine a large room with many bills ($1, $5, $10, ...) on the floor, > > but you are only allowed to pick up 10 of them (and put them in your > > pocket). A smart move would be to survey the room *first and then* > > pick up the largest ones. But if you are carrying a 500 lbs backpack, > > you would just want to pick up whichever that's in front of you rather > > than walk the entire room. > > > > MGLRU should only scan (or lookaround) secondary MMUs if it can be > > done lockless. Otherwise, it should just fall back to the existing > > approach, which existed in previous versions but is removed in this > > version. > > IIUC, by "existing approach" you mean completely ignore secondary MMUs th= at don't > implement a lockless walk? No, the existing approach only checks secondary MMUs for LRU folios, i.e., those at the end of the LRU list. It might not find the best candidates (the coldest ones) on the entire list, but it doesn't pay as much for the locking. MGLRU can *optionally* scan MMUs (secondary included) to find the best candidates, but it can only be a win if the scanning incurs a relatively low overhead, e.g., done locklessly for the secondary MMU. IOW, this is a balance between the cost of reclaiming not-so-cold (warm) folios and that of finding the coldest folios. Scanning host MMUs is likely to be a win because 1) there is usually access locality 2) there is no coarsed locking. If neither holds, scanning secondary MMUs would likely be a loss. And 1) is generally weaker for secondary MMUs, since it's about (guest) physical address space.