From patchwork Wed Nov 27 08:21:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13887193 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 E23D9D6ACF2 for ; Wed, 27 Nov 2024 16:28:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 625746B008C; Wed, 27 Nov 2024 11:28:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AF4F6B0092; Wed, 27 Nov 2024 11:28:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38CE86B0093; Wed, 27 Nov 2024 11:28:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0D45B6B008C for ; Wed, 27 Nov 2024 11:28:49 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B727F819CD for ; Wed, 27 Nov 2024 16:28:48 +0000 (UTC) X-FDA: 82832408442.01.EA40152 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf06.hostedemail.com (Postfix) with ESMTP id BF8AA18000A for ; Wed, 27 Nov 2024 16:28:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=hGJijRtS; spf=pass (imf06.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.169 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732724923; 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=1YVRetr6ViR4L1BBUGXRQMyVoFD2gs0Ovt3TmolcbLM=; b=vZMyWanO1McwBd8RKMS0YFX58AONZyT+buYNCuK6jOjAduBc9++BbQLb+EgVMckWN5Lo0m 2dHb+LsjIy40OIp7fMOcrVdzX9fRohJ2WJkiBB2rAPCd+qLafKTApq3gdtocVs8Q/MZvUE hHfUukFWZ6QnfcAuCaHry+IyBJk25cQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732724923; a=rsa-sha256; cv=none; b=r7dvAlM61JqDAaEjinJnrnV6x4eL6HmVVZyXdTxMOxF4SgMKuShoI8bSI5RKrWpOfpc/c1 CIwItChv9/0gr03nr7bUpeQRRKAE9RqbBNVWRkDxw6njhTveetJkR5jKANQlUBHsl5futR QeVgkdD0RqY2EtIElebfW6ssyC/KfXw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=hGJijRtS; spf=pass (imf06.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.169 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7b15d330ce1so478070585a.1 for ; Wed, 27 Nov 2024 08:28:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1732724925; x=1733329725; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1YVRetr6ViR4L1BBUGXRQMyVoFD2gs0Ovt3TmolcbLM=; b=hGJijRtS7twiQbxAQfPCjI4lTFdX6gre+rMN+HDMLExxYf8NuzIgDyLCSIfFs+w3PM IMRslbyAiojpI/GUrI07gMB4OBPmtu9g7IBbzYy+VF8AbT5as4UHUsJpOeGFRNe4Yt2Y TY+VI9RafLQehe+fZ3EZkR/zPHVAAmjh0hWI6pdnThQTxPN4sVFojOqr3tEM/gRnun9T GujdLL6GEo7dKWdqbJje4rHiOvOqiGpHzUf8/jt4sgFFmUJVoMMGV2uMT9dzEW6WFs88 4aKWabDjOJMBMd9BrSaqGFSdCAraRvFpQpouxXPlRBQNMTxOfcx25TEGdE2IrE1wlbN8 hqTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732724925; x=1733329725; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1YVRetr6ViR4L1BBUGXRQMyVoFD2gs0Ovt3TmolcbLM=; b=PMvyBkSewM48AldBlG3h8jVwsygTMjqwhDuUhdDh8x1abe9P3K70WPnoYhZkHL8L6O 86DyemUqPku6VwxnlCkb2BklcK/a/MlrCinGzOMn+6K950y/C1P+fP7tMcwbnsPxQdT6 eyZilx2L2TOWDyCo3ZwU0Tpwy7WkHcgrwU6CX5rjDwtJKg7gFl4CFJ8/7B7RJOnQa5ss ZNJTtNLSfW9ihkwMqX4wggbuSVbA9E31/EKSKxyP7BfO3dqjX1vlex2aoXJ0z4h46DXr LX76njV6Qn1DzbbIlCkVH+HmHqu00i7gZukG66+jG94ShY0+O5cKnrkHhbYIYD+WzfYF KGbQ== X-Gm-Message-State: AOJu0YzKa5LYR8I8E+RWWANwVl0xhQryFQtvqYgKqOA6sOA44oMx9G6j XK3rbJF5qZY9GNIeVvr3M26nhf1s/ATmNkxgbzs2l8L4ISFg9slzud+RkohGkWagClVGs3NCmJ4 E X-Gm-Gg: ASbGnctmESBmptSRkfPifG56Jo3aEOMY9YIXRmbkVY4UFuDDRC6/2tGI6Y75srh6rpG 02kszTzxEZuJp1Q0Bc9xq3/aiEr07tCvhdM5MWw8NvJ2OVG1qfrJnSpDmk6pFEbU+hcyHmhcp0Y RgnS08tsxJLK5470LARFOiwv1MC5MSgUximMfuZN2SllD+il+w1uu3x3S7BEWo6ArQg2U/0u/67 bukDTnEuy0G8UZwdKyLXLO5IJ4IwCAgCkCCPGsS0MRFEzNSN/57VqOSbI8BxyeJAo6AUBWXs1Do ZHzmoiGFQB4zrlBPHL/aqEzEJ6n0PU5prRc= X-Google-Smtp-Source: AGHT+IE7MyR6097VIWfq3+is83/Yc33iicre1dSbm4nHjYBDTL/wY941BZN4EnUeI4leGNLYuU1nKQ== X-Received: by 2002:a05:620a:2915:b0:7b3:51a5:556 with SMTP id af79cd13be357-7b67c292a7cmr475141385a.22.1732724925502; Wed, 27 Nov 2024 08:28:45 -0800 (PST) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-466871721c2sm45002921cf.17.2024.11.27.08.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 08:28:45 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, nehagholkar@meta.com, abhishekd@meta.com, kernel-team@meta.com, david@redhat.com, ying.huang@intel.com, nphamcs@gmail.com, gourry@gourry.net, akpm@linux-foundation.org, hannes@cmpxchg.org, feng.tang@intel.com, kbusch@meta.com Subject: [PATCH 2/4] memory: allow non-fault migration in numa_migrate_check path Date: Wed, 27 Nov 2024 03:21:59 -0500 Message-ID: <20241127082201.1276-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241127082201.1276-1-gourry@gourry.net> References: <20241127082201.1276-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BF8AA18000A X-Stat-Signature: f5m9tgxqnpfuhks6ckn4ir3md4oqfi4f X-Rspam-User: X-HE-Tag: 1732724922-623147 X-HE-Meta: U2FsdGVkX19xSiCXfKbfpTWRLuSlmZRXF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GJn8U7wMxexLReot2mR11ZasHNmCySeaStYX5LtLQnyXgE3TRPQOAsBv0yH978+I1QjnXA7PxXKhLvDgwD3mx3afB/VvjvAXlnhYWL/dSf3iG8eRDOuTCROxiDmb+w6UPCVBTx/T0le1/i3jfACw2lE4Tx90xLCXRVrAfrhl50ih1th19dKTaaU1LinsMClPMWmrl6CrBDncBTCL/FlpAkCuuFeSaG96EmMEaxjxOkZ3n+vvoT8zc 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: numa_migrate_check and mpol_misplaced presume callers are in the fault path with accessed to a VMA. To enable migrations from page cache, re-using the same logic to handle migration prep is preferable. Mildly refactor numa_migrate_check and mpol_misplaced so that they may be called with (vmf = NULL) from non-faulting paths. Also move from numa balancing defines inside the appropriate ifdef. Signed-off-by: Gregory Price --- mm/memory.c | 28 ++++++++++++++++------------ mm/mempolicy.c | 25 +++++++++++++++++-------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 209885a4134f..a373b6ad0b34 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5471,7 +5471,20 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf, unsigned long addr, int *flags, bool writable, int *last_cpupid) { - struct vm_area_struct *vma = vmf->vma; + if (vmf) { + struct vm_area_struct *vma = vmf->vma; + const vm_flags_t vmflags = vma->vm_flags; + + /* + * Flag if the folio is shared between multiple address spaces. + * This used later when determining whether to group tasks. + */ + if (folio_likely_mapped_shared(folio)) + *flags |= vmflags & VM_SHARED ? TNF_SHARED : 0; + + /* Record the current PID acceesing VMA */ + vma_set_access_pid_bit(vma); + } /* * Avoid grouping on RO pages in general. RO pages shouldn't hurt as @@ -5484,12 +5497,6 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf, if (!writable) *flags |= TNF_NO_GROUP; - /* - * Flag if the folio is shared between multiple address spaces. This - * is later used when determining whether to group tasks together - */ - if (folio_likely_mapped_shared(folio) && (vma->vm_flags & VM_SHARED)) - *flags |= TNF_SHARED; /* * For memory tiering mode, cpupid of slow memory page is used * to record page access time. So use default value. @@ -5499,17 +5506,14 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf, else *last_cpupid = folio_last_cpupid(folio); - /* Record the current PID acceesing VMA */ - vma_set_access_pid_bit(vma); - - count_vm_numa_event(NUMA_HINT_FAULTS); #ifdef CONFIG_NUMA_BALANCING + count_vm_numa_event(NUMA_HINT_FAULTS); count_memcg_folio_events(folio, NUMA_HINT_FAULTS, 1); -#endif if (folio_nid(folio) == numa_node_id()) { count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL); *flags |= TNF_FAULT_LOCAL; } +#endif return mpol_misplaced(folio, vmf, addr); } diff --git a/mm/mempolicy.c b/mm/mempolicy.c index bb37cd1a51d8..eb6c97bccea3 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2727,12 +2727,16 @@ static void sp_free(struct sp_node *n) * mpol_misplaced - check whether current folio node is valid in policy * * @folio: folio to be checked - * @vmf: structure describing the fault + * @vmf: structure describing the fault (NULL if called outside fault path) * @addr: virtual address in @vma for shared policy lookup and interleave policy + * Ignored if vmf is NULL. * * Lookup current policy node id for vma,addr and "compare to" folio's - * node id. Policy determination "mimics" alloc_page_vma(). - * Called from fault path where we know the vma and faulting address. + * node id - or task's policy node id if vmf is NULL. Policy determination + * "mimics" alloc_page_vma(). + * + * vmf must be non-NULL if called from fault path where we know the vma and + * faulting address. The PTL must be held by caller if vmf is not NULL. * * Return: NUMA_NO_NODE if the page is in a node that is valid for this * policy, or a suitable node ID to allocate a replacement folio from. @@ -2744,7 +2748,6 @@ int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, pgoff_t ilx; struct zoneref *z; int curnid = folio_nid(folio); - struct vm_area_struct *vma = vmf->vma; int thiscpu = raw_smp_processor_id(); int thisnid = numa_node_id(); int polnid = NUMA_NO_NODE; @@ -2754,18 +2757,24 @@ int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, * Make sure ptl is held so that we don't preempt and we * have a stable smp processor id */ - lockdep_assert_held(vmf->ptl); - pol = get_vma_policy(vma, addr, folio_order(folio), &ilx); + if (vmf) { + lockdep_assert_held(vmf->ptl); + pol = get_vma_policy(vmf->vma, addr, folio_order(folio), &ilx); + } else { + pol = get_task_policy(current); + } if (!(pol->flags & MPOL_F_MOF)) goto out; switch (pol->mode) { case MPOL_INTERLEAVE: - polnid = interleave_nid(pol, ilx); + polnid = vmf ? interleave_nid(pol, ilx) : + interleave_nodes(pol); break; case MPOL_WEIGHTED_INTERLEAVE: - polnid = weighted_interleave_nid(pol, ilx); + polnid = vmf ? weighted_interleave_nid(pol, ilx) : + weighted_interleave_nodes(pol); break; case MPOL_PREFERRED: