From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B82CC433EF for ; Fri, 15 Apr 2022 06:44:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 797AD6B0071; Fri, 15 Apr 2022 02:44:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7470F6B0073; Fri, 15 Apr 2022 02:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E9076B0074; Fri, 15 Apr 2022 02:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 4FCE76B0071 for ; Fri, 15 Apr 2022 02:44:20 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 18CC620D49 for ; Fri, 15 Apr 2022 06:44:20 +0000 (UTC) X-FDA: 79358174280.01.F739FEB Received: from mail-io1-f46.google.com (mail-io1-f46.google.com [209.85.166.46]) by imf30.hostedemail.com (Postfix) with ESMTP id 9E31480005 for ; Fri, 15 Apr 2022 06:44:19 +0000 (UTC) Received: by mail-io1-f46.google.com with SMTP id e194so3168741iof.11 for ; Thu, 14 Apr 2022 23:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=/fLGJbyPSE6xRKCPoqOb0r29CUXjvQxIOZTemHPZg9I=; b=dfGKPZIrjcd9mm+yubZt6QjiN5aGfnKq8fln8jmtj6lgprpmUfDA/ocuYvoro1yuX/ Aaw4gnYOVtnG8xAqM4x8YukqX6UHi1qPVR512nIqQ0alEUiD79cE5dbK4+9MChqkGQ8D Vl7TqarR4PYbuygD3gGYOjB+19TitOapup1F9ynJRRI5B0ugNwc/+PhUZUYwqu93mjE2 hLYsF9igmKUd/MPswbIdk5HiZIygq0ynFVby2OjjcI0hws9yHg42+0b3YbT8cC18hohQ R/zQPDZBGaORvQ5GsPDzcM8UExE/AH5eVxGhxDC6vrw9GFS2aV35ptlvCM0/nQfFlcpX Cnsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=/fLGJbyPSE6xRKCPoqOb0r29CUXjvQxIOZTemHPZg9I=; b=oQAhtV1cyYoUYuh2CHzhBrhDaEQBVDavhQYnTHdokTQh9TuOl/hIsznnFs+nLlVd4Z JWjxDFSpsNx8cQiiqCIyt8OdFmqT6pTqC4LazcHVFtv330H1yaT8XDaMLAWoQETg7ghc /fU+ezFMnAALX1iZu1YgV3vgjlXmICcc6Qyz3r8tMzwyAX7r7t6GO4rd1dwand/Vvzq0 Ey4i+F8SAOW/jVy9QXWqj4nShEj//89rAGmVxXdpzccI/Ul9XwhFiP3EVl1LzAabuXF+ kDB/m8R7rvtgg5eAyJAKr1tgtgTcA8dvuQ2hLqvoh59wnf7xtNPrWfreSpBRyjFV2TQV l3Dg== X-Gm-Message-State: AOAM533q78Yeqk/O3dNKH/SJK6h81bPjjPi5xndfopkXHFqcZqz6eyGx hn340i3px+xxYsfpXNrKXJeVew== X-Google-Smtp-Source: ABdhPJyLCRXzb7HIHHESkI0VcqbNjDKYQkRX+ir+tnPRtFjnFebfY+a4CCujF2b5x20BRFZderliUg== X-Received: by 2002:a5d:848a:0:b0:648:b2f4:d5cd with SMTP id t10-20020a5d848a000000b00648b2f4d5cdmr2706447iom.53.1650005058681; Thu, 14 Apr 2022 23:44:18 -0700 (PDT) Received: from google.com ([2620:15c:183:200:e02:decc:64d3:b1d3]) by smtp.gmail.com with ESMTPSA id f15-20020a056e020c6f00b002cbc9935527sm2191136ilj.83.2022.04.14.23.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 23:44:18 -0700 (PDT) Date: Fri, 15 Apr 2022 00:44:14 -0600 From: Yu Zhao To: Chen Wandun Cc: Stephen Rothwell , linux-mm@kvack.org, Andi Kleen , Andrew Morton , Aneesh Kumar , Barry Song <21cnbao@gmail.com>, Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Linus Torvalds , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Rik van Riel , Vlastimil Babka , Will Deacon , Ying Huang , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, page-reclaim@google.com, x86@kernel.org, Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , Holger =?iso-8859-1?Q?Hoffst=E4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain Subject: Re: [PATCH v10 06/14] mm: multi-gen LRU: minimal implementation Message-ID: References: <20220407031525.2368067-1-yuzhao@google.com> <20220407031525.2368067-7-yuzhao@google.com> <71af92d2-0777-c318-67fb-8f7d52c800bb@huawei.com> <4c416f09-5304-07fd-cb53-5c9c8c75f6fa@huawei.com> <9e3ca922-1448-2eb1-b056-218236e7c72f@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9e3ca922-1448-2eb1-b056-218236e7c72f@huawei.com> X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9E31480005 X-Stat-Signature: 5wnez6zw1i93j3dr4fwtjq79g3uiaknf Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=dfGKPZIr; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of yuzhao@google.com designates 209.85.166.46 as permitted sender) smtp.mailfrom=yuzhao@google.com X-HE-Tag: 1650005059-544317 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Apr 15, 2022 at 02:31:37PM +0800, Chen Wandun wrote: > > > 在 2022/4/15 13:25, Yu Zhao 写道: > > On Fri, Apr 15, 2022 at 10:23:18AM +0800, Chen Wandun wrote: > > > 在 2022/4/15 4:53, Yu Zhao 写道: > > > > On Thu, Apr 14, 2022 at 07:47:54PM +0800, Chen Wandun wrote: > > > > > On 2022/4/7 11:15, Yu Zhao wrote: > > > > > > +static void inc_min_seq(struct lruvec *lruvec) > > > > > > +{ > > > > > > + int type; > > > > > > + struct lru_gen_struct *lrugen = &lruvec->lrugen; > > > > > > + > > > > > > + VM_BUG_ON(!seq_is_valid(lruvec)); > > > > > > + > > > > > > + for (type = 0; type < ANON_AND_FILE; type++) { > > > > > > + if (get_nr_gens(lruvec, type) != MAX_NR_GENS) > > > > > > + continue; > > > > > I'm confused about relation between aging and LRU list operation. > > > > > > > > > > In function inc_max_seq,  both min_seq and max_seq will increase, > > > > > the lrugen->lists[] indexed by lru_gen_from_seq(max_seq + 1) may > > > > > be non-empty? > > > > Yes. > > > > > > > > > for example, > > > > > before inc_max_seq: > > > > > min_seq == 0, lrugen->lists[0][type][zone] > > > > > max_seq ==3, lrugen->lists[3][type][zone] > > > > > > > > > > after inc_max_seq: > > > > > min_seq ==1, lrugen->lists[1][type][zone] > > > > > max_seq ==4, lrugen->lists[0][type][zone] > > > > > > > > > > If lrugen->lists[0][type][zone] is not empty before inc_max_seq and it is > > > > > the most inactive list,however lurgen->lists[0][type][zone] will become > > > > > the most active list after inc_max_seq. > > > > Correct. > > > > > > > > > So,  in this place, > > > > > > > > > > if (get_nr_gens(lruvec, type) != MAX_NR_GENS) > > > > > continue; > > > > > > > > > > should change to > > > > > > > > > > if (get_nr_gens(lruvec, type) == MAX_NR_GENS) > > > > > continue; > > > > No, because max/min_seq will overlap if we do so. > > > > > > > > lrugen->lists[max_seq+1] can only be non-empty for anon LRU, for a > > > > couple of reasons: > > > > 1. We can't swap at all. > > > > 2. Swapping is constrained, e.g., swapfile is full. > > > > > > > > Both cases are similar to a producer (the aging) overrunning a > > > > consumer (the eviction). We used to handle them, but I simplified the > > > > code because I don't feel they are worth handling [1]. > > > Can lrugen->lists[max_seq+1]  also be non-empty for file LRU? > > On reclaim path, no. But it can be forced to do so via debugfs. > > > > > such as in dont reclaim mapped file page case(isolation will fail). > > You mean may_unmap=false? Pages stays in the same generation if > > isolation fails. So lrugen->lists[min_seq] won't be empty in this > > case. > > > > > If so, after aging, eviction will reclaim memory start from > > > lrugen->lists[min_seq+1], but some oldest file page still > > > remain in lrugen->lists[max_seq+1]. > > > > > > sort_folio can help to put misplaced pages to the right > > > LRU list, but in this case, it does't help, because sort_folio > > > only sort lrugen->lists[min_seq+1]. > > On reclaim path, inc_max_seq() is only called when need_aging=true, > > and this guarantees max_seq-min_seq[LRU_GEN_FILE]+1 < MAX_NR_GENS. > yes, I think so, but I did't find the logical in function get_nr_evictable, > or am I missing something > >         if (min_seq[LRU_GEN_FILE] + MIN_NR_GENS > max_seq) >                 *need_aging = true; >         else if (min_seq[LRU_GEN_FILE] + MIN_NR_GENS < max_seq) >                 *need_aging = false; This branch. And the following is also relavent: static int __init init_lru_gen(void) { BUILD_BUG_ON(MIN_NR_GENS + 1 >= MAX_NR_GENS);