From patchwork Mon Feb 6 15:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13130097 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 C6985C636D3 for ; Mon, 6 Feb 2023 15:29:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A13746B0073; Mon, 6 Feb 2023 10:29:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C35F6B0078; Mon, 6 Feb 2023 10:29:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88B4C6B007B; Mon, 6 Feb 2023 10:29:00 -0500 (EST) 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 7BC506B0073 for ; Mon, 6 Feb 2023 10:29:00 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 50DE01A07B5 for ; Mon, 6 Feb 2023 15:29:00 +0000 (UTC) X-FDA: 80437250040.02.0B404D0 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf06.hostedemail.com (Postfix) with ESMTP id 4F0E6180025 for ; Mon, 6 Feb 2023 15:28:58 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=msHRiZid; spf=pass (imf06.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.126 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=1675697338; 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=RvSDe78RU2nTL9I6q9br/wM5C6UDPPKvFCHYVrqRQSA=; b=mQ57qyQPFbnawb2e9+Br2zWsKp1bTREvWmNPWPv5dx+T14S+zsQTKF6WinH4aXXgbQvz2v 4d+srTVqX+9xsKBkH8YhfEOL3BwGnIdpVBUiOQddQ4go0CeKltDsTteW6C9WboCUJC360X OWy2NCuuSRcgkQBDwg8JT+femN1akP4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=msHRiZid; spf=pass (imf06.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675697338; a=rsa-sha256; cv=none; b=pM3SbVeBG9PouTh9RPiB5txu8e5kUUxkvXnZwq5LO65QWRHkuLXgOXXxzgnXG/Qdj5UwkF 5QXdCukKeX1uDw+5P6GpUrEabPKuLsPSEozJX5iAQn5mYejaD5JmAgdW9gvWm3DngF5gpX sFd/bS84UwVK9xlP76tD1+U73ePafYY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675697338; x=1707233338; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TKcs1pJnuf9fzvs4mZBzCmsjSee88jH1Cx1fsFE5aTs=; b=msHRiZidZABgGnpr4aywG9uh1zkFpTEsN/4X0KHEmw31RILTw8zK/43B E6CxlrKLJ+wA80h4t7B7l06Q4J0PA2NqVyJkQ2oKviFlY9XcjYqrWnA8u RMz+G2J80/LaKZ19lrNPMOpgQeRn2BMFrq4l5F3OnqSFnL82x3Zg1qHZs 1gHo/paGRX4poeU5fwyG//bIUMGTJpWeGy0KxKCrOc7ibFxZXq6kroI0n 558twJN4LdxTpcjFEftkOTP2dyxBiuN9fXtKvgl8mp8iezo2nZ0nmBlaH rg8H3KDwTNa5bDILtoGfyAsNJKQxUc6vUXoQKKOJTWA4O63KRRgsEaq94 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="312884032" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="312884032" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 07:28:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="840381225" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="840381225" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga005.jf.intel.com with ESMTP; 06 Feb 2023 07:28:55 -0800 From: Yin Fengwei To: willy@infradead.org, linux-mm@kvack.org Cc: dave.hansen@intel.com, tim.c.chen@intel.com, ying.huang@intel.com, fengwei.yin@intel.com Subject: [RFC PATCH 1/2] rmap: Add function to handle entire folio rmap removing Date: Mon, 6 Feb 2023 23:30:48 +0800 Message-Id: <20230206153049.770556-2-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230206153049.770556-1-fengwei.yin@intel.com> References: <20230206153049.770556-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4F0E6180025 X-Stat-Signature: mepxenxbh3jn71ejb8k9ee11no1fouia X-HE-Tag: 1675697338-917759 X-HE-Meta: U2FsdGVkX18sXVKy2Tid8UTko6vcUHICyDwUP7J7r3f3dlDLiFJycqVBK3kYFZqkup+LQS4XvaFDylygYwV/83AYaT01cdHWfSLW+3dNwsWPpDMHUUQX4G34clQDf0WLY8GO6zPF72rVTqtxvAKNK3M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ence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add folio_remove_entire_rmap(). It will handle the entire folio rmap removing. Signed-off-by: Yin Fengwei --- mm/rmap.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index c07c4eef3df2..3ab67b33094b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1394,6 +1394,32 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, nr_pages, vma, compound); } +static void folio_remove_entire_rmap(struct folio *folio, + int *nr, int *nr_pmdmapped) +{ + bool last; + atomic_t *mapped = &folio->_nr_pages_mapped; + + last = atomic_add_negative(-1, &folio->_entire_mapcount); + if (last) { + *nr = atomic_sub_return_relaxed(COMPOUND_MAPPED, mapped); + if (likely(*nr < COMPOUND_MAPPED)) { + *nr_pmdmapped = folio_nr_pages(folio); + *nr = *nr_pmdmapped - (*nr & FOLIO_PAGES_MAPPED); + + /* Raced ahead of another remove and an add? */ + if (unlikely(*nr < 0)) + *nr = 0; + } else { + /* An add of COMPOUND_MAPPED raced ahead */ + *nr = 0; + } + } + + if (!folio_test_pmd_mappable(folio)) + *nr_pmdmapped = 0; +} + /** * page_remove_rmap - take down pte mapping from a page * @page: page to remove mapping from @@ -1431,20 +1457,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, } else if (folio_test_pmd_mappable(folio)) { /* That test is redundant: it's for safety or to optimize out */ - last = atomic_add_negative(-1, &folio->_entire_mapcount); - if (last) { - nr = atomic_sub_return_relaxed(COMPOUND_MAPPED, mapped); - if (likely(nr < COMPOUND_MAPPED)) { - nr_pmdmapped = folio_nr_pages(folio); - nr = nr_pmdmapped - (nr & FOLIO_PAGES_MAPPED); - /* Raced ahead of another remove and an add? */ - if (unlikely(nr < 0)) - nr = 0; - } else { - /* An add of COMPOUND_MAPPED raced ahead */ - nr = 0; - } - } + folio_remove_entire_rmap(folio, &nr, &nr_pmdmapped); } if (nr_pmdmapped) {