From patchwork Tue Aug 8 02:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13345579 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 54F90C00528 for ; Tue, 8 Aug 2023 02:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFE016B0071; Mon, 7 Aug 2023 22:10:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B86476B0074; Mon, 7 Aug 2023 22:10:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A001C8D0001; Mon, 7 Aug 2023 22:10:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8B8EC6B0071 for ; Mon, 7 Aug 2023 22:10:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 57D04A0B1D for ; Tue, 8 Aug 2023 02:10:43 +0000 (UTC) X-FDA: 81099308766.27.6183FD1 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by imf13.hostedemail.com (Postfix) with ESMTP id 4BB5320016 for ; Tue, 8 Aug 2023 02:10:40 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LwPnDs3k; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf13.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691460641; 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=nxIcTJJIcuoAgpAn/H1eWO64VvlSIo1Dt/soZB9CeDA=; b=0yvTmsK66ApL6PTHGoU85qq1S8Z51EgIt/pRvqtpQ24JVRH9eafaFEmHMM6y2ylLwYwomr UMZGNOgYP9+3+xP/JQAz+b1trASgQPhohHNzaj82FRk5qf0lXJs1KGAIV9fModALLI/v67 eBM+9fVbZhIqHklD2Id8Sjf1WXPAUw8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LwPnDs3k; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf13.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691460641; a=rsa-sha256; cv=none; b=4GcDyCRjDvlWpDaflCcaM+5mdMf5gNrYIqKgPsSPA5OgnfGWWRy41TUUQNrp6mrHpGeM4V y4qkeDE3B4qIIxj79J7+ZVvuFmYnwuv1GR41oSY8vTHJzL3iIyAV5w3OaZK3J8LlB6uGM8 p9zdcdW3x7LllawhQJJTT5S9cKC72cs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460640; x=1722996640; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uG3NDhRuxMTWT3J/vbhAok1ojRTKKVWwCGRMvfusbWg=; b=LwPnDs3kznndFW1pnzMugsmp/9iGFGYxxPRRYpj1eMWDALaTVsx+tw7U SkXxunQfjPDQ2niOj4gMuyBF7yTmkNRqjvO4aFfF9Yi7ofFVE5LPmZ05X l9R3VwRcObprSI+HiPU0Bg/pg53U9wTIahTFXt6J1zRS1Bcupun9kQw16 aX2ORiMW6JfpGRwHuOsLTk52s2Gf5bCXxZvaj7QhQ22nLBlXk0jhgWsw8 oO4uzI9Bs+4gT1j5ksistDuKKZWCMvS2dn8muV5/PAhEt5lOmOFdlcXn5 nhwLUaAwhxc1FiV9EfEeYDNS//UOWAJIG7hI/1Pa/spsjZlbjFM8ecuBX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="360786312" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="360786312" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2023 19:10:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="1061813239" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="1061813239" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga005.fm.intel.com with ESMTP; 07 Aug 2023 19:10:35 -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 0/3] don't use mapcount() to check large folio sharing Date: Tue, 8 Aug 2023 10:09:14 +0800 Message-Id: <20230808020917.2230692-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: okga15j87suu71w74e5ikdmok7ot3doo X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4BB5320016 X-HE-Tag: 1691460640-184038 X-HE-Meta: U2FsdGVkX18hrdMoUIktD4Is3seRGtQpKIG3P5sZfSuULj9p2mJNIF6xHswvIj13OQ7IIjHnf3aU7tfrbrCwddFEeLV5JT/XpC2x4SiX+IqMK3A01GbcbrSv+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3uibD/C+N6WIwv5K0rQovGZ6XOXY6TgcHpIzvd6S+tMEF7mJsJ0GBgL9J3hw27MpJ2hdN2j1nOoAKYJGJyCWX5KR33UpEnb9OcQJ3djaUnHEVAu0kxK6p55A51ceXbBC6pGMZ9CA== 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: In madvise_cold_or_pageout_pte_range() and madvise_free_pte_range(), folio_mapcount() is used to check whether the folio is shared. But it's not correct as folio_mapcount() returns total mapcount of large folio. Use folio_estimated_sharers() here as the estimated number is enough. This patchset will fix the cases: User space application call madvise() with MADV_FREE, MADV_COLD and MADV_PAGEOUT for specific address range. There are THP mapped to the range. Without the patchset, the THP is skipped. With the patch, the THP will be split and handled accordingly. David reported the cow self test skip some cases because of MADV_PAGEOUT skip THP: https://lore.kernel.org/linux-mm/9e92e42d-488f-47db-ac9d-75b24cd0d037@intel.com/T/#mbf0f2ec7fbe45da47526de1d7036183981691e81 and I confirmed this patchset make it work again. Changelog from v1: - Avoid two Fixes tags make backport harder. Thank Andrew for pointing this out. - Add note section to mention this is a temporary fix which is fine to reduce user-visble effects. For long term fix, we should wait for David's solution. Thank Ryan and David for pointing this out. - Spell user-visible effects out. Then people could decide whether these patches are necessary for stable branch. Thank Andrew for pointing this out. V1: https://lore.kernel.org/linux-mm/9e92e42d-488f-47db-ac9d-75b24cd0d037@intel.com/T/#med74caad0cbd0049641cfddc5b9fe793b4b50276 Yin Fengwei (3): madvise:madvise_cold_or_pageout_pte_range(): don't use mapcount() against large folio for sharing check madvise:madvise_free_huge_pmd(): don't use mapcount() against large folio for sharing check madvise:madvise_free_pte_range(): don't use mapcount() against large folio for sharing check mm/huge_memory.c | 2 +- mm/madvise.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)