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 7B88CC5478C for ; Mon, 26 Feb 2024 21:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D47D4401C7; Mon, 26 Feb 2024 16:17:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05CF144017F; Mon, 26 Feb 2024 16:17:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E19FD4401C7; Mon, 26 Feb 2024 16:17:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CAEF644017F for ; Mon, 26 Feb 2024 16:17:44 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8A30312097E for ; Mon, 26 Feb 2024 21:17:44 +0000 (UTC) X-FDA: 81835216848.04.D1413D4 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) by imf27.hostedemail.com (Postfix) with ESMTP id E3A514000C for ; Mon, 26 Feb 2024 21:17:42 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Tgl3u7+I; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.44 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=1708982262; 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=2TQ+MmPJfo/s3a/JqGkoS+XmBHvpeeHVf2ayrPsV/n4=; b=qgEN6yc4/vlfTA6c80v7DpYQzVL/Bn8Ig/ZJMwBsq+HvijLna3hgeGUR++5hlMjMDWGys1 MxqIqKXYMEkTyNNZy3i4JTwTRzKfQr2fMC6E//HvgagX7MbMn+7atY3dQWBM2NEmtHdb+A CITpwJ8ooViXsXbuVjHlhaGWzsvM8rc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Tgl3u7+I; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708982262; a=rsa-sha256; cv=none; b=xi1RczvHcHNdTVOO+aGBivdmsi5y9ctxNTHZWtRHOdVjgNROAQhfKw8orpmAQCfG1wJquY gcZFdyEaDd7pTQJ1qPKwWtLiiz0YuCqAaNoTqZaiKdeOiZr2Teltt43Ygxrxdh8fPdKUBf DDHKfuH05zgiV6TR3ptzBP3JC1BeOd4= Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-4706de5227aso482795137.3 for ; Mon, 26 Feb 2024 13:17:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708982262; x=1709587062; 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=2TQ+MmPJfo/s3a/JqGkoS+XmBHvpeeHVf2ayrPsV/n4=; b=Tgl3u7+IJpIViOVa0HnMfaw8wu/Pg2jzibaLOKSYpw3Ay+G7QY1lxXe/u4GdVzdZnX Xsnqknp8by2n4eb1Da820DLnuzrPJTQ2H4Ar3qnSCMGr16Zo/1brOlf441ZFYax3oww2 K27Se1oZsvUmcYckyq2YMDgV0gXHGVL0lvUoSoL7btoHMcEj6guARB1qDEMNtE8OnohL btokGylt6zGwlX57zPBjL6oLaTMA/GG95ihgkP5R4MsAHYlO7sj8pX3IhqmaCjxH4fwQ y/Q4CE1dhgdm1s8Wr3vkQIhjFZa/WR63hslzUwTSSUnUjg5QT5Nym7b0GCb2/hG0GBr7 IDjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708982262; x=1709587062; 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=2TQ+MmPJfo/s3a/JqGkoS+XmBHvpeeHVf2ayrPsV/n4=; b=MFGI+qYLq1JbnJ1rCp7IeyyOQdLqIg6vArzLgHFroaU/KGQteW1C7fK/XQE5k5jeeY g8gGyEgonvEx7rGrpH+gNiS0txb1zDwI4mT+9tLf63bIufbsi4QMMrMxXq78tGORZSQV IvRDPn9Gmfa0BFqLfcS+9/Q6xJ0VEfpFVD4pnqFmb9XPnsNgmaVeblOEBJIseG9oq3+b w70I1Cn6e6dMeHARujf89PGP+jyncGKwRuWmIsEtGrCtfsJix3eURylR7oiw7G3ElGJE GF7Mn3iqZ/Ks5OX4+DsyUCeyXSJMa7f4uwL21kxToG5iAa2yPEAteIwNNZ0gSB25L8rR OFlA== X-Forwarded-Encrypted: i=1; AJvYcCVzKTrbaOzB1CvJjMEmJa1pBnSUt0L43ETI2pJhjyrTuq51TXSgoalfcFqtBvG0aajV7Pyhlx1qwacp+ju1jiNRXtA= X-Gm-Message-State: AOJu0YxPkwHIlBwzhe5usUvnjbxvrKqh1oPLapmElEVsTCvpMlCxnEBc 3vk1tl2LjzQDt2tDVODoIbEe+HHqtm8OO4U+hNT0+Y8my/d8DcdMB/mzY6VKGMWfNTFemKr8iv5 vy/ag2ymDRFd/53i5Uas4H6rwPJM= X-Google-Smtp-Source: AGHT+IGrTdeGg3MeiiEt+KWIFd0JzOV1GwJm6Dbq6J6o8jBXpCOykKFMIATUeymYpLNw3rc1ZtxClcNTwXRDECitVto= X-Received: by 2002:a05:6102:3a09:b0:471:e447:f1d5 with SMTP id b9-20020a0561023a0900b00471e447f1d5mr5239146vsu.13.1708982261969; Mon, 26 Feb 2024 13:17:41 -0800 (PST) MIME-Version: 1.0 References: <20240221085036.105621-1-21cnbao@gmail.com> <71fa4302-2df6-4e55-a5a8-7609476c41d4@arm.com> In-Reply-To: <71fa4302-2df6-4e55-a5a8-7609476c41d4@arm.com> From: Barry Song <21cnbao@gmail.com> Date: Tue, 27 Feb 2024 10:17:30 +1300 Message-ID: Subject: Re: [PATCH] madvise:madvise_cold_or_pageout_pte_range(): allow split while folio_estimated_sharers = 0 To: Ryan Roberts Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Yin Fengwei , Yu Zhao , David Hildenbrand , Kefeng Wang , Matthew Wilcox , Minchan Kim , Vishal Moola , Yang Shi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E3A514000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: p9xs39xdmwa4mhdfainmeuxr6gg6sxb3 X-HE-Tag: 1708982262-238216 X-HE-Meta: U2FsdGVkX1+VGrh9IRARvEr20oaHaW1Z5SijATmnP90K2VU1Woite21ILd6c6ORliUEwbZBP4STUP6bZ8/g6RQZDkBNT4nQi3p3wV9dcS0T1URBXUZofATBks+mq7R9SfVBo2IgmSWTdJAuB+x7GTxdt/8oT50G+keHZBlUfLDa6NlOsSi69aiXhBVYbkumQW7UlGk82hSh95pD77Rb+hVOj4EJW4iB4WRwSxJrG8yVVokohbiJ5ztfvrqIh149ATmCrNgs5zjA5NsyBzwl5IFxcDkrOurp18q+cVyzLrqUfSlExElg5oewT+Qkc7Zyg1SCisA4BP59e5pWRf6jizIkGBar9eYZpEIG40jnEwAtT9ANtW/M975Fff0w0xq1Zy8t6ScRKQqYy+1ccVfHN0f1D4o2E1ZG8G5qwOs0qdkBi2E9KzGxw+ToQDk8wDOWuxKyLTZf3D/34m4Ma2YzSD3PDDHIL2LDnIk7BDFkfUSn8R+xce5ekhlTizrvbxrwqKawWHW31O3ouV6jpkaOKmBKrfehyz5VIfdbn79bq7v4+yz3FPZGD/FiJ2xmeOvOo5LHUdhYU00/p/iGhxJDhE9HJQ0JgR8UbjO1h046vY7Muv3ExtBCe7DEzpM9lk0+L9+PQY6a4EFFR1kDZJG564CWn30fn9i2mc7hQE+vaC8jSUoatlOUb+W9nGZYwWfk3HXkngDkRtMmohoqmAvAxPvwV9+MJwVKlaTSSF956cvxZOC0VTIDwzPFTNOm7n+cDs9yNeW4mUF25kiwBhCreA16rfmz09n7gQ5F4zBS1v6fhpzzlkFmpn/tKc7WAcV2WgiyhQWZUCJLqIie1PVKU6tz42GiZgQ8mObBq7hHjGOCSF1cIUlBtvignZJrqJFpG3EfG/SpCBUX/HyY+LhOLO7QCxoTp/MGLJhM2fFRHs8opqT46yh/jDjALwZYw6SmMRb8kgfhK7kJoQ0IX3Ko WLEhfmq+ H5vbPQXMoRlgAWVbzryunZ7FykcPZbTqD4HwiOdSi2dK4UTotxv2YWfzAJUfd4P02opMq6woBdiYdsgTCqpjHvZhfNKisdqFPDrPZW4ZWihY/STKrhjNQQozwR2iATan8LJppq085wAjMoUY+fuyOlQEQZoWXHYEHxnqr 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 Tue, Feb 27, 2024 at 2:46=E2=80=AFAM Ryan Roberts = wrote: > > On 21/02/2024 08:50, Barry Song wrote: > > From: Barry Song > > > > The purpose is stopping splitting large folios whose mapcount are 2 or > > above. Folios whose estimated_shares =3D 0 should be still perfect and > > even better candidates than estimated_shares =3D 1. > > > > Consider a pte-mapped large folio with 16 subpages, if we unmap 1-15, > > the current code will split folios and reclaim them while madvise goes > > on this folio; but if we unmap subpage 0, we will keep this folio and > > break. This is weird. > > > > For pmd-mapped large folios, we can still use "=3D 1" as the condition > > as anyway we have the entire map for it. So this patch doesn't change > > the condition for pmd-mapped large folios. > > This also explains why we had been using "=3D 1" for both pmd-mapped an= d > > pte-mapped large folios before commit 07e8c82b5eff ("madvise: convert > > madvise_cold_or_pageout_pte_range() to use folios"), because in the > > past, we used the mapcount of the specific subpage, since the subpage > > had pte present, its mapcount wouldn't be 0. > > > > The problem can be quite easily reproduced by writing a small program, > > unmapping the first subpage of a pte-mapped large folio vs. unmapping > > anyone other than the first subpage. > > > > Fixes: 2f406263e3e9 ("madvise:madvise_cold_or_pageout_pte_range(): don'= t use mapcount() against large folio for sharing check") > > Cc: Yin Fengwei > > Cc: Yu Zhao > > Cc: Ryan Roberts > > Cc: David Hildenbrand > > Cc: Kefeng Wang > > Cc: Matthew Wilcox > > Cc: Minchan Kim > > Cc: Vishal Moola (Oracle) > > Cc: Yang Shi > > Signed-off-by: Barry Song > > --- > > mm/madvise.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index cfa5e7288261..abde3edb04f0 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -453,7 +453,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t = *pmd, > > if (folio_test_large(folio)) { > > int err; > > > > - if (folio_estimated_sharers(folio) !=3D 1) > > + if (folio_estimated_sharers(folio) > 1) > > break; > > if (pageout_anon_only_filter && !folio_test_anon(= folio)) > > break; > > I wonder if we should change all the instances: > > folio_estimated_sharers() !=3D 1 -> folio_estimated_sharers() > 1 > folio_estimated_sharers() =3D=3D 1 -> folio_estimated_sharers() <=3D = 1 > > It shouldn't cause a problem for the pmd case, and there are definitely o= ther > cases where it will help. e.g. madvise_free_pte_range(). right. My test case covered PAGEOUT only and I agree madvise_free and others have exactly the same issue. for pmd case, it doesn't matter whether we change the condition or not because we have already pmd-mapped in the page table. And good to know David will have a wrapper in folio_mapped_shared() to mor= e widely address this issue. > > Regardless: > > Reviewed-by: Ryan Roberts > Thanks though we might have missed your tag as this one has been in mm-stable. Best regards, Barry