Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1696410rda; Mon, 23 Oct 2023 23:44:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAf1v9jRU2D/vze5rXjMKOlMg3w3/hsTccd7XgKoxvqzpMjP3gjK4CQ3KDlng2sU9yrV6O X-Received: by 2002:a17:90a:355:b0:273:cb91:c74f with SMTP id 21-20020a17090a035500b00273cb91c74fmr10711614pjf.8.1698129873062; Mon, 23 Oct 2023 23:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698129873; cv=none; d=google.com; s=arc-20160816; b=rxp8ONXhhTsnZ/S6ZGC08MA92GwLMxkkQgLAOJf8hg3V6/p+oyShA3JHewLX58Frft DtxOmRN8IRQAio07gQyr/HnaUvlF+Yg1sDstX2GwkhGcNKJNfNiXtf6BCtF7L8jdXowi 9I7I57OgQzXVqCErZycq8v8cmVZKtLq+bzUz4WgfvhJIlzNnvcSD8gr1Th1cKKpXOL+y T8mWUokyXHk+kxb9J/SlxMlf0iEa7N/fJSpoPt0n8cgncEeYNz49W9819loplczk/lGp 5NeYowQDZ38L2hbjOy59CQkw0m9ObJaNZRnHb36mdbabkqTY+QtTVguzWxAxRMjfN6t4 5u+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=oWkAilm3qKxCzp8T0O3zII3wehqdTtuy7Tj/TdEVfLI=; fh=poeLZuDRtCLDXQc30ucK56SEwEIZd8Im5NzhZCW4rOc=; b=TW3d8R4/l4sTvfP5p6wjPbE8EcWTkuzJuXH/QRFfHFLfkF90BAQX12llxX3vUzqlBd 0zibpmy2EuFac+p3CB/P5s4ohY7JIQHq6cxrqzRcs0KVM6nBOVu6LpZDn7ffXOo697Nw b5tUoAHpCyoU8ip2wvV7IMd79C11jwAo/REiOtUv27uDbimgTU535XgMOg9SlDdMfUtU AC6y3T+nsbi4ieo9UMkr7DMMwNqUYWj0YpTmfmFVcjgVqL1wj+iaKWRJrYwIWHl71qwN ja3W9SF9Cndgn/NADHGW5QpEYUSOeD6Pd/8t5J2q6Gk2M3SYtr8PsWyzQkpqV8YE+ZGv pYdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=afOW5pvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b132-20020a63348a000000b005b8ebd6a0c2si645636pga.69.2023.10.23.23.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 23:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=afOW5pvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 924C380C5936; Mon, 23 Oct 2023 23:44:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbjJXGo1 (ORCPT + 99 others); Tue, 24 Oct 2023 02:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjJXGo0 (ORCPT ); Tue, 24 Oct 2023 02:44:26 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCFFDF9 for ; Mon, 23 Oct 2023 23:44:22 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-d9beb863816so3692711276.1 for ; Mon, 23 Oct 2023 23:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698129862; x=1698734662; 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=oWkAilm3qKxCzp8T0O3zII3wehqdTtuy7Tj/TdEVfLI=; b=afOW5pvi6IxOeWreS3k6+dElC0aPPbXzl44LfwlkQKJag+i5aE37dxTBim87U8+WtH qkjOcLb0wI4iaA4mNi0jB4POghkSQoG4CDAVICa6r42Xb0GHABV7bPwqMNkBcgyllmsn 78UhsPKf/f5wDidNEzKk8kdxvdutrjkN0sDMBvOVhS5i4VGvks/H8E3JTv4PW9A3JQgR H4GE7+R5jbBGAH4texZg1VLWqq4v2WiAUiBkVoOONZjVA9Ef7q1mva2kZMZO6YCa47At mUHq09/2P9gcITRQ4UtEUuTaeurWZXtEZVomDy27U5207gq5wO7hoekrbGJtUka/ykAg Smyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698129862; x=1698734662; 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=oWkAilm3qKxCzp8T0O3zII3wehqdTtuy7Tj/TdEVfLI=; b=WkOI5Me/NoxDGP7/fq2o4iqNHU8o3b/PEF2l1g0vVn1N8WbgyYcm3ESyQnVpS9mfRv g7/zsINk4ruGgNbIKJPVJYkMHw5pwG90kVVR5xpy2d8eJUoydUvuJFf47ae44wGjXwD3 UvgB8/TrbhUAPnjW5fhrHQKd1ruDDAPx94HDZcLcoHLmR9lAZqS19X6ficLIR5o4Pasp mGcrcmZWTCHn3/4P6lJ+JNuuef+z/KJ+XTyAsXUCa3RmjSgzf26mm1rbCXz4X77OM3kA 6MhgEOhaldhWl3RRFZ6zLB8dquKYfXdZRAdTeZi61ywWvTS1Yt42pU2OiHmyU82Y9PE1 TZ1g== X-Gm-Message-State: AOJu0YwWcrRv/P6x2DIQBCvalh806WR4+yLArfeVAcABUfTW+SFkgoNX MCPTUHR394q8viwKeuFHc2NV0Q== X-Received: by 2002:a25:5f09:0:b0:d89:5638:8bb7 with SMTP id t9-20020a255f09000000b00d8956388bb7mr9710375ybb.20.1698129861840; Mon, 23 Oct 2023 23:44:21 -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 a32-20020a25ae20000000b00d7b9fab78bfsm3361396ybj.7.2023.10.23.23.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 23:44:21 -0700 (PDT) Date: Mon, 23 Oct 2023 23:44:18 -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] mempolicy: alloc_pages_mpol() for NUMA policy without vma: fix In-Reply-To: <20231023190555.GA1964810@cmpxchg.org> Message-ID: <00dc4f56-e623-7c85-29ea-4211e93063f6@google.com> References: <74e34633-6060-f5e3-aee-7040d43f2e93@google.com> <1738368e-bac0-fd11-ed7f-b87142a939fe@google.com> <20231023105331.311373ed33a0dfe78ddaa9e5@linux-foundation.org> <20231023190555.GA1964810@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 23 Oct 2023 23:44:31 -0700 (PDT) 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-7040d43f2e93@google.com/T/#mf08c877d1884fc7867f9e328cdf02257ff3b3ae9 Suggested-by: Johannes Weiner Fixes: 48a7bd12d57f ("mempolicy: alloc_pages_mpol() for NUMA policy without vma") Signed-off-by: Hugh Dickins --- include/linux/mempolicy.h | 2 ++ mm/mempolicy.c | 2 -- mm/zswap.c | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index 2801d5b0a4e9..dd9ed2ce7fd5 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -17,6 +17,8 @@ struct mm_struct; +#define NO_INTERLEAVE_INDEX (-1UL) /* use task il_prev for interleaving */ + #ifdef CONFIG_NUMA /* 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 nodemask */ #define MPOL_MF_WRLOCK (MPOL_MF_INTERNAL << 2) /* Write-lock walked vmas */ -#define NO_INTERLEAVE_INDEX (-1UL) - static struct kmem_cache *policy_cache; static struct kmem_cache *sn_cache; 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 = entry->swpentry; struct page *page; + struct mempolicy *mpol; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; struct zpool *pool = zswap_find_zpool(entry); @@ -1075,8 +1077,9 @@ static int zswap_writeback_entry(struct zswap_entry *entry, } /* try to allocate swap cache page */ - page = __read_swap_cache_async(swpentry, GFP_KERNEL, NULL, 0, - &page_was_allocated); + mpol = get_task_policy(current); + page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, + NO_INTERLEAVE_INDEX, &page_was_allocated); if (!page) { ret = -ENOMEM; goto fail; -- 2.35.3