Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp847423lqd; Wed, 24 Apr 2024 20:46:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUo8UQmjOvgDCjN7BHCeLMtd5xVaMa+jr7n2N6MEul1WWlWAs1NFQ5o2UFDIp7JR8XmJ3HIYumL3muX7U/hcK5pAlFd+/v34e9iLSptlQ== X-Google-Smtp-Source: AGHT+IEZjSNmFAZNbnoBAkxCl2Y42UbLXSeK2Cf809BNDT76XMvP6prhthyH+H1ZfNYm4nRd9YKG X-Received: by 2002:a17:902:8d8d:b0:1e2:a467:1b6b with SMTP id v13-20020a1709028d8d00b001e2a4671b6bmr4131013plo.16.1714016760667; Wed, 24 Apr 2024 20:46:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714016760; cv=pass; d=google.com; s=arc-20160816; b=eIwu76H9+9noMdDa0e0eEmxwnug5KXj9lEC4AUkVUk+7UBNwXIXi9v8FkCrRStOklX yPuggks/d/KW5SPBriW6K+rKg4+/QPIDsYrsgiowOmAB3zdxsVg9Z1SpHFI+KlUik4C9 GZAvrVUBYbwpQ3/zE6Njk7/sG2asvlvz6+OJre5lEXo/6SIpGWAmRVH6mAnnzOVf8rJc MILc59Ks5xaGFqQCFGN9fnDDoIqmQ8u6BWN6jcqxfqvZpWSzeBpGlyTqJnsbmuKU9B/D sBy43+SWQM3R+K+lhzq+3Pyn+JxQWqS7IN/uRCbLGkEcLPTng5NbxbeJA/GZV/F4UKvf gYYQ== 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=CYp/Zt/Vz1rh4t2A6hBeOpmR/pnEahF8TAkSRflBIyQ=; fh=owARRgEZGQ4JAAo+mgBAGNoDkHWpJfC1ZJ8VoAyiurM=; b=iwQwhqJntC3IeRkgx5ga7GPKOgdARacLm0/hC4tJtk+v6UBwCBr9WQnLbpOkZARlcQ GrsHpb++CudXpBIPwIEOg/Q0xFeZ2AtX/G4BqlGc79z/FvURzSUquon+8Z8Ces6vGhFU D8AhNTORKj1Ev32yXD1QCRUXTuNf+t+ioEbyqUm2Iru5OlL5P/hx8UwKoE7Nv2A94ITi adVn7b0JGU6YWIRGRQZhU0V2cnxt0vQmQihkLxnA7UASEbs4TRWHl08dtziOW8ofN8EI TBhyl78zOXvd0iKq6dQr1xcJCghEpOvHn5wssjSBqdA3RTies46+7GS/0SXjQGYcHXrE OM/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Ux/vNoVH"; 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-157977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157977-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 x9-20020a170902ec8900b001e9058495e5si9709363plg.498.2024.04.24.20.46.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 20:46:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157977-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="Ux/vNoVH"; 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-157977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157977-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 17178B23977 for ; Thu, 25 Apr 2024 03:45:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 098BE2940B; Thu, 25 Apr 2024 03:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ux/vNoVH" Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.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 90571199BC for ; Thu, 25 Apr 2024 03:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714016748; cv=none; b=P/J3D/zr+4cfKsVUd8jcH17lT50CtB7kzq92xLJj8KUqo+viTuYW6s+swpCY0Vs8FMEAEBd3K+KMy1saLUq4PDnIK2J8pcqkYWH4Ajk9Aqi34RTriJkV1QuYO8gEG/qyBETlCry9vxxXKx9BuS8wYnkzNygw8/Xgd4wNAHqX1As= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714016748; c=relaxed/simple; bh=3wiy6p6CNyk/Ga/V/ig0sSA3z9IL32moAG77P03rwN0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=QDTBut8a+CEd7J94q0hXEgEkcxwXFu14jnRRAfydp9DYzDQNqkQ27r75FoktJoj4cmEiwUrhPB5eZKm2MUlxYkbIc/c6nzb9XBVyx5SYw6l9/g8DKk8QzYEy6Oj/zA8weKoUSImiUvUveXDiSDjSXrT9uETW6XzIXu/VxW/tKEY= 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=Ux/vNoVH; arc=none smtp.client-ip=209.85.128.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-wm1-f48.google.com with SMTP id 5b1f17b1804b1-41b4ff36277so432705e9.1 for ; Wed, 24 Apr 2024 20:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714016745; x=1714621545; 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=CYp/Zt/Vz1rh4t2A6hBeOpmR/pnEahF8TAkSRflBIyQ=; b=Ux/vNoVHA82hgtWdit1g3grnSFuVpLnGXII7TfMjDGg4ZmQYeL19j33jsOe/cas9Oz JodW9oFvw6RBk3c8614xEUZ6xZPO2SPbNIH7d9deS9O43GehK1wCHj1D2giZ9YcSNL91 V/mEG5ZWfYDXFghhUfEhiVo+s+OMd17KOiEKg/GwCCtb/f4aLqnqRqgqs1UBDWDswlXB NIbfcOaejZ87e1IrjXrieUh3Aa07UixymbhIJz97dzddBr8Vrx8R0xjYUu/PXK1MFv3Y DewJznUfO59551kspfRnIpSe4nuU5yjDeqmFscvpTtNuTPwCgYEz0n0zqgREGuMZdeKQ FiIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714016745; x=1714621545; 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=CYp/Zt/Vz1rh4t2A6hBeOpmR/pnEahF8TAkSRflBIyQ=; b=DfuN+XRmMtWK7apuU3v8dEROnLkwujlIzc5km60OpkeMpEOoVDO+AN9SE9WpggCCk1 my7rrd3Qk/Gj8HQ0WoITWFoe9TQLE6CBXuu2t8mATHUrqknnH8aU4LIm8fKeUAqCAqvd pfbE7vYzPClJffD3q52pgs3NZw5DWop13c00FsjjdTazAfBPn3EBZaRmVju/a9noU8gZ FK522AiiwD5g6DmsZFuHIVztX7hCxpC3dKNJA7iuIVzXa2BsNX6VVhWxsZiqhjAUqRDx XW9Df7tLWsDA05q8997Cso1vE3c9/SuLEe7vchkCeDzXyVUWNnYIKLLNHh6xMWKDFdaW PzbA== X-Forwarded-Encrypted: i=1; AJvYcCVSOYLWAckjRQQMw0IvmtBbcq81rn2zrkKTSQGvIBRL4DM30FnM5SRA+VzV8Y1F5wcyS7MwMh7z3VcPBlhtvVlwraXaVz3GWMIMyUOX X-Gm-Message-State: AOJu0Yzd07P9W1Mgkb3RmEsuN14yNUP8Gw6TOJcMi9MVB3dxlPd08Ppo Q/kROTz//M9roZ4+n8aD8egnVYBaiDJyJbmPX188kQ7VbQLLvKJ4r0GvIny4SN5AfMct2wwTk2y 1bETAnMik4jDV/4018gM3rJt0MPw= X-Received: by 2002:a05:600c:354d:b0:419:f088:249c with SMTP id i13-20020a05600c354d00b00419f088249cmr3133032wmq.12.1714016744574; Wed, 24 Apr 2024 20:45:44 -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> In-Reply-To: <20240424224614.477221-1-zi.yan@sent.com> From: Lance Yang Date: Thu, 25 Apr 2024 11:45:33 +0800 Message-ID: Subject: Re: [PATCH v3] mm/rmap: do not add fully unmapped large folio to deferred split list To: Zi Yan Cc: linux-mm@kvack.org, Andrew Morton , "Matthew Wilcox (Oracle)" , Yang Shi , Ryan Roberts , Barry Song <21cnbao@gmail.com>, David Hildenbrand , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 list > 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_mapped > 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 not > 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-mapped > 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(st= ruct folio *folio, > * page of the folio is unmapped and at least one page > * is still mapped. > */ > - if (folio_test_large(folio) && folio_test_anon(folio)) > - if (level =3D=3D RMAP_LEVEL_PTE || nr < nr_pmdmap= ped) > - deferred_split_folio(folio); > + if (folio_test_large(folio) && folio_test_anon(folio) && > + ((level =3D=3D RMAP_LEVEL_PTE && atomic_read(mapped))= || > + (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. - if (folio_test_large(folio) && folio_test_anon(folio)) - if (level =3D=3D RMAP_LEVEL_PTE || nr < nr_pmdmappe= d) - deferred_split_folio(folio); + if (folio_test_large(folio) && folio_test_anon(folio) && + folio_mapcount(folio)) + deferred_split_folio(folio); Thanks, Lance > + deferred_split_folio(folio); > } > > /* > > base-commit: 2541ee5668b019c486dd3e815114130e35c1495d > -- > 2.43.0 >