From patchwork Tue Oct 24 06:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13433970 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 A66A7C00A8F for ; Tue, 24 Oct 2023 06:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2896D6B017D; Tue, 24 Oct 2023 02:44:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 239746B017E; Tue, 24 Oct 2023 02:44:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 101E06B017F; Tue, 24 Oct 2023 02:44:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 008156B017D for ; Tue, 24 Oct 2023 02:44:24 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B993F140DED for ; Tue, 24 Oct 2023 06:44:24 +0000 (UTC) X-FDA: 81379416048.10.14C334F Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by imf12.hostedemail.com (Postfix) with ESMTP id E853940015 for ; Tue, 24 Oct 2023 06:44:22 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lAHUc91w; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of hughd@google.com designates 209.85.219.182 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=1698129862; 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=oWkAilm3qKxCzp8T0O3zII3wehqdTtuy7Tj/TdEVfLI=; b=Kg++4qiNv5KQHSBcobiZ4ehilmS/SKFk8grajNCOtVStTweXdnzAoE90MA8KQJaLBfriSn Xom7mYrO5R6jP1pqD9pR5Ga7HtWwUTwsX0kkydvuXbDOb/FXrVX492CScl/kegCKkki/Bx bU3vB8Nojj2LvREnhdWC4iHdr1pRYho= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lAHUc91w; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of hughd@google.com designates 209.85.219.182 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698129863; a=rsa-sha256; cv=none; b=3sn+SvBhm3G5GkggEZlWFTAfsHne66kLCsnbrhl3l8sXewvuw+8rY1Pxb0gD5XjAr5JIOr EtVXi4iz2KoUVmoJgE6HUlmE4Pt8opf9MxCK/RqgGmXXSG2cybNkvcm64eTXFQ51JVhGtE ss3sT639BCrZaUM9OWuToWvujGxY8ck= Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-d9beb863816so3692713276.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=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=oWkAilm3qKxCzp8T0O3zII3wehqdTtuy7Tj/TdEVfLI=; b=lAHUc91wN0myMbqJJcloXEJR49NcTzwBZ1XKsgo+RPt/1F8VrOGS1X85sj5EevWVQf baIpHXx9pSgSfhLtKC1PDvdVos6ukZGpsbsNdqqQyFIxiLl4qW6ubmhojBZFSVkKWp00 u5LvGvtGxPicFNee3Qt82V1HHjLECZ0DykW6iFmBNeBSrrOq6uvhObzrzUBuvysFP2vu etDxPESWEgkh8NEN3ivU4NFa+KWyophTYgaWK6aJZcjoa35kbUuJpg1R+IbZFUY3e0yc la/bcllyAyrbwyh2Ke7RBRTedRz0/4hTdq0Zh3bjzl8zdgh61G8NeJk5dskr83O0bg/p MOyg== 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=a1bbheHigvVYJUY583cmprYcJfQvqV5CWwX2JFu1Vb5Eyb4QrzkI58OSjoY2eeKWmu tugLh+OfwiAh7QCjP+rC2+RwVL3aFz2nmdEIED/XLUi7Br1vE92jWtFZx5nzzaMmRuek zNKeDoG6IqVxZOWZJW4UUCB7H9IWlxgbPB5vlYwPzaf41lmJ6Xuw4SFtjpt8TuH9fwhs xVnzBcI+IMrcy49nOGkfIUDZnHm54gQotvAloSyMnx+FFxHdyzsMr63B//s/pgtgtsu/ BH7XWDGyj1l4GZCMHP6NYsOR4bsag0hIqicp258zY9QhkVZzj1VDQ5L04CsLN+26pxc2 oaxw== X-Gm-Message-State: AOJu0YxEMhFFYLJSsADSx2nFvXLoi0nnh62ja1KxImNyhid+IGx0Lbwz IP94G3iX1iQ9VH+JG6kiUq4eTQ== X-Google-Smtp-Source: AGHT+IFRjXjXsGt5DJkxXS0KJojysZ8XeQK/gsibTxLGbsR00Tz1R2O1nDPs/rt5ugs3IqWEGWnc/Q== 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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E853940015 X-Stat-Signature: o56gortsgaaodnu788ammd9p19dxbij9 X-HE-Tag: 1698129862-617662 X-HE-Meta: U2FsdGVkX1/2xLwk0i04qnAV1bIlXext8A9KdyA22X/pwWWr6elWy5ZhOrq8IYk6FRSQgMX3KIg8Z0xrAc3xdIXJZz0I+rxeKqqWX+7P+eIPlGZaGayEl1ePLAOwhK39TufWZ4ScJtCXL8pQ6RpsONIdYsAeDBDe59sXLAVj9v5xcR3rLrYQpUWUQ7dLM1t41V4b9IhTkWxCMOka8dsAqAgc4WNnxUS4twBFszg5p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hnuImbil0E17TIB706wtb6pDnlPZrtUfCZmZax8qZzg9WAOojmVUOXELGbBANVtKcO+YFY8m4sxOZ0ehAELocV9pYzy5A8buv6Q0smmB5v2J6A4wixJXhvfS/TKrpfR9bIBGumanqheBvPhP5imzyg1dYZGB2pLqFAUd6KsEnwmuRPp397IpoXCwoTUDjt8PCzpjHPqeEeeubCAIBvEQuXPIoW2Ymn2faoxTk6j+m6QCNrwT/pq73U8Y3hlUp3XnDFXDJ1IKezi9+ay0yk+Yg3cgc= 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 --- 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;