From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 DCE6F425CD8 for ; Mon, 29 Jun 2026 16:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782750825; cv=none; b=ZHSQdIX5sZKpxcmO5B1MrjIiPZRnGbT5NQEdxbMynaycXRsqmirG4ijDVU7FNY3e8enPJwH3pQ7AardvfQv5jags5oCm3uyYK5LXKKjwC0qx5LTPQRMJ/mEtC25gSYSeqv23y/UMUgS+Sy/wY8T8L+OLjztr4RAT2tgd3wCu5EY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782750825; c=relaxed/simple; bh=7RUTFoXpzrDUjXtZR43bXxFYj0a/UvZmCnl5Uxkuy1s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fNjW3JxRIQph523/H3oExvgG5M2oaolZU+3dRVM8BjBu6cQpB56ujkedjUXoyXHsT5B+pPYp3gOlSS+NJO3uUn7vf+DLzyHWeuvX2G8Eo2KCaDr2A9K2l6wa29s2P0ia/zCurjdL2Fre9CYFnO7MVkYdIYwgeZz0wWLzBUejvGg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=JG2xi2sw; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="JG2xi2sw" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-8de412e58edso35026426d6.3 for ; Mon, 29 Jun 2026 09:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1782750822; x=1783355622; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kN1HdUbHSwBU7r5YIRy1kGjvINfYo7yRqPYydSfH+gc=; b=JG2xi2swyhtiAuKkkG4EOI2CNn7Zfs6V2iaIN6W/2hmWQqBdslzE+Rn8vh9pQhLPsC PE4V7rAfOI3d+3TcfknVh0TUvyxPvAqYoIdd7u0QbOvNwk92qx6BthIQPStLAxhu0cEj iZtECjo1cz3HG+/l7xLLXR78yLwkxOFZu//OOaQMYqHeB6lZufBltyw16YqRCrQ9czSz tsxMgh3pFmdzg65ztcEIsPgia28EYKa9+ynhcFD0zsUIieiMTnuvHRYSGAvcKT2qULKn SBiBJs/11Zah/c9/K7XvLC9qEDAvh0F6dnnRKcOsRUv1eP1ZzxI2O47Zfp66DG8C5bjM QvOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782750822; x=1783355622; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kN1HdUbHSwBU7r5YIRy1kGjvINfYo7yRqPYydSfH+gc=; b=fMH8TQaNp0lLKt7JRviCHfee+8d5kOtrsY3yKm4kYx14chWn4CEZ4GeRImeGjb5Ngj 6ks8Q2AyqGqhh/X0Tar/BjLUnngfoCLC62eeXaeizcMPgrl3Uly4KmwOzU7RVRVP7bwz SV5zIfbDylvGoo62t7L+jvpzct+Aq91EtbKW5mSuVUfcItOoOih7ik4RqdSn6ANtDYGs i+vO/7t1LPh32HJPPc4fmQn8HPSTkyGH68vPEoen6VHRgKR+FVMgeY7v3F5QldXTdhBX IGv9Svhzv4M38Inoe9aNjTU9i4fkLNEsFchU8tR9bXu0l3mWG2daau/+tGvaB+ugqhQT Y+cg== X-Forwarded-Encrypted: i=1; AHgh+RpViXe/LLudLFRcJZ3lhM8qGd6vqtuUHPlAtd0CmvET39FuzXRQYfS3l9dxw1nSE35p+LbcaNg4a8NYhYE=@vger.kernel.org X-Gm-Message-State: AOJu0YwAlvKtXqPCiX4ilf94d9AKTF2C8RXJsGpKFeUFaNvjX0R2WTfb l0AAVBKNdD0ljE5iG7d6GeL6ZSJaJX72r/TxkuWhBY/y0+YqA2A+TkKprk+N3nVf7SU= X-Gm-Gg: AfdE7cnk6Y4+/3YqhH/9bTsbMaTv8izNlPf/qolm7XHDTM+UZzGUCtRzSlmZvuc9WrA SZX92jpjlRqoL30f6PGcp8NFRE5SjryBJkdO21vl9xc8Q+EHtyu2MDjGlsRpW++TZtdhvAcU3tA dY1mnNix3NbwQo4U9OmSh/cNxPKtVwglZAQjyhzSJtx6eRQqwGOeSQwFg4sxOIxaF/yG9fIT4Us XA3CYhCuTEequJPUhR5l0z46WNf4hA+SRRv+isNmArZ8EOMbVqr/WaaxKGw4lVP3A7ganrE1977 pyChh7o3xGGKTopbh9b6kSt5WK0qXbvb0x71B3xisjsFtF3SxCS+S4Bl3mcXINLXPM1pFKYC928 aMkVpDuYSlLMRtolvjfY9Yi2C9fQteFA4xx2BtvnqC7GObMbBbsaFZDjnXBQXEKii/TLmNPCiJp FSDbC4z3oMwWs= X-Received: by 2002:a05:6214:8109:b0:8f1:323a:fc45 with SMTP id 6a1803df08f44-8f1b9fc70dbmr307846d6.15.1782750821627; Mon, 29 Jun 2026 09:33:41 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8f1a27e64a9sm2397176d6.4.2026.06.29.09.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2026 09:33:41 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Neha Gholkar Subject: [PATCH] mm: mempolicy: fix automatic numa balancing for shmem Date: Mon, 29 Jun 2026 12:33:37 -0400 Message-ID: <20260629163337.1264881-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Neha reports that mapped shmem aren't considered for NUMA balancing, noting convergence problems and bandwidth bottlenecking for cachelib based workloads on tiered memory systems. Looking at the code and going through the git history, this doesn't actually seem intentional: Commit fc3147245d19 ("mm: numa: Limit NUMA scanning to migrate-on-fault VMAs") added a vma_policy_mof() gate to task_numa_work() so VMAs whose policy lacks MPOL_F_MOF are skipped from NUMA balancing scans. The motivation was a real usecase: Oracle was pinning shared segments with mbind(MPOL_BIND) so trapping faults was both expensive and pointless. The handling of NULL from vm_ops->get_policy, however, treated "user explicitly opted out" the same as "user never specified anything." For VMAs whose shared policy is absent - the common case for shmem - the scan was disabled too. This issue is old. It probably hurts less in conventional NUMA. But it's very noticable on tiered systems, where entire tmpfs workingsets can get stuck on lower-bandwidth memory. Fix this by having vma_policy_mof() use __get_vma_policy() directly, and thereby handle the fallback to task policy (-> preferred_node_policy() has MPOL_F_MOF per default). Every other consumer of vm_ops->get_policy already handles it this way, the scan-eligibility check was the outlier. This preserves Mel's intended fix: don't scan stuff the user explicitly pinned. But allow default policy vmas to participate in balancing. Reported-by: Neha Gholkar Tested-by: Neha Gholkar Fixes: fc3147245d19 ("mm: numa: Limit NUMA scanning to migrate-on-fault VMAs") Signed-off-by: Johannes Weiner --- mm/mempolicy.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 36699fabd3c2..bba65898aee1 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2057,24 +2057,15 @@ struct mempolicy *get_vma_policy(struct vm_area_struct *vma, bool vma_policy_mof(struct vm_area_struct *vma) { struct mempolicy *pol; + pgoff_t ilx; + bool mof; - if (vma->vm_ops && vma->vm_ops->get_policy) { - bool ret = false; - pgoff_t ilx; /* ignored here */ - - pol = vma->vm_ops->get_policy(vma, vma->vm_start, &ilx); - if (pol && (pol->flags & MPOL_F_MOF)) - ret = true; - mpol_cond_put(pol); - - return ret; - } - - pol = vma->vm_policy; + pol = __get_vma_policy(vma, vma->vm_start, &ilx); if (!pol) pol = get_task_policy(current); - - return pol->flags & MPOL_F_MOF; + mof = pol->flags & MPOL_F_MOF; + mpol_cond_put(pol); + return mof; } bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone) -- 2.54.0