From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C644C677F1 for ; Thu, 23 Feb 2023 20:29:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B26206B0073; Thu, 23 Feb 2023 15:29:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD6AA6B0074; Thu, 23 Feb 2023 15:29:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 977386B0075; Thu, 23 Feb 2023 15:29:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 87EC56B0073 for ; Thu, 23 Feb 2023 15:29:03 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 260AD160788 for ; Thu, 23 Feb 2023 20:29:03 +0000 (UTC) X-FDA: 80499695766.16.2B322E4 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf23.hostedemail.com (Postfix) with ESMTP id 5FF2C14000B for ; Thu, 23 Feb 2023 20:29:01 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Oj0JNHRf; spf=pass (imf23.hostedemail.com: domain of 3jMz3YwYKCCsZLHUQJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--seanjc.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3jMz3YwYKCCsZLHUQJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677184141; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iMpgRmyVDog12gGF5u00S3GFVvfa3RjsGhYYuIghQuw=; b=UAJYXs6HDFWKDA3vn22lclLaZmk11uezhtT2wDHJNnHq627m/dgvbZrEZy7uPK8oVed8Lv h2DwtbWs+K2Z5qcr7jxkyNbX0S4mxpRghzAhrCSxmN5TbyuQUZNglicKJ3P7sxTjYO1P/v AY5AZIkZzT5ZrAMtYeY2Iq8zVhmLpIk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Oj0JNHRf; spf=pass (imf23.hostedemail.com: domain of 3jMz3YwYKCCsZLHUQJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--seanjc.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3jMz3YwYKCCsZLHUQJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677184141; a=rsa-sha256; cv=none; b=a+FQdJDBy7UYk0qd+u5FKda/Oimxxfzva8xctpDNh4AdGXBUja9U+vXW/GMSpc6hxIVMYE m9H1NwE0YQStY8uIDpRgrX/zPiNsvSPBlbNo1MygTEt0Un+NCyftUjfTqJp6Kg1WVTM+JT c89VUXOZveE1K7zsKZQPNitU/SDJHL0= Received: by mail-pj1-f73.google.com with SMTP id x10-20020a17090a6b4a00b002342e23955cso153818pjl.7 for ; Thu, 23 Feb 2023 12:29:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=iMpgRmyVDog12gGF5u00S3GFVvfa3RjsGhYYuIghQuw=; b=Oj0JNHRfBF0003MFOrybvJRxKWvg4a//DfyLNclUK+7N5/s7VjeN2Ybz0ne96gQ+y/ Kce+Q0ZXdzbS+HItx2LVYs6XbJeGYav5T0kxtg6oSGyyAnYLkgfUmKMvnWrz/RJr2iGt BiNuY4XQIP71ObixRoPGWBrf5q6zjI9OvmSI5XqGwGSoaN4Qo8PjJcVdjNQWqFmCbaNT fDylmTkY2OnILfYvuCp/0wvlS/vK3WqeY+Vs8jpgS0bDY+Fzi+bVe+j3RecifYahcIhh j4oJs7UNz2z7WtDg2Ub7n9qah3g+mR+nVEw9Z6a8GUszbe4QIdPOG3iK1M22brh9bkyW z3qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=iMpgRmyVDog12gGF5u00S3GFVvfa3RjsGhYYuIghQuw=; b=xKyFqxmCUwq2NtIrN1g9JCt0OIxriDHznLR7RQYuFfKlukLZpJ9OM01YNhbbUdEUrC 6vePAK4ovzW5QuzY1yCRIqD3g/nsKnlnBt/0Uq3PtX8/5aY46Y6hQ68wbAhJT1gqOSa7 Odzq+1suL1lXUXuC3KldmlI59BIfUgirfiI0L4n/gKtFfy3GjBpxUFht2LBWIgygntuG wu1TYe+McE93LuNFor14AKuv9GN4GPimeh0LgjWPBOOTbXqZ3Gvm8DVJi1Okky64fPMt SLiU5zBKyQYEvoiA9WhYPvNaIfbsNaZ7iq4rxKkgNNzp2WGt+GIKRgzPm0DFxHz0d0lh e/4Q== X-Gm-Message-State: AO0yUKWQ4rwxccECOF0fzJakLcaKzHbpQwAYNIgydOvuVq648mCtrkA4 p7bxGw9ijRqHy45d+k5KKqJn6hwBnCQ= X-Google-Smtp-Source: AK7set/XyWT2OAnpm11r3FBKVIDwL0kXrUZRkKccpnOexZiyXc1HvjHh6IvJEeYAirA5lDcDXm4Ck4IuD34= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1955:b0:593:f5e4:8d87 with SMTP id s21-20020a056a00195500b00593f5e48d87mr2471665pfk.6.1677184140109; Thu, 23 Feb 2023 12:29:00 -0800 (PST) Date: Thu, 23 Feb 2023 12:28:58 -0800 In-Reply-To: Mime-Version: 1.0 References: <20230217041230.2417228-1-yuzhao@google.com> <20230217041230.2417228-6-yuzhao@google.com> Message-ID: Subject: Re: [PATCH mm-unstable v1 5/5] mm: multi-gen LRU: use mmu_notifier_test_clear_young() From: Sean Christopherson To: Yu Zhao Cc: Johannes Weiner , Andrew Morton , Paolo Bonzini , Jonathan Corbet , Michael Larabel , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-mm@google.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5FF2C14000B X-Stat-Signature: z5ftmwb7hiu1co6qi7mocf7779dmhtrt X-HE-Tag: 1677184141-819284 X-HE-Meta: U2FsdGVkX19RRniKY5qSdoW7kVBaQ5v/AYtotnHqgZjPvLpzLoLigV+iymgMWcrJjYONOIvWsmax1Arh/1I7kXoNoNOU+9jzSEKJTh+eT4zBJBc1T0HNlrb+WGSSqMeSBK7QOQqfuDckjgjnDZvbUY37xraCHWrHRWtsMAUUsg01DUA97xh8bZw+lVlyviz/cfpLIH4LO6Hx6fMrJsQq5G1YIuZhTKdVZrefhwRiARqFnE0xtAph4FEpz3AJGr7Rhu/X8TWH1Pc1XKzVlFGx8QsZ9VXOjQC0imwUtFFijpw/8rHBirREohRlYPJxoeNXjfIBdQ1lBTCobIGif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CN4u+S3If1UCEMsUAeI0UQGSans1OKIFqs1Xp2LdlHHqDEu6GlpA0yezQ1RE6ozYXWKWwlSTh42PlaRNlMGVfpChHX7CxjzZ2D9Hgq+TH7j8H1fVbvlqwDlhCto4lXtHjE4l572oTKL3pv8/BiZOxN2R9bg5djM7ZXK5+7DJ/wYOD+7Dg9QfvBRGkH/KmI8ttFxAIAqaJXVqJMdERsDyyy1rXPBcj6VdrOchBnYEnhQTT1kCy5bQd3vgiUagIJLoi+xQf+qWgVmt+Xe03N8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Feb 23, 2023, Yu Zhao wrote: > On Thu, Feb 23, 2023 at 12:58=E2=80=AFPM Sean Christopherson wrote: > > > > On Thu, Feb 23, 2023, Yu Zhao wrote: > > > On Thu, Feb 23, 2023 at 12:11=E2=80=AFPM Sean Christopherson wrote: > > > > > > > > On Thu, Feb 23, 2023, Yu Zhao wrote: > > > > > > As alluded to in patch 1, unless batching the walks even if KVM= does _not_ support > > > > > > a lockless walk is somehow _worse_ than using the existing mmu_= notifier_clear_flush_young(), > > > > > > I think batching the calls should be conditional only on LRU_GE= N_SPTE_WALK. Or > > > > > > if we want to avoid batching when there are no mmu_notifier lis= teners, probe > > > > > > mmu_notifiers. But don't call into KVM directly. > > > > > > > > > > I'm not sure I fully understand. Let's present the problem on the= MM > > > > > side: assuming KVM supports lockless walks, batching can still be > > > > > worse (very unlikely), because GFNs can exhibit no memory localit= y at > > > > > all. So this option allows userspace to disable batching. > > > > > > > > I'm asking the opposite. Is there a scenario where batching+lock i= s worse than > > > > !batching+lock? If not, then don't make batching depend on lockles= s walks. > > > > > > Yes, absolutely. batching+lock means we take/release mmu_lock for > > > every single PTE in the entire VA space -- each small batch contains > > > 64 PTEs but the entire batch is the whole KVM. > > > > Who is "we"? >=20 > Oops -- shouldn't have used "we". >=20 > > I don't see anything in the kernel that triggers walking the whole > > VMA, e.g. lru_gen_look_around() limits the walk to a single PMD. I fee= l like I'm > > missing something... >=20 > walk_mm() -> walk_pud_range() -> walk_pmd_range() -> walk_pte_range() > -> test_spte_young() -> mmu_notifier_test_clear_young(). >=20 > MGLRU takes two passes: during the first pass, it sweeps entire VA > space on each MM (per MM/KVM); during the second pass, it uses the rmap o= n each > folio (per folio). Ah. IIUC, userspace can use LRU_GEN_SPTE_WALK to control whether or not to= walk secondary MMUs, and the kernel further restricts LRU_GEN_SPTE_WALK to secon= dary MMUs that implement a lockless walk. And if the answer is "no", secondary = MMUs are simply not consulted. If that's correct, then the proper way to handle this is by extending mmu_n= otifier_ops to query (a) if there's at least one register listeners that implements test_clear_young() and (b) if all registered listeners that implement test_= clear_young() support lockless walks. That avoids direct dependencies on KVM, and avoids= making assumptions that may not always hold true, e.g. that KVM is the only mmu_no= tifier user that supports the young APIs. P.S. all of this info absolutely belongs in documentation and/or changelogs= .