Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2138974iof; Tue, 7 Jun 2022 21:03:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+1TbKw6THkv6kFRJUQb1eJt4+C7x+jDa/qMmbxDXLAfc5dSzsPr0otMwLaaL0BWuvEkUY X-Received: by 2002:a17:90b:180e:b0:1e8:3023:eeb9 with SMTP id lw14-20020a17090b180e00b001e83023eeb9mr27972669pjb.55.1654661017168; Tue, 07 Jun 2022 21:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661017; cv=none; d=google.com; s=arc-20160816; b=V17f61wsAwCWMWNHK3ecwSFNC/2aYZ6QTtRGxktmrxoKew6ZyBHnR9gJGzo1GiwqUx pYqZ1OZEOWct2/m/+OXS4vCIu8bSK4J9iYW+1w87YtSK9jSBZHSiFry6kWeaNtw1345s EbrOpZWVf6NlyOj/LAQQbXJdOs277QxHl2Q23Zyn/9UZHg6thzBtX8L9RlGMn4ILasnM wv9pi+xiqiRC0kizqQuSCdZ40YCtqTQ2+vdkhXsEbuSKeVPi8Rw4b7JOAe5DEbz0MxZ1 dSVf0Pdvzdzf87rhujXn1BpukCNN2qInjbH2fW6eU49IRphlmJprth6bGOfKQSQF6Hfd yfrA== 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=9Elzb0WSXIXlROa5Ne/fkFdeuavdNhknMmaOlUejDTY=; b=TVVWLASA6Hxw2+UmvojhJdAH8xxuTN1dwBiJKajJ7flaEKJiBHgDyxo6hI4GzaCKbL 7FV6DKO+yIvsIuaq3XnKzjpU+X/uMywatXiie14gifTkybFA0pwvuQn0y+njauO3H8bB GB8kuYL+UT39o50HXSuyQCm/4tdT7P+NtbC2rIVZ0VB/xSmd2r4CxdSALsZHL4btJ64M LtLQ80Q+lbODRXCBrmVqOfUTGjxay6jSvT3k3sL3Ze6Kgc/srLZfZhJd1V1fvLnsAAq9 rTbuQDvklQ9u6WWqhuK2aHJJfCLynedrU4CBsVpKLoqHsB1HWro67ea2RggtlqL/xp6q Mq6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Cv0f7VDX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p1-20020a170902e74100b0016213dc7805si23801487plf.324.2022.06.07.21.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Cv0f7VDX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A31C91285E5; Tue, 7 Jun 2022 20:28:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380468AbiFGW1g (ORCPT + 99 others); Tue, 7 Jun 2022 18:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376837AbiFGVSj (ORCPT ); Tue, 7 Jun 2022 17:18:39 -0400 Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5C1E224118 for ; Tue, 7 Jun 2022 11:59:23 -0700 (PDT) Received: by mail-vs1-xe2e.google.com with SMTP id 68so17527482vse.11 for ; Tue, 07 Jun 2022 11:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9Elzb0WSXIXlROa5Ne/fkFdeuavdNhknMmaOlUejDTY=; b=Cv0f7VDXY7aEPKcXAgnBc/m7gn4KcwOMCSs6PnP0SNIDWWYURJ50n1BCOckHKyAo4L osssjroBU4blBT4uRm44yv1fi6oI2L3ujbMxK0o1i7oGhzuJEZHYVRVpCkNRjU/hFtxf Ifer0vvxCoOUoY1v9kjyMENImilrTTM4fAy0Btq15FrFxyPHCeK2B0D84LFU8iZVCbEM TH8Id7ZOemPx6JqSCTpgYaMPAPVA73HfyKXhphSlNjINHTMX+uRZzLvngc5H22ab9HNY 8jkBwlmf+zLp0DZxf4DQWE1GgEnOF/mife+Vv/Z4dmejaQyeRkI9GPk+3cw2UFYny78M GbTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9Elzb0WSXIXlROa5Ne/fkFdeuavdNhknMmaOlUejDTY=; b=MT6L6TgAYCsaz39abgzZBMQe+kb1LtBl7vUTFKK/4ZUSA7puDl+ZkjBsZUrX3VNpBt ptfNZyBglSgx9TcdR5kA7+13hDT6z3YMmQ89orUY+2hgqznx1eJwEfrKxpdvyxcQMo7J BffGl+abskKvOIq5TFHt05IIqWI9Ae4kJ80lii/nvBxtq34GRbd/Q2d0g0Tm358PkKjY tB+sHAbciU2pjcrUvHUlBbUC+YgoeU2oGkP6liOSBtoq77oyjVg9IGg5nuJ0CPktzT97 RJxUCDOCm0CIoqDTYiJZJIMRA+bTQwqT53m1JJDg2FhAjU/c/qCCeAIe0EbZIcDoOGhW aB3A== X-Gm-Message-State: AOAM5308R7EcoBhOtpHRXv3Rb3+2T9hka3QhmRY7ZJNZuEe7dUxSIqMR y4M1wgjkoaS2uHf8Nx1JEwZuoTK3JlRgM3nxaU22zg== X-Received: by 2002:a67:f3d0:0:b0:34b:b52d:d676 with SMTP id j16-20020a67f3d0000000b0034bb52dd676mr6382966vsn.6.1654628358760; Tue, 07 Jun 2022 11:59:18 -0700 (PDT) MIME-Version: 1.0 References: <20220518014632.922072-1-yuzhao@google.com> <20220518014632.922072-8-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Tue, 7 Jun 2022 12:58:42 -0600 Message-ID: Subject: Re: [PATCH v11 07/14] mm: multi-gen LRU: exploit locality in rmap To: Barry Song <21cnbao@gmail.com> Cc: Andrew Morton , Linux-MM , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Johannes Weiner , Jonathan Corbet , Linus Torvalds , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Peter Zijlstra , Tejun Heo , Vlastimil Babka , Will Deacon , LAK , Linux Doc Mailing List , LKML , x86 , Kernel Page Reclaim v2 , Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , =?UTF-8?Q?Holger_Hoffst=C3=A4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Mon, Jun 6, 2022 at 3:25 AM Barry Song <21cnbao@gmail.com> wrote: > > On Wed, May 18, 2022 at 4:49 PM Yu Zhao wrote: ... > > @@ -821,6 +822,12 @@ 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); > > + referenced++; > > + } > > + > > if (ptep_clear_flush_young_notify(vma, address, > > Hello, Yu. > look_around() is calling ptep_test_and_clear_young(pvmw->vma, addr, pte + i) > only without flush and notify. for flush, there is a tlb operation for arm64: > static inline int ptep_clear_flush_young(struct vm_area_struct *vma, > unsigned long address, pte_t *ptep) > { > int young = ptep_test_and_clear_young(vma, address, ptep); > > if (young) { > /* > * We can elide the trailing DSB here since the worst that can > * happen is that a CPU continues to use the young entry in its > * TLB and we mistakenly reclaim the associated page. The > * window for such an event is bounded by the next > * context-switch, which provides a DSB to complete the TLB > * invalidation. > */ > flush_tlb_page_nosync(vma, address); > } > > return young; > } > > Does it mean the current kernel is over cautious? Hi Barry, This is up to individual archs. For x86, ptep_clear_flush_young() is ptep_test_and_clear_young(). For arm64, I'd say yes, based on Figure 1 of Navarro, Juan, et al. "Practical, transparent operating system support for superpages." [1]. int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) { /* * On x86 CPUs, clearing the accessed bit without a TLB flush * doesn't cause data corruption. [ It could cause incorrect * page aging and the (mistaken) reclaim of hot pages, but the * chance of that should be relatively low. ] * * So as a performance optimization don't flush the TLB when * clearing the accessed bit, it will eventually be flushed by * a context switch or a VM operation anyway. [ In the rare * event of it not getting flushed for a long time the delay * shouldn't really matter because there's no real memory * pressure for swapout to react to. ] */ return ptep_test_and_clear_young(vma, address, ptep); } [1] https://www.usenix.org/legacy/events/osdi02/tech/full_papers/navarro/navarro.pdf > is it > safe to call ptep_test_and_clear_young() only? Yes. Though the h/w A-bit is designed to allow OSes to skip TLB flushes when unmapping, the Linux kernel doesn't do this. > btw, lru_gen_look_around() has already included 'address', are we doing > pte check for 'address' twice here? Yes for host MMU but no KVM MMU. ptep_clear_flush_young_notify() goes into the MMU notifier. We don't use the _notify variant in lru_gen_look_around() because GPA space generally exhibits no memory locality. Thanks.