From nobody Sun Feb 8 17:51:27 2026 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C242A4653A for ; Wed, 7 Aug 2024 22:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723071521; cv=none; b=Ha31sJNc3LP2qYB9/cK1t1l82FSLttTyfD6fQNEk420QZRcgXgQP72wgeE7Ez4hD3O2d0PBa6Qivwr2I7d/Sq27yWcFj7Lh+B4nIL4Yh1i7WPWKzFn3b3D7VOXE6jxqgSW/BP6kss4lwVf3g++q45MkTsweDwkDy2YZt0iEgP0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723071521; c=relaxed/simple; bh=B+8bRGXO4DK1cT+o30T7FGqx1ulK2x+MXDKixLIUT7g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iS3CRJCnS4M4ntCHiGhIHgmM1z9lglZzwoZ+c4W2hXRyuvkC/eSQrttk+pU7Z1eejIjAGhW/0SEf+2EJSW2vTBemJBgzDh4MigDAYH3IDynQrVagKpd3+Kftt0KWh3hUcus3RFELphb76kw0Z0iJJVAyVPtaE4jC9okYCODjXbw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=DELT7BSy; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="DELT7BSy" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6b79b93a4c9so3181336d6.1 for ; Wed, 07 Aug 2024 15:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1723071518; x=1723676318; darn=vger.kernel.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=8vSGQ3ghJDXeBny3dBQsvq0Nux9zcDNCjlxZWS4Ivb4=; b=DELT7BSyxAZVRBPJsCc03u3MfzXgXmN4nyyaQx5yv5/xPJ2Gn6w2Py79sXICfe5tzP ae4rOWXb49reofFQetN9D7iWUmSW5/X3ZUv3eAo9XXflTMafIgfw0S50hSiZEZflRgU3 suV1TeLCspIEEqp8NcuxIWGZ0ievgsWeoXHV3bxQbcz4OQnooEk6ZhfWxFp7TtZ6kaSK IMCh2poKLCMlQzljUvns3PnNvgT+11DJmgsnT/16OYhaeIRPynasM9BvKwsnaIx4SOiT s/yqCpqBX+7LYu7tfLosqqzouQ1iSHIH9GxMVvJpgmzmySPu1DJJW8kesKxUkzjY1r3C F8Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723071518; x=1723676318; 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=8vSGQ3ghJDXeBny3dBQsvq0Nux9zcDNCjlxZWS4Ivb4=; b=gNA5EB/XPWnl1dRtoKnFZnktBEm4UQChv4btcUYzLzK97XD+yoROu+NENa8EMbJHFP 56zTjUPvO/YN8P4f5W4AqFUMspfZd9Eo9lBh4KNnApfoM5YDYe9LeqLFUCrqO1d7fNmf jCoxEsL1r8dWXyAdeeYBjYQ0/JtOpGn1hZPV96O4toLIq/gwBWt5XM8W5cOymbmw2ItD zZCuRGe6VTCYlmMonHk7HPDiYhkKAFash5EN7/yG8e2HU58QXRPGwn0/QXq84K/Taz50 qTKODCGkgG4nrWH/4Jru55SihfKI+gHVYUgWYdCa6b4LjJC428HIk0q0sVQQ9/iptqRR 6iQQ== X-Gm-Message-State: AOJu0YyMPE24zZVrv6FopoioINSNFg5fPDyC5MaAUwWllEBb/JGhaiRZ m9xDM4zQ+rn46Yy7sxuiUszTpaw+op1xN8yd6+mvZS6/jByLlzqbSlryKjs7VMs= X-Google-Smtp-Source: AGHT+IHrmXvSFPR8DEpCEZoK/8ZCUguaRRqJB0WtVruTixcSBpQ7PFaE5Ryt/O/El3X3FdLuFEvGrg== X-Received: by 2002:a05:6214:33c3:b0:6b5:81ac:6b84 with SMTP id 6a1803df08f44-6bd6c340ce3mr545126d6.14.1723071518498; Wed, 07 Aug 2024 15:58:38 -0700 (PDT) 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 6a1803df08f44-6bb9c7b82cbsm59997096d6.61.2024.08.07.15.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 15:58:38 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, david@redhat.com, ying.huang@intel.com, nphamcs@gmail.com, nehagholkar@meta.com, abhishekd@meta.com, Johannes Weiner Subject: [PATCH 1/3] migrate: Allow migrate_misplaced_folio APIs without a VMA Date: Sat, 3 Aug 2024 05:47:13 -0400 Message-ID: <20240803094715.23900-2-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240803094715.23900-1-gourry@gourry.net> References: <20240803094715.23900-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To migrate unmapped pagecache folios, migrate_misplaced_folio and migrate_misplaced_folio_prepare must handle folios without VMAs. migrate_misplaced_folio_prepare checks VMA for exec bits, so allow a NULL VMA when it does not have a mapping. migrate_misplaced_folio does not require a VMA, remove it from the argument list. Suggested-by: Johannes Weiner Signed-off-by: Gregory Price --- include/linux/migrate.h | 6 ++---- mm/huge_memory.c | 2 +- mm/memory.c | 2 +- mm/migrate.c | 7 +++---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 644be30b69c8..553bdb4a65db 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -141,16 +141,14 @@ const struct movable_operations *page_movable_ops(str= uct page *page) #ifdef CONFIG_NUMA_BALANCING int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node); -int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vm= a, - int node); +int migrate_misplaced_folio(struct folio *folio, int node); #else static inline int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node) { return -EAGAIN; /* can't migrate now */ } -static inline int migrate_misplaced_folio(struct folio *folio, - struct vm_area_struct *vma, int node) +static inline int migrate_misplaced_folio(struct folio *folio, int node) { return -EAGAIN; /* can't migrate now */ } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f4be468e06a4..f79c42e36d37 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1725,7 +1725,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf) spin_unlock(vmf->ptl); writable =3D false; =20 - if (!migrate_misplaced_folio(folio, vma, target_nid)) { + if (!migrate_misplaced_folio(folio, target_nid)) { flags |=3D TNF_MIGRATED; nid =3D target_nid; } else { diff --git a/mm/memory.c b/mm/memory.c index 34f8402d2046..1d97bdfd0ed6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5355,7 +5355,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) ignore_writable =3D true; =20 /* Migrate to the requested node */ - if (!migrate_misplaced_folio(folio, vma, target_nid)) { + if (!migrate_misplaced_folio(folio, target_nid)) { nid =3D target_nid; flags |=3D TNF_MIGRATED; } else { diff --git a/mm/migrate.c b/mm/migrate.c index e7296c0fb5d5..c648dc08758b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2546,7 +2546,7 @@ static struct folio *alloc_misplaced_dst_folio(struct= folio *src, =20 /* * Prepare for calling migrate_misplaced_folio() by isolating the folio if - * permitted. Must be called with the PTL still held. + * permitted. If VMA is not NULL, Must be called with the PTL still held. */ int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node) @@ -2563,7 +2563,7 @@ int migrate_misplaced_folio_prepare(struct folio *fol= io, * See folio_likely_mapped_shared() on possible imprecision * when we cannot easily detect if a folio is shared. */ - if ((vma->vm_flags & VM_EXEC) && + if (vma && (vma->vm_flags & VM_EXEC) && folio_likely_mapped_shared(folio)) return -EACCES; =20 @@ -2614,8 +2614,7 @@ int migrate_misplaced_folio_prepare(struct folio *fol= io, * elevated reference count on the folio. This function will un-isolate the * folio, dereferencing the folio before returning. */ -int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vm= a, - int node) +int migrate_misplaced_folio(struct folio *folio, int node) { pg_data_t *pgdat =3D NODE_DATA(node); int nr_remaining; --=20 2.43.0 From nobody Sun Feb 8 17:51:27 2026 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1142E1552F5 for ; Wed, 7 Aug 2024 22:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723071523; cv=none; b=jVnwpNlBN378q6v1dEXtjA6SqOUYM9eEteeQgMYU4gmIQ/vYNWdh55wYtywdX2lGs2jNgUwRvtOKMeI/aYRVLMORbC7hQDrUJcsLQ90GRcb95kOHr1hFE/WgoRElC4HNp/09gu4Ktsg4Pwc5FjzmkOUxJoWQxEVONetsQn45+Nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723071523; c=relaxed/simple; bh=JXuF/AUNV55eySyafE/MsTxi+gk8RZaCii1ThT5rnlE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LzQh1HQ6SUznRmmeNo1jB2cSpf3d+KFhc6duZoOeNUOKIK0FTz7abifUrKoy1jv2MQ4CTU4mjZjDIp6l4UWUmgesGcIOQu1b4acjoGBteSQcahGLd+L0bfsZGWxdG/7YVrjtorRizrq/qyX4alRDFhHUbfVOoreINyGlIqkJhz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=WKmZTY4k; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="WKmZTY4k" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6b78c980981so2275566d6.2 for ; Wed, 07 Aug 2024 15:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1723071520; x=1723676320; darn=vger.kernel.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=f/7er4oz/4902b2ijGv9reJfVXMZ4xWqxFGlkwKTX4E=; b=WKmZTY4kM87LfluZxYbbpv9jSkA1fYR3WQNGhwINwEwH3yoXYUVQ/uzQTZrzntJ6Wj PI7llZcsfEzCLSS9dcIfiZ0xnBa7jxpTLRIWrb9+62MbLCacixemyojiNWgc6PWMUJZe F6/k+CWfZHfzgkXled5gvwQ3vU6f/3rkgcsmwi9Nb46hvGQzFNminQrjMATUcY8ug3IV 0LVafkeq4K/AEm95WawZOQ+02vBX5ChcHkFIpS2RQvD8v1mia275ubJr/Uim4ySurkoV s+ZZwiaaRdfkNC+4o9qyRodgn5H05Rw0OoRcH/Y820qg22urAKSDU59IeoqWfX2Jm9Hc CAHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723071520; x=1723676320; 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=f/7er4oz/4902b2ijGv9reJfVXMZ4xWqxFGlkwKTX4E=; b=rPktNn8WL27iDNjpK7oUYQahf4JFzer2P8ZMbUIv0YFK8gmEMgWNbUXHj9YlJT3sIi 5RiRp909D6OM71tSxj/r/eT6TVUe5XtteOi3li9IEZ8uxKdCTJOCY4sxgzBs7SSkhw4D FS6MvR+ECDIJgG7+YSsgJdbS4pfM/7uNjrtOcE6y7m6Fg0yDY2QydAGs4t60Z0PolHU5 YH6jUA5M6e5wwi9FHuHSTRU+CtXKWCfjhaH3Q3CVgE5yRrZuNqMNHcqCdxzjsQM+2TUA JSv9MdUl5ImVBrv631eBBFo17ux1WWIZfBSyOAY9ByqseMT7QFhoONQd9aWKer/wjyaU fKcQ== X-Gm-Message-State: AOJu0YzOWvTEp9V2ePRtrFmCcVHKeRfy6Tg9Ex/BmEUO591YqPBFKau6 xEbgKZZwcQk/DtuAQUMG6NGd+L7qnNmJhWsaN29lBAA4DAbfgFRn8p443fQa21M= X-Google-Smtp-Source: AGHT+IGFCy2UHYgt4IIneWbe6R0Qmijoz2vCe9+ULRLqYf4jz2jZaZqML+9wKCYl3E8e9BtQP0+9yw== X-Received: by 2002:a05:6214:5f0d:b0:6bb:b9fe:cd15 with SMTP id 6a1803df08f44-6bd6bd7e51dmr1695066d6.40.1723071519924; Wed, 07 Aug 2024 15:58:39 -0700 (PDT) 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 6a1803df08f44-6bb9c7b82cbsm59997096d6.61.2024.08.07.15.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 15:58:39 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, david@redhat.com, ying.huang@intel.com, nphamcs@gmail.com, nehagholkar@meta.com, abhishekd@meta.com Subject: [PATCH 2/3] memory: allow non-fault migration in numa_migrate_prep path Date: Sat, 3 Aug 2024 05:47:14 -0400 Message-ID: <20240803094715.23900-3-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240803094715.23900-1-gourry@gourry.net> References: <20240803094715.23900-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" numa_migrate_prep and mpol_misplaced presume callers are in the fault path. To enable migrations from the pagecache, re-using the same logic to handle migration prep would be preferable. Mildly refactor numa_migrate_prep and mpol_misplaced so that it may be called with (vmf=3DNULL) from non-faulting paths. Count non-fault events as page-cache numa hints instead of fault hints. Signed-off-by: Gregory Price --- include/linux/vm_event_item.h | 1 + mm/memory.c | 19 ++++++++++--------- mm/mempolicy.c | 25 +++++++++++++++++-------- mm/vmstat.c | 1 + 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 747943bc8cc2..b917bcfffe6d 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -62,6 +62,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, NUMA_HUGE_PTE_UPDATES, NUMA_HINT_FAULTS, NUMA_HINT_FAULTS_LOCAL, + NUMA_HINT_PAGE_CACHE, NUMA_PAGE_MIGRATE, #endif #ifdef CONFIG_MIGRATION diff --git a/mm/memory.c b/mm/memory.c index 1d97bdfd0ed6..8b664b08915c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5205,15 +5205,16 @@ static vm_fault_t do_fault(struct vm_fault *vmf) int numa_migrate_prep(struct folio *folio, struct vm_fault *vmf, unsigned long addr, int page_nid, int *flags) { - struct vm_area_struct *vma =3D vmf->vma; - - /* Record the current PID acceesing VMA */ - vma_set_access_pid_bit(vma); - - count_vm_numa_event(NUMA_HINT_FAULTS); - if (page_nid =3D=3D numa_node_id()) { - count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL); - *flags |=3D TNF_FAULT_LOCAL; + /* If accessed in fault path, record the current PID acceesing VMA */ + if (vmf) { + vma_set_access_pid_bit(vmf->vma); + count_vm_numa_event(NUMA_HINT_FAULTS); + if (page_nid =3D=3D numa_node_id()) { + count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL); + *flags |=3D TNF_FAULT_LOCAL; + } + } else { + count_vm_numa_event(NUMA_HINT_PAGE_CACHE); } =20 return mpol_misplaced(folio, vmf, addr); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b858e22b259d..0f654aff477a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2726,12 +2726,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. @@ -2743,7 +2747,6 @@ int mpol_misplaced(struct folio *folio, struct vm_fau= lt *vmf, pgoff_t ilx; struct zoneref *z; int curnid =3D folio_nid(folio); - struct vm_area_struct *vma =3D vmf->vma; int thiscpu =3D raw_smp_processor_id(); int thisnid =3D numa_node_id(); int polnid =3D NUMA_NO_NODE; @@ -2753,18 +2756,24 @@ int mpol_misplaced(struct folio *folio, struct vm_f= ault *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 =3D get_vma_policy(vma, addr, folio_order(folio), &ilx); + if (vmf) { + lockdep_assert_held(vmf->ptl); + pol =3D get_vma_policy(vmf->vma, addr, folio_order(folio), &ilx); + } else + pol =3D get_task_policy(current); + if (!(pol->flags & MPOL_F_MOF)) goto out; =20 switch (pol->mode) { case MPOL_INTERLEAVE: - polnid =3D interleave_nid(pol, ilx); + polnid =3D vmf ? interleave_nid(pol, ilx) : + interleave_nodes(pol); break; =20 case MPOL_WEIGHTED_INTERLEAVE: - polnid =3D weighted_interleave_nid(pol, ilx); + polnid =3D vmf ? weighted_interleave_nid(pol, ilx) : + weighted_interleave_nodes(pol); break; =20 case MPOL_PREFERRED: diff --git a/mm/vmstat.c b/mm/vmstat.c index 04a1cb6cc636..5a02e6ff043d 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1316,6 +1316,7 @@ const char * const vmstat_text[] =3D { "numa_huge_pte_updates", "numa_hint_faults", "numa_hint_faults_local", + "numa_hint_page_cache", "numa_pages_migrated", #endif #ifdef CONFIG_MIGRATION --=20 2.43.0 From nobody Sun Feb 8 17:51:27 2026 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96BF3155725 for ; Wed, 7 Aug 2024 22:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723071524; cv=none; b=B+Vmnnc8FY+CyPX0UFohg7vvjZCgjD4LuvQY9UCZSgcgwyZrS/bVmCC7uuZw6fTpUW3VoV3j1Ed1H/MtMPwsNRekzOrlsgrFScJDi9EdflhLRSTW8Fdb73r1iumII6mFHr2LjTOLpetKiFaxQ/+HMWfNTdPL6fR08Va58lnoqyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723071524; c=relaxed/simple; bh=i4bQ2f0KhzqS43M84Z+6cqfFzyMKd1/zGXIzDO7oaj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OiyDnO5h92FW1tTIlIGQaDRj+0SgAWzdqcs/RfsoqowucM8pyfb1PzHSxpLlIvpRWB0Oum6cWdF+U+uHXiEagtYL0heSilBi3Ou3r5LWl6bwk0hMqYAGjU+hR22jtCvHBGknqtt7AbjqJ0PwuLyaslBL08xGv9MLCkyCEDMXvXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=J6UtWubh; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="J6UtWubh" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6bbbd25d216so8584166d6.0 for ; Wed, 07 Aug 2024 15:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1723071521; x=1723676321; darn=vger.kernel.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=vgTw1MJpREDKtA8MBDfFpK1lRDgpnFo5p3QGqe5q1yE=; b=J6UtWubhaRhGAHbPO5ynOJvh18bsgu94ds9pXyf2X6W9Mk8WvExO9Qkf0O/5k26X7x IHgCn82f198H1cBK3LyteR2LhfzpXOyNia2tBkVWxqZwForoiPBs3LRuJVwiiHTYeoXr rFj3YB0Mvl6PjGjiWOAxr7SQzgfLUImNhZVffvoawHj7yZk7rEIfjnD+QbuEj57pkJhs /hEQ8ocbiyw1t+DH984l70lMN7HzoqPYBHsYPu+8fB1zeYQU4xKw26pL8dbT8OzqKbPv Q++eq5Dehij7wCqaV5H1EYx5tLxtww5G+HCgEVudfnVrB7c+TBvQZ9T5jYS+eNdshckg 7tFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723071521; x=1723676321; 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=vgTw1MJpREDKtA8MBDfFpK1lRDgpnFo5p3QGqe5q1yE=; b=Arp5ruR0es276pc99OEkWyENZJel4tRez17N4H34IgNs2DRdGvt7+KK5ZqA7jJtZ84 xwOxh0PVsULGQXxlo7fqvUuPqKeAW2eODkeiN1cK3ea58ZGfJicEORT0Y2Db30CZg5mf 3tMMWd6OJ+k/UhdCy2oa3kBkfnL0EA2+L4tMRvyeBn2+4djHh0hVk4AgcVuHw46uZoGV uTQBrtG4o4qSUdfQKkcylLKPcRhGFij1rZoV55Ru+q6QTJZYjF8rK4TS93mxR5bRj+Fx 9EFlZ8t2v7E3hsVL57gIRPyY0m+swbjzP29BhQTniT+8e6LBgCLaV9KvrU1EXR6Rqj/w QpPw== X-Gm-Message-State: AOJu0YzDfTV7/p9f0S742gvsMi5jLhIoT3JJRmTzBKJUHaAEJD1F4snc gCNGaKJxuOoJnwpnXDdhMLslR2NfNunJr9lrQGuzY3NiP1rZUcGD6O20deU46bM= X-Google-Smtp-Source: AGHT+IESTvxvIP/0NsY/nNAedSv7eOQc6S3fHV+zRTAbSx6VH57uc+pCgilTBNWuC9GtEa+9Xyvohw== X-Received: by 2002:a05:6214:5784:b0:6b5:2f57:1a63 with SMTP id 6a1803df08f44-6bd6c3b4356mr418216d6.21.1723071521363; Wed, 07 Aug 2024 15:58:41 -0700 (PDT) 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 6a1803df08f44-6bb9c7b82cbsm59997096d6.61.2024.08.07.15.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 15:58:41 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, david@redhat.com, ying.huang@intel.com, nphamcs@gmail.com, nehagholkar@meta.com, abhishekd@meta.com, Johannes Weiner Subject: [PATCH 3/3] swap: enable promotion for unmapped pagecache on access Date: Sat, 3 Aug 2024 05:47:15 -0400 Message-ID: <20240803094715.23900-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240803094715.23900-1-gourry@gourry.net> References: <20240803094715.23900-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unmapped pagecache presently cannot be promoted off of lower tiers, even if they are being accessed by read/write calls. Enable migration in mark_folio_accessed if a given folio presently resides on a lower tier of memory. Suggested-by: Johannes Weiner Signed-off-by: Gregory Price --- mm/swap.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mm/swap.c b/mm/swap.c index 9caf6b017cf0..08f76d748e29 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include =20 #include "internal.h" =20 @@ -463,9 +466,26 @@ static void folio_inc_refs(struct folio *folio) * * When a newly allocated folio is not yet visible, so safe for non-atomic= ops, * __folio_set_referenced() may be substituted for folio_mark_accessed(). + * + * This call may also attempt to migrate the folio memory to the local node + * if it presently resides on a lower memory tier. */ void folio_mark_accessed(struct folio *folio) { + int nid =3D folio_nid(folio); + + /* If folio is on lower tier, try to promote to local node */ + if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING && + (nid =3D=3D NUMA_NO_NODE || !node_is_toptier(nid))) { + int flags; + + nid =3D numa_migrate_prep(folio, NULL, 0, nid, &flags); + if ((nid !=3D NUMA_NO_NODE) && + !migrate_misplaced_folio_prepare(folio, NULL, nid)) { + migrate_misplaced_folio(folio, nid); + } + } + if (lru_gen_enabled()) { folio_inc_refs(folio); return; --=20 2.43.0