Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp162863pxb; Thu, 7 Apr 2022 02:02:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWJcrwBgt3ysllnD0+Mt7UDuZDYWyfhBWAJEOE/JfgqiSO4fxhv9W4QxTvziqwn1lEvG2J X-Received: by 2002:a05:6402:278d:b0:419:3794:de39 with SMTP id b13-20020a056402278d00b004193794de39mr13019866ede.137.1649322150330; Thu, 07 Apr 2022 02:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649322150; cv=none; d=google.com; s=arc-20160816; b=FuliADyJFf758Y+0QZWYOur1WBnWfMQmt0cVyPnvsAheC+S1JvXfmnkNxMDSrnxxWd kVexUi3R7X7YAfJypt/H7ZzVqEs5j4ZXiib9sEJzjOKrXUVrxZxoo24QmH+yeud1lYrL bhgVEre1hVjhRDNTxtzbRGBo7azBrM0dTB0zknKcIA3MoDzvK1MUeLJdIP03WNXdX3i8 s0EtcfKfRwXYUksNz4HgvLTDRpNfp506ZtnPlc5S3ii9DwLDnwgsQmL/Vc7u1wcPnDlE dcYlwKiqvBvNyPABM716ixzJlb0Vi2lAmETbacN8WPRfPCymqsXiDuD28r/wQDMD24AM UFtA== 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=2osYizLMrar7QqOz8LD8setUutp7c0I8CuIlWyU0pBg=; b=DE9pOc7xtCuVZ4dMZNnZxQCTTImqnN0I6cCcVVXHH8jfY9PtFPFu58HqmijuWvAD2c pueFTGh9wtxjZpo91i2jaIrDQqJK6kabT0IB7JLWD8Dq+jhJiI4mOeckAOe92nQE7uE+ RIQVKWj91jc7eL4CqF1euA8vPrIL8pEzsgRC8HANAE7JZM/7Fu2SHFuGrPED91bZ/Mwh 9sHzAR+y+HbHywS/p6B2nvPgqzJF9F2pHdf+wU4Y2doxNWJR6VboCCMep/tdR7mTjyuN KSS621nCnzNjw31QK5gFgW6dKFWAzU9abvnzfs/yFIMmr47o6G+VNFbXoEstecBv+qJq 6g0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="cKZ6do/t"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p24-20020a1709061b5800b006e7efcd98ccsi8105135ejg.622.2022.04.07.02.02.03; Thu, 07 Apr 2022 02:02:30 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b="cKZ6do/t"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236976AbiDGDso (ORCPT + 99 others); Wed, 6 Apr 2022 23:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233268AbiDGDsl (ORCPT ); Wed, 6 Apr 2022 23:48:41 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABEB5BEE; Wed, 6 Apr 2022 20:46:41 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id p15so8161263ejc.7; Wed, 06 Apr 2022 20:46:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2osYizLMrar7QqOz8LD8setUutp7c0I8CuIlWyU0pBg=; b=cKZ6do/t2L9vKakesKtxffn9PtC9S2qbMr1610jgtP28xQz6M/jTZXicOp3+64uVHX qijM4rThv3VpwivwHnyedSzyRpf3vh4n1k0TQAAJPm/h8Bz9d85Jpr49IYQeUIVlM+cD ZmTFDpFRzm4xJyYGwYoOJ5+X2mqr09Y7sRAuxURsQ/icMKA7Wu8S7D+O6hq1eDEY8BDA VC8YgH7lGf+Yey31F5KelHmIX5na8552lGQkasonqsXOqDgLwPKyDx4wi/yPs6zzQhcB MZZWYzVqqtyDwlF3O6Ax60y95AqQ2heZZg3yOdHV9oD/k0Powk68JmG7cbwav6DWN2zp M2VQ== 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=2osYizLMrar7QqOz8LD8setUutp7c0I8CuIlWyU0pBg=; b=jZ2QtuS1dYRnxBH0eMk0c70d1/CsfnGSRsVsQztg+PxLQSeBJEFiq9Y8fFGzjGJ5D8 7aWTnLbCSojG2sJKYV1GfLCAOyqBI0MOd4KKmU1cNGVCH5hhzVmb5VGk1K0zttSUIOFd WnmpYEqNHjcRYybQKCGJ9M9Ubz7liSJ+uT8KjnMO8vSpqrG4rGZo7n6VeUpHXEPVYZlD O+eAS7R2OAMEpA3VUR3/k52a+PdQrbp8R8J+NRLlePejGvNeMneJjWwD3sOeiBjJClIp kWWq85cfLSk0DGOospaYARzjfaWClnHZ8buQfb5/i2VQzTQmglpM+HIrzJUZ2J0pXjOF Qskg== X-Gm-Message-State: AOAM530EIhLPxoBvNWiuvnNdGD+FDsMvtpkykZY30z9zQF09AKwK3uBD ZD7rrCxar/xmXoirdgP8U+Ce0VnNIyslxRtRzcQ= X-Received: by 2002:a17:906:39da:b0:6cf:7f09:a7bc with SMTP id i26-20020a17090639da00b006cf7f09a7bcmr11870481eje.457.1649303200136; Wed, 06 Apr 2022 20:46:40 -0700 (PDT) MIME-Version: 1.0 References: <20220309021230.721028-1-yuzhao@google.com> <20220309021230.721028-8-yuzhao@google.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Thu, 7 Apr 2022 15:46:29 +1200 Message-ID: Subject: Re: [PATCH v9 07/14] mm: multi-gen LRU: exploit locality in rmap To: Yu Zhao 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Thu, Apr 7, 2022 at 3:04 PM Yu Zhao wrote: > > 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. for example page A is the neighbour of page B in process 1, when we do rmap for B, we look-around and clear A's pte in process 1. but A's ptes are still set in process 2,3,4,5. > > 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. thanks barry