From patchwork Wed Feb 21 08:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13565125 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 1B786C48BC3 for ; Wed, 21 Feb 2024 08:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A06E56B0074; Wed, 21 Feb 2024 03:51:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B68C6B0075; Wed, 21 Feb 2024 03:51:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87E4F6B0080; Wed, 21 Feb 2024 03:51:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 796446B0074 for ; Wed, 21 Feb 2024 03:51:00 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 58FB5809CC for ; Wed, 21 Feb 2024 08:51:00 +0000 (UTC) X-FDA: 81815191080.01.0942787 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf12.hostedemail.com (Postfix) with ESMTP id 93C5A40011 for ; Wed, 21 Feb 2024 08:50:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aQDyrHQP; spf=pass (imf12.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708505458; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=JDWnFuWwtAaGkWdbKqeZ52kl0lx5mRMgSrEjZRcEHMc=; b=aSGbjwB4Kwh0x4GkrVhUeVdyfU35Usbt+GLuH4OGtwgMOX0wEYOxRAabOl0PGSX7MPRkSZ AWTNywEIhdSvky1/vKFuiARwG4Uj9MSkqty8Q+g2T6nhhomu7YSrGHXfQeNBGt/CIh6ZnP AdZ4ozpWJJV2TLlaH/luLKNcvuUk47A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708505458; a=rsa-sha256; cv=none; b=6A31YVBHzrGXak3XyANWIt4wvrOumpKw9yKmVf+Ei5kA7OxK+BCS4c7ADE0KUt0hFfu8FC qFOVt87wOcm6Cea04WGNn0ZmHfzb8jHQw6emB6woXpuotjPmdy35lfh+XXTLsyZwPZ15Mi pbVT1m0Dmfjob39d3qTQ85pf5XPX5Zk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aQDyrHQP; spf=pass (imf12.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5cdf76cde78so282932a12.1 for ; Wed, 21 Feb 2024 00:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708505457; x=1709110257; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JDWnFuWwtAaGkWdbKqeZ52kl0lx5mRMgSrEjZRcEHMc=; b=aQDyrHQPNPU/k5K0UOsh0j4OtqqsaIIur83MK56h0x4JhOu73o7taPwJ+bxzVDf0Rd r1M8n8SdQ96hIBFnjMY6g8wZ1Zuts1EHfmyyhXwYDuwrJH0t2a2PcfI044roBvx6+xnX 86AnrNejtZuhSXjp4mFYtSfx2U6wzp+HmDGUq6yNHzDljy7TWq4BE+LCpOVOeq7fsa5+ GrPP7meTrxP8cw4dbh8iZ7DNaRNcpkHFzBy14+6l1JMsVP+ib7uBRrkd7HDH5FLP4iW4 bdHGk4ZTBy9OUcwI4v4nOGkgf0omqZ3Bcn1veDEmKUpOZmTcLFv8li04r4jYgCRvhzki yxpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708505457; x=1709110257; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JDWnFuWwtAaGkWdbKqeZ52kl0lx5mRMgSrEjZRcEHMc=; b=kBYKP0aqYNGJQdHOQEjHZIMhpm2gVu12XlmtoCuPctaF7Anv9J/clKt00BUi9cwbFq R5NEMZDEZwO0ZTq6N837i8waLjSorAb58sYv2vQxpIBojQ5QCoKfOB4i2TnIGEalsQC8 /Z35pk5gw6rSaE3/+dRFk8OUb84+VtyCML0QrwCYNQQS0kV1ukCSGwlSuYkACNJXTtH9 zZpUWwd7fRLsapAZGfQofZYkCOTrHzxow3aVM+bVVzSdL6eJcNahcKQZvXFACZzGU97g nPBwNWJMy+j0UefjlrMSs1WmGfl2r9LNsk3vahcKyyvl1DeJmRLA21MnSXUfGAZflqYh 948A== X-Forwarded-Encrypted: i=1; AJvYcCWwfv8FeLZ2h9liZ/oaG9KOA++5pscnme3asPDH1lAiUy8O0t16+C5kSAaAYvl9q99bE6sh9AtLCfsQAu+DuXv3DzA= X-Gm-Message-State: AOJu0Yw1r3tJqpE/y4PSZ9H8KmKqT33AH8cFiSLMabi29Jqi8WGlliNm aQd60ptMd2j/2RQ16v/bMLhJt8Mj5VcjD4kbhry8Pe7ZKiKjPuxF X-Google-Smtp-Source: AGHT+IEtfwHJ2P/VzyLpHiPxWMWwHmaEnoEaIxoJZF/ZzNUugWmiHmu8f5bXFT18km945yC9oh+zaQ== X-Received: by 2002:a05:6a21:8cc4:b0:1a0:5fb6:fc52 with SMTP id ta4-20020a056a218cc400b001a05fb6fc52mr21506181pzb.15.1708505457217; Wed, 21 Feb 2024 00:50:57 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e5f3:9cc7:f0fb:8762]) by smtp.gmail.com with ESMTPSA id h23-20020a17090aea9700b00298c633bd5fsm1121192pjz.30.2024.02.21.00.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 00:50:56 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song , Yin Fengwei , Yu Zhao , Ryan Roberts , David Hildenbrand , Kefeng Wang , Matthew Wilcox , Minchan Kim , Vishal Moola , Yang Shi Subject: [PATCH] madvise:madvise_cold_or_pageout_pte_range(): allow split while folio_estimated_sharers = 0 Date: Wed, 21 Feb 2024 21:50:36 +1300 Message-Id: <20240221085036.105621-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: cmoxxy43aagiu5h5yrf5bzgsdxg9mmkm X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 93C5A40011 X-Rspam-User: X-HE-Tag: 1708505458-887382 X-HE-Meta: U2FsdGVkX1/CQa1FDIoV0l9DOjMfsz/bo8uOTWD2/g9s74o4XDCt1+iRXDd+RECYOTHAdM4ltaJGNWUcb67pZiHq6Fph24uxOGscxZjcTInoOEBuYDzXxucITwmZbjcxrXwxAoz0KfzfFVWLgcIkNbjEne/KH8FrsP+F0AsK6EcHXeBrp57STnL3HDfgnx3XDWKZVVplWuVNKziq0q9dYbpEivvoeTsQ7BHB6H5pMHERcB9rBfmy27EI7Ijz26BtC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SFA15s5eZaGexJ01mZ3X+cglPUsKKwEtW6h+Dp9quhavOelRe2oh86XN/7f2iGy3A4NvKP8qtRasJ+UH+asyfm6mqSbBHn9qWCkCJKGiYkrOV1y74hgm62BpT5Aaw7/TAST6NbJRlhYqtnmLpDr9Ljh59ZlL0KsgK5jvd6hiSRdY0hbi76qkoZnh0/BD18AHOpKB8x+TTnxkYIDYw0IBhRrJXA43H5jNO6OjEkTjs2Wl8hRprKGBaugIn/eAEuNJL9PlmsX/aPgGM8fq4h36rqIVXzwjCDEp6DeeKEr2vg6f0rp2wxGqlmPxAxx8szJwN8O1AjL78idufaKBmFHvNzrs+HL5pn/hnYZ0TFGtlCFvVXOSlCjdryrbwuaMUs49+xDLoLch97k25+muGosiK0ivMZrIxViY5N7PMJLC58TyWMu0OiK/m5UgWRNAK5YMFtEH8nX31INynwTY2X/3Zg2WKt55Dz15vQOiz0/GhK/yGIsC/sxXmmosK45yJ0g77pzmGtFM41xzvXSRR5JJ8dWINrrLBEdMki+/shNrqG4= 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: From: Barry Song The purpose is stopping splitting large folios whose mapcount are 2 or above. Folios whose estimated_shares = 0 should be still perfect and even better candidates than estimated_shares = 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 "= 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 "= 1" for both pmd-mapped and 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 Reviewed-by: David Hildenbrand Reviewed-by: Vishal Moola (Oracle) Reviewed-by: Ryan Roberts --- 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) != 1) + if (folio_estimated_sharers(folio) > 1) break; if (pageout_anon_only_filter && !folio_test_anon(folio)) break;