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 CC271E7716D for ; Wed, 4 Dec 2024 10:37:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B9746B0088; Wed, 4 Dec 2024 05:37:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 442E06B0089; Wed, 4 Dec 2024 05:37:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BBAE6B008A; Wed, 4 Dec 2024 05:37:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0A1E76B0088 for ; Wed, 4 Dec 2024 05:37:29 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B253D8072C for ; Wed, 4 Dec 2024 10:37:28 +0000 (UTC) X-FDA: 82856924430.13.485DDF8 Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) by imf20.hostedemail.com (Postfix) with ESMTP id 73F1C1C0002 for ; Wed, 4 Dec 2024 10:37:11 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ArLSpwHc; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.177 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733308637; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IZbxezCA1GDh5/tCHGYe+MRSelgs1h7TrsEnWijG4Y0=; b=S24UHfyVQcYXdA+H3tO/bC0Lb5iuuTPxq23sXse9jVEpF73H/unJZHqn76ibJsmGJt1jcV bvbwfcbJWzlwJ2QpH+7ID763Y79imgGlY+HOU7FLh4YcUXiytNxCPKEyFNil9j4otCMaKk bpZ+vUuiLsDiY8yAeRQixo5lI8bHQbQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733308637; a=rsa-sha256; cv=none; b=C2xaJlyYwgWEf7yQpQNw95toRrayvQer9NDJc5JnUFzhMx+BgfMgsV/2mYwaLDqg1OY1JV 0Ief8FIuRr3AiX019w50fBhVn1w557u0cupMHsy+z4SZ7NLjkuyG5WPKu7siYb40L6xVm3 u+nNF13vho0QXa5gfJxhefAF2EBJn/I= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ArLSpwHc; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.221.177 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-51511a1bd53so1466057e0c.1 for ; Wed, 04 Dec 2024 02:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733308646; x=1733913446; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IZbxezCA1GDh5/tCHGYe+MRSelgs1h7TrsEnWijG4Y0=; b=ArLSpwHcuR2PN79aCvL3LBxfOcefE+1+akQIJFOHL63u2QL9H6EDk/uj0hIhyjDCns 6q2MjK8+kky1FFRL1OHyFxPHwdS3bDkYKUXm2VBE4584lu4SWQBVhcb0uN71VK43eu5X Onb+xNF2HiiSYIitDd+imTxc0F9O1WmpWJSW92J7JKb9h/UqlD67w7jYE0QN9kbaTsni D6sYAB80ahbXtFKCTByOiCWDB24YvTNTkEiD54DFYstBHdT06nzPIGsJCil8QegGyhIr +XYcNE8khXhJ8z40+4VHiQEJOr3V/r59JfCB0+2wWe6nQWFlAiTSPN9/DFSQzvggQvEH ECDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733308646; x=1733913446; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IZbxezCA1GDh5/tCHGYe+MRSelgs1h7TrsEnWijG4Y0=; b=vB/Qry+TYp8i95Xl0oVFDKodXt9acjzho2S3YupxXu0DZepGpwb+gjaptv8P/pe1Cz Byqbkx7z6MuHULBsXTJvb8rggoF/fn3UikAdZ2Znhqy8gAgBH/szW6wo025J9qqV/3zF DcRETP0Xuj83ax+nB5fsgcg5H3az18inXyNKFlzV4w1ANKhPqxKK2nIhlz6rYJuxfQcy CL6SYU3BgwBOm7Rm2k+co+LDr/o7IvIxFZ/sk67FBUigA1RHxxSbTzLpWvYU99/VJHgD MjXHIFKjX3FIrvB6BbjnaonKewBCRrbFOqwc472asidsiZ+ka4Y3FVo3rhSt9tRdinqC uOjw== X-Forwarded-Encrypted: i=1; AJvYcCWLkDXkYs+ppdvPF5VBL3ODeWYN02G5yEbrvnicy/oysx1vncAaaBcaYpZ2BtoqneFQ1vl5I0+0Ug==@kvack.org X-Gm-Message-State: AOJu0YwJ7BtJGahYUTkTw3HBRiKn2EOx7GeFrhPtwATw/NkFS4tqkZna pis80cDfpO20TXxxsKFeU6UWOY9DWSuDICHtcW3pHJMUWo4M2ZJMOW0h4LD9Zhao86UHJ2TPlnx 6itkPPpDpoh3MByQxb5MYmzq1fvk= X-Gm-Gg: ASbGncvKG8zpA1DTDJy+TJNpTC6qzgZ+idBdeNW+8EpttUP57wxLLwGJICLDYtW5iC4 DX3VbTyuThNLhO0vgsutwgWGPL2R6QeuMG6AfxMnuF5GrijqWosqOOipJTJB4EzjB X-Google-Smtp-Source: AGHT+IHynhX/MX8+WVPjQua2f8a9Inty5yJv/GwXFtGCCbN7HirfTPNz/j5lLcj3e1kdQQopvdnQpiUTWAIhbC53AWA= X-Received: by 2002:a05:6122:21a5:b0:515:3bfb:d4d0 with SMTP id 71dfb90a1353d-515bf29dda6mr7446680e0c.1.1733308645997; Wed, 04 Dec 2024 02:37:25 -0800 (PST) MIME-Version: 1.0 References: <20241204040158.2768519-1-chenridong@huaweicloud.com> <20241204040158.2768519-2-chenridong@huaweicloud.com> In-Reply-To: <20241204040158.2768519-2-chenridong@huaweicloud.com> From: Barry Song <21cnbao@gmail.com> Date: Wed, 4 Dec 2024 23:37:15 +1300 Message-ID: Subject: Re: [RFC PATCH v3 1/2] mm: vmascan: add find_folios_written_back() helper To: Chen Ridong Cc: akpm@linux-foundation.org, mhocko@suse.com, hannes@cmpxchg.org, yosryahmed@google.com, yuzhao@google.com, david@redhat.com, willy@infradead.org, ryan.roberts@arm.com, wangkefeng.wang@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chenridong@huawei.com, wangweiyang2@huawei.com, xieym_ict@hotmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 73F1C1C0002 X-Stat-Signature: 6hu65qroj43mf9fdt41bokadfneez8ax X-Rspam-User: X-HE-Tag: 1733308631-849802 X-HE-Meta: U2FsdGVkX1+KFo7OaMy/ieIaX6KldOYJlBPACbtWjYa9wwMtsK9FU90DLd8zdcXAI6QlhQXmj1lr6DjNtBawWampep3ZCuX4H86e7WkNsj1AH/430flR/GRzPkb/dfE1xHhum57F0CDCjwmF3fC+z0qJjtNbmBhO8LFOOYr4X20gg4a4k5Hl/Ai6GHdcmtf7IBTMEEjFgbS89lLmPx3g+xr5y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44FS+v+3q7oFmP51G5yTOpZuRaWWh3sOrBatKPd0LcD19UyeK40Yevnrvr5vIG8nkgvxZap6Sr4ZwYGjfSoQv3jmjSr/tJfKUEtfWrr5C4OgK0SlW 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: List-Subscribe: List-Unsubscribe: On Wed, Dec 4, 2024 at 5:11=E2=80=AFPM Chen Ridong wrote: > > From: Chen Ridong > > Add find_folios_written_back() helper, which will be called in the > shrink_inactive_list function in subsequent patch. This is not about adding a helper but rather extracting a function that can be used by both lru_gen and the traditional active/inactive LRU. Making it a separate patch may not be ideal, as it isn=E2=80=99t an external function that warrants special attention. Combining patch 1 and patch 2 into a single patch creates a more cohesive a= nd logical flow, making it easier to review. > > Signed-off-by: Chen Ridong > --- > mm/vmscan.c | 73 +++++++++++++++++++++++++++++++---------------------- > 1 file changed, 43 insertions(+), 30 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 76378bc257e3..af1ff76f83e7 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -283,6 +283,48 @@ static void set_task_reclaim_state(struct task_struc= t *task, > task->reclaim_state =3D rs; > } > > +/** > + * find_folios_written_back - Find and move the written back folios to a= new list. > + * @list: filios list > + * @clean: the written back folios list > + * @skip: whether skip to move the written back folios to clean list. > + */ > +static inline void find_folios_written_back(struct list_head *list, > + struct list_head *clean, bool skip) > +{ > + struct folio *folio; > + struct folio *next; > + > + list_for_each_entry_safe_reverse(folio, next, list, lru) { > + if (!folio_evictable(folio)) { > + list_del(&folio->lru); > + folio_putback_lru(folio); > + continue; > + } > + > + if (folio_test_reclaim(folio) && > + (folio_test_dirty(folio) || folio_test_writeback(foli= o))) { > + /* restore LRU_REFS_FLAGS cleared by isolate_foli= o() */ > + if (lru_gen_enabled() && folio_test_workingset(fo= lio)) > + folio_set_referenced(folio); > + continue; > + } > + > + if (skip || folio_test_active(folio) || folio_test_refere= nced(folio) || > + folio_mapped(folio) || folio_test_locked(folio) || > + folio_test_dirty(folio) || folio_test_writeback(folio= )) { > + /* don't add rejected folios to the oldest genera= tion */ > + if (lru_gen_enabled()) > + set_mask_bits(&folio->flags, LRU_REFS_MAS= K | LRU_REFS_FLAGS, > + BIT(PG_active)); > + continue; > + } > + > + /* retry folios that may have missed folio_rotate_reclaim= able() */ > + list_move(&folio->lru, clean); > + } > +} > + > /* > * flush_reclaim_state(): add pages reclaimed outside of LRU-based recla= im to > * scan_control->nr_reclaimed. > @@ -4567,8 +4609,6 @@ static int evict_folios(struct lruvec *lruvec, stru= ct scan_control *sc, int swap > int reclaimed; > LIST_HEAD(list); > LIST_HEAD(clean); > - struct folio *folio; > - struct folio *next; > enum vm_event_item item; > struct reclaim_stat stat; > struct lru_gen_mm_walk *walk; > @@ -4597,34 +4637,7 @@ static int evict_folios(struct lruvec *lruvec, str= uct scan_control *sc, int swap > scanned, reclaimed, &stat, sc->priority, > type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); > > - list_for_each_entry_safe_reverse(folio, next, &list, lru) { > - if (!folio_evictable(folio)) { > - list_del(&folio->lru); > - folio_putback_lru(folio); > - continue; > - } > - > - if (folio_test_reclaim(folio) && > - (folio_test_dirty(folio) || folio_test_writeback(foli= o))) { > - /* restore LRU_REFS_FLAGS cleared by isolate_foli= o() */ > - if (folio_test_workingset(folio)) > - folio_set_referenced(folio); > - continue; > - } > - > - if (skip_retry || folio_test_active(folio) || folio_test_= referenced(folio) || > - folio_mapped(folio) || folio_test_locked(folio) || > - folio_test_dirty(folio) || folio_test_writeback(folio= )) { > - /* don't add rejected folios to the oldest genera= tion */ > - set_mask_bits(&folio->flags, LRU_REFS_MASK | LRU_= REFS_FLAGS, > - BIT(PG_active)); > - continue; > - } > - > - /* retry folios that may have missed folio_rotate_reclaim= able() */ > - list_move(&folio->lru, &clean); > - } > - > + find_folios_written_back(&list, &clean, skip_retry); > spin_lock_irq(&lruvec->lru_lock); > > move_folios_to_lru(lruvec, &list); > -- > 2.34.1 > Thanks Barry