From patchwork Mon Dec 4 14:21:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13478541 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 18484C4167B for ; Mon, 4 Dec 2023 14:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D3B86B02E3; Mon, 4 Dec 2023 09:23:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 384E86B02E4; Mon, 4 Dec 2023 09:23:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B2276B02E6; Mon, 4 Dec 2023 09:23:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA3A66B02E3 for ; Mon, 4 Dec 2023 09:23:37 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BE0E51201E2 for ; Mon, 4 Dec 2023 14:23:37 +0000 (UTC) X-FDA: 81529354074.30.7A6813B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id CF73A1C0025 for ; Mon, 4 Dec 2023 14:23:35 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TwbH7afj; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701699815; 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=fiJf6xaTCn9hTJUSpG0inAWeRQ8SaM/ZLU1i30jXpOI=; b=Noqtlffydx7zPp/iZHA0PjpAPy8PlLqPHSImg8QuRROm/z25wjcWbjtV2QxQFdj3byxZoC xXrJkBu0m1VVAi1u4RdZzWSLZCuz5m/xzPSknczTurZVKN1SjRsjjYSBv73jLQ4c/9tXxT fHAtK5G9fOG9cIZsMDP4hwpU/IYlV98= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701699815; a=rsa-sha256; cv=none; b=m7PBWrDzsBUDWAAihfnNU4WACR3aU/gMGi8CvYUX1KQ2ByfflUTK7f7kI1nAthedaGcwOk tdi4OZOL+yBny+puvxUPm3usCg3wL0/jS/pQtdnAftXxO3ikhx73y7L93a11V5mhw+zJ8M C6JEVyDQunA/SGmxqSSaDVDXZ++scBk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TwbH7afj; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701699815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fiJf6xaTCn9hTJUSpG0inAWeRQ8SaM/ZLU1i30jXpOI=; b=TwbH7afjQKQEnyqLEGtIb9t5bXh3U5QEDCJWgVHdQtBaeZebGIrAxoQTCzZQqmeWYyDfXQ EBTqGPsfxOjKnwLSxLUp/2FxdxnNGxB+5Xgs47yzYBJDiiloKy4mWUY2JVoEHH6KoYrcgl rX+gF2/UnIhaVoE2qkza9sX14fhE3RI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-164-gWsSkqhfMSOvilQ5o3bMzQ-1; Mon, 04 Dec 2023 09:23:25 -0500 X-MC-Unique: gWsSkqhfMSOvilQ5o3bMzQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 53AF1811E82; Mon, 4 Dec 2023 14:22:51 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.195.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD95F2026D4C; Mon, 4 Dec 2023 14:22:49 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Hugh Dickins , Ryan Roberts , Yin Fengwei , Mike Kravetz , Muchun Song , Peter Xu Subject: [PATCH RFC 33/39] mm/rmap: convert page_dup_file_rmap() to folio_dup_file_rmap_[pte|ptes|pmd]() Date: Mon, 4 Dec 2023 15:21:40 +0100 Message-ID: <20231204142146.91437-34-david@redhat.com> In-Reply-To: <20231204142146.91437-1-david@redhat.com> References: <20231204142146.91437-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Rspamd-Queue-Id: CF73A1C0025 X-Rspam-User: X-Stat-Signature: 9y3y6wrfq9cuoond1npjch4abjd3j6ub X-Rspamd-Server: rspam03 X-HE-Tag: 1701699815-554988 X-HE-Meta: U2FsdGVkX18gq1fazmpehLDkfeB2zI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UYj5dH1zwPWE2H+QFZe6/z1RzHhe+F+9dgAcRSRqQB4nskYH3p2qyo2Y+CF/ABiP6gJUR9gb1r6HjWyWzy+2GfgpF01k7D8XPnJjS+PD 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: Let's convert page_dup_file_rmap() like the other rmap functions. As there is only a single caller, convert that single caller right away and remove page_dup_file_rmap(). Add folio_dup_file_rmap_ptes() right away, we want to perform rmap baching during fork() soon. Signed-off-by: David Hildenbrand --- include/linux/rmap.h | 56 ++++++++++++++++++++++++++++++++++++++++---- mm/memory.c | 2 +- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index bdbfb11638e4f..21d72cc602adc 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -303,6 +303,57 @@ static inline void hugetlb_remove_rmap(struct folio *folio) atomic_dec(&folio->_entire_mapcount); } +static inline void __folio_dup_rmap(struct folio *folio, struct page *page, + unsigned int nr_pages, enum rmap_mode mode) +{ + __folio_rmap_sanity_checks(folio, page, nr_pages, mode); + + if (likely(mode == RMAP_MODE_PTE)) { + do { + atomic_inc(&page->_mapcount); + } while (page++, --nr_pages > 0); + } else if (mode == RMAP_MODE_PMD) { + atomic_inc(&folio->_entire_mapcount); + } +} + +/** + * folio_dup_file_rmap_ptes - duplicate PTE mappings of a page range of a folio + * @folio: The folio to duplicate the mappings of + * @page: The first page to duplicate the mappings of + * @nr_pages: The number of pages of which the mapping will be duplicated + * + * The page range of the folio is defined by [page, page + nr_pages) + * + * The caller needs to hold the page table lock. + */ +static inline void folio_dup_file_rmap_ptes(struct folio *folio, + struct page *page, unsigned int nr_pages) +{ + __folio_dup_rmap(folio, page, nr_pages, RMAP_MODE_PTE); +} +#define folio_dup_file_rmap_pte(folio, page) \ + folio_dup_file_rmap_ptes(folio, page, 1) + +/** + * folio_dup_file_rmap_pmd - duplicate a PMD mapping of a page range of a folio + * @folio: The folio to duplicate the mapping of + * @page: The first page to duplicate the mapping of + * + * The page range of the folio is defined by [page, page + HPAGE_PMD_NR) + * + * The caller needs to hold the page table lock. + */ +static inline void folio_dup_file_rmap_pmd(struct folio *folio, + struct page *page) +{ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + __folio_dup_rmap(folio, page, HPAGE_PMD_NR, RMAP_MODE_PTE); +#else + WARN_ON_ONCE(true); +#endif +} + static inline void __page_dup_rmap(struct page *page, bool compound) { VM_WARN_ON(folio_test_hugetlb(page_folio(page))); @@ -317,11 +368,6 @@ static inline void __page_dup_rmap(struct page *page, bool compound) } } -static inline void page_dup_file_rmap(struct page *page, bool compound) -{ - __page_dup_rmap(page, compound); -} - /** * page_try_dup_anon_rmap - try duplicating a mapping of an already mapped * anonymous page diff --git a/mm/memory.c b/mm/memory.c index 8c4f98bb617fa..eaab6a2e14eba 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -961,7 +961,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, rss[MM_ANONPAGES]++; } else if (page) { folio_get(folio); - page_dup_file_rmap(page, false); + folio_dup_file_rmap_pte(folio, page); rss[mm_counter_file(page)]++; }