Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1104151rdh; Fri, 24 Nov 2023 05:28:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsBx7U1fSTJpzTY10G3jKu9Gw/zJqq0+QO+7IPdQvx8XUy+Ug6jw86G826/oLRdyE4Cbsh X-Received: by 2002:a17:90b:388f:b0:280:97c2:5db7 with SMTP id mu15-20020a17090b388f00b0028097c25db7mr2933346pjb.17.1700832504933; Fri, 24 Nov 2023 05:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700832504; cv=none; d=google.com; s=arc-20160816; b=XQ6ffUizx8MWlD+tlKJQTNk6Qx068iEvxYu0+0Za/Md7SeouNsbWNnMP1OKmtU8wPE hYulbTgAcOZdhFiDH6A1CRBXxCegfNXamsLHuWqdf+7o+RMlytl2xh0A2aHto7zQuWs9 Jq4UmhIJvmveWEQYmsHlqd9XHR5NWEfc/WWSIoVLQTeWo9dMjHwC7DAOyZPEgHPzpuUg mFZ3CGY2omsqkonbJRS3elo3VRUQF6tAve5lN9j8ZXiYRv5iuT6MUhYQVmh7AihT7S+z l3D12nO9Oh48Bm+CPG74QOgWR1FhAC8CwW7sNMp1E9XZ0PCdKoAC3DW4Ao/g6hb7Tzdu 9XQg== 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=hWu/0kIJvur5UANFtettn6VuzgBBSt2XXjypdyFb6aY=; fh=UVV9UP3jB+jR+DJP/Pn6IwXb1P9vDh5E3FRL6G+mlkU=; b=FshwaGwDlVrtBPl/5PGbhUOhHKGE/UfYgnugMo5i+qx2kecRE/o25MId/oWihMLLLI yu7HUbb2dzuSGJxBQdTQX1lVbWpFlLiQiouKqEpQHoK4buy10+HieMpf4/O0XoUM6smh AUSlMa2VRGFHIuzK3lrNhQ04T+d7DCguowDq2jipn451xpIrsHSKygNjH++RzIbWkC3Y 6xqkblsP+H69zKR3anWbl72uBFjBl8/THqtV+wSURqK8T9Eu/DwbIUfSheiNIEoGq1SS DXFp0pQl3Fnx4ssOATjloBWr+PYftAOQ7xF/2uoEx6e1WNq8Zn8LlYk9xYF847g7KE4U od1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E1drljMP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p1-20020a170902e74100b001cc5ada2b94si3734572plf.366.2023.11.24.05.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 05:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E1drljMP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 9BFEF8043CA4; Fri, 24 Nov 2023 05:28:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345351AbjKXN1q (ORCPT + 99 others); Fri, 24 Nov 2023 08:27:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345366AbjKXN1V (ORCPT ); Fri, 24 Nov 2023 08:27:21 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F57E1BE for ; Fri, 24 Nov 2023 05:27:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700832424; 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=hWu/0kIJvur5UANFtettn6VuzgBBSt2XXjypdyFb6aY=; b=E1drljMPaYYgsDkAyRrgoAZQkECwwlQYnT824exfvTCspKDlxc3StsNHa8adqhYAlYpmiU eid3XrLsNm5/42r01WqszDEYY/Es3nDR9VaKOGIVMaNHlEq7HXv6ToEtkjO+kJtwYMu7Ea 9kAw1Maz+Oyx9y25DIErl4EqdiRozMI= 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-351-57hRR764P9m-_xbjczRUpw-1; Fri, 24 Nov 2023 08:27:01 -0500 X-MC-Unique: 57hRR764P9m-_xbjczRUpw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 DCBB085A5BD; Fri, 24 Nov 2023 13:26:59 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 003162166B2A; Fri, 24 Nov 2023 13:26:56 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Linus Torvalds , Ryan Roberts , Matthew Wilcox , Hugh Dickins , Yin Fengwei , Yang Shi , Ying Huang , Zi Yan , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , "Paul E. McKenney" Subject: [PATCH WIP v1 08/20] mm: pass MM to folio_mapped_shared() Date: Fri, 24 Nov 2023 14:26:13 +0100 Message-ID: <20231124132626.235350-9-david@redhat.com> In-Reply-To: <20231124132626.235350-1-david@redhat.com> References: <20231124132626.235350-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 24 Nov 2023 05:28:12 -0800 (PST) We'll need the MM next to make a better decision regarding partially-mappable folios (e.g., PTE-mapped THP) using per-MM rmap IDs. Signed-off-by: David Hildenbrand --- include/linux/mm.h | 4 +++- mm/huge_memory.c | 2 +- mm/madvise.c | 6 +++--- mm/memory.c | 2 +- mm/mempolicy.c | 14 +++++++------- mm/migrate.c | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 17dac913f367..765e688690f1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2117,6 +2117,7 @@ static inline size_t folio_size(struct folio *folio) * folio_mapped_shared - Report if a folio is certainly mapped by * multiple entities in their page tables * @folio: The folio. + * @mm: The mm the folio is mapped into. * * This function checks if a folio is certainly *currently* mapped by * multiple entities in their page table ("mapped shared") or if the folio @@ -2153,7 +2154,8 @@ static inline size_t folio_size(struct folio *folio) * * Return: Whether the folio is certainly mapped by multiple entities. */ -static inline bool folio_mapped_shared(struct folio *folio) +static inline bool folio_mapped_shared(struct folio *folio, + struct mm_struct *mm) { unsigned int total_mapcount; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0228b04c4053..fd7251923557 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1639,7 +1639,7 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, * If other processes are mapping this folio, we couldn't discard * the folio unless they all do MADV_FREE so let's skip the folio. */ - if (folio_mapped_shared(folio)) + if (folio_mapped_shared(folio, mm)) goto out; if (!folio_trylock(folio)) diff --git a/mm/madvise.c b/mm/madvise.c index 1a82867c8c2e..e3e4f3ea5f6d 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -365,7 +365,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, folio = pfn_folio(pmd_pfn(orig_pmd)); /* Do not interfere with other mappings of this folio */ - if (folio_mapped_shared(folio)) + if (folio_mapped_shared(folio, mm)) goto huge_unlock; if (pageout_anon_only_filter && !folio_test_anon(folio)) @@ -441,7 +441,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (folio_test_large(folio)) { int err; - if (folio_mapped_shared(folio)) + if (folio_mapped_shared(folio, mm)) break; if (pageout_anon_only_filter && !folio_test_anon(folio)) break; @@ -665,7 +665,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, if (folio_test_large(folio)) { int err; - if (folio_mapped_shared(folio)) + if (folio_mapped_shared(folio, mm)) break; if (!folio_trylock(folio)) break; diff --git a/mm/memory.c b/mm/memory.c index 14416d05e1b6..5048d58d6174 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4848,7 +4848,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) * Flag if the folio is shared between multiple address spaces. This * is later used when determining whether to group tasks together */ - if (folio_mapped_shared(folio) && (vma->vm_flags & VM_SHARED)) + if (folio_mapped_shared(folio, vma->vm_mm) && (vma->vm_flags & VM_SHARED)) flags |= TNF_SHARED; nid = folio_nid(folio); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 0492113497cc..bd0243da26bf 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -418,7 +418,7 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = { }; static bool migrate_folio_add(struct folio *folio, struct list_head *foliolist, - unsigned long flags); + struct mm_struct *mm, unsigned long flags); static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *pol, pgoff_t ilx, int *nid); @@ -481,7 +481,7 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk) return; if (!(qp->flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) || !vma_migratable(walk->vma) || - !migrate_folio_add(folio, qp->pagelist, qp->flags)) + !migrate_folio_add(folio, qp->pagelist, walk->mm, qp->flags)) qp->nr_failed++; } @@ -561,7 +561,7 @@ static int queue_folios_pte_range(pmd_t *pmd, unsigned long addr, } if (!(flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) || !vma_migratable(vma) || - !migrate_folio_add(folio, qp->pagelist, flags)) { + !migrate_folio_add(folio, qp->pagelist, walk->mm, flags)) { qp->nr_failed++; if (strictly_unmovable(flags)) break; @@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask, * easily detect if a folio is shared. */ if ((flags & MPOL_MF_MOVE_ALL) || - (!folio_mapped_shared(folio) && !hugetlb_pmd_shared(pte))) + (!folio_mapped_shared(folio, walk->mm) && !hugetlb_pmd_shared(pte))) if (!isolate_hugetlb(folio, qp->pagelist)) qp->nr_failed++; unlock: @@ -981,7 +981,7 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, #ifdef CONFIG_MIGRATION static bool migrate_folio_add(struct folio *folio, struct list_head *foliolist, - unsigned long flags) + struct mm_struct *mm, unsigned long flags) { /* * Unless MPOL_MF_MOVE_ALL, we try to avoid migrating a shared folio. @@ -990,7 +990,7 @@ static bool migrate_folio_add(struct folio *folio, struct list_head *foliolist, * See folio_mapped_shared() on possible imprecision when we cannot * easily detect if a folio is shared. */ - if ((flags & MPOL_MF_MOVE_ALL) || !folio_mapped_shared(folio)) { + if ((flags & MPOL_MF_MOVE_ALL) || !folio_mapped_shared(folio, mm)) { if (folio_isolate_lru(folio)) { list_add_tail(&folio->lru, foliolist); node_stat_mod_folio(folio, @@ -1195,7 +1195,7 @@ static struct folio *alloc_migration_target_by_mpol(struct folio *src, #else static bool migrate_folio_add(struct folio *folio, struct list_head *foliolist, - unsigned long flags) + struct mm_struct *mm, unsigned long flags) { return false; } diff --git a/mm/migrate.c b/mm/migrate.c index 341a84c3e8e4..8a1d75ff2dc6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2559,7 +2559,7 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, * every page is mapped to the same process. Doing that is very * expensive, so check the estimated mapcount of the folio instead. */ - if (folio_mapped_shared(folio) && folio_is_file_lru(folio) && + if (folio_mapped_shared(folio, vma->vm_mm) && folio_is_file_lru(folio) && (vma->vm_flags & VM_EXEC)) goto out; -- 2.41.0