Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp930011lqd; Thu, 25 Apr 2024 00:29:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXY6juEcIlRlOyJaW+VHQEl/Q/0Ekiqx+yoh8jJLeZaRiytnkg3s4n4COfOlzIOt2uHipeQbo5WF+YCtCemtLzRxW5mRWJHhK+31wJRZw== X-Google-Smtp-Source: AGHT+IGpQAIiztOqwhpOMZ2a3sbx8RzskFWGNP479NVnb+6ethCBrgixRUIM/t0yBKB1q18fsjaK X-Received: by 2002:a9d:7e8a:0:b0:6eb:5b4a:867f with SMTP id m10-20020a9d7e8a000000b006eb5b4a867fmr5972377otp.22.1714030148882; Thu, 25 Apr 2024 00:29:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714030148; cv=pass; d=google.com; s=arc-20160816; b=kqcexPddMGkG/QE5O3/1EoAVCHrrzb1zeEgtLQcW2cLaYOLLE3MjaBl1Frv7XwkF1K hqKdhcrTbW+MvLGIaEzQMktwINsUlYtLJ9GlbkfsEkObJuw5F0yrJaBujKXy+uxxDJZm y/kFMcgKcVgmYT0lp9V+0GMiRIAk7VI0tY2IeFZ53ikamZg28IytCI5ZbuSvkmBnTBdp LRPRjdywlpWRgtM2PtlhoNidGiApvXAIbUTY1B948cdP9mqrDaSdU+C6oJs8SBiBXtUW BlEJXRnunCnBIaCK6IxIf5tyeEJp7WCy4dy82/Oj3pJ1GgxAxSLa0R60TJRh5E7AQH1o C+WQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=zxuVfL2Zyw6cKo0nF1CV5taOl0JsDHqcVQE/hlTCDsk=; fh=6yRnfpzSLHKiOq+/1ki9PYUfOe8xEebbZOLLCtPfNss=; b=vrxl7eQLm37/UEVtWh4V66cnWMDvMXjgoDInU2Mdds2qz00nAnGp4Z4fDvN2PRbkJ0 PMsWre29sojThgBBvl4qNQm37OK5vnz74Wk0P85jsJYS/WnE0calSlUJ9kCZKYEyxPwU b2n8eZFMOKYDgui02T6XB1AzK8iTyohuLcihd11zaZgoLJv5md/PnFqadq8DU/aCFdE0 c05Mv316c0u6/Zl2UT+ZB05dXxIw1afcMXGLhnpmM2aIjeMtMdSoUixVYLlC4o0csBla g1LaTmg4pd7kwOm9dFlqJ6hwQ75B+ysLkjyo5xgWW0LYw76Iau7HP1Fj+JejGwavcF5W f+9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=M7DTF6GB; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-158124-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158124-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u5-20020a634705000000b005dbd0ff2e5dsi13177217pga.811.2024.04.25.00.29.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 00:29:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158124-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=M7DTF6GB; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-158124-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158124-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6D430B22E22 for ; Thu, 25 Apr 2024 07:27:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 990576CDC8; Thu, 25 Apr 2024 07:27:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M7DTF6GB" Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B610134A8 for ; Thu, 25 Apr 2024 07:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714030064; cv=none; b=pgqfLRpJuHdU/2fj2CDxf9eWBXK5+r/hsj5OU37eRSBnx8PZtX8IQS0NsjZn1t7sAVX9aRQJXDSEmIovKjueRMYfSbXjDiCBHWcZG7RzxHxZAjHfn+xc3058RzDNkg9KvrjQIe9jhSqydul0A50XK2lUgkog1mzN30YRViQ3gJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714030064; c=relaxed/simple; bh=/QY7cLIc7OYA55brXdj7bScKa7WaRCG8YneMxeLduMs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ITEM4pcrE8xpkWHAor1bHI1n1mGUZNEmZ0M3iGzZGhQh4YVq8IeEFfrRvIiX4+02sDiKN5lTPRs+Kia/NRfIxBuy90QewsO3S1wBWcoXltlVzXmj5SzjZnDwZgO5Vh4irTFDiUmAqCHea0oCBGmQcnRb+CoIQgRLcu+XR8iS3eY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M7DTF6GB; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-572347c2ba8so611268a12.3 for ; Thu, 25 Apr 2024 00:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714030061; x=1714634861; darn=vger.kernel.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=zxuVfL2Zyw6cKo0nF1CV5taOl0JsDHqcVQE/hlTCDsk=; b=M7DTF6GB4NWCSHJ7ZP/WWsN/Rh9q3wptIFbeRNhkn+hqy4f4jMxXCtiL6Y5+cHOKHH JmzgSetGXWvjMA3UZLCc/WSs+TeiKGk4Vx+qxNFdenJhSQAJW8OaQzWyBH335xuZJSFv ZEHsiZwwMHMnR/+wDYuvQNfS1+q6Gd8XgEL/Rez19ZAuzgiPwRflVkTObpvQ2LIVX+s9 VMRNKpR4OVwW7esJNPiAPu6dKi/3CoPHZs9McKGpxBr8Brx21JGzItQ/GgKSa0YCSiXK 4UpINi2xlSlvwjAy3jzORCfcKEUtg3GNdl9FN7O7soe1NUlThgQjgeJFHwZ04dXJZPvw pW4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714030061; x=1714634861; 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=zxuVfL2Zyw6cKo0nF1CV5taOl0JsDHqcVQE/hlTCDsk=; b=bDDGIqnCYtk8KYDiYZo9NRK61azP8bnyELhWm69eCa/iIhLBOcm6ciMZihyyBdwRLO 2bi+OxqrInyHiMs38fCi5dGSrStUqtD28UHGur1C9CDm/oBFFUvBKujzPPABi2kzdfES EGNuQrmQkDh2JYFnzgWbKeJT+brNPWArIliAqXZu3aoFX5okF286lWisnpY0AXFOGNop CeHpTV4F3tAJJ1OLyIPwfvSCGhfauvqqhG9Baz0O26k9Lax9+p4EJJEjO4TSgwUUo5yo FYjHdYXJqE2VpUbsz4DHKgWsVs0Rj8sXPPuqZ7M9NPPoKVpS/LvOVporeb7nFXwAxupi QQyw== X-Forwarded-Encrypted: i=1; AJvYcCXqPqApBRimwEzvf5e/5+O98UBtb5lddAKCweX4YX9ebUpNkP13JFGWbvd5tkTGx/wSf9gtw1EOfKyQPPJGpgGVcohy6qSeGLoAQBuI X-Gm-Message-State: AOJu0YyPZxn+LMYEVnUL9SSNo1x4UEkxe3+zX8aK1QtvFbt+Y4syigH9 D6WK++XcIwTzdftjYpt1Xl5szqp4kAa2cK7FT1NzJlG/TtE7cBG0/XrehScR0v3tb95F52+s16U XMiRep1YLVo+GpUHGhHXrjHYOjoc= X-Received: by 2002:a50:8752:0:b0:56b:ec47:a846 with SMTP id 18-20020a508752000000b0056bec47a846mr2800988edv.25.1714030061009; Thu, 25 Apr 2024 00:27:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240424224614.477221-1-zi.yan@sent.com> <5e6bf4c6-c4a5-4be3-b203-ecc77ba4e5d9@redhat.com> In-Reply-To: <5e6bf4c6-c4a5-4be3-b203-ecc77ba4e5d9@redhat.com> From: Lance Yang Date: Thu, 25 Apr 2024 15:27:29 +0800 Message-ID: Subject: Re: [PATCH v3] mm/rmap: do not add fully unmapped large folio to deferred split list To: David Hildenbrand Cc: Zi Yan , linux-mm@kvack.org, Andrew Morton , "Matthew Wilcox (Oracle)" , Yang Shi , Ryan Roberts , Barry Song <21cnbao@gmail.com>, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 25, 2024 at 3:21=E2=80=AFPM David Hildenbrand wrote: > > On 25.04.24 05:45, Lance Yang wrote: > > Hey Zi, > > > > On Thu, Apr 25, 2024 at 6:46=E2=80=AFAM 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. It is possible that > >> the folio is unmapped fully, but it is unnecessary to add the folio > > > > Agreed. If a folio is fully unmapped, then that's unnecessary to add > > to the deferred split list. > > > >> to deferred split list at all. Fix it by checking folio->_nr_pages_map= ped > >> before adding a folio to deferred split list. If the folio is already > >> on the deferred split list, it will be skipped. This issue applies to > >> both PTE-mapped THP and mTHP. > >> > >> 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(). > >> However, this miscount was present even earlier due to implementation, > >> since PTEs are unmapped individually and first PTE unmapping adds the = THP > >> into the deferred split list. > >> > >> With commit b06dc281aa99 ("mm/rmap: introduce > >> folio_remove_rmap_[pte|ptes|pmd]()"), kernel is able to unmap PTE-mapp= ed > >> folios in one shot without causing the miscount, hence this patch. > >> > >> Signed-off-by: Zi Yan > >> Reviewed-by: Yang Shi > >> --- > >> mm/rmap.c | 7 ++++--- > >> 1 file changed, 4 insertions(+), 3 deletions(-) > >> > >> diff --git a/mm/rmap.c b/mm/rmap.c > >> index a7913a454028..2809348add7b 100644 > >> --- a/mm/rmap.c > >> +++ b/mm/rmap.c > >> @@ -1553,9 +1553,10 @@ static __always_inline void __folio_remove_rmap= (struct folio *folio, > >> * page of the folio is unmapped and at least one pag= e > >> * is still mapped. > >> */ > >> - if (folio_test_large(folio) && folio_test_anon(folio)) > >> - if (level =3D=3D RMAP_LEVEL_PTE || nr < nr_pmd= mapped) > >> - deferred_split_folio(folio); > >> + if (folio_test_large(folio) && folio_test_anon(folio) = && > >> + ((level =3D=3D RMAP_LEVEL_PTE && atomic_read(mappe= d)) || > >> + (level =3D=3D RMAP_LEVEL_PMD && nr < nr_pmdmapped= ))) > > > > Perhaps we only need to check the mapcount? > > > > IIUC, if a large folio that was PMD/PTE mapped is fully unmapped here, > > then folio_mapcount() will return 0. > > See discussion on v1. folio_large_mapcount() would achieve the same > without another folio_test_large() check, but in the context of this > patch it doesn't really matter. Got it. Thanks for pointing that out! I'll take a closer look at the discussion in v1. Thanks, Lance > > -- > Cheers, > > David / dhildenb >