Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2740458rdb; Mon, 4 Dec 2023 06:24:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9ndNDVOzgmPnVAse3QEu9ZI38u4sGXU1GcfOWPuqOI5pv1O8K0x5nDU0xxmIJogpuoMtQ X-Received: by 2002:a17:903:1104:b0:1d0:6ffd:6e71 with SMTP id n4-20020a170903110400b001d06ffd6e71mr2183313plh.105.1701699885566; Mon, 04 Dec 2023 06:24:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701699885; cv=none; d=google.com; s=arc-20160816; b=lAihyl7bqBdOvVuW9tGtAc7fTnlb2QqQMR/E10/wEUO2hKEwNu46yG971EFLIOO2OB 6QxtDlxtAlzE4BwiPgcc6u8thyVQXz8f3iq4WhkZtibgCG/qn/zXrkJbqUwmunWky8Ew qaogHUnNWKXNHTR/oIJwQA8ZsdAAWlwWCkNJmrnRXRIlkvQ+dxyOn+fM86g/orLLR1Rf R8Oxk0BZ1rOYaay4nPVlg0RtKPk83R/7F48SdQayFH5UAbqFv5V8ZNg2y9ij06dUejft Q4LCC0DSSPRT50hwkk4GgPxb+UrT48Jp7TyLZ/jTO0owQ8BBhQnEQT6cwlwChqopOHNM bznw== 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=nWXNFAD1MN3p2bcOLf/LK1onshg4c1syDBwJJ/+GHnY=; fh=UlFXU+hKOMcm6idRzNfe3Pu+B5L1f7aeir3C6i/NWQA=; b=QXGuhD5YlQDJTOvOa7f1r+kcFvIQN95e2lQrqm24yqgqVip8TwBEm+8ntUnWqeKnC3 JNY5oZvq1ZAUT+r70vjE/1Mgxxe2p0PNqxenTzdVCt2h85Kl/HAtokfJZUiQgzVvXzjF c2IRF24WeFrNhR6vTpY2rIEcWByIk17RjUxdG7yJHqbAN4KDEqCYkAs9v1wC3thcNg1z Tbg7tfIPdL/5PQKLgMocngX8XCHjW89SjGAbzmPeEH+LH61rFoDw+y5jppE+MrAjq/MZ Y5Pl3KbTS5MusOierH7PQBSRR8Basky0MK9gDQvHtN9CKKEeA7f7/JZ+Su6wunU4yS7i jSdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dwT+6TRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y10-20020a170902864a00b001cfa70f3a2asi7572673plt.245.2023.12.04.06.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:24:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dwT+6TRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 932108054C24; Mon, 4 Dec 2023 06:24:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345085AbjLDOYT (ORCPT + 99 others); Mon, 4 Dec 2023 09:24:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235912AbjLDOXg (ORCPT ); Mon, 4 Dec 2023 09:23:36 -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 5B53B1B9 for ; Mon, 4 Dec 2023 06:22:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701699764; 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=nWXNFAD1MN3p2bcOLf/LK1onshg4c1syDBwJJ/+GHnY=; b=dwT+6TRX6ItsxFnwBsyZx/EDPJpyZGHZPV2lZD7CgFlX+5ASdL7uw51ezPR1pCoaMUQ1o7 VjPV4ZGpTEkMvv/JRuKi/erQG2NgZgAlB3dPK1Lf0O4XrAZ82Ish6PH+w4SM7p9NtrST0X DbX8RRYyo5b36Ao/0vmcOQkZi8rIfYE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-208-G1DqHr0HMdSb4ua9mh5Iag-1; Mon, 04 Dec 2023 09:22:42 -0500 X-MC-Unique: G1DqHr0HMdSb4ua9mh5Iag-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 A7F1A29AA3AE; Mon, 4 Dec 2023 14:22:41 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.195.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C88C2026D4C; Mon, 4 Dec 2023 14:22:39 +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 28/39] mm/memory: page_remove_rmap() -> folio_remove_rmap_pte() Date: Mon, 4 Dec 2023 15:21:35 +0100 Message-ID: <20231204142146.91437-29-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 06:24:42 -0800 (PST) Let's convert zap_pte_range() and closely-related tlb_flush_rmap_batch(). While at it, perform some more folio conversion in zap_pte_range(). Signed-off-by: David Hildenbrand --- mm/memory.c | 23 +++++++++++++---------- mm/mmu_gather.c | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 9543b6e2b749b..8c4f98bb617fa 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1425,6 +1425,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, arch_enter_lazy_mmu_mode(); do { pte_t ptent = ptep_get(pte); + struct folio *folio; struct page *page; if (pte_none(ptent)) @@ -1450,21 +1451,22 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, continue; } + folio = page_folio(page); delay_rmap = 0; - if (!PageAnon(page)) { + if (!folio_test_anon(folio)) { if (pte_dirty(ptent)) { - set_page_dirty(page); + folio_set_dirty(folio); if (tlb_delay_rmap(tlb)) { delay_rmap = 1; force_flush = 1; } } if (pte_young(ptent) && likely(vma_has_recency(vma))) - mark_page_accessed(page); + folio_mark_accessed(folio); } rss[mm_counter(page)]--; if (!delay_rmap) { - page_remove_rmap(page, vma, false); + folio_remove_rmap_pte(folio, page, vma); if (unlikely(page_mapcount(page) < 0)) print_bad_pte(vma, addr, ptent, page); } @@ -1480,6 +1482,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (is_device_private_entry(entry) || is_device_exclusive_entry(entry)) { page = pfn_swap_entry_to_page(entry); + folio = page_folio(page); if (unlikely(!should_zap_page(details, page))) continue; /* @@ -1491,8 +1494,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, WARN_ON_ONCE(!vma_is_anonymous(vma)); rss[mm_counter(page)]--; if (is_device_private_entry(entry)) - page_remove_rmap(page, vma, false); - put_page(page); + folio_remove_rmap_pte(folio, page, vma); + folio_put(folio); } else if (!non_swap_entry(entry)) { /* Genuine swap entry, hence a private anon page */ if (!should_zap_cows(details)) @@ -3210,10 +3213,10 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * threads. * * The critical issue is to order this - * page_remove_rmap with the ptp_clear_flush above. - * Those stores are ordered by (if nothing else,) + * folio_remove_rmap_pte() with the ptp_clear_flush + * above. Those stores are ordered by (if nothing else,) * the barrier present in the atomic_add_negative - * in page_remove_rmap. + * in folio_remove_rmap_pte(); * * Then the TLB flush in ptep_clear_flush ensures that * no process can access the old page before the @@ -3222,7 +3225,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * mapcount is visible. So transitively, TLBs to * old page will be flushed before it can be reused. */ - page_remove_rmap(vmf->page, vma, false); + folio_remove_rmap_pte(old_folio, vmf->page, vma); } /* Free the old page.. */ diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 4f559f4ddd217..604ddf08affed 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -55,7 +55,7 @@ static void tlb_flush_rmap_batch(struct mmu_gather_batch *batch, struct vm_area_ if (encoded_page_flags(enc)) { struct page *page = encoded_page_ptr(enc); - page_remove_rmap(page, vma, false); + folio_remove_rmap_pte(page_folio(page), page, vma); } } } -- 2.41.0