From patchwork Mon Oct 2 14:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13406285 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 DF79AE784B3 for ; Mon, 2 Oct 2023 14:30:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69DFC6B0140; Mon, 2 Oct 2023 10:30:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64DE66B0158; Mon, 2 Oct 2023 10:30:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53D256B0159; Mon, 2 Oct 2023 10:30:01 -0400 (EDT) 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 40B356B0140 for ; Mon, 2 Oct 2023 10:30:01 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 092DF402DD for ; Mon, 2 Oct 2023 14:30:01 +0000 (UTC) X-FDA: 81300755802.30.165D64D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 284594000D for ; Mon, 2 Oct 2023 14:29:57 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y5U0Y6mU; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1696256998; 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=74/4kguVt+JNeClEzh2bgjVFXMUXyl4kPsimySG+lfk=; b=4nlyeFJlFgZJqIfmN+hpUo/B7tNcLdoSz1PAvYyxyNMvn+zYERGeAEGqkgPMAKYX5r1ewV LeOGdvmOq4oeWNXjfi7SBoIVd8/hMCqGiG19UyhtPAzuIEZX02NCb7wQuzslmxNbYKRT2R t2fANdy0Pd55pnICv5qYd3bURZtibcw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y5U0Y6mU; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696256998; a=rsa-sha256; cv=none; b=FPsWYnxqQdW6Ucu5EVl8BcgamK8VtmhVknTj3Yrksemaue9VDML9McwErXUzCyTp+xLZcf O8znbqv+1OdIyca1XfQfpLFbnAn1DHD6M97PPD1hyf9HcPZM9ylgatP5qsQiumi1ALTZhS eBXG8QwAuLtpX47eiFG2emeYjmUXOZU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696256997; 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=74/4kguVt+JNeClEzh2bgjVFXMUXyl4kPsimySG+lfk=; b=Y5U0Y6mUvc8tOXPyv+L+x1UMw0c1OVT8QsrdyGbyM1M/50aKRRxm6XtRpswBuwazG1AzP7 lV8tLpNd/idC0q8/4mPNDBCJTLSbwbVei6gZ1VJjwg5HYTXSeCmwzEfP0Cw7hYv5EZpVI8 pIkD6uJfBxaJmPygfwPQdY3+Cd/aZmA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237-MXePQoblNP-G9nwx88mC8A-1; Mon, 02 Oct 2023 10:29:53 -0400 X-MC-Unique: MXePQoblNP-G9nwx88mC8A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5A84801779; Mon, 2 Oct 2023 14:29:52 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52811005B90; Mon, 2 Oct 2023 14:29:51 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song , Suren Baghdasaryan Subject: [PATCH v1 1/3] mm/rmap: move SetPageAnonExclusive() out of page_move_anon_rmap() Date: Mon, 2 Oct 2023 16:29:47 +0200 Message-ID: <20231002142949.235104-2-david@redhat.com> In-Reply-To: <20231002142949.235104-1-david@redhat.com> References: <20231002142949.235104-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 284594000D X-Rspam-User: X-Stat-Signature: f1qz6sidbxhczrb1jw4s5rppmi95jg3g X-Rspamd-Server: rspam01 X-HE-Tag: 1696256997-845418 X-HE-Meta: U2FsdGVkX1+PFMVT7g83O3OLDieWyicCBPVzgAzvUHjuTLm0KdfYoVjxFxHSrd53+tOB8dNc8FgptLzkG924/olzK5jXMGOKzkEPEIyIxyVW3Ns/jZf3oc/snlfS6TUR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6dvbuU6FEDlA== 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: Let's move it into the caller: there is a difference between whether an anon folio can only be mapped by one process (e.g., into one VMA), and whether it is truly exclusive (e.g., no references -- including GUP -- from other processes). Further, for large folios the page might not actually be pointing at the head page of the folio, so it better be handled in the caller. This is a preparation for converting page_move_anon_rmap() to consume a folio. Signed-off-by: David Hildenbrand Reviewed-by: Suren Baghdasaryan Reviewed-by: Vishal Moola (Oracle) --- mm/huge_memory.c | 1 + mm/hugetlb.c | 4 +++- mm/memory.c | 1 + mm/rmap.c | 1 - 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e54fb9c542bb..01d0d65ece13 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1506,6 +1506,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf) pmd_t entry; page_move_anon_rmap(page, vma); + SetPageAnonExclusive(page); folio_unlock(folio); reuse: if (unlikely(unshare)) { diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9c22297d9c57..24591fc145ff 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5460,8 +5460,10 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, * owner and can reuse this page. */ if (folio_mapcount(old_folio) == 1 && folio_test_anon(old_folio)) { - if (!PageAnonExclusive(&old_folio->page)) + if (!PageAnonExclusive(&old_folio->page)) { page_move_anon_rmap(&old_folio->page, vma); + SetPageAnonExclusive(&old_folio->page); + } if (likely(!unshare)) set_huge_ptep_writable(vma, haddr, ptep); diff --git a/mm/memory.c b/mm/memory.c index d4820802b01b..9de231c92769 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3484,6 +3484,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) * sunglasses. Hit it. */ page_move_anon_rmap(vmf->page, vma); + SetPageAnonExclusive(vmf->page); folio_unlock(folio); reuse: if (unlikely(unshare)) { diff --git a/mm/rmap.c b/mm/rmap.c index 77222adccda1..854ccbd66954 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1165,7 +1165,6 @@ void page_move_anon_rmap(struct page *page, struct vm_area_struct *vma) * folio_test_anon()) will not see one without the other. */ WRITE_ONCE(folio->mapping, anon_vma); - SetPageAnonExclusive(page); } /**