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 421B4C4345F for ; Sat, 27 Apr 2024 09:32:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FB8D6B0082; Sat, 27 Apr 2024 05:32:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AAD56B0085; Sat, 27 Apr 2024 05:32:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89A236B0087; Sat, 27 Apr 2024 05:32:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6C5936B0082 for ; Sat, 27 Apr 2024 05:32:21 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D222D120A0D for ; Sat, 27 Apr 2024 09:32:20 +0000 (UTC) X-FDA: 82054796040.29.2567855 Received: from mail-vs1-f41.google.com (mail-vs1-f41.google.com [209.85.217.41]) by imf03.hostedemail.com (Postfix) with ESMTP id 381052001B for ; Sat, 27 Apr 2024 09:32:19 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PHeYilxY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.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=1714210339; 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=miy8rObJQOFD7a6RxpdDR5fplId/ZmKxfdplFT7AJPU=; b=PyDiuK0YTHlJRlG5RdHmvFDMAPZcSKn4UfIeXJnCGQQ4Q8V+PfxhAItjGxvof2zvYc3HCW bGO97fWcY7uD+nsfdTyAwy+8wxjHfRIZ5FfZ5UUt9sFAjoZbNbfEFq1odPiTFTylR1Up8D hOKih1Qgnt5nuWC4sTlVAzyPGmMd0EA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PHeYilxY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.41 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714210339; a=rsa-sha256; cv=none; b=0tOThp0Ycj2PP0YYE9WFYDNDm3gRm3cVMYfOuG2SmkZX5Mmj03bMXVDT8J93ocTVsy/+m3 RAd21Pyq2cb9+X/b7ArTachFS5Wp3dQdZrYJi2BEQ1oBVK/yGD/nTqtWJ9vg7JNYvyegN1 Z+blpTUxSWV1fq7Egh0oqb6IpuK6TxM= Received: by mail-vs1-f41.google.com with SMTP id ada2fe7eead31-47c0d9bc65aso1157792137.3 for ; Sat, 27 Apr 2024 02:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714210338; x=1714815138; 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=miy8rObJQOFD7a6RxpdDR5fplId/ZmKxfdplFT7AJPU=; b=PHeYilxYACSdLoqbj1GlziWPmHMv0c6/g54gUE7MDfnPAoC15qJ9RZxwsg8haRmANl YELPsGauz/HJqdwh/EhXoTGweh32FA+NO2iyh3XU+NdRNjbuvkaWsaC8ogmtkSpFC3DT Snr4dbRCTY27KSzvzgnVsjZJDFiJOY8+nYmQyp6w4aGmlbH3UO3Bb6P7R11KkF63p2Ya claXwO4Yz3BoXbYFxw5oEzcVGl8piFTfgrqYAdt1PxE4hpA7AtGJNT9zk8X8yF0f5jIW LRBgfLPafIPMHD1lnq3O2pl4Ha9nP7odERZikUN/2Z1E9vQoxZmd+tAQDt1MHqRESiB+ 1U2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714210338; x=1714815138; 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=miy8rObJQOFD7a6RxpdDR5fplId/ZmKxfdplFT7AJPU=; b=YJ/sbYn9i+YRf+1JGAQwu205mHkZMYfnfzrt2igLLvrsvsZW1Hlg3xlkXet52OAO6m UYuf9yTwpEDkTJhsW7h/wyZm1gg8tMScS6uP8Nnt9Jgd+Li+Mcdvt014pD5xz2MCsFXe HNHg5zbOWNBGB04BYVIF8nvfSS5nrKqiG+Gw2LyJa8OJgEYQcTwgY28UyICbmZ7cuL6c PEzPtLddyTZQZXA4en0T6kobfIi638EaGhsAskTLyZYw3BIOyPxqzs6qa2TABVYis4K0 9cQzTlo+SHUA+FEhQ24hKODwmz3f31CJM036tpTAPi8EHABKPNF/JyWhmD71mm14V4KW CdyQ== X-Forwarded-Encrypted: i=1; AJvYcCWzi2fasDP1SwG7srFkIDtVRjQzPRckwtVyijpahju8FMJzGBjXwcwCWthRY6qdVm6gkbQ2i4263MXyZ/GCMgvYp9U= X-Gm-Message-State: AOJu0YyzR2eFHDgGrZIQ/sRi3jichXUzlUz8ze0T142yi83LWPFWOErM ejyeo8QeSrQCU+nsBmTjDkcfv4LN8l/pX3ffQey5itVfNYwa02dDtySbdkJIqK7EIIhcGmlli9v YgYoCIxbzyBsEapiliiQ9o5czVME= X-Google-Smtp-Source: AGHT+IGI2EMELholAHRxu2R2Fs8lKaa4cJMxVhzg55OuCrkk7HwFt7DoLKSdDNYH6JZpirbIOCLkUu38yY2kccbCpOs= X-Received: by 2002:a67:e947:0:b0:47b:c614:8bd8 with SMTP id p7-20020a67e947000000b0047bc6148bd8mr5664441vso.12.1714210336722; Sat, 27 Apr 2024 02:32:16 -0700 (PDT) MIME-Version: 1.0 References: <20240426190253.541419-1-zi.yan@sent.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Sat, 27 Apr 2024 17:32:04 +0800 Message-ID: Subject: Re: [PATCH v5] mm/rmap: do not add fully unmapped large folio to deferred split list To: Zi Yan Cc: David Hildenbrand , Andrew Morton , linux-mm@kvack.org, "Matthew Wilcox (Oracle)" , Yang Shi , Ryan Roberts , Lance Yang , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 381052001B X-Stat-Signature: qkn1fxne6kx4dq8dnow7y33gpoxrangp X-Rspam-User: X-HE-Tag: 1714210339-746245 X-HE-Meta: U2FsdGVkX18DF4cPFUkpvzVhXc5K3vx+NmUFT0Jb9h+LbPZwVh/CMytQxArfXzjUtLxJUfOqa/P36OKHYr4gwxXZE1hSHkMNQ3QDXjDCp6+hs0Xv4MXO+hsDnVdRxmZ9g5NiGEUdMQr4q6hfoA+tFBwNScZMQVI+S4TiBNeVybT9Z1ADJ40bZefH4pefzAEKWoi87PYXFJylNzHH02pOMQuSJ14icxnKUL082+2s+q9tB8yqJm5YUaCFizx2OxnSi7CH/yPKyuycwyH/SWOz/Kj4MC2JvQhW5vPL/O5nh+z8mL7/NgPp28GfEkUS2OROgGmbr2IiTg+bWlstqVgpgEbV0JrEqBU/7AAY4thmpjgDYM9voPgwDBFiQwLkwgsBl1CU+w3JHdg7XzwxgyFcBj7zBs52Jh/9kSDw2XI/9641HVTLMVsIfw1VkC52TIyE47BOGpIdSUmmBbGEjlAXDKxANSlDQp1y1ZxWGJLWmLOu4OYl9+jG++7ZHsCCF3i72nRedM1YvWynXYqZYikT46+ZQXGl6N6FD//sS4WHYp2LbLHnH09UVlD2h/290UDQ6s4XD8NhX2hyk8/habTIPxV1brYdauKjJt99O5jK+nAuUg5Z/KASLUBW0/pIGYcwUKK3OkFF+Y5pNol5+sa1aVHWo+/nnqQDh13upg4c7gFXQ1axeN1flcxcbLn52v+2NXUsZmDNuPcgE11Jh0QDhMfRbbbPUWf+dPrktyhCFu+Lm/yxeeYG1G9mO+rPuNhq0FfF4j7RiFDdeueqCH/o4IbD4qoskqD8y9nHY5Z4QkS0TAyOOoFsSJF1hPxZb1g/iUwdE8l46ykpG/cghzwSCs0M1CXysnhr/1HqVE2r143Othcg2/5pBnShkoftBsy8JJv6+8hQJdGIGY1nmYHgoivG7uL0ieeMGHd7zMdZzBt2qVGzm2D1ckJoFUTQI6IQm/VJ95JwD24XxDN4hEY ZUrfnbUi ccMzgAE5sbhoJPU/1/vjcNXm6VEZMaq6OGt1X 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 Sat, Apr 27, 2024 at 3:20=E2=80=AFAM Zi Yan wrote: > > On 26 Apr 2024, at 15:08, David Hildenbrand wrote: > > > On 26.04.24 21:02, Zi Yan wrote: > >> From: Zi Yan > >> > >> In __folio_remove_rmap(), a large folio is added to deferred split lis= t > >> if any page in a folio loses its final mapping. But it is possible tha= t > >> the folio is fully unmapped and adding it to deferred split list is > >> unnecessary. > >> > >> For PMD-mapped THPs, that was not really an issue, because removing th= e > >> last PMD mapping in the absence of PTE mappings would not have added t= he > >> folio to the deferred split queue. > >> > >> However, for PTE-mapped THPs, which are now more prominent due to mTHP= , > >> they are always added to the deferred split queue. One side effect > >> is that the THP_DEFERRED_SPLIT_PAGE stat for a PTE-mapped folio can be > >> unintentionally increased, making it look like there are many partiall= y > >> mapped folios -- although the whole folio is fully unmapped stepwise. > >> > >> Core-mm now tries batch-unmapping consecutive PTEs of PTE-mapped THPs > >> where possible starting from commit b06dc281aa99 ("mm/rmap: introduce > >> folio_remove_rmap_[pte|ptes|pmd]()"). When it happens, a whole PTE-map= ped > >> folio is unmapped in one go and can avoid being added to deferred spli= t > >> list, reducing the THP_DEFERRED_SPLIT_PAGE noise. But there will still= be > >> noise when we cannot batch-unmap a complete PTE-mapped folio in one go > >> -- or where this type of batching is not implemented yet, e.g., migrat= ion. > >> > >> To avoid the unnecessary addition, folio->_nr_pages_mapped is checked > >> to tell if the whole folio is unmapped. If the folio is already on > >> deferred split list, it will be skipped, too. > >> > >> Note: commit 98046944a159 ("mm: huge_memory: add the missing > >> folio_test_pmd_mappable() for THP split statistics") tried to exclude > >> mTHP deferred split stats from THP_DEFERRED_SPLIT_PAGE, but it does no= t > >> fix the above issue. A fully unmapped PTE-mapped order-9 THP was still > >> added to deferred split list and counted as THP_DEFERRED_SPLIT_PAGE, > >> since nr is 512 (non zero), level is RMAP_LEVEL_PTE, and inside > >> deferred_split_folio() the order-9 folio is folio_test_pmd_mappable(). > >> > >> Suggested-by: David Hildenbrand > >> Signed-off-by: Zi Yan > >> --- > >> mm/rmap.c | 12 +++++++++--- > >> 1 file changed, 9 insertions(+), 3 deletions(-) > >> > >> diff --git a/mm/rmap.c b/mm/rmap.c > >> index 2608c40dffad..a9bd64ebdd9a 100644 > >> --- a/mm/rmap.c > >> +++ b/mm/rmap.c > >> @@ -1495,6 +1495,7 @@ static __always_inline void __folio_remove_rmap(= struct folio *folio, > >> { > >> atomic_t *mapped =3D &folio->_nr_pages_mapped; > >> int last, nr =3D 0, nr_pmdmapped =3D 0; > >> + bool partially_mapped =3D false; > >> enum node_stat_item idx; > >> __folio_rmap_sanity_checks(folio, page, nr_pages, level); > >> @@ -1515,6 +1516,8 @@ static __always_inline void __folio_remove_rmap(= struct folio *folio, > >> nr++; > >> } > >> } while (page++, --nr_pages > 0); > >> + > >> + partially_mapped =3D !!nr && !!atomic_read(mapped); > > > > Nit: The && should remove the need for both !!. > > My impression was that !! is needed to convert from int to bool and I do > find "!!int && !!int" use in the kernel. If this is unnecessary, Andrew > can apply the fixup below. I can send a new version if it is really neede= d. > > diff --git a/mm/rmap.c b/mm/rmap.c > index a9bd64ebdd9a..c1fd5828409b 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1517,7 +1517,7 @@ static __always_inline void __folio_remove_rmap(str= uct folio *folio, > } > } while (page++, --nr_pages > 0); > > - partially_mapped =3D !!nr && !!atomic_read(mapped); > + partially_mapped =3D nr && atomic_read(mapped Reviewed-by=EF=BC=9ABarry Song > break; > case RMAP_LEVEL_PMD: > atomic_dec(&folio->_large_mapcount); > > > > > Reviewed-by: David Hildenbrand > > Thanks. > > -- > Best Regards, > Yan, Zi