From patchwork Tue Jan 7 00:03:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13927910 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 65F26E77198 for ; Tue, 7 Jan 2025 00:04:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6CE16B00C8; Mon, 6 Jan 2025 19:04:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1F836B00CA; Mon, 6 Jan 2025 19:04:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAC416B00CB; Mon, 6 Jan 2025 19:04:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 497086B00C8 for ; Mon, 6 Jan 2025 19:04:00 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 18C901A0531 for ; Tue, 7 Jan 2025 00:04:00 +0000 (UTC) X-FDA: 82978707840.07.E85808A Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by imf18.hostedemail.com (Postfix) with ESMTP id 48BB21C0015 for ; Tue, 7 Jan 2025 00:03:58 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Mi7AFiPm; spf=pass (imf18.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.176 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=1736208238; 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=EhQxXMUURDFkAZ5scirPLfGBPx39x7Cq7gDAj234rcY=; b=bz/IGJY2YnU8aXdxTQR7kRHFZd5LaWlOlHh8nCZ0FjOAl9X+r1jGYZSzVHQxvlCWOAu++V LD59YSaG+c7X977bCUJlrRnxoyAE1U89jtWyOfdIUY6Lvk63WOW6aOakt24o53S27rYCMZ 5p2FD9M4dj8zTfM2JxEp+rkkm+IUSmg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736208238; a=rsa-sha256; cv=none; b=mtBzZkQesbx34Yf2+jMHlPsmrTdivgSkYyAveQ3tdM2INmlQA9AqM4lD91Opslj2f/NPE+ 48xXCQLLj9pbj4apUobYgFTUMD5V4jl0J6MKV5ZnFsI7d5c6RLcKisNC3BvuB5wVbfBUp2 dd5/HRlos6ZZRQ4uD+fEYeZiHhalKJM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=Mi7AFiPm; spf=pass (imf18.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.176 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b6c3629816so769967785a.1 for ; Mon, 06 Jan 2025 16:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1736208237; x=1736813037; 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=EhQxXMUURDFkAZ5scirPLfGBPx39x7Cq7gDAj234rcY=; b=Mi7AFiPm04TJlOGt+VFge9IemM7hAz3XskZhtBJ2BqZQoKjs02tvACrGfM/M6BA2mb H62JCPP6klTgy2Po5kvVDiYRpD4EYkTrGOM9uUSKPKpx91j1YN3YZCR5B/5Pk5VP+gYQ IU95ZkNh8rPDckZnvStp5n8SNrf8VCaWJrbnDncGD9cRFF5BZ+NIrCfLGsEb9P0UJ4Hz ZkWtjEqLIQpW4sKT7LnjkyHz+WQv/pAdMWhCxD+LDplLsXdHYrVjSvVX2zmfH9h8BSzE xp1x2ozeFjiYGpfvp0yWNXkRncgkq5c9MNvbAYAIy4fct3P5+3Q/QPmFddz56iM3C7nv wzDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736208237; x=1736813037; 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=EhQxXMUURDFkAZ5scirPLfGBPx39x7Cq7gDAj234rcY=; b=R2xFb1kiFzKO5y+T5oQZRdU75k8gyyghAW7nghyFhtA2PrqxVdP7Xh8qXr9mD8GcYE 1A6b3VCkTr2xN45tVyQKq1m/jcGnjJK01GBlEjJY3S3YbRF5YsLUwWYwtmpnkmhlkude UGO5Mgy5oBxU4xzgNU0aYTbsQWKr7sJf6aJ62ipi+9FEw2+urNFjc9JxNsNAd0Q4KoV5 QEl0oJddA/uLkG6vTVErx9Q/qKXcCRG7Ixh4xy04Ziv/gKSBOgj/ckycn1ZVCSEgwwkt peNhBxcNImcKE8suIhaD6DdghJ4FneuXRoS6mybnwcs4JdyPqGQCLG11Ms5wT4D6Yoo+ oSug== X-Gm-Message-State: AOJu0YwTVnjpyXVBHADUQKebUE7wHYu1GvHIwimDEFOZefdfo9gafm9q /IbdLobKomOBZALWK3uMQsu04eeLnnVwWabvzenh8WHHS+XuvqdEAONRppEMEx0iz+GMcBHjmaB J X-Gm-Gg: ASbGnct+HdOBbyeeHdKrDIoHJ0A07VOY+O2cKxg9FtknqvbCSp9eFSXYjktZFIAbtoM ALB4YcfhTzBmFnPSMzcHOAKVgNFRfToRdudVz+ySFWWdWOjY6ummuaAtFQ2tynlJ7GoyhgH5KGy dIB4ZBhKQQOgFHlCpkwNsyN0Wy2JFxkR3wF/6PtUTKwR/JjfJjWbEGatyEl9tXjTBCOc0fqP1In nOk3KKh+xy1edNVyih1tn7y2CYzaER8feqDOMc/oI1Q7GTEsLSDMklIWWBSJvXUENAPp+4CVxOd MsU4LfTXBYj21DJKsNnjSylES5GPXjlv2gOjGUoB+qJ7 X-Google-Smtp-Source: AGHT+IGxVrqjx+Di9dmI2xKMOrXvW3nylvanO8oTfhpUycZZo5Se/q08YTn9jxqPITzbOyS3wtn8GQ== X-Received: by 2002:ad4:4eac:0:b0:6da:dc79:a3c9 with SMTP id 6a1803df08f44-6dd23306794mr895686556d6.9.1736208237050; Mon, 06 Jan 2025 16:03:57 -0800 (PST) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd18137218sm174104476d6.57.2025.01.06.16.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 16:03:56 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, nehagholkar@meta.com, abhishekd@meta.com, david@redhat.com, nphamcs@gmail.com, gourry@gourry.net, akpm@linux-foundation.org, hannes@cmpxchg.org, kbusch@meta.com, ying.huang@linux.alibaba.com, feng.tang@intel.com, donettom@linux.ibm.com Subject: [PATCH v3 3/6] memory: allow non-fault migration in numa_migrate_check path Date: Mon, 6 Jan 2025 19:03:43 -0500 Message-ID: <20250107000346.1338481-4-gourry@gourry.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250107000346.1338481-1-gourry@gourry.net> References: <20250107000346.1338481-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: 48BB21C0015 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 6hinjaywwfybmnmqs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pcsNyg+biGwdKmZXH3wzhrlvH7AZrR4KxzU7Nen9V1BmcXAGc3XcBWIskK4B+iSDQa+JOs5yaKYhab+ciMbB+8mKSdh/6oh12OsLLedr11ERQbEsjAu0NWnQW36OiekqRlYmkPHsl1z9R4XJLywNlrcmGKia4Y182w4PswjBefNt1ICEHW8l0U8OfGLeyLd8BtqbsyvTSP1raJ0pyWXEI2pg0n+Rdz8uXE5UKA3Bru0Uag1ZaYDXsa+jG+wn1ZkMAJ5cue7s8zIgHRTDCdswQVzk4zpP2HfExApq2s2WxcURG+w6HUBmLK 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. Signed-off-by: Gregory Price --- mm/memory.c | 24 ++++++++++++++---------- mm/mempolicy.c | 25 +++++++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 8d254e97840d..24acac94399c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5540,7 +5540,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 @@ -5553,12 +5566,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. @@ -5568,9 +5575,6 @@ 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); - #ifdef CONFIG_NUMA_BALANCING count_vm_numa_event(NUMA_HINT_FAULTS); count_memcg_folio_events(folio, NUMA_HINT_FAULTS, 1); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 305aa3012173..9a7804f65782 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2747,12 +2747,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. @@ -2764,7 +2768,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; @@ -2774,18 +2777,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: