From patchwork Tue Nov 28 14:52:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13471278 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 E22DFC4167B for ; Tue, 28 Nov 2023 14:52:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E0BB6B0302; Tue, 28 Nov 2023 09:52:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7914A6B0306; Tue, 28 Nov 2023 09:52:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659776B0307; Tue, 28 Nov 2023 09:52:19 -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 569F16B0302 for ; Tue, 28 Nov 2023 09:52:19 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3351216027A for ; Tue, 28 Nov 2023 14:52:19 +0000 (UTC) X-FDA: 81507653598.20.FA0D302 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 5826780014 for ; Tue, 28 Nov 2023 14:52:17 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RUxfsXEw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701183137; 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=v3TJbNWNpIXvBErov8koQ5cDTRfHHR66tcHCVvKwONQ=; b=6WXxhLo+lfB8k96qSvEijwsWJx4vvXquBbBV61I7JZj10BBQddxFyGj3SXxw8bT1l2r/Iv TFoS5BvvG6Y0/Q6+7VhvPFCfR2NiV+JyFeWAR2+uv4bn/KDWcBjQoACxINolaJzG1QcL9Y d+DratKn3JwInT5OXNYXMfQaSPUoo60= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RUxfsXEw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701183137; a=rsa-sha256; cv=none; b=pwQqKq0vS21N8uO/5WT69eHpLpl1JlGQMhPytayx5R79lMNPIjdkQNSt86mWVvWzgOU+Ho 42aUD7d0A/wheHHVv7+/PEfpdFOILvYlHFe8n8bnUqreDigXtF+weBcpkJax/ZMw/xIwC6 m1PFz0eSUT6jYR4IafiPzg3gHsJqeo8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183136; 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=v3TJbNWNpIXvBErov8koQ5cDTRfHHR66tcHCVvKwONQ=; b=RUxfsXEwVlLDutCxgkVC6g65nzDeoOiiDHea83quOvvxeDTT5Fq4gK2dKpNyg+dVp5l6y0 T3mXxYR6J0sIMATsYc5AzZI5tM7zwzcQoSXjiJ27AqN7ZGJYzMWjgbeDg1Mwmorz2p0Z5s yPikfd+Pnjr6eFwxGN4T3v26z3Jsd7E= 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-625-Ns9ZSoWwPHWGhnYE2l0gLQ-1; Tue, 28 Nov 2023 09:52:08 -0500 X-MC-Unique: Ns9ZSoWwPHWGhnYE2l0gLQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 3029D1019C83; Tue, 28 Nov 2023 14:52:08 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 232B85028; Tue, 28 Nov 2023 14:52:07 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song Subject: [PATCH v1 1/5] mm/rmap: rename hugepage_add* to hugetlb_add* Date: Tue, 28 Nov 2023 15:52:01 +0100 Message-ID: <20231128145205.215026-2-david@redhat.com> In-Reply-To: <20231128145205.215026-1-david@redhat.com> References: <20231128145205.215026-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5826780014 X-Stat-Signature: 5bh4g41o7kakb86g3yeedpnnrj8ni3ep X-Rspam-User: X-HE-Tag: 1701183137-249597 X-HE-Meta: U2FsdGVkX1/8gTao+4nQOMbt4H2YhoB3ECBdf5R03fjIjZnLB1RDgkbcuTGdxk4KF0vXkIC9rqEEx0Hwa284OEeg/RuyPmIoRsKVWfSgPtboJmxHTRK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DaLx0PbDBvfA4e1mmwWGiW8HQ== 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 just call it "hugetlb_". Yes, it's all already inconsistent and confusing because we have a lot of "hugepage_" functions for legacy reasons. But "hugetlb" cannot possibly be confused with transparent huge pages, and it matches "hugetlb.c" and "folio_test_hugetlb()". So let's minimize confusion in rmap code. Signed-off-by: David Hildenbrand Reviewed-by: Muchun Song --- include/linux/rmap.h | 4 ++-- mm/hugetlb.c | 8 ++++---- mm/migrate.c | 4 ++-- mm/rmap.c | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b26fe858fd44..4c5bfeb05463 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -203,9 +203,9 @@ void folio_add_file_rmap_range(struct folio *, struct page *, unsigned int nr, void page_remove_rmap(struct page *, struct vm_area_struct *, bool compound); -void hugepage_add_anon_rmap(struct folio *, struct vm_area_struct *, +void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address, rmap_t flags); -void hugepage_add_new_anon_rmap(struct folio *, struct vm_area_struct *, +void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); static inline void __page_dup_rmap(struct page *page, bool compound) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1169ef2f2176..4cfa0679661e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5278,7 +5278,7 @@ hugetlb_install_folio(struct vm_area_struct *vma, pte_t *ptep, unsigned long add pte_t newpte = make_huge_pte(vma, &new_folio->page, 1); __folio_mark_uptodate(new_folio); - hugepage_add_new_anon_rmap(new_folio, vma, addr); + hugetlb_add_new_anon_rmap(new_folio, vma, addr); if (userfaultfd_wp(vma) && huge_pte_uffd_wp(old)) newpte = huge_pte_mkuffd_wp(newpte); set_huge_pte_at(vma->vm_mm, addr, ptep, newpte, sz); @@ -5981,7 +5981,7 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, /* Break COW or unshare */ huge_ptep_clear_flush(vma, haddr, ptep); page_remove_rmap(&old_folio->page, vma, true); - hugepage_add_new_anon_rmap(new_folio, vma, haddr); + hugetlb_add_new_anon_rmap(new_folio, vma, haddr); if (huge_pte_uffd_wp(pte)) newpte = huge_pte_mkuffd_wp(newpte); set_huge_pte_at(mm, haddr, ptep, newpte, huge_page_size(h)); @@ -6270,7 +6270,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, goto backout; if (anon_rmap) - hugepage_add_new_anon_rmap(folio, vma, haddr); + hugetlb_add_new_anon_rmap(folio, vma, haddr); else page_dup_file_rmap(&folio->page, true); new_pte = make_huge_pte(vma, &folio->page, ((vma->vm_flags & VM_WRITE) @@ -6725,7 +6725,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, if (folio_in_pagecache) page_dup_file_rmap(&folio->page, true); else - hugepage_add_new_anon_rmap(folio, dst_vma, dst_addr); + hugetlb_add_new_anon_rmap(folio, dst_vma, dst_addr); /* * For either: (1) CONTINUE on a non-shared VMA, or (2) UFFDIO_COPY diff --git a/mm/migrate.c b/mm/migrate.c index 35a88334bb3c..4cb849fa0dd2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -249,8 +249,8 @@ static bool remove_migration_pte(struct folio *folio, pte = arch_make_huge_pte(pte, shift, vma->vm_flags); if (folio_test_anon(folio)) - hugepage_add_anon_rmap(folio, vma, pvmw.address, - rmap_flags); + hugetlb_add_anon_rmap(folio, vma, pvmw.address, + rmap_flags); else page_dup_file_rmap(new, true); set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte, diff --git a/mm/rmap.c b/mm/rmap.c index 7a27a2b41802..112467c30b2c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2583,8 +2583,8 @@ void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc) * * RMAP_COMPOUND is ignored. */ -void hugepage_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, - unsigned long address, rmap_t flags) +void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, + unsigned long address, rmap_t flags) { VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); @@ -2595,8 +2595,8 @@ void hugepage_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, PageAnonExclusive(&folio->page), folio); } -void hugepage_add_new_anon_rmap(struct folio *folio, - struct vm_area_struct *vma, unsigned long address) +void hugetlb_add_new_anon_rmap(struct folio *folio, + struct vm_area_struct *vma, unsigned long address) { BUG_ON(address < vma->vm_start || address >= vma->vm_end); /* increment count (starts at -1) */ From patchwork Tue Nov 28 14:52:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13471282 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 A1524C10DC2 for ; Tue, 28 Nov 2023 14:52:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A54036B030F; Tue, 28 Nov 2023 09:52:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DC886B0316; Tue, 28 Nov 2023 09:52:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82E406B031A; Tue, 28 Nov 2023 09:52:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6D0CD6B030F for ; Tue, 28 Nov 2023 09:52:25 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 482F6A024C for ; Tue, 28 Nov 2023 14:52:25 +0000 (UTC) X-FDA: 81507653850.19.F453F9D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 7E1FE20026 for ; Tue, 28 Nov 2023 14:52:23 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dzmtyfQO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701183143; 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=PmPjXh3Vh8+yuItVsdShx0BHlebvdn/GvnE6+gvw2TQ=; b=mIqX92IA4RMLohGgI8KiL7anAbFdiHez9OH60Z29wEtk6Hj9zQ4RoSh4/GjeD9KcQDr8P6 e+t5Btjn/zoNL4epD80V2v0vIYO2kg+ertJUDHgCe1F/JSu7dvw9qhzfqUVI1qNktx8JUj OJKTP2QassrC1ljB+xlJOrlqXmea+28= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dzmtyfQO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701183143; a=rsa-sha256; cv=none; b=PN+2QsbFIEFoHRzGJJWJqCmYqIah4IunJgC9sJUuGtKPYqh9BUZGNAHozQaiNB8MEc4WUj 0zKHoSYhu4d00fUCIwjFa4yeIoIX0WuetUXRSmHEMwUyvcJ298nHbFAJSOC6X9IwXENyxB 55zJnHiNAFOXrwHl0Zv4s3kbCxVY9A8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183142; 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=PmPjXh3Vh8+yuItVsdShx0BHlebvdn/GvnE6+gvw2TQ=; b=dzmtyfQOVZZI55bgVGlwTGB3I++v+L9YaheHQ8gyaFNfPTTW/SuIBjkLWuRuv7c4AHempr 4UjdVOFAIp7QmrYKtQtp2oPcvp358cxchCHT4YlJzAE+q08KmNnRC9+ls6uPiep5HKfZFG +Ovt4CJuEGasINxRNp+aDie/J7Wi6EA= 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-623-3AskqEHWOzuit0KMJT14zw-1; Tue, 28 Nov 2023 09:52:12 -0500 X-MC-Unique: 3AskqEHWOzuit0KMJT14zw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 665EB101A52D; Tue, 28 Nov 2023 14:52:09 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B2E35028; Tue, 28 Nov 2023 14:52:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song Subject: [PATCH v1 2/5] mm/rmap: introduce and use hugetlb_remove_rmap() Date: Tue, 28 Nov 2023 15:52:02 +0100 Message-ID: <20231128145205.215026-3-david@redhat.com> In-Reply-To: <20231128145205.215026-1-david@redhat.com> References: <20231128145205.215026-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7E1FE20026 X-Stat-Signature: ufquixwf4cgxeyym6gqdhw4ep4eosmmk X-HE-Tag: 1701183143-603522 X-HE-Meta: U2FsdGVkX1+jhy99eeqzY247W7YIUHHLirs85BOK2LYZSIZPySc6yP0VtvN0lXiVlT5SBADO74xG7WKA2TwxWdhhBuKGiRkwKyhFWyexDnxvtXvmO1u9U+vZm70YODlQojTHNY+7Ja5EYRJLprv3+PFimG7gTeQsNvsV3LghxMeX5Ls85CGT40FRFmdoehB1lYDUNF+YvDdfXBYQxHIclGWWuwJsygCEpzQRgIWj+5+o3b0HbXguwme0SkyfmQqA3IlPoVKNmpG6kEbpvEQBeF97miGN0w64XYtiaabGOCjzuP4gUZ3u7/7rNCDBkHieiu7ujPZ3Orjct00EVVqXJPF+Fp+19+2+nJ0jcEOF3dhmkCi4cK2cEcInP5SxRfc7S8j1nayl/tt1oheb4kp8CgtZVUZiT7OePgqHuZ21pWcCv6ZTQMAUkYOzZfp7FGovwQph4r76/L6Ceou1wd3jNhUcJ16iRAP8lRgG43rK2EhqjXg/GGSorwV7AF4a5mzf4UNgxoGhvqIzJk3DoLG3XPQ0kysOtw55CvvwRYorQ9vdrKEfeoHj7cJDVJBsqraWsKa2oPWj7YsaO5beHGJAWs4poXkj78wVlG92FjAda06VIPwCav/92JrUQgjtylG6OSakKtD9/panIVbT/49Kex+nBN/4J5Qr5/rQq96YM7Z/zW4mIiO5qUibDZtUyoXDV5ihOkihI4HuDrfX65u0cL95jm5jJfioqjUB/qJXssl9dRAfPH+Bqridsd45vV4vTAJ30XZUal6mLVJDSrPmKyuWQo/OXPQky0W2hT0O9a5vunF7WeEV+2ryoVAMDLc7fvqz0fM61LhaVnSwS9PupNDSQIM7Yw5j6wyyUhcUuVs+raYEfbFQg/NJUxlWtH2ELDpriRWtlrE5LqpDBF01ICMfNMo48wvQblNwypcdVt3xtRVTmj3mE0alAQdsCZ1p9Or7yvqrsVvO9xeTN+/ 9pHw781z NxTlTBcx62+/83MmvsNDXX26Ssrm+vdhj9NODEntHfQDq+9Fr5N+BBZZEUQLDfEgiq6I3XhhpWVJkEgA5D4GGQE4nd6FMC9ZrarY3Sq+PwLCkS+RxneV9NSoSTgQQuLqR7uljKZ2V/QNSi8WjXiOhfDfrkJvVcWOPVEnWsG+vcP303f5Gd1oxmHJT9r9DuMJomkuuF+CeelDtoMEmA0p70jG9sQ== 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: hugetlb rmap handling differs quite a lot from "ordinary" rmap code. We don't want this hugetlb special-casing in the rmap functions, as we're special casing the callers already. Let's simply use a separate function for hugetlb. Let's introduce and use hugetlb_remove_rmap() and remove the hugetlb code from page_remove_rmap(). This effectively removes one check on the small-folio path as well. While this is a cleanup, this will also make it easier to change rmap handling for partially-mappable folios. Note: all possible candidates that need care are page_remove_rmap() that pass compound=true. Signed-off-by: David Hildenbrand --- include/linux/rmap.h | 5 +++++ mm/hugetlb.c | 4 ++-- mm/rmap.c | 17 ++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 4c5bfeb05463..e8d1dc1d5361 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -208,6 +208,11 @@ void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *, void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); +static inline void hugetlb_remove_rmap(struct folio *folio) +{ + atomic_dec(&folio->_entire_mapcount); +} + static inline void __page_dup_rmap(struct page *page, bool compound) { if (compound) { diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4cfa0679661e..d17bb53b19ff 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5669,7 +5669,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, make_pte_marker(PTE_MARKER_UFFD_WP), sz); hugetlb_count_sub(pages_per_huge_page(h), mm); - page_remove_rmap(page, vma, true); + hugetlb_remove_rmap(page_folio(page)); spin_unlock(ptl); tlb_remove_page_size(tlb, page, huge_page_size(h)); @@ -5980,7 +5980,7 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, /* Break COW or unshare */ huge_ptep_clear_flush(vma, haddr, ptep); - page_remove_rmap(&old_folio->page, vma, true); + hugetlb_remove_rmap(old_folio); hugetlb_add_new_anon_rmap(new_folio, vma, haddr); if (huge_pte_uffd_wp(pte)) newpte = huge_pte_mkuffd_wp(newpte); diff --git a/mm/rmap.c b/mm/rmap.c index 112467c30b2c..5037581b79ec 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1440,13 +1440,6 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, VM_BUG_ON_PAGE(compound && !PageHead(page), page); - /* Hugetlb pages are not counted in NR_*MAPPED */ - if (unlikely(folio_test_hugetlb(folio))) { - /* hugetlb pages are always mapped with pmds */ - atomic_dec(&folio->_entire_mapcount); - return; - } - /* Is page being unmapped by PTE? Is this its last map to be removed? */ if (likely(!compound)) { last = atomic_add_negative(-1, &page->_mapcount); @@ -1804,7 +1797,10 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, dec_mm_counter(mm, mm_counter_file(&folio->page)); } discard: - page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); + if (unlikely(folio_test_hugetlb(folio))) + hugetlb_remove_rmap(folio); + else + page_remove_rmap(subpage, vma, false); if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); folio_put(folio); @@ -2157,7 +2153,10 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, */ } - page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); + if (unlikely(folio_test_hugetlb(folio))) + hugetlb_remove_rmap(folio); + else + page_remove_rmap(subpage, vma, false); if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); folio_put(folio); From patchwork Tue Nov 28 14:52:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13471281 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 78576C10DAA for ; Tue, 28 Nov 2023 14:52:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A61C6B0308; Tue, 28 Nov 2023 09:52:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03EF26B0316; Tue, 28 Nov 2023 09:52:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC1FE6B0308; Tue, 28 Nov 2023 09:52:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8CA666B030D for ; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 68830A022A for ; Tue, 28 Nov 2023 14:52:21 +0000 (UTC) X-FDA: 81507653682.28.CA31D47 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 890C02001D for ; Tue, 28 Nov 2023 14:52:19 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FRqSDapY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701183139; 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=PsWlt7VFXdpW+l7o+7c53krc3omwX16daxLcjKx1KOM=; b=uL/GP0KBZJe7A5CUlrSgiWm0ToB26IQo/bSS45wdhcwg3Y5uz+L6DXP8xReyJB3fHzh9W0 WoYGvuvgnk+hoBDkdB8pbUvmaUxmnrCfS0p8z7rtQ8xywOxjiUJvgKTOCSqFGtO0H/kplo fIgvzAv8cRqiD4F+EGC3jhtH9o5Iym4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FRqSDapY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701183139; a=rsa-sha256; cv=none; b=XMXLsdu//1mMiMrCOdNuLE5YRqYXlAUsr+PSfi4/4YYL3UjWeOQEf3TYruZoFlzCJJpyTn tW2sbaQX0Pz1rq4BZjgyvUy1GzJgxOehuWzLdBZoDrFLvnSjynwRV5EYBouuBtELxkiIGp SuTkjTZFWGH4sH04qCqh6KsVOwwflvE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183138; 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=PsWlt7VFXdpW+l7o+7c53krc3omwX16daxLcjKx1KOM=; b=FRqSDapYzfhrI0qEbxk8QirMz6Rjvo6PzfuSquooTdH5lkMF5eLT7/BPWNv+srIcaNjR4O 7YlmiVlEWNc9S7yRXSVeqIBXugXuaftbvNBWKF+QA02LqpdntApUo4lffWBqp1JVwl7YEo o+SFJfB6h2ewAfY7lysZ8Nju+s4HEtw= 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-671-OEY_3b4gMlmzc9twX3txxQ-1; Tue, 28 Nov 2023 09:52:15 -0500 X-MC-Unique: OEY_3b4gMlmzc9twX3txxQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 A088B3812597; Tue, 28 Nov 2023 14:52:10 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E85F503A; Tue, 28 Nov 2023 14:52:09 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song Subject: [PATCH v1 3/5] mm/rmap: introduce and use hugetlb_add_file_rmap() Date: Tue, 28 Nov 2023 15:52:03 +0100 Message-ID: <20231128145205.215026-4-david@redhat.com> In-Reply-To: <20231128145205.215026-1-david@redhat.com> References: <20231128145205.215026-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Queue-Id: 890C02001D X-Rspam-User: X-Rspamd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VJU+suu1QLSSc7yEjYYU6vM79Chyztd/zRv2WnoraLM8vDbJZNSmin/jwV+X5i1kM5ifHRpHjzaPyvV7Gc4epi9bAL6LIbS6N8rBi0PS7hh61PELbkKDwtYoEVedUnlSzOnRjWU1zTo+RieSrcQEX/U4hBGLIMar4WfeMGauYCrm9gtms5NTh0grsHhV2mJGNcdoTTsmtQ== 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: hugetlb rmap handling differs quite a lot from "ordinary" rmap code, and we already have dedicated functions for adding anon hugetlb folios and removing hugetlb folios. Right now we're using page_dup_file_rmap() in some cases where "ordinary" rmap code would have used page_add_file_rmap(). So let's introduce and use hugetlb_add_file_rmap() instead. We won't be adding a "hugetlb_dup_file_rmap()" functon for the fork() case, as it would be doing the same: "dup" is just an optimization for "add". While this is a cleanup, this will also make it easier to change rmap handling for partially-mappable folios. What remains is a single page_dup_file_rmap() call in fork() code. Signed-off-by: David Hildenbrand --- include/linux/rmap.h | 7 +++++++ mm/hugetlb.c | 6 +++--- mm/migrate.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index e8d1dc1d5361..0a81e8420a96 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -208,6 +208,13 @@ void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *, void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); +static inline void hugetlb_add_file_rmap(struct folio *folio) +{ + VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); + + atomic_inc(&folio->_entire_mapcount); +} + static inline void hugetlb_remove_rmap(struct folio *folio) { atomic_dec(&folio->_entire_mapcount); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d17bb53b19ff..541a8f38cfdc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5401,7 +5401,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, * sleep during the process. */ if (!folio_test_anon(pte_folio)) { - page_dup_file_rmap(&pte_folio->page, true); + hugetlb_add_file_rmap(pte_folio); } else if (page_try_dup_anon_rmap(&pte_folio->page, true, src_vma)) { pte_t src_pte_old = entry; @@ -6272,7 +6272,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, if (anon_rmap) hugetlb_add_new_anon_rmap(folio, vma, haddr); else - page_dup_file_rmap(&folio->page, true); + hugetlb_add_file_rmap(folio); new_pte = make_huge_pte(vma, &folio->page, ((vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_SHARED))); /* @@ -6723,7 +6723,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out_release_unlock; if (folio_in_pagecache) - page_dup_file_rmap(&folio->page, true); + hugetlb_add_file_rmap(folio); else hugetlb_add_new_anon_rmap(folio, dst_vma, dst_addr); diff --git a/mm/migrate.c b/mm/migrate.c index 4cb849fa0dd2..de9d94b99ab7 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -252,7 +252,7 @@ static bool remove_migration_pte(struct folio *folio, hugetlb_add_anon_rmap(folio, vma, pvmw.address, rmap_flags); else - page_dup_file_rmap(new, true); + hugetlb_add_file_rmap(folio); set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte, psize); } else From patchwork Tue Nov 28 14:52:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13471280 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 7214AC07CA9 for ; Tue, 28 Nov 2023 14:52:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4B3A6B0307; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD33F6B030D; Tue, 28 Nov 2023 09:52:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B14DB6B030F; Tue, 28 Nov 2023 09:52:21 -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 84AEE6B0307 for ; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 52A6A40265 for ; Tue, 28 Nov 2023 14:52:21 +0000 (UTC) X-FDA: 81507653682.28.F25242A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 6CF0F120008 for ; Tue, 28 Nov 2023 14:52:19 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Lajk4O61; spf=pass (imf29.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=1701183139; 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=OTmuEGR3gJmZpzV6zcBNIBMMhBTdNFHIsA/oNnAKXzk=; b=ExzLCOB4nuhnFQ55Pr/s8qiXsS/meJJ+cW0jUVZU+NW+WVWZGEKsOl3kg+Lcq/9I6vA+Ao N+nuupe6mLf+I5C2+10tBwz8XOrVb2LejrH72wLZ2nZR+7N9e5Br6Gy9P4qJeNOKMIc6Uq 3R9lIYseBiJWD2EDX+nmB4Ofy4IGMMA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701183139; a=rsa-sha256; cv=none; b=ZgBe4V8U/cb767oHFmaHfb3AsITG4n8yL7CuJGhJ6DJ039rbsKVadNmv3HAwmhEoNW+LTX DRNOhQB9zTnVJTnBGwe1v+Ww1EISzZTGNJjjM6CQM8sxh8+q/gNbf9koNKGPOUeyFY/EUB DEjXbbwHJVtZ1nKRykkinS5aAMiSPiI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Lajk4O61; spf=pass (imf29.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183138; 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=OTmuEGR3gJmZpzV6zcBNIBMMhBTdNFHIsA/oNnAKXzk=; b=Lajk4O61sCSZ46Eo29/44tmEoAt02sWZYeveNXPg5vfLdv3xKlkd5iVPdYadeteDBT4eMW xVBHxBsgZwFOp4jusnARHDNeNPsDKLj+zrzCJLkdgHh/HCW0nwXrStRoIa5PHj+6HMgmzY dT3mFtjuKc1NE66qp7eGOe/F926OqlQ= 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-111-vnhnDkNXPWC8poKFInuLGw-1; Tue, 28 Nov 2023 09:52:12 -0500 X-MC-Unique: vnhnDkNXPWC8poKFInuLGw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 DDC0C2825E9F; Tue, 28 Nov 2023 14:52:11 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8D0D5028; Tue, 28 Nov 2023 14:52:10 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song Subject: [PATCH v1 4/5] mm/rmap: introduce and use hugetlb_try_dup_anon_rmap() Date: Tue, 28 Nov 2023 15:52:04 +0100 Message-ID: <20231128145205.215026-5-david@redhat.com> In-Reply-To: <20231128145205.215026-1-david@redhat.com> References: <20231128145205.215026-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Queue-Id: 6CF0F120008 X-Rspam-User: X-Stat-Signature: qytjip7tt6rfmdd7zu3resjgayddhsji X-Rspamd-Server: rspam03 X-HE-Tag: 1701183139-984605 X-HE-Meta: U2FsdGVkX19pq9etjqe5r7+KNNQlivxqPt8R/EvsZ2f2B7Jeq8scpKhAsZAPINnIMc6rel+N9t044ZSGmIw0FHZsn2LJgwRMnJUyybw/XUcQ2GDXL3/0uopQJTDP0vedbhJd0IYpE/GIQq6rb96K2nlOLYxiaJjLnRVAas++KmEldfKYaMW6DV7/FbROUH5W5i2YBHbW3NFnOeKY+YwcYQza4Y9rht0h/56HL/8vOgyCySWvkO5RX9ee/zm/pxWLA0+lRB+t7oWagmByRrq4xsiJFNHRWbIBcsrBYX8JreD0GdIfMtIPj5Dw8V/7LkXQYCIdzoNOpw/qAFGRPSHwN9PCCS6ImoScTRk63GbPAiU5jo4r003+RtULe/3VIde6k+KqFBurfLeVvoHAjJYKg4/XVwk1rBdFvl8cAMZmQzXZZZnGQUFUOyORJa8WxScfNqsmlPqRzDsN4s0vqTvgxHesdqjRA0GzJnQQJzJfYJEaYBqfBTT1GJ+xEIqQsoW/7m9oe5jz9Jz4vQ+oK2gnRWIu89lJNXbyU0PIRZ0iUKoXz+Mj6O3dj9ub2GeWyBOEoegkBa7iy/DhgPz+0nku9Ou3G4PENdOFKDrZaEVvLCiutkUYxfBjAz+bKl+k9lKy0bPERzyJM2sSrhgmeDymhpfpWuPpReWJE3kDqafXqpfbB0wO0zWW3d+/6LhR+vEfXRl7kAMx01kHu1U5I8eyrCMFHFXBPbHTxibv4Tmlr3BpAmWlgXCjXAHc0vRPZ3PxygJwtw5nyrxZHWUK896eO/gMMPDBAUrfkbhIKkG4HsXWjYNNw2rW7d7lLp1elXpCHpVnjn0CPY1835F2uksHNBw37eubTzb7jRCsT4AEE44Y1KXbd0Yuq/Kr6NCBY+YyKTBfmV8N9b73clLrmMv5f1HJgTI7cjjnDIR5BqaGs2Qup/f05IGpSHR0iFXMVmLuKUOwE1gduVrLSzxsmW4 RPPtjwUx XeWv++c3UX0hG+CXYOWmStO6zAEpawC5kV2CxhQGCLrzRS1/zNYRJaZp/fPe3ZrkbQ/0HnbaQL2doLpf7msi3BLqmScN7FpKEwnAa6lgrKZ5pNN4wgVCOACmLCNayl5oV7KYfAbhrPNvdgY6BchF7mzXcigEyCoAkP6zwZUo+U25Ojyy0xWXmyxuP1G3WtS0oa4faaEx+b5f8GwLO9+DkqZupNw== 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: hugetlb rmap handling differs quite a lot from "ordinary" rmap code, and we already have dedicated functions for adding anon hugetlb folios and removing hugetlb folios. So let's introduce and use hugetlb_try_dup_anon_rmap() to make all hugetlb handling use dedicated hugetlb_* rmap functions. While this is a cleanup, this will also make it easier to change rmap handling for partially-mappable folios. Note that is_device_private_page() does not apply to hugetlb. Signed-off-by: David Hildenbrand --- include/linux/mm.h | 12 +++++++++--- include/linux/rmap.h | 15 +++++++++++++++ mm/hugetlb.c | 3 +-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 418d26608ece..24c1c7c5a99c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1953,15 +1953,21 @@ static inline bool page_maybe_dma_pinned(struct page *page) * * The caller has to hold the PT lock and the vma->vm_mm->->write_protect_seq. */ -static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, - struct page *page) +static inline bool folio_needs_cow_for_dma(struct vm_area_struct *vma, + struct folio *folio) { VM_BUG_ON(!(raw_read_seqcount(&vma->vm_mm->write_protect_seq) & 1)); if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags)) return false; - return page_maybe_dma_pinned(page); + return folio_maybe_dma_pinned(folio); +} + +static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, + struct page *page) +{ + return folio_needs_cow_for_dma(vma, page_folio(page)); } /** diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 0a81e8420a96..8068c332e2ce 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -208,6 +208,21 @@ void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *, void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); +/* See page_try_dup_anon_rmap() */ +static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, + struct vm_area_struct *vma) +{ + VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); + + if (PageAnonExclusive(&folio->page)) { + if (unlikely(folio_needs_cow_for_dma(vma, folio))) + return -EBUSY; + ClearPageAnonExclusive(&folio->page); + } + atomic_inc(&folio->_entire_mapcount); + return 0; +} + static inline void hugetlb_add_file_rmap(struct folio *folio) { VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 541a8f38cfdc..d927f8b2893c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5402,8 +5402,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, */ if (!folio_test_anon(pte_folio)) { hugetlb_add_file_rmap(pte_folio); - } else if (page_try_dup_anon_rmap(&pte_folio->page, - true, src_vma)) { + } else if (hugetlb_try_dup_anon_rmap(pte_folio, src_vma)) { pte_t src_pte_old = entry; struct folio *new_folio; From patchwork Tue Nov 28 14:52:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13471279 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 0A5FDC07E97 for ; Tue, 28 Nov 2023 14:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DE0E6B0306; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94ED36B030E; Tue, 28 Nov 2023 09:52:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6816B6B0308; Tue, 28 Nov 2023 09:52:21 -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 550516B0306 for ; Tue, 28 Nov 2023 09:52:21 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2D7D51A0233 for ; Tue, 28 Nov 2023 14:52:21 +0000 (UTC) X-FDA: 81507653682.28.02DD2D9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 61A7CA0006 for ; Tue, 28 Nov 2023 14:52:19 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bHgU9yEq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701183139; 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=2oP52ROWQFWEf94d+ZcdDH9xIN9/viIr5hzxAC40F1s=; b=4qoxftS6JiSbC4SQi7ndfPfBTFT37f5a+qTOOXQEAxaHJq2tx442XLOtpHoinkSU2fyq7V y0bY/MCiXxPTE6ztbRCXgY6SKjjFEt70/txuGFMtmVjd16f5/DnBmXNhgtzB7PQ+bSqVeH xj9Jj1bSpfz/+ETDkN3tIIVobz90toY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bHgU9yEq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701183139; a=rsa-sha256; cv=none; b=uWJdz5xIoHMHogF5qpDPFSYlI7V4pr/YlKpXQqhXux7dWhVJ/2yXYJ7m6VtcvaZjOcKZqC DbrS+Ev2BL1X9eel3kCzVwuLch7dQ840XZe14/+5CArlzVAsrgJ0S1Rs8MidW0r+4umL9y M4Vlbwa2EEMF9qZ1kbXshKBbCEs07Zo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701183138; 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=2oP52ROWQFWEf94d+ZcdDH9xIN9/viIr5hzxAC40F1s=; b=bHgU9yEq+dDV+rdqinsao6CZWoerjtoMyOJiIh4EL4itHUImqxF5MCOk2flgvFp+9S+sgJ H/ExO4QavNNQUh9cnvw7m8qyoiHmH3FqHy99tR0frTUdPGjBDaLGYASZSbGiSWWPZKasNz zvyKSQeIGby6lKI7wUE+F7lDTQPDrPI= 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-271-n6VIUHicO2m-dt6V1ZNSMQ-1; Tue, 28 Nov 2023 09:52:13 -0500 X-MC-Unique: n6VIUHicO2m-dt6V1ZNSMQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 237E03C100B4; Tue, 28 Nov 2023 14:52:13 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24AC310E45; Tue, 28 Nov 2023 14:52:12 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Kravetz , Muchun Song Subject: [PATCH v1 5/5] mm/rmap: add hugetlb sanity checks Date: Tue, 28 Nov 2023 15:52:05 +0100 Message-ID: <20231128145205.215026-6-david@redhat.com> In-Reply-To: <20231128145205.215026-1-david@redhat.com> References: <20231128145205.215026-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1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Uv/nwgL6K3uPB+GFbn2T9aqEpVvO/W/0ij SB26PBwV 1sOYJF4wFaxrTxTjv3Ij0+c5LIJbk9uTsAc6F52WXLtk6X43p0deBWja96xjZzQDt36gaYGclsQ48DiTT8g4dMKN/FVwI7FnHe+q+cgGreThI4VVIWCE7rsjV04gfpQ2sCgtjPiWmjf6bRHOibZJjgWzCK4ZwCfV/n0SxfFpWU7FOeYe4PHiU66e8Vb0BLQD09FlsrAEeA3Odbq4n9zAdBTiY4Q== 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 make sure we end up with the right folios in the right functions. Signed-off-by: David Hildenbrand --- include/linux/rmap.h | 6 ++++++ mm/rmap.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 8068c332e2ce..9625b6551d01 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -212,6 +212,7 @@ void hugetlb_add_new_anon_rmap(struct folio *, struct vm_area_struct *, static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, struct vm_area_struct *vma) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); if (PageAnonExclusive(&folio->page)) { @@ -225,6 +226,7 @@ static inline int hugetlb_try_dup_anon_rmap(struct folio *folio, static inline void hugetlb_add_file_rmap(struct folio *folio) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); atomic_inc(&folio->_entire_mapcount); @@ -232,11 +234,15 @@ static inline void hugetlb_add_file_rmap(struct folio *folio) static inline void hugetlb_remove_rmap(struct folio *folio) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); + atomic_dec(&folio->_entire_mapcount); } static inline void __page_dup_rmap(struct page *page, bool compound) { + VM_WARN_ON(folio_test_hugetlb(page_folio(page))); + if (compound) { struct folio *folio = (struct folio *)page; diff --git a/mm/rmap.c b/mm/rmap.c index 5037581b79ec..466f1ea5d0a6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1313,6 +1313,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, { int nr; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma); __folio_set_swapbacked(folio); @@ -1353,6 +1354,7 @@ void folio_add_file_rmap_range(struct folio *folio, struct page *page, unsigned int nr_pmdmapped = 0, first; int nr = 0; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(compound && !folio_test_pmd_mappable(folio), folio); /* Is page being mapped by PTE? Is this its first map to be added? */ @@ -1438,6 +1440,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, bool last; enum node_stat_item idx; + VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_BUG_ON_PAGE(compound && !PageHead(page), page); /* Is page being unmapped by PTE? Is this its last map to be removed? */ @@ -2585,6 +2588,7 @@ void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc) void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address, rmap_t flags) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); atomic_inc(&folio->_entire_mapcount); @@ -2597,6 +2601,8 @@ void hugetlb_add_anon_rmap(struct folio *folio, struct vm_area_struct *vma, void hugetlb_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address) { + VM_WARN_ON_FOLIO(!folio_test_hugetlb(folio), folio); + BUG_ON(address < vma->vm_start || address >= vma->vm_end); /* increment count (starts at -1) */ atomic_set(&folio->_entire_mapcount, 0);