From nobody Thu Jan 1 07:18:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 005C6C25B48 for ; Tue, 24 Oct 2023 16:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344066AbjJXQJ6 (ORCPT ); Tue, 24 Oct 2023 12:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234286AbjJXQJ4 (ORCPT ); Tue, 24 Oct 2023 12:09:56 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36152D7D for ; Tue, 24 Oct 2023 09:09:54 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-5a7afd45199so48056157b3.0 for ; Tue, 24 Oct 2023 09:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698163793; x=1698768593; darn=vger.kernel.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=9uwebOammgYNOokYzgscdbftdR0pMLZxQ7ReST9beIs=; b=xrDdVZEPl66hK7bC1XfxTZe0LV7yfnlWwEF7VPeBCjlH5AqJqAA5dnfJsa92rfMES7 hV16HfB/fLbvkIRn9MtLyq3txz1O5Wbtzn/B0oFRaR9Kn0L6GlhHUZRlOr1KjaXDIaMX Qfs7xwhYVdVCmpLY9at3ElYTs5TWtuSUJGA14geTrLMMu1zrDTkKuXHg+0jA+D3ZsMOw vZ3GCIwfEj8YoUY0hyy+bW4p5PSM4UxvVEgm8IIYSgggQrpf+GLnLlGRRoJkCYujBCBK iarZUTS+husiAM/Pr5Lg04krJfGpqIHkcHjw9/p+b3VWkrt7/OU4NTpdTlYFICkLJJk9 7GKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698163793; x=1698768593; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9uwebOammgYNOokYzgscdbftdR0pMLZxQ7ReST9beIs=; b=Ve580ClGiOjPOHoKoxUdnixXAoiI2GeALG1pGkRZUeV2jqViAcjJIDCww1SK4N2mqT d2wC2awmvl0gBw0zHL1THxBKkakdNroUBcaausFRCNk3KkQAln/qHLNN8tHIuU+2m3KL b8q+unH8yBP10yIkH3vYt0ZBzSy8+VgK8NR9UPMWRXHrLhph3h5reFlz2pN/JORha9Jj k1FMoHci0M9NRZnki1RY1CoBbsJx8CThogCGD4gZzdj7PM4j3K43dFGVyaYRI/0IAZca puevN2OYdsiQoVsT3sZwah0ChzJsOoCP+u3IAPdV41hQBzlF/87SfsrKAln6SDsnEMAP SBaw== X-Gm-Message-State: AOJu0YwkYYtGtxPOhckwmQ33tYDJ+qCjW07HkBS6FG7Xy/B2/32G9fOf eN0oemYnOsSXXxYxG9NNsnCzRw== X-Google-Smtp-Source: AGHT+IFYSVPo7yy9HeVbLbMVQ6/aFEFb+qcE4/a5SXXKaSxcMB9+EZkYJQg5qpUHBV1yTvOcAtoRQA== X-Received: by 2002:a0d:d494:0:b0:5a8:78b0:a9fd with SMTP id w142-20020a0dd494000000b005a878b0a9fdmr13896756ywd.29.1698163793274; Tue, 24 Oct 2023 09:09:53 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id e6-20020a0df506000000b005837633d9cbsm4117562ywf.64.2023.10.24.09.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 09:09:52 -0700 (PDT) Date: Tue, 24 Oct 2023 09:09:39 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Johannes Weiner , domenico cerasuolo , Andi Kleen , Christoph Lameter , Matthew Wilcox , Mike Kravetz , David Hildenbrand , Suren Baghdasaryan , Yang Shi , Sidhartha Kumar , Vishal Moola , Kefeng Wang , Greg Kroah-Hartman , Tejun Heo , Mel Gorman , Michal Hocko , "Huang, Ying" , Nhat Pham , Yosry Ahmed , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] mempolicy: alloc_pages_mpol() for NUMA policy without vma: fix In-Reply-To: <00dc4f56-e623-7c85-29ea-4211e93063f6@google.com> Message-ID: References: <74e34633-6060-f5e3-aee-7040d43f2e93@google.com> <1738368e-bac0-fd11-ed7f-b87142a939fe@google.com> <20231023105331.311373ed33a0dfe78ddaa9e5@linux-foundation.org> <20231023190555.GA1964810@cmpxchg.org> <00dc4f56-e623-7c85-29ea-4211e93063f6@google.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mm-unstable commit 48a7bd12d57f ("mempolicy: alloc_pages_mpol() for NUMA policy without vma") ended read_swap_cache_async() supporting NULL vma - okay; but missed the NULL mpol being passed to __read_swap_cache_async() by zswap_writeback_entry() - oops! Since its other callers all give good mpol, add get_task_policy(current) there in mm/zswap.c, to produce the same good-enough behaviour as before (and task policy, acted on in current task, does not require the refcount to be dup'ed). But if that policy is (quite reasonably) MPOL_INTERLEAVE, then ilx must be NO_INTERLEAVE_INDEX rather than 0, to provide the same distribution as before: move that definition from mempolicy.c to mempolicy.h. Reported-by: Domenico Cerasuolo Closes: https://lore.kernel.org/linux-mm/74e34633-6060-f5e3-aee-7040d43f2e9= 3@google.com/T/#mf08c877d1884fc7867f9e328cdf02257ff3b3ae9 Suggested-by: Johannes Weiner Fixes: 48a7bd12d57f ("mempolicy: alloc_pages_mpol() for NUMA policy without= vma") Signed-off-by: Hugh Dickins --- v2: !CONFIG_NUMA builds with a get_task_policy() added in mempolicy.h include/linux/mempolicy.h | 7 +++++++ mm/mempolicy.c | 2 -- mm/zswap.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index 2801d5b0a4e9..931b118336f4 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -17,6 +17,8 @@ =20 struct mm_struct; =20 +#define NO_INTERLEAVE_INDEX (-1UL) /* use task il_prev for interleaving */ + #ifdef CONFIG_NUMA =20 /* @@ -179,6 +181,11 @@ extern bool apply_policy_zone(struct mempolicy *policy= , enum zone_type zone); =20 struct mempolicy {}; =20 +static inline struct mempolicy *get_task_policy(struct task_struct *p) +{ + return NULL; +} + static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b) { return true; diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 898ee2e3c85b..989293180eb6 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -114,8 +114,6 @@ #define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1) /* Invert check for n= odemask */ #define MPOL_MF_WRLOCK (MPOL_MF_INTERNAL << 2) /* Write-lock walked = vmas */ =20 -#define NO_INTERLEAVE_INDEX (-1UL) - static struct kmem_cache *policy_cache; static struct kmem_cache *sn_cache; =20 diff --git a/mm/zswap.c b/mm/zswap.c index 37d2b1cb2ecb..060857adca76 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1057,6 +1058,7 @@ static int zswap_writeback_entry(struct zswap_entry *= entry, { swp_entry_t swpentry =3D entry->swpentry; struct page *page; + struct mempolicy *mpol; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; struct zpool *pool =3D zswap_find_zpool(entry); @@ -1075,8 +1077,9 @@ static int zswap_writeback_entry(struct zswap_entry *= entry, } =20 /* try to allocate swap cache page */ - page =3D __read_swap_cache_async(swpentry, GFP_KERNEL, NULL, 0, - &page_was_allocated); + mpol =3D get_task_policy(current); + page =3D __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, + NO_INTERLEAVE_INDEX, &page_was_allocated); if (!page) { ret =3D -ENOMEM; goto fail; --=20 2.35.3