From patchwork Tue Aug 8 02:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13345582 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 84847EB64DD for ; Tue, 8 Aug 2023 02:11:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EB506B0078; Mon, 7 Aug 2023 22:11:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 175286B007B; Mon, 7 Aug 2023 22:11:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 015F98D0001; Mon, 7 Aug 2023 22:11:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DA63A6B0078 for ; Mon, 7 Aug 2023 22:11:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A6DBEA0609 for ; Tue, 8 Aug 2023 02:11:24 +0000 (UTC) X-FDA: 81099310488.20.1ACE43F Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by imf13.hostedemail.com (Postfix) with ESMTP id 8B93B2000B for ; Tue, 8 Aug 2023 02:11:22 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EuJd4qa0; spf=pass (imf13.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691460682; 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:in-reply-to:references:references:dkim-signature; bh=SnBkVWTLCU6LpGHkVu+arSBfRN4pTVOEAmzdbz8UspQ=; b=E8BtDC3D/MDBkSsoHENPcx1orVnSnsyYVnk+pTKl6a6D5nOqFZgcIFewYoOzSYg4BG0aRD MFE8QiTJ+nZ0Jiwb80c3EXtXLzoMYfXXHdP/lyHIrTIlJ/gBy172nGWQAbUsBcfrnb2LqN kmV6Nthr0wqutDxnIa3BOPyrStB1M2M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691460682; a=rsa-sha256; cv=none; b=H7K5jYpqhp75kP/zDClCqg9TvuYHdrUd/Uxn/3aSPJnGocTCSaoXxq9m6rWC6pNvm9E0sf 9t7qjrS0586LwiFkard7sEUsPkO6FBzRoyZsmFSXAY9v5bBL0iTnRTbKswjA8JugUza6kQ 353VMkXtK6pSzjms0D9dxfYfKJW2ATE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EuJd4qa0; spf=pass (imf13.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460682; x=1722996682; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d3VIX2xY+fu1wWsahOfoN14pobtO1cM2MgEWqpBvgLY=; b=EuJd4qa0AAArhVMsFAlVuljUHzrNuN+NCuFOvd/FratfgL2JETvU6eCh qg6KhSCb58AqZmPXhmlnGTLUklrJP7iYSWSXQYEQRj7TcTSSk+e0wJc+m JURZuL/L5ni+vhYi93jQ0OaAWfp8hWPV15Xe0MPextHEwx2/gBdsKQHPx 12/mcxBQm0bm7Olx+egeufVxqoqMDaxF/ysXGR2cqJc/UB5n5PAPL8Hvp iQzc2W1QdyXnuBwG/qtj/XSzk3PlTQcOZVp0R3aZ0IrVRgu1tzPhbFvzG dsZRTrN9URLfshzRnuKIzObcL+fm3PdBJpkYAg1HUJIQWN7+NgtF1ONx1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="373453599" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="373453599" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2023 19:11:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="977689411" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="977689411" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga006.fm.intel.com with ESMTP; 07 Aug 2023 19:11:18 -0700 From: Yin Fengwei To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, minchan@kernel.org, yuzhao@google.com, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com Cc: fengwei.yin@intel.com Subject: [PATCH v2 3/3] madvise:madvise_free_pte_range(): don't use mapcount() against large folio for sharing check Date: Tue, 8 Aug 2023 10:09:17 +0800 Message-Id: <20230808020917.2230692-4-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808020917.2230692-1-fengwei.yin@intel.com> References: <20230808020917.2230692-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8B93B2000B X-Rspam-User: X-Stat-Signature: jo5i49te3gax54yb6s3w61xr3ey1qk9d X-Rspamd-Server: rspam03 X-HE-Tag: 1691460682-963969 X-HE-Meta: U2FsdGVkX19EpkaMURR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JqL6jBVaqxtmCgIznw9jSAW+k3QwnLYNxnEVh7YI1E5qpBPaYHFaUC5SwAORC45lNgisZmVHPS0Tm8+FsqwBGuUuOzYmdFB4G8DrbGlhratpL0JzBgsV0lv0zYoQxGaXYxQuqRYGjGSE2y4DLaZ/Gr23H1DHaGR5J0iWG+0auj0VqiOmYvicc+M50LIDEjtOrpB6flG+5vmKCC3LxRwzFV3GrDfCojgpyHjkmGLMrYRXPx1eLDpkJpZDs+dfNDYivOYfscZPMnnBNTt0j/252FfhtyT25Bp7Oz1s7cFAi0w2g9pQvO/u 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: Commit 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") replaced the page_mapcount() with folio_mapcount() to check whether the folio is shared by other mapping. It's not correct for large folios. folio_mapcount() returns the total mapcount of large folio which is not suitable to detect whether the folio is shared. Use folio_estimated_sharers() which returns a estimated number of shares. That means it's not 100% correct. It should be OK for madvise case here. User-visible effects is that the THP is skipped when user call madvise. But the correct behavior is THP should be split and processed then. NOTE: this change is a temporary fix to reduce the user-visible effects before the long term fix from David is ready. Fixes: 98b211d6415f ("madvise: convert madvise_free_pte_range() to use a folio") Cc: stable@vger.kernel.org Signed-off-by: Yin Fengwei Reviewed-by: Yu Zhao 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 49af35e2d99a..4dded5d27e7e 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -683,7 +683,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, if (folio_test_large(folio)) { int err; - if (folio_mapcount(folio) != 1) + if (folio_estimated_sharers(folio) != 1) break; if (!folio_trylock(folio)) break;