Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4272802pxf; Tue, 16 Mar 2021 09:26:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTqVM4a1hqHo0y+b0en6LxYPjOFBhCtU7xDapb0GHLG5CbVExM37j/BXm/q4E2IeOMHexB X-Received: by 2002:a05:6402:4405:: with SMTP id y5mr18188887eda.32.1615911979894; Tue, 16 Mar 2021 09:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615911979; cv=none; d=google.com; s=arc-20160816; b=UI+90Rf8vFqBvdjhYcjgLUVd+5UXiXRWvtmBHXWL9ue8u4oUOeTQrTV0urGKw7FH+n 54IfzoSHmlI4hKs4slNUbcFGm2Sgk7G3td3yVtKfV9zkNwlzFSVj2kt3Dw0fjhD8NLv0 Q83BGEX/zAKj7bc16qtJHcB+1t1aQSGav5yCl0ryLQ/izKEae3IPv0E43TnkPPdY83GP Kyb9KzNaH1wz0O16vQMN6+YbxRTEhVwWxwx3CTYtWN+J7aKrtFdLHzU1U6m2pHPmxZ6B aSMGVJ3trdRKiEJt2bHOOKZmgdw7IOxbCIStzaYTkR3jYbJYlJbpIlf2NzdE2VHJanlJ 49OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:cc:to:subject:ironport-sdr:ironport-sdr; bh=MXv5tlR1HvY+ECKLbuJeU5l74YCBqEks1MCdRgxJgQw=; b=AXIa57ssJPmXLAqnGXaQ3l1XcOcmxocyRfIpT+QhIW0QIaDT0O+TIIsJOLWVyen0fz QffrI/suNaZ3EVl+5bdStOxpj8Zsx1P0SPuOxJJP5tpjBfhb+c2MCFQVJGvmHWKHoeho IGq+q1Ac/A3tgAAdYLTR6/wiOOwB4eRlaVNrrOJkRMn8y1uOCqpuvHM1FRe3IJ9Mmwre EWf4yrlmMJObmiOuqvQSKFCNs8mgyqedGbW9EqYR94XDLkVWPVc62asrpOW+0k1xmpyt AMiEofDXmOdrCaWYeEywrqyDnol0SBv8wq/p8kWnWgOIAGnpRSlio2Rm1Fq/WZpBDnco E0uQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s19si15159738edc.275.2021.03.16.09.25.56; Tue, 16 Mar 2021 09:26:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbhCPOup (ORCPT + 99 others); Tue, 16 Mar 2021 10:50:45 -0400 Received: from mga09.intel.com ([134.134.136.24]:11637 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237549AbhCPOuZ (ORCPT ); Tue, 16 Mar 2021 10:50:25 -0400 IronPort-SDR: ejHloLz8SsRHhqvDCD57qblc1xi0wjk9bLtQZ8RvPUspGr0PLTc8f4wMsDbAWCqbxNE9ugrqnU g6b0WmHp3nfw== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="189364484" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="189364484" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 07:50:24 -0700 IronPort-SDR: dduCDcrqNHwBtIHWmbo41zv1TZ4439pS/93WddD+L98QVReXubOHa0J1o38YoR6SOTgf027/SJ 2Fju8tl6A+Gg== X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="449740667" Received: from kcarrier-mobl.amr.corp.intel.com (HELO [10.209.124.168]) ([10.209.124.168]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 07:50:23 -0700 Subject: Re: [PATCH v1 00/14] Multigenerational LRU To: Yu Zhao Cc: linux-mm@kvack.org, Alex Shi , Andrew Morton , Dave Hansen , Hillf Danton , Johannes Weiner , Joonsoo Kim , Matthew Wilcox , Mel Gorman , Michal Hocko , Roman Gushchin , Vlastimil Babka , Wei Yang , Yang Shi , Ying Huang , linux-kernel@vger.kernel.org, page-reclaim@google.com References: <20210313075747.3781593-1-yuzhao@google.com> <5f621dd6-4bbd-dbf7-8fa1-d63d9a5bfc16@intel.com> From: Dave Hansen Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668QpaEOdLGhtvrVYVK7x4skyT3nGWcgDCl5/Vp3TWA4K+IofwvXzX2ON/Mj7aQwf5W iC+3nWC7q0uxKwwsddJ0Nu+dpA/UORQWa1NiAftEoSpk5+nUUi0WE+5DRm0H+TXKBWMGNCFn c6+EKg5zQaa8KqymHcOrSXNPmzJuXvDQ8uj2J8XuzCZfK4uy1+YdIr0yyEMI7mdh4KX50LO1 pmowEqDh7d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1Ov4/50JY9pXzgIDVSrgy6LYSMc4vKZ3QfCY7ipLRORyalFDF3j5AGCMRENJjHPD6O7bl3Xo 4DzMID+8eucbXxKiNEbs21IqBZbbKdY1GkcEGTE7AnkA3Y6YB7I/j9mQ3hCgm5muJuhM/2Fr OPsw5tV/LmQ5GXH0JQ/TZXWygyRFyyI2FqNTx4WHqUn3yFj8rwTAU1tluRUYyeLy0ayUlKBH ybj0N71vWO936MqP6haFERzuPAIpxj2ezwu0xb1GjTk4ynna6h5GjnKgdfOWoRtoWndMZxbA z5cecg== Message-ID: <7378f56e-4bc0-51d0-4a61-26aa6969c0de@intel.com> Date: Tue, 16 Mar 2021 07:50:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/15/21 7:24 PM, Yu Zhao wrote: > On Mon, Mar 15, 2021 at 11:00:06AM -0700, Dave Hansen wrote: >> How bad does this scanning get in the worst case if there's a lot of >> sharing? > > Actually the improvement is larger when there is more sharing, i.e., > higher map_count larger improvement. Let's assume we have a shmem > page mapped by two processes. To reclaim this page, we need to make > sure neither PTE from the two sets of page tables has the accessed > bit. The current page reclaim uses the rmap, i.e., rmap_walk_file(). > It first looks up the two VMAs (from the two processes mapping this > shmem file) in the interval tree of this shmem file, then from each > VMA, it goes through PGD/PUD/PMD to reach the PTE. The page can't be > reclaimed if either of the PTEs has the accessed bit, therefore cost > of the scanning is more than proportional to the number of accesses, > when there is a lot sharing. > > Why this series makes it better? We track the usage of page tables. > Specifically, we work alongside switch_mm(): if one of the processes > above hasn't be scheduled since the last scan, we don't need to scan > its page tables. So the cost is roughly proportional to the number of > accesses, regardless of how many processes. And instead of scanning > pages one by one, we do it in large batches. However, page tables can > be very sparse -- this is not a problem for the rmap because it knows > exactly where the PTEs are (by vma_address()). We only know ranges (by > vma->vm_start/vm_end). This is where the accessed bit on non-leaf > PMDs can be of help. That's an interesting argument. *But*, this pivoted into describing an optimization. My takeaway from this is that large amounts of sharing are probably only handled well if the processes doing the sharing are not running constantly. > But I guess you are wondering what downsides are. Well, we haven't > seen any (yet). We do have page cache (non-shmem) heavy workloads, > but not at a scale large enough to make any statistically meaningful > observations. We are very interested in working with anybody who has > page cache (non-shmem) heavy workloads and is willing to try out this > series. I would also be very interested to see some synthetic, worst-case micros. Maybe take a few thousand processes with very sparse page tables that all map some shared memory. They wake up long enough to touch a few pages, then go back to sleep. What happens if we do that? I'm not saying this is a good workload or that things must behave well, but I do find it interesting to watch the worst case. I think it would also be very worthwhile to include some research in this series about why the kernel moved away from page table scanning. What has changed? Are the workloads we were concerned about way back then not around any more? Has faster I/O or larger memory sizes with a stagnating page size changed something? >> I'm kinda surprised by this, but my 16GB laptop has a lot more page >> cache than I would have guessed: >> >>> Active(anon): 4065088 kB >>> Inactive(anon): 3981928 kB >>> Active(file): 2260580 kB >>> Inactive(file): 3738096 kB >>> AnonPages: 6624776 kB >>> Mapped: 692036 kB >>> Shmem: 776276 kB >> >> Most of it isn't mapped, but it's far from all being used for text. > > We have categorized two groups: > 1) average users that haven't experienced memory pressure since > their systems have booted. The booting process fills up page cache > with one-off file pages, and they remain until users experience > memory pressure. This can be confirmed by looking at those counters > of a freshly rebooted and idle system. My guess this is the case for > your laptop. It's been up ~12 days. There is ~10GB of data in swap, and there's been a lot of scanning activity which I would associate with memory pressure: > SwapCached: 1187596 kB > SwapTotal: 51199996 kB > SwapFree: 40419428 kB ... > nr_vmscan_write 24900719 > nr_vmscan_immediate_reclaim 115535 > pgscan_kswapd 320831544 > pgscan_direct 23396383 > pgscan_direct_throttle 0 > pgscan_anon 127491077 > pgscan_file 216736850 > slabs_scanned 400469680 > compact_migrate_scanned 1092813949 > compact_free_scanned 4919523035 > compact_daemon_migrate_scanned 2372223 > compact_daemon_free_scanned 20989310 > unevictable_pgs_scanned 307388545 > 2) engineering users who store git repos and compile locally. They > complained about their browsers being janky because anon memory got > swapped even though their systems had a lot of stale file pages in > page cache, with the current page reclaim. They are what we consider > part of the page cache (non-shmem) heavy group. Interesting. You shouldn't have a shortage of folks like that among kernel developers.