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 1DAD4C54EED for ; Mon, 30 Jan 2023 12:53:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B7AE6B0075; Mon, 30 Jan 2023 07:53:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 768896B0078; Mon, 30 Jan 2023 07:53:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 630896B007B; Mon, 30 Jan 2023 07:53:37 -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 53F686B0075 for ; Mon, 30 Jan 2023 07:53:37 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F1A94AAA28 for ; Mon, 30 Jan 2023 12:53:36 +0000 (UTC) X-FDA: 80411456832.29.83299A6 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf23.hostedemail.com (Postfix) with ESMTP id 99B5014001C for ; Mon, 30 Jan 2023 12:53:34 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="U2Z1/gaj"; spf=pass (imf23.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=1675083215; 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=4WRcDdNgpYDV/LC6/nL1u74puVQasX2vgeOtMR/D/Ug=; b=ZC4sWOhwI7XwH4HFsgbDjh/VsjKcvdSyPyuAqgG6JipcG+NtesgEHG9+cP3AsC6BBdpXMA 4SWQ91Ghmt6bgVob03729jlnG8rb5DJ2BbGpcg5I9O9Btzah+r1c1GWuIAE4alC/BCBBt9 H3xOEilVoWmhOCRl4W7FBrlTpFKuA4o= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="U2Z1/gaj"; spf=pass (imf23.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675083215; a=rsa-sha256; cv=none; b=pptBMXcBUMCLd4JmiIerexxl0rIcSPgTxMcOrHOcXgqv00MkYSzontpCimv40uh+ShTCGu AZ6mnMbKx/PeRLK4gGAEwVetQeOU33q2LoyDYXUO3XiSs0sKbj9488aQsUZtSG6iAjI9pT z5rPp4jRqFvAUQh3wZCtM4DkSIyPyG4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675083215; x=1706619215; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ueNrgpVcUcxsqqen652gJ61fvtMnDOWPrp2ZsZCpvic=; b=U2Z1/gajSDyUx3Pqm8TMj8y+ZOEI4CjXxLV2fonXIomgI7fF82yYmHPj PMRADkqXbTZZh5VmMB9TKUJvEqgY/6yHZX6xIdycjmct8PTSkElCM1UIx 165WNwW7kUdaff25m3F6iZYR+H9Vm3g3MHlzZ4ry7U6d4lLeRfWwFNvI8 EpSLfcC8ZA1UapSywHqwk9DPJ7wVSW+qThGy1cVcX1s7J41MwvlkAvnzg DyBZgLLuHXWwIr7ngaUum1chYfP29S6uYvAg3CV1iQC45sL2A/9C1HynR jTs5V7L1OYTm5YHIJLqB7CG5Ng8VyIvK9gygSvkxrmkM2bppIsVxNnYwE Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="328823687" X-IronPort-AV: E=Sophos;i="5.97,258,1669104000"; d="scan'208";a="328823687" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2023 04:53:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10605"; a="614014996" X-IronPort-AV: E=Sophos;i="5.97,258,1669104000"; d="scan'208";a="614014996" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga003.jf.intel.com with ESMTP; 30 Jan 2023 04:53:22 -0800 From: Yin Fengwei To: willy@infradead.org, david@redhat.com, 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 3/5] rmap: add page_add_file_rmap_range() Date: Mon, 30 Jan 2023 20:55:02 +0800 Message-Id: <20230130125504.2509710-4-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230130125504.2509710-1-fengwei.yin@intel.com> References: <20230130125504.2509710-1-fengwei.yin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: sq8mffp31boh7y7pnh9kbrpfmu7qjn7p X-Rspamd-Queue-Id: 99B5014001C X-HE-Tag: 1675083214-285528 X-HE-Meta: U2FsdGVkX1+Jl8zEATRw89E8+ZKQR4bhdeG6SX90DUQsv9goQuYJOnE0XsyezmDPGsBb+lSAcGzqaLfZFkz8dHdaqDSZifsNP1OQSJJ5bPipZcM3TVPwhyowyL0XmQeiK9OmCynJwDU8oyC+qG4E8hK3ma+hnAA2vULnf7J2lHBzmR5vhbFU1RP+Nz1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linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: page_add_file_rmap_range() allows to add specific range of large folio rmap. Signed-off-by: Yin Fengwei --- include/linux/rmap.h | 2 ++ mm/rmap.c | 70 ++++++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index a6bd1f0a183d..063e0addcbf8 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -198,6 +198,8 @@ void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); void page_add_file_rmap(struct page *, struct vm_area_struct *, bool compound); +void page_add_file_rmap_range(struct folio *, struct page *, int len, + struct vm_area_struct *, bool compound); void page_remove_rmap(struct page *, struct vm_area_struct *, bool compound); diff --git a/mm/rmap.c b/mm/rmap.c index 948ca17a96ad..cc7fe3010330 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1301,40 +1301,19 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, __page_set_anon_rmap(folio, &folio->page, vma, address, 1); } -/** - * page_add_file_rmap - add pte mapping to a file page - * @page: the page to add the mapping to - * @vma: the vm area in which the mapping is added - * @compound: charge the page as compound or small page - * - * The caller needs to hold the pte lock. - */ -void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, - bool compound) +void page_add_file_rmap_range(struct folio *folio, struct page *page, int len, + struct vm_area_struct *vma, bool compound) { - struct folio *folio = page_folio(page); atomic_t *mapped = &folio->_nr_pages_mapped; - int nr = 0, nr_pmdmapped = 0; + int nr = 0, nr_pmdmapped = 0, nr_pages = folio_nr_pages(folio); bool first; - VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); - - /* Is page being mapped by PTE? Is this its first map to be added? */ - if (likely(!compound)) { - first = atomic_inc_and_test(&page->_mapcount); - nr = first; - if (first && folio_test_large(folio)) { - nr = atomic_inc_return_relaxed(mapped); - nr = (nr < COMPOUND_MAPPED); - } - } else if (folio_test_pmd_mappable(folio)) { - /* That test is redundant: it's for safety or to optimize out */ - + if (compound) { first = atomic_inc_and_test(&folio->_entire_mapcount); if (first) { nr = atomic_add_return_relaxed(COMPOUND_MAPPED, mapped); if (likely(nr < COMPOUND_MAPPED + COMPOUND_MAPPED)) { - nr_pmdmapped = folio_nr_pages(folio); + nr_pmdmapped = nr_pages; nr = nr_pmdmapped - (nr & FOLIO_PAGES_MAPPED); /* Raced ahead of a remove and another add? */ if (unlikely(nr < 0)) @@ -1344,6 +1323,20 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, nr = 0; } } + } else { + int i = 0, new_mapped = 0, count; + + count = min_t(int, len, nr_pages - folio_page_idx(folio, page)); + do { + first = atomic_inc_and_test(&page->_mapcount); + new_mapped = first; + if (first && folio_test_large(folio)) { + new_mapped = atomic_inc_return_relaxed(mapped); + new_mapped = (new_mapped < COMPOUND_MAPPED); + } + if (new_mapped) + nr++; + } while (page++, ++i < len); } if (nr_pmdmapped) @@ -1355,6 +1348,31 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, mlock_vma_folio(folio, vma, compound); } +/** + * page_add_file_rmap - add pte mapping to a file page + * @page: the page to add the mapping to + * @vma: the vm area in which the mapping is added + * @compound: charge the page as compound or small page + * + * The caller needs to hold the pte lock. + */ +void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, + bool compound) +{ + struct folio *folio = page_folio(page); + int nr_pages; + + VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); + + if (likely(!compound)) + nr_pages = 1; + else + nr_pages = folio_nr_pages(folio); + + page_add_file_rmap_range(folio, page, nr_pages, vma, compound); +} + /** * page_remove_rmap - take down pte mapping from a page * @page: page to remove mapping from -- 2.30.2