From patchwork Tue Oct 24 16:09:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13435046 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 1AC1CC07545 for ; Tue, 24 Oct 2023 16:09:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 916106B02C6; Tue, 24 Oct 2023 12:09:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C69D6B02C7; Tue, 24 Oct 2023 12:09:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78F9E6B02C8; Tue, 24 Oct 2023 12:09:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 695C76B02C6 for ; Tue, 24 Oct 2023 12:09:56 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3C0C7B592F for ; Tue, 24 Oct 2023 16:09:56 +0000 (UTC) X-FDA: 81380841192.23.519DB51 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) by imf02.hostedemail.com (Postfix) with ESMTP id 59E108001F for ; Tue, 24 Oct 2023 16:09:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=NiwCRfJn; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.175 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698163794; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9uwebOammgYNOokYzgscdbftdR0pMLZxQ7ReST9beIs=; b=11DIFyuAAUSPE2W0SopONT8HpmpKnuu84OszqD1stb4w7lYx8gCFB6t2JY9XMpxnesXVts NjiS7wwBbCRGcQ4QDqj+nKS6aXelntzBWEdVyCQ2bKEXfX2BE31j5j4018WVQok5PimqsK nH/j3MioSuzH6IEDd6XS2qXt7w/4VPQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=NiwCRfJn; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.175 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698163794; a=rsa-sha256; cv=none; b=7Pw+euNMG5C0/Fk1u/1fzXb0ipEVQ9JIZV4uxmgeCZ/goR/b34j6/HjaYd8Y2RsmOA7/Fi QdBKwRck72qwT//yTpThaGLa++/qkUbNsApUvU1RhWbw01A/Kj9ROYYz46fwa4FPadTwfM tRJnGxHqNc10bw/FERmIF+kdovA2lqM= Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-5a7afd45199so48056127b3.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=kvack.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=NiwCRfJn4YVz5hT5fRkuUU63hFzs81RCbu/kfiwvMVtJhq/ZEI3Bq0xISvD6M7wtkF 55ZAZ3eNI0W3fT+bkVI/l1mxtBEmVzrsP5Onb32t1temh5ZwyUJ3wXSB8dgXnl0svCKH lYSPPhXrPNODpa/KCMkRLCvAthmGyhrsqz7LttjNze0HXG/x/h1xTAXZ1MIZWzRUpXHo rwxjNTcbO1UdT1Aqni/hfUlODzS3NqHlW+ww5aiMTpINvpUZwHllfj4jjNFWE5QLGZMb PNXVY/qDjinl4nx5Y3jj1LpH/im1BFKMY029v3A5zO4GA5FDLE/Kq3+1BemkScFf476f zBhg== 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=sM65PJODHBLbt/d8W5dWGAzMrNejJNS4n76Bmp7lPDJNeP+MYFAuaoUlbJZmylHbcM EnL7Ip5uQDVJ38Dxr5DjW26Oi7GpQatcqJ4+MWmka0H+2g9TdIdEjWRKJBPwhq7A4+NZ 3A4+9/Ww4sleDoQZkc3n8EdFug9nLxlEVLNpPwLlPH210jASooBVN1f7LbUADb4yQFfZ 1/AgsJmpeqam0+Z01er/CcuT2RZWgHNXHO+EqxzxzAs0eazCN6tlxlA923MghNx72eY0 iqHX21NNgUk4jilK6AdPZgK5gSlzq8S8vQjGXGEA0Y4BC3aYGdA09nml+3MYGWk52F/i xnFg== X-Gm-Message-State: AOJu0YxD6FTLhZME3P9axKU/gUey0OKOiYPZrBu0OOQMlOR46zIICMQe P5R2AiJee/dc6qbcNLMJMo80/g== 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 X-Rspamd-Queue-Id: 59E108001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: at6xgje9zaohpg6668p4kkq1xwq1mw1k X-HE-Tag: 1698163794-211432 X-HE-Meta: U2FsdGVkX18ebdF4kiaYGG1eisOfQn6/Fq+V2O7BKoOiprYMeMzb/b9rS4MX+ArbWL6HXmF3gOzgxUu4kVYsnxVHjM2vgp4Gx6H8MUpEbuKERNywCNu0nUJLAq3vkH3JkAkWo/YtEBvICMBXkGNdEhjdiPesILSWigUm+oH/hVs2aqK5gAYGG/J4AgaUO0vpxMUdinSAUIVhlOY+X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fIxKsp+vVYDvhRz1ydshneOHO9WYIn/J6EmTe7JUJm6tyrNKwlx8E0U4EWpLbFh2mYf1NAHNqgSQMd7jVDG6+sMsF93KtjONbV2WJs5YPgsG/JytzGqI/JAPjBEID91UV41a4yxxTXiuxdRtUghKxXwYyNHW3F5AcVnpzT5XC0iPT6uhq5f1CrziQBy3oJkt47wh3kfiTMPw5N8l0mgZ5LKNGD1JE2ZgbPMmgEw9NeLK2uOROcKOFBcAc7qg4D2bGo+YvCfXdc74Wiah4akbNiyvxuU9BRpcox9MxRLg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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 @@ struct mm_struct; +#define NO_INTERLEAVE_INDEX (-1UL) /* use task il_prev for interleaving */ + #ifdef CONFIG_NUMA /* @@ -179,6 +181,11 @@ extern bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone); struct mempolicy {}; +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 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;