Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2741739rdb; Mon, 4 Dec 2023 06:26:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSioaLzrAaxDla+yu4n8yTAA6xVk0juJOuR5dmxyDoud1XWjJxp170xSRXqiwQaKw5o8q1 X-Received: by 2002:a17:902:a716:b0:1d0:6ffd:6122 with SMTP id w22-20020a170902a71600b001d06ffd6122mr4114082plq.68.1701700008012; Mon, 04 Dec 2023 06:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701700007; cv=none; d=google.com; s=arc-20160816; b=vcagmlK5e7K2mG2dosRi3MMbb8aVti2bWdLAMtwMKVoXOyWTh/JlWs/JRHFCUn8vxF Qh8Hg5f6O3ETHsIEdlnz8iDot+A4U30dyRGbNjVBSkD0gJ8mMxg8EsX1A1xSQI2NwXIz OAtH9CxetWHlBvbToxTv2aMhz7j4hHmwt96Tip7+anRkDk9noXHzUsw3gf/Tm5ENadVH nsuEKMLmcd+r+WW+XFJ9MLzeCjra7jgkpmaEe61p6wL1mJZObHcOuC67nzxrhBNUylES Yr0wfA3VryA55GkAFnks8jXrR45hlTahg80kniJB6DivYxji31PG7SncNT18PUecQgZl bpGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fiJf6xaTCn9hTJUSpG0inAWeRQ8SaM/ZLU1i30jXpOI=; fh=UlFXU+hKOMcm6idRzNfe3Pu+B5L1f7aeir3C6i/NWQA=; b=ln2eTIXViLdxKLTzxBgatyF8VofnOX5iyBk3dveHk257Mpfv5GPC8E0iBaZGaRCMFz vRf/zkz8Z1P+Ewvsmnu/QogEPlRA7SUEgHne3jY4XCnM8rP/WXA7aZ31rpmEzhtWT6IX ddtXDRKfm2LizPJ4Q1Us5XbMutip64cyexlKsjQh5xk7C87lOzDqgyXVdGtEgPwZzTf2 A0dJ7pINi+on+ZpNPoQGXprcAI1xxp7RW7A3Z4vr1qv3yDp5+gHp9L0Tzln+bs0reiPP Eu1HZCDGzOhhOd3ZBnQ82mNPgGmY0o7N9uBTQVu2c1Cm6/CpZerYpDJSgl+zbIO9FQvc tqrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=asngjzMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id v13-20020a170903238d00b001cfb55da13bsi1787959plh.332.2023.12.04.06.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:26:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=asngjzMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A89D1808D8EB; Mon, 4 Dec 2023 06:26:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234200AbjLDO01 (ORCPT + 99 others); Mon, 4 Dec 2023 09:26:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236044AbjLDO0B (ORCPT ); Mon, 4 Dec 2023 09:26:01 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A49F30C1 for ; Mon, 4 Dec 2023 06:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701699814; 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=asngjzMlhUU39DZx8hK0LeWM/KllccQY6HZzT294anYLK9LdIA71uEj3s5gGq8qD1epNdq MYnfJTpXsM+Lbc3/MquA/QILABOPLl+uMXI9HFcEpmjFHfffi/z3rVYQaEdOanYodWNjJh en8w42Ajh2Jq/HkqogoQnNp/q9YWQJE= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 06:26:44 -0800 (PST) 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)]++; } -- 2.41.0