From patchwork Tue Dec 10 21:37:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13902104 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 8196AE7717F for ; Tue, 10 Dec 2024 21:38:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7410A8D0018; Tue, 10 Dec 2024 16:38:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F0BD8D0013; Tue, 10 Dec 2024 16:38:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56AA88D0018; Tue, 10 Dec 2024 16:38:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3C6508D0013 for ; Tue, 10 Dec 2024 16:38:18 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E5A4B120EDD for ; Tue, 10 Dec 2024 21:38:17 +0000 (UTC) X-FDA: 82880362194.13.FC0431B Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf19.hostedemail.com (Postfix) with ESMTP id 6EC9B1A000B for ; Tue, 10 Dec 2024 21:37:52 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=IZqa84yf; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.182 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733866675; a=rsa-sha256; cv=none; b=DbBeonwPuObVV3La215GsmwJi7M9spVFQMCkjnUj9hg3bT3GE0+l7FJoVC5fpMSGMdChcU peS4iVLvcE3Ox7PFvcyEW1PgNT0iRmFrS0DU2ZVd8defqzlEsD60a9r5+A+OXut/NR8gXU 7oOEO+0KQFGszMNRLbjevWKqD6VnDRA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=IZqa84yf; spf=pass (imf19.hostedemail.com: domain of gourry@gourry.net designates 209.85.160.182 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=1733866675; 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=rD13RBY30Rrvkd04V+Adk5FJ3Ta4BXdJd5R/HBJ/aEU=; b=Z/kZK5HYtbe+SFJ57mLTKURjk6Juc0wnQ3qGAexolC/30XOy+OG4DXzBPIOw4uso/c4kY+ houDN84CMxdRb4j7UudW2khdLhFaEsWHucowgpojUFo6UQ6PZRhDv7ANRZJ+e9SYqHFGTs eNOfBaMBwAZdzAmY6xVJQovHLcdt/N4= Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-46783d44db0so8008511cf.1 for ; Tue, 10 Dec 2024 13:38:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1733866695; x=1734471495; 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=rD13RBY30Rrvkd04V+Adk5FJ3Ta4BXdJd5R/HBJ/aEU=; b=IZqa84yfZID2Z1UDLqFVzDxqaGDN4FoPEK3qjZuisbL8zJBvkrwD/ot2B9UqQCpSjE Lc80S/t+/uUlVoGw6R5XRpi7ZVorpAblBAOKdEZcKKJfyvJCUiBWtUCD5zJe92cje7Kt PW0L2zURcHnKZknIjChdeLx3HyHyTUCtMk+5VunFdNDwwFu+ZG3baUszhal1Qxf0ajIu uZ2myilMvlqC8Re2yPjSoKa3JlsZHpXpiRxI5Gf+Sn19d0jbbO00/DXTKzElZ7cfHh2x rBAEEt2IQQFmqijBNjjnXuIEw/3RmtUloMg1Lu3EBC3dxe7NxWceLuqOqiAZDw/f3Vki Agzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733866695; x=1734471495; 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=rD13RBY30Rrvkd04V+Adk5FJ3Ta4BXdJd5R/HBJ/aEU=; b=YpG/6rQkiKjTjKel3IHyTyXVEE95EW58Zj/eE0msyuT/k/DsfridjCsbI77bSoeL1L 5gIgSzfjrcN4D1+u822z1xPOFLjJeTL655IoJsibvEvaaWpZbn3LnEN9Y3D67i+YzbkB FR6UbKu4WyLB6UEnd1xBP/XK7qBu0MrbhygZrJ7zfOTvaTF0j7F/AC5mIbv4g/uT+NZE NA+CdiQ+0EkYriU1wBbYet8NxySGAcy9JUx0wF2a+pRxPqNYtbjNFXBbrivEGSeFWfmF v4lXGWiuLb+elb1dMDn96B/PT/OzCyQwFVqUmGUuRhW7MNL0CFGBPtoOt3LGcGdeAtpr m0aQ== X-Gm-Message-State: AOJu0Yy3zGa2+JrOoQ72cYFD+K6fI2733FT0GfwcTh7hGQzeIDeLFkqb AajTNsNehhVDnW7tb58iJ7QCujdIL50knq4tHFWx6yNjVRflW/xjOzrrIpb38muZ5oXB7dw4vp1 v X-Gm-Gg: ASbGncuzuVercFfjxl2PyAoQ7S7V7eOadIHQ1vWaAUdXY76QRnXdNsAwGKwmPdg4wfi ZH61hLn/TdD941ajWcdtKxWyXzJY+2onRIOVxJoqjARqPhgCTMkTlrcSrKfzeU4N6mapaHW7jom Np7yIyinVyfMOo03oFp8nWC/u8ZbQt0vnvuGPKVLbOGDq0BzX4ydnPUSzfrKU5wTaMwZkk6D/BY qtwB32ORsG/I7vu7Yp8AtjZsHEr+mHgAlrXQd7zdl+By41DeZxrrEspe85wnfPpgtSIWQ5+Nisu f8Lg0GrYcWXLLALN/6VygTRcNItRSRw/d4T70FI= X-Google-Smtp-Source: AGHT+IFsnNfg3615eI3lmfgEmFA2vm6QMKjB1yR8PQ1ci2ihqRLidFlxPlnZADQfcm/FjEoxGxlntQ== X-Received: by 2002:a05:622a:15c8:b0:466:77d0:5941 with SMTP id d75a77b69052e-4678929f162mr8994041cf.10.1733866695082; Tue, 10 Dec 2024 13:38:15 -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-467296f61f6sm65978991cf.43.2024.12.10.13.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 13:38:14 -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, nphamcs@gmail.com, gourry@gourry.net, akpm@linux-foundation.org, hannes@cmpxchg.org, kbusch@meta.com, ying.huang@linux.alibaba.com Subject: [RFC v2 PATCH 3/5] memory: allow non-fault migration in numa_migrate_check path Date: Tue, 10 Dec 2024 16:37:42 -0500 Message-ID: <20241210213744.2968-4-gourry@gourry.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241210213744.2968-1-gourry@gourry.net> References: <20241210213744.2968-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6EC9B1A000B X-Stat-Signature: acwjb63g9iirpnwiyxnpcrq9hb5aj1mj X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733866672-682989 X-HE-Meta: U2FsdGVkX19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BxWejjA/b4w1wzkIMY6oTgj+OoPi6ugRBkeAMiAAcJb3DnIzaidvfHtU05cgpbrmRP1CtnuHtgxhHOXplEfhj399coxiWfAyOnU7htFoClfbuZ/z9bAcU3dz+/AL0qL6gEpNVjhltmYQ2TVBvYcF4Wpiv+4geMp18fMSdiQW7+rzjhatzZHN7A2HZC0G/HYWshW2szayAVRZkD0bgUST81XYcBAZr1LFetNIy939TUNcehvu1mKgdOaigkE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000054, 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 access 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 6ad7616918c4..af7ba56a4e1e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5542,7 +5542,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 @@ -5555,12 +5568,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. @@ -5570,9 +5577,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 88eef9776bb0..77a123fa71b0 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2746,12 +2746,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. @@ -2763,7 +2767,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; @@ -2773,18 +2776,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: