Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2399635rwb; Sun, 15 Jan 2023 14:53:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXtcNPl0uATGipgQl2Qmq+k0ucl7SveVakjPqpAf1LKrp1Z5AzMnCKmTenBYt0f72RmcscJL X-Received: by 2002:a62:e703:0:b0:577:7cfb:a896 with SMTP id s3-20020a62e703000000b005777cfba896mr19208542pfh.31.1673823224898; Sun, 15 Jan 2023 14:53:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673823224; cv=none; d=google.com; s=arc-20160816; b=SCksc0Dg3hZhwpnCNZMqWqNzNvUW0Sba5kPTGBOgeQrkACG5pKkR9VTO+Kif7T9Rqz gwF/WLrkiPYQXScWfQMgLUQ3JYW+9oAwGUXjfQ/UXCtSq++9hNplMdTu9w1ghOXW69Zu 4ICwxMHHSgBJYwrhPRAqvvOttTyVLzubUcztbSKoy17qTYeUo1O/nGheQWRdaNv/S1oT 3rx+oZayUmT7VaBJeDTeHSNKJKXS6RLV1sZ92DPL6v6uWO+DHQg5goTFav7+/iaMW/w0 kB1xR/aH9lxvTFdMUS3ptnRoIChpPoh/StKetdj3Xj5+Htk4uC6kPm8KlPnlVw4104b0 5zfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=g9a9lt8imHWrU+aXyiCvzH9wJ7qwkvw7ijcrlz3p08E=; b=zw/pk5avkcHsMtWFziPeHWsS+nt4kWkrEeigeCbmlLPkbLLm3TiwDBRkT5IbpTmQqQ MVFqFH9e4luvlhkgF89hk7SXvIuydZhZD21Q/QOHUQXmSy4iMTQerIlbkJMhphlHPPRY I+IuPdYr2lHuYfn3RUsdtw0HEE4FJSuoingpEEel7uE4E+Q7UhnpfbgDQy/zJzlUrPPj ujUz+49iUiA4RSjhOeJN4X8qAH5BDt7gvIBZxa9sUMsw5VaOO67v9UdMVFGp6n14IJic 7/E4Xx+Qm67HvY7Hi4Rk2H/+KrdP2gnGYtmvB237ay0NpkwWUYnqe/y39cauB8ieTWdt vYYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=L8op4Oh3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a056a00244b00b0057f8d82dda4si27764960pfj.218.2023.01.15.14.53.38; Sun, 15 Jan 2023 14:53:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=L8op4Oh3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231459AbjAOWrf (ORCPT + 54 others); Sun, 15 Jan 2023 17:47:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbjAOWrd (ORCPT ); Sun, 15 Jan 2023 17:47:33 -0500 Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 014471B57D for ; Sun, 15 Jan 2023 14:47:32 -0800 (PST) Received: by mail-vs1-xe35.google.com with SMTP id n190so23569342vsc.11 for ; Sun, 15 Jan 2023 14:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=g9a9lt8imHWrU+aXyiCvzH9wJ7qwkvw7ijcrlz3p08E=; b=L8op4Oh3wmW7ZO1rKWQ+9oiUo2ArZN5aVXCeZ+J1MeT0cUpNaG8QshC1aYRCHaJJNV kF1lJOk0q5CzNuoTHP0QGJfrmiDH4t6lc5xbcCpOvc2WsCSTcZ87zXjgT2MRhPPY1Isl G2js3JIo5HBwSU0gCfyjjZHO0tThNK/l2pk63ggbL24wvyd/yHiYVTuCrm/y12atEbrA f3rISqiZ0oQadioZZXRn2NeS7P+frMkBiojt8iOoJl5ba6X3rUD2smXK1kDYSl5vsZ4u tB7AE7YKt/xWQUXi/eqGJ5raiyQzPPAwwij1Be/g4uRVClbzg8J/b8ehfWW0TBlFo0e+ /Mrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=g9a9lt8imHWrU+aXyiCvzH9wJ7qwkvw7ijcrlz3p08E=; b=yvzzMaFTytCL7w2Ks3Sd2hMOgjvyZmY1X2SzcH8zyiJrqzady2mB4eSxR15tcVj+Wf Vg/5HuOcihXhtLv7vEGcaNUNpyDqajeuStFHk0R7dBvmrxbLOdvIeoXEsiAwJmhvBQYO acCZuOd/gqn7jjHlVdMgPUMReXLsZYWey3RBqvVTnvAGcZlmDD1lDOaqA0QpHOxzSN/1 UzzoXwPVK/ZWCuaSQewmiMjanaRKgfbg1Ot3zWe3qVeS9IWuLAHwbxnMwe3rFlLIIwli JarzfKnyaY8tHyZyozQSd/8B2WFTgpYVMhOf2FTv7HZ2Fn8yEHf+EJuapyNP/ybGNiGY IkTA== X-Gm-Message-State: AFqh2krfw5OPMgV04H67oETNdWdXjl63+ikgLFtY8V2hLZv27XF3q8cV jWLocmWNMiw1OxlCvakYHO3ldoBlH9iF+Y6yGglnPnaxgqq3F/1Y X-Received: by 2002:a05:6102:40b:b0:3d3:db6b:e761 with SMTP id d11-20020a056102040b00b003d3db6be761mr79727vsq.46.1673822851026; Sun, 15 Jan 2023 14:47:31 -0800 (PST) MIME-Version: 1.0 References: <20230115125721.3553-1-tjytimi@163.com> In-Reply-To: <20230115125721.3553-1-tjytimi@163.com> From: Yu Zhao Date: Sun, 15 Jan 2023 15:46:54 -0700 Message-ID: Subject: Re: [PATCH v1] mm: multi-gen LRU: reduce repeated scans in rmap To: Jinyu Tang Cc: yuanchu@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, falcon@tinylab.org, ttjjyystupid@163.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 15, 2023 at 5:57 AM Jinyu Tang wrote: > > The folio is physically and virtually contiguous. If a folio have > more than one pages, lru_gen_look_around() will run several times in > the while loop in folio_referenced_one(), but most of times is > unnecessary. Because these pages always belong to the same pmd and > vma, lru_gen_look_around() will scan the same range. Thanks -- the commit message is quite clear, so I think I understand what you're thinking. Let me clarify: 1. First of all, there are no repeated scans, because after lru_gen_look_around() clears the A-bit in a range, the pte_young() test stops it from going into the same range again. 2. Of course, pte_young() can become true later, but this is not a problem because it's cache hot. 3. Physically and virtually contiguous mapping existed before folios: a THP can be mapped by 512 PTEs. > while (page_vma_mapped_walk(&pvmw)) { > address = pvmw.address; > @@ -825,7 +826,13 @@ static bool folio_referenced_one(struct folio *folio, > if (pvmw.pte) { > if (lru_gen_enabled() && pte_young(*pvmw.pte) && > !(vma->vm_flags & (VM_SEQ_READ | VM_RAND_READ))) { > - lru_gen_look_around(&pvmw); > + unsigned long pmd_now = pvmw.address & PMD_MASK; > + unsigned long pmd_former = former_address & PMD_MASK; > + > + if ((!former_address) || (pmd_now != pmd_former)) { > + lru_gen_look_around(&pvmw); > + former_address = pvmw.address; > + } > referenced++; > }