Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp42865pxh; Thu, 7 Apr 2022 13:25:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzNpEbORIgGw+LwT4Pmac47RpGp1l/y87AvLqL5+95AQIn5Lv+xOFygiOd861biji1dQ3U X-Received: by 2002:a17:90b:3851:b0:1c7:80f9:5306 with SMTP id nl17-20020a17090b385100b001c780f95306mr17714926pjb.207.1649363144733; Thu, 07 Apr 2022 13:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363144; cv=none; d=google.com; s=arc-20160816; b=03pkmEYCVv0E5Ls5jjogHoOJjq+ahLWPw7l+i0bqNR5AKUIBoTbLM0pPCg0eEXvAQn 40OGL4QmKrwhgiTE0OAApF1/uKUJnh/YPTKqGv3NogdWby4CTouYhINvirKUdG/QMtxt jbarHd0avdBncuSj9xkD8ppQ3YCBna9N1XRFtoSBLmDQnY6KlKwUp4/bgXlclnZHBLAf vuN8njsZLX4ioXDPwpxYcOGvLVT57qSBTOvpUkz5kqlV9ANtAXRq2avZISW9Cj75uuAH 1IEtWmDaCRgsL0JQq0N6pguvUMdWRvIxFTmEVi3tRnehRuAMCRBeAfza69YO1t31jOyd +7+w== 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=JlG6HVFbiriXMTJdqZSQqniMpGFV8xnAyrnEzIlMNOY=; b=wFXkxj/ioJbt0ul26XMX+ukHrMnmJT6vp95aD86Alv9Hc3wFXf+fgiLZDMAqA5VnDv 8gASUcQAmuVHM+1/MIMKlgLxJbDh/GtGnqEUdBDDxNf4HEb8aB+YRcdl3gMYSIrbsuHW Nbz483CZrU+sAVVC9YP7Zzd22uhoiMDIVeUSaMgyvQ7j7V1RD/oU6Szo1YUgXoNkppZI w+V/1yI6IjIah5FYRa/QqW+TQIC2y87NvZ/zO1tLnlIOTJ8EbWKHmpkczKA/zpW78Yd/ eWjsR1Rt38RF2E94B7rzA5gt5Mum7XHDlkl+4J2vrSGtmX+UmVo64PTml+OqNfD3/5F6 hbbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=g3dD8HMI; 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 k75-20020a633d4e000000b003816043eee5si18623999pga.218.2022.04.07.13.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:25:44 -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=g3dD8HMI; 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 C3D0C3553A1; Thu, 7 Apr 2022 12:41:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbiDGDHU (ORCPT + 99 others); Wed, 6 Apr 2022 23:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238425AbiDGDGi (ORCPT ); Wed, 6 Apr 2022 23:06:38 -0400 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 91A4B14DFFC for ; Wed, 6 Apr 2022 20:04:39 -0700 (PDT) Received: by mail-vs1-xe35.google.com with SMTP id a127so2412865vsa.3 for ; Wed, 06 Apr 2022 20:04:39 -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=JlG6HVFbiriXMTJdqZSQqniMpGFV8xnAyrnEzIlMNOY=; b=g3dD8HMIW9o4XOj5/F4RYCZnbEq63R4EFyiRBbXsQlUUpD8109X/uRO1gnNIi0+9Pi lM1gQs/hacv3X7DHc77AbOsPgGGj22DYZPNeVsSVPpo97gzaVorDV1FW/tOTqx+DYT/P jBJwysHsCHMQOUC3rMpl0RAjgDGuNdLmjaqRyAgu6yjOnfQwLgp70zPEKn1m4byVx+Gn oaQ4TwpPmIJlhF6DGjFJDaCj+IZModFF71wQbWOneko1mH8M9Gnp2X+nPDvv8I+bcUjq 1KXKi2GF347JNly/H9fpusZvX9svfQ6yBM2A9CFZJRzmHwYsiNuDABJBRzlGNgaeCuWI BRNw== 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=JlG6HVFbiriXMTJdqZSQqniMpGFV8xnAyrnEzIlMNOY=; b=Ptj8wT/XxS9nQHQpLERL9OxdPee3AsDzXeUtHyuJFEt715wfSUvBJenr/gPK0XiXwh HOZeB0xZVaG0yhUt717vlcRnLoCB8MIirIZAIjOy0uHMqWRb8bsTeDZVCxGVzA+bB7Vq AR7wEEzXVR1OpJ13BtA4ktlJOeLun8PU1GE6kzSmjeA4UMpBHL+qfuHaLOupy4L7nW0L yefX7mc7uj5K6tMX0VcfSCFHx38B9+pmuD2qCdM+F6GfzIywyUu7sKW7Mrx8vYcu1od/ GbNTTvGDBbZgAjj5V5/J/IMMJETrGCMHRlDPpADyaEaA3G+WOZrk4v3m915voZmJG0ie ZTyQ== X-Gm-Message-State: AOAM533m5WEw7LyMi4VtxtxuArL1rtJzrEfaZuJYNlGNxC0zWzmwrwoe 73e246f0TNOXNJiKp3FBvLKZ45P2uKNavta/9NvLXA== X-Received: by 2002:a05:6102:2922:b0:325:7818:8669 with SMTP id cz34-20020a056102292200b0032578188669mr4104348vsb.41.1649300678575; Wed, 06 Apr 2022 20:04:38 -0700 (PDT) MIME-Version: 1.0 References: <20220309021230.721028-1-yuzhao@google.com> <20220309021230.721028-8-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Wed, 6 Apr 2022 21:04:27 -0600 Message-ID: Subject: Re: [PATCH v9 07/14] mm: multi-gen LRU: exploit locality in rmap To: Barry Song <21cnbao@gmail.com> Cc: Andrew Morton , Linus Torvalds , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Rik van Riel , Vlastimil Babka , Will Deacon , Ying Huang , LAK , Linux Doc Mailing List , LKML , Linux-MM , Kernel Page Reclaim v2 , x86 , 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 Wed, Apr 6, 2022 at 8:29 PM Barry Song <21cnbao@gmail.com> wrote: > > On Wed, Mar 9, 2022 at 3:48 PM Yu Zhao wrote: > > > > Searching the rmap for PTEs mapping each page on an LRU list (to test > > and clear the accessed bit) can be expensive because pages from > > different VMAs (PA space) are not cache friendly to the rmap (VA > > space). For workloads mostly using mapped pages, the rmap has a high > > CPU cost in the reclaim path. > > > > This patch exploits spatial locality to reduce the trips into the > > rmap. When shrink_page_list() walks the rmap and finds a young PTE, a > > new function lru_gen_look_around() scans at most BITS_PER_LONG-1 > > adjacent PTEs. On finding another young PTE, it clears the accessed > > bit and updates the gen counter of the page mapped by this PTE to > > (max_seq%MAX_NR_GENS)+1. > > Hi Yu, > It seems an interesting feature to save the cost of rmap. but will it lead to > possible judging of cold pages as hot pages? > In case a page is mapped by 20 processes, and it has been accessed > by 5 of them, when we look around one of the 5 processes, the page > will be young and this pte is cleared. but we still have 4 ptes which are not > cleared. then we don't access the page for a long time, but the 4 uncleared > PTEs will still make the page "hot" since they are not cleared, we will find > the page is hot either due to look-arounding the 4 processes or rmapping > the page later? Why are the remaining 4 accessed PTEs skipped? The rmap should check all the 20 PTEs. Even if they were skipped, it doesn't matter. The same argument could be made for the rest of 1 millions minus 1 pages that have been timely scanned, on a 4GB laptop. The fundamental principle (assumption) of MGLRU is never about making the best choices. Nothing can because it's impossible to predict the future that well, given the complexity of today's workloads, not on a phone, definitely not on a server that runs mixed types of workloads. The primary goal is to avoid the worst choices at a minimum (scanning) cost. The second goal is to pick good ones at an acceptable cost, which probably are a half of all possible choices.