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 14484C433F5 for ; Sun, 13 Feb 2022 10:04:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17DB56B0072; Sun, 13 Feb 2022 05:04:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 106A36B0073; Sun, 13 Feb 2022 05:04:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F10CB6B0078; Sun, 13 Feb 2022 05:04:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id DE0486B0072 for ; Sun, 13 Feb 2022 05:04:32 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 839CB987A4 for ; Sun, 13 Feb 2022 10:04:32 +0000 (UTC) X-FDA: 79137321984.17.BD7A0B9 Received: from mail3-163.sinamail.sina.com.cn (mail3-163.sinamail.sina.com.cn [202.108.3.163]) by imf07.hostedemail.com (Postfix) with SMTP id 9276140003 for ; Sun, 13 Feb 2022 10:04:30 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.61.131]) by sina.com (172.16.97.27) with ESMTP id 6208D79C00036744; Sun, 13 Feb 2022 18:04:14 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 55300549283491 From: Hillf Danton To: Yu Zhao Cc: Johannes Weiner , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v7 05/12] mm: multigenerational LRU: minimal implementation Date: Sun, 13 Feb 2022 18:04:17 +0800 Message-Id: <20220213100417.1183-1-hdanton@sina.com> In-Reply-To: <20220208081902.3550911-6-yuzhao@google.com> References: <20220208081902.3550911-1-yuzhao@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9276140003 X-Stat-Signature: rd6jbirgc96hrtgb5rgpwmssjc6infgx X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.163 as permitted sender) smtp.mailfrom=hdanton@sina.com X-HE-Tag: 1644746670-67924 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.108239, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello Yu On Tue, 8 Feb 2022 01:18:55 -0700 Yu Zhao wrote: > + > +/*********************************************************************= ********* > + * the aging > + *********************************************************************= *********/ > + > +static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, b= ool reclaiming) > +{ > + unsigned long old_flags, new_flags; > + int type =3D folio_is_file_lru(folio); > + struct lru_gen_struct *lrugen =3D &lruvec->lrugen; > + int new_gen, old_gen =3D lru_gen_from_seq(lrugen->min_seq[type]); > + > + do { > + new_flags =3D old_flags =3D READ_ONCE(folio->flags); > + VM_BUG_ON_FOLIO(!(new_flags & LRU_GEN_MASK), folio); > + > + new_gen =3D ((new_flags & LRU_GEN_MASK) >> LRU_GEN_PGOFF) - 1; Is the chance zero for deadloop if new_gen !=3D old_gen? > + new_gen =3D (old_gen + 1) % MAX_NR_GENS; > + > + new_flags &=3D ~LRU_GEN_MASK; > + new_flags |=3D (new_gen + 1UL) << LRU_GEN_PGOFF; > + new_flags &=3D ~(LRU_REFS_MASK | LRU_REFS_FLAGS); > + /* for folio_end_writeback() */ /* for folio_end_writeback() and sort_folio() */ in terms of reclaiming? > + if (reclaiming) > + new_flags |=3D BIT(PG_reclaim); > + } while (cmpxchg(&folio->flags, old_flags, new_flags) !=3D old_flags)= ; > + > + lru_gen_balance_size(lruvec, folio, old_gen, new_gen); > + > + return new_gen; > +} ... > +/*********************************************************************= ********* > + * the eviction > + *********************************************************************= *********/ > + > +static bool sort_folio(struct lruvec *lruvec, struct folio *folio, int= tier_idx) > +{ Nit, the 80-column-char format is prefered. > + bool success; > + int gen =3D folio_lru_gen(folio); > + int type =3D folio_is_file_lru(folio); > + int zone =3D folio_zonenum(folio); > + int tier =3D folio_lru_tier(folio); > + int delta =3D folio_nr_pages(folio); > + struct lru_gen_struct *lrugen =3D &lruvec->lrugen; > + > + VM_BUG_ON_FOLIO(gen >=3D MAX_NR_GENS, folio); > + > + if (!folio_evictable(folio)) { > + success =3D lru_gen_del_folio(lruvec, folio, true); > + VM_BUG_ON_FOLIO(!success, folio); > + folio_set_unevictable(folio); > + lruvec_add_folio(lruvec, folio); > + __count_vm_events(UNEVICTABLE_PGCULLED, delta); > + return true; > + } > + > + if (type && folio_test_anon(folio) && folio_test_dirty(folio)) { > + success =3D lru_gen_del_folio(lruvec, folio, true); > + VM_BUG_ON_FOLIO(!success, folio); > + folio_set_swapbacked(folio); > + lruvec_add_folio_tail(lruvec, folio); > + return true; > + } > + > + if (tier > tier_idx) { > + int hist =3D lru_hist_from_seq(lrugen->min_seq[type]); > + > + gen =3D folio_inc_gen(lruvec, folio, false); > + list_move_tail(&folio->lru, &lrugen->lists[gen][type][zone]); > + > + WRITE_ONCE(lrugen->promoted[hist][type][tier - 1], > + lrugen->promoted[hist][type][tier - 1] + delta); > + __mod_lruvec_state(lruvec, WORKINGSET_ACTIVATE_BASE + type, delta); > + return true; > + } > + > + if (folio_test_locked(folio) || folio_test_writeback(folio) || > + (type && folio_test_dirty(folio))) { > + gen =3D folio_inc_gen(lruvec, folio, true); > + list_move(&folio->lru, &lrugen->lists[gen][type][zone]); > + return true; Make the cold dirty page cache younger instead of writeout in the backgro= ungd reclaimer context, and the question rising is if laundry is defered until= the flusher threads are waken up in the following patches. > + } > + > + return false; > +} Hillf