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 9CDAFC369B1 for ; Wed, 16 Apr 2025 07:48:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76EC96B00CA; Wed, 16 Apr 2025 03:48:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71C616B00CB; Wed, 16 Apr 2025 03:48:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E5326B00CC; Wed, 16 Apr 2025 03:48:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 418DD6B00CA for ; Wed, 16 Apr 2025 03:48:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 555ED1601E4 for ; Wed, 16 Apr 2025 07:48:54 +0000 (UTC) X-FDA: 83339130588.20.BACE7FA Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by imf10.hostedemail.com (Postfix) with ESMTP id A1354C000E for ; Wed, 16 Apr 2025 07:48:52 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OeCuMA67; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.41 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744789732; a=rsa-sha256; cv=none; b=WA2uC+H1E6BvffbJhxK7u7KAqsKRR2n9BT1mBM6yW5YyyRosHhsJ7PcPGcZNIKYccBgd58 EI1ZfduD9OPaYpnPP3wE/JaiuDawvdxlzCi5tWw5vr/uWV7nFeFUFY580vJy7yxxuxQux3 W7OgPJRiMU343D3kfeSQD4TRY/G+Fao= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OeCuMA67; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.222.41 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744789732; 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=RyV7NSNEAVoyLMhl/ZYfvyA50ZgGTsXuVFPalj5U1c8=; b=Yz64FLQlciuSQaTgZUCaujSdnDVggCoJTnU+4VXEZsKGG//X9Elj3q4rkKoDzTw4iXS+63 1xA13iVH8tMdFTnAijAmti7GU8jRY9IbQvg0ivxOd+81Os2HphmvBw6BFL1Fx4H+lh3SpS S1Beo8wvnHhJxjZbOpUTRbng+mcBKvw= Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-86dc3482b3dso482761241.0 for ; Wed, 16 Apr 2025 00:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744789731; x=1745394531; 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=RyV7NSNEAVoyLMhl/ZYfvyA50ZgGTsXuVFPalj5U1c8=; b=OeCuMA674zR6xNys5+xUXYD2X5TA0OeFoKNuMfF0R4FyzOywuRLjazW+aWs5LeKeb+ yZmevYopC852NKvAGNgHozBLrfFjj6OFiMHjWit7u9njkiV2QA/XOzjrB5kMsd5doch3 HRzgE4b7sGs7xfqGPgQTkwsWEhp7RBvm+xhBZwR44Ep3WYHzI46lYUgFGif0SciaAwas Lb3b2jOpkqC7Lq4jMwERnX46wkfFgeO9ThYM7eWK5h/ZoHqEtOIVrT9QguvMRnKzo84J gJOFo1CIR61Wqluetia0byRy9+SYqx0SMVdrWsc/U+6584XrNVHetcG3eWhHoSEc7ITS ooLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744789731; x=1745394531; 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=RyV7NSNEAVoyLMhl/ZYfvyA50ZgGTsXuVFPalj5U1c8=; b=O8BMPpXoPQgh7KzU/5syPStSAAGsSA2Hl1oTsjXosC7HmZwXsWcNvccpmaGtopyut6 fdmi8uWAtRDeSLq3BXxltavDY4z4OtwwrEwcePHQqPHKd9q8JFTRVPBP8agPCVef5QkG S2QtOZTfvVCNvt17cKQ92KB4hkrKY/CKDVOZDH20yBQJ5jHbVS/tDqcNpw5lr5jvD80w VhOujGmBfFu3sLQ0keosN4vKXy+m/uNuBMsbU0YKi56bMJVqQtWoWuYCryK51NiN+Jze bqJgzRbkroakv5BseEuZ4kWMOm4S+gshqlFpqFlzyDT7CvRyK9Bj2RlYDdkx2WFRoBjP I/4w== X-Forwarded-Encrypted: i=1; AJvYcCXYqqcR4Ks9XBTw5C7bJnjNbzpS/Fbw1tsefF8VkK8jeRrky01tLyogbiPLHEzhZbcZvNhUf725CA==@kvack.org X-Gm-Message-State: AOJu0Yyrnmd0nA7AiiE9J3QX/pPlVsSgbhvLoOuX9quqerHm9BpPvPGM I++BnR1Zk7WUydGtD96nkocYw6kihZu+X+NfF8jPtcZExOMHTz8ybVebsDTAa9O+EpRFq4X0Ebw 4QNMr64ARz12Bu/c1Sv73kvElH7I= X-Gm-Gg: ASbGncvkJva7oPovxuv/4Mmb2CMw8EiYrpxzZxjRJ3NPATQKLch1Pgf5T/7+089eTU4 ZAKGXuqB40fICnTjBiXXGtF8C9HYmfc+o1Z7sMs7jmvkbmzuKdLSKls6xwijhz2DtFvOAR/dLiR 0QNzr+YgXA8GbwdRxaAEjZZw== X-Google-Smtp-Source: AGHT+IHJV5MIND7VjTur2PvUkLR7tbC0UWfpgC5/T6rBoCvXM9oiPQLPWmmLQgIyQdB+KzSfS0m8wEw7Rnf5i7m4woI= X-Received: by 2002:a05:6102:3101:b0:4c3:346:29ef with SMTP id ada2fe7eead31-4cb597d1cf8mr222369137.11.1744789731571; Wed, 16 Apr 2025 00:48:51 -0700 (PDT) MIME-Version: 1.0 References: <20250412085852.48524-1-21cnbao@gmail.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Wed, 16 Apr 2025 15:48:40 +0800 X-Gm-Features: ATxdqUEBfwrh1CuxGybuxs6d2Tz8XKF3y1m1Q4prVjmiNEfg70ItcMYK-EHHnjA Message-ID: Subject: Re: [RFC PATCH] mm: don't promote exclusive file folios of dying processes To: Zi Yan , Tangquan Zheng Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Baolin Wang , David Hildenbrand , Johannes Weiner , Matthew Wilcox , Oscar Salvador , Ryan Roberts Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: A1354C000E X-Stat-Signature: rkk4bwc94mof4byqioyo3531rcuddd3n X-Rspam-User: X-HE-Tag: 1744789732-333117 X-HE-Meta: U2FsdGVkX18FmLbZSBoMRQgD5IU5kKeUhxrOFMH9zZnmvim+ZlPZgHf4NqdHZnLQ7h2TvnXzHBljmWzmJYcZ5DdIypuNDwt7Mz2LG+Y3fzujgpsZ9KA21lQihkdoV8vGGfzjInM5C6RcdK8WRP0v53RrQgwoCKtg4Y2bp39sGm4EAkt6um/Fm6RC0EGq91DpvjdjaHBXWIJpELxDlc2zt21iLXWlz5+m+ywoyjnMX2RbZMO9ixyYkzHe0FMS4alSyq4nKTNZKGI/r4savtZDpoqrt1sFqbvSkrZKb4W+Z+f8RXK2NbVe+J1oGksJciXcpctbIRV7czilPnKZMMkmILYQidECzYhHe1c+yN0mqlhwtMp1iZ+uxW2L1j44bgM0fg0lGKgZFAEQGVVCMOe5EuF0Zax3Fx+evxXult7AbYGYuCPXduWJ9P8+UDEvXxamydC9dcqLhmVpFvKOuk5tQ7mV3Xr13m1hpv9tQp6cBjZO1359PyQhwpyKiIsqUXImp9L3nhByF0Mm8QQlhUEmzsGYuxDp2BCP1DBiMpqZailjefMZmcaOwaAGyKXoXUVP+1vcuSwTTiVgAiXjs68omszhJVcu8+TtuqUk99OLpXahV3BTVcpmX4TtzphyIdVulvzJXnflwpgZ5aARmwspViSsZbzrg3MrPXyslkpA1NAG5b0Js+B+OfLg6NKhHS6aSk+W5swfRXZVARG3YWoUFIttzXmaV/Z9WVtWrnuZx8pw3th2VTB4P5yCah8F75GlRWTIYVxCdu5+j/IokEdnhWSAIansQU1wqIOXzuqOhNErWFUfKEAvC8O4ssURd6avrwide+prRRNO3KzoCy0f1khRjmsac6zbFKuRVyvt/eFtoU8+3GgcrdXpkikLnOusOU0ZZ3XQp5dk4SrBFQXRnXUX/46H6XnI2PaldQIQvjK74f/m6BaxnNDHPjUEwqsMi9F9GDQmc1w= 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 Sun, Apr 13, 2025 at 12:31=E2=80=AFAM Zi Yan wrote: > > On 12 Apr 2025, at 4:58, Barry Song wrote: > > > From: Barry Song > > > > Promoting exclusive file folios of a dying process is unnecessary and > > harmful. For example, while Firefox is killed and LibreOffice is > > launched, activating Firefox's young file-backed folios makes it > > harder to reclaim memory that LibreOffice doesn't use at all. > > > > An exiting process is unlikely to be restarted right away=E2=80=94it's > > either terminated by the user or killed by the OOM handler. > > The proposal looks reasonable to me. Do you have any performance number > about the improvement? Tangquan ran the test on Android phones and saw 3% improvement on refault/thrashing things: w/o patch w/pa= tch workingset_refault_anon 2215933 2146602 3.13% workingset_refault_file 9859208 9646518 2.16% pswpin 2411086 2337790 = 3.04% pswpout 6482838 6264865 3= .36% A further demotion of exclusive file folios can improvement more, but might be controversial. it could be a separate patch later. > > > > > Cc: Baolin Wang > > Cc: David Hildenbrand > > Cc: Johannes Weiner > > Cc: Matthew Wilcox (Oracle) > > Cc: Oscar Salvador > > Cc: Ryan Roberts > > Cc: Zi Yan > > Signed-off-by: Barry Song > > --- > > mm/huge_memory.c | 4 ++-- > > mm/internal.h | 19 +++++++++++++++++++ > > mm/memory.c | 9 ++++++++- > > 3 files changed, 29 insertions(+), 3 deletions(-) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index e97a97586478..05b83d2fcbb6 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -2264,8 +2264,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct v= m_area_struct *vma, > > * Use flush_needed to indicate whether the PMD e= ntry > > * is present, instead of checking pmd_present() = again. > > */ > > - if (flush_needed && pmd_young(orig_pmd) && > > - likely(vma_has_recency(vma))) > > + if (!exclusive_folio_of_dying_process(folio, vma)= && flush_needed && > > + pmd_young(orig_pmd) && likely(vma_has_recency= (vma))) > > folio_mark_accessed(folio); > > } > > > > diff --git a/mm/internal.h b/mm/internal.h > > index 4e0ea83aaf1c..666de96a293d 100644 > > --- a/mm/internal.h > > +++ b/mm/internal.h > > @@ -11,6 +11,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -130,6 +131,24 @@ static inline int folio_nr_pages_mapped(const stru= ct folio *folio) > > return atomic_read(&folio->_nr_pages_mapped) & FOLIO_PAGES_MAPPED= ; > > } > > > > +/* > > + * Return true if a folio is exclusive and belongs to an exiting or > > + * oom-reaped process; otherwise, return false. > > + */ > > +static inline bool exclusive_folio_of_dying_process(struct folio *foli= o, > > + struct vm_area_struct *vma) > > +{ > > + if (folio_maybe_mapped_shared(folio)) > > + return false; > > + > > + if (!atomic_read(&vma->vm_mm->mm_users)) > > + return true; > > + if (check_stable_address_space(vma->vm_mm)) > > + return true; > > + > > + return false; > > +} > > + > > /* > > * Retrieve the first entry of a folio based on a provided entry withi= n the > > * folio. We cannot rely on folio->swap as there is no guarantee that = it has > > diff --git a/mm/memory.c b/mm/memory.c > > index b9e8443aaa86..cab69275e473 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -1515,7 +1515,14 @@ static __always_inline void zap_present_folio_pt= es(struct mmu_gather *tlb, > > *force_flush =3D true; > > } > > } > > - if (pte_young(ptent) && likely(vma_has_recency(vma))) > > + > > + /* > > + * Skip marking exclusive file folios as accessed for pro= cesses that are > > + * exiting or have been reaped due to OOM. This prevents = unnecessary > > + * promotion of folios that won't benefit the new process= being launched. > > + */ > > + if (!exclusive_folio_of_dying_process(folio, vma) && pte_= young(ptent) && > > + likely(vma_has_recency(vma))) > > folio_mark_accessed(folio); > > rss[mm_counter(folio)] -=3D nr; > > } else { > > -- > > 2.39.3 (Apple Git-146) > > > -- > Best Regards, > Yan, Zi Thanks Barry