From mboxrd@z Thu Jan 1 00:00:00 1970 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 08507C00140 for ; Tue, 2 Aug 2022 06:40:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E0426B0071; Tue, 2 Aug 2022 02:40:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88F0A8E0002; Tue, 2 Aug 2022 02:40:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 756868E0001; Tue, 2 Aug 2022 02:40:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 626986B0071 for ; Tue, 2 Aug 2022 02:40:21 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3C93B1A0DD8 for ; Tue, 2 Aug 2022 06:40:21 +0000 (UTC) X-FDA: 79753703442.24.9DABCE8 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf27.hostedemail.com (Postfix) with ESMTP id 3C1EA4010B for ; Tue, 2 Aug 2022 06:40:19 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id 15-20020a17090a098f00b001f305b453feso17537511pjo.1 for ; Mon, 01 Aug 2022 23:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=wUGqIvgtVcDWxzjz/d8Dldte2zUIUWVuAUjRKRevA5c=; b=CGzfWvfjfMBz1r6a/zGfmZHY8idAPKPrpacRnP2wgvBHLK/dFFCdpEUrG2WDcvcdAe Mv3NoUT8+4kY18ZzAcgArd/KbySeQsVPnADcrbqZ+le2LJbRBo03lvgnkqrlLjq5RniY wLeokzNG/xRKOFdqk3/g34zCCtL4eTr5se20c1X6a6+044U7mLdb+7XX/Dw6zlDT8p24 zLc9hi7ZNULcstEjqzNdEbpTAVy8Txf/oZg4Wy8CznCV7K8e0MRn54gid2Ve27WRhNdi /QhMXoYvapPM58dL6K+c6u+4z+1y6u+x/EHezQCZ6W+sPulZrljsajliFs1ZGgl2PF8G 5lOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=wUGqIvgtVcDWxzjz/d8Dldte2zUIUWVuAUjRKRevA5c=; b=JgnJFJxp77RCq0bbtNTWaU+OWf4qx9lUaksJJWtN2CC/35ZIScGpb7xLlPp9A27E/w lNgyo2tpYqqQUWbu5/Hw+CHssmctAXn53yiD+tuaUFS/oKv4G3C65lrq8I0o7cEJRV06 OEgmhdNHKeGb0gjqbbUz/WMp247SjKsh4qQCqvajOC9lrDX76+0uUiVH+n+poBFdD8O8 90Zg985XQ7ezQSzSTP/kQklby9nTnGxULgKJyvK0wapD5jUz6R+0FIwH+rxzIMDuLRu6 MdP2XPPNEnveUUxyEO1F9TZXrqyVXIcHL9Ic73jUC0HgZPi0P+CUiQWh6NpPbSWMCW2A d1WA== X-Gm-Message-State: ACgBeo3FdXvYm4GlZkTYRh8Dl8xYsUd/J1JzmDrdMpyEn/4mY45pacqI VSeVdL9sbNwk9okBIl5pCKSUGA== X-Google-Smtp-Source: AA6agR6tSaIxCAX0D9/F0bPa8vj9UvzHwyPEvKMAjcghwOMEs0b14UWs5jVZ4ZsUC4CMuxXAueFuag== X-Received: by 2002:a17:902:ec88:b0:16d:cf9b:cdf8 with SMTP id x8-20020a170902ec8800b0016dcf9bcdf8mr20025808plg.128.1659422418094; Mon, 01 Aug 2022 23:40:18 -0700 (PDT) Received: from localhost ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id t21-20020a170902b21500b0016be596c8afsm8822226plr.282.2022.08.01.23.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 23:40:17 -0700 (PDT) Date: Tue, 2 Aug 2022 14:40:11 +0800 From: Muchun Song To: Feng Tang Cc: "Hocko, Michal" , "akpm@linux-foundation.org" , "bwidawsk@kernel.org" , "dave.hansen@linux.intel.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] mm: mempolicy: fix policy_nodemask() for MPOL_PREFERRED_MANY case Message-ID: References: <20220801084207.39086-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659422420; 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=wUGqIvgtVcDWxzjz/d8Dldte2zUIUWVuAUjRKRevA5c=; b=AtJ/oxQrjMKf/Vj5ZwZJtnVWbvy0T2VMwtcERZY3PawcC2AdKYtd0WWNxPjAoI2tX2VzRC Bz2eANBLoKWs+Kceg/1AGbtTgk/tF3aQzF7wDbipolMzATzG2vDVyUOGex+0dgTy7+H/yU p2lO81le7vtLNT/UgZ1cSkB37KlBHr0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=CGzfWvfj; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659422420; a=rsa-sha256; cv=none; b=0KPa/cTAdD669T0masq5kBUiCFJNTZZ4ZvQYYDKKlUI+DqlcxQ9Oa07lgo8Ui4zYNALBXq DJ2CCFYhdU9JMEmUB2shT8R9g5ZIM+b5c4sbUhB/x9QsGt87WHSzzwnTXnIiWGl1N3EmcO wK5Kb6PIUJIjtCrnKrJGUQrTRS8B8Z4= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=CGzfWvfj; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Stat-Signature: 4psdjff896a3316xuj59ewgaoaczdwju X-Rspamd-Queue-Id: 3C1EA4010B X-HE-Tag: 1659422419-833922 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: On Tue, Aug 02, 2022 at 01:52:05PM +0800, Feng Tang wrote: > On Tue, Aug 02, 2022 at 11:42:52AM +0800, Muchun Song wrote: > > On Mon, Aug 01, 2022 at 05:26:23PM +0800, Feng Tang wrote: > > > On Mon, Aug 01, 2022 at 05:06:14PM +0800, Michal Hocko wrote: > > > > On Mon 01-08-22 16:42:07, Muchun Song wrote: > > > > > policy_nodemask() is supposed to be returned a nodemask representing a mempolicy > > > > > for filtering nodes for page allocation, which is a hard restriction (see the user > > > > > of allowed_mems_nr() in hugetlb.c). However, MPOL_PREFERRED_MANY is a preferred > > > > > mode not a hard restriction. Now it breaks the user of HugeTLB. Remove it from > > > > > policy_nodemask() to fix it, which will not affect current users of policy_nodemask() > > > > > since all of the users already have handled the case of MPOL_PREFERRED_MANY before > > > > > calling it. BTW, it is found by code inspection. > > > > > > > > I am not sure this is the right fix. It is quite true that > > > > policy_nodemask is a tricky function to use. It pretends to have a > > > > higher level logic but all existing users are expected to be policy > > > > aware and they special case allocation for each policy. That would mean > > > > that hugetlb should do the same. > > > > > > Yes, when I worked on the MPOL_PREFERRED_MANY patches, I was also > > > confused about policy_nodemask(), as it is never a 'strict' one as > > > the old code is: > > > > > > if (unlikely(mode == MPOL_BIND) && > > > apply_policy_zone(policy, gfp_zone(gfp)) && > > > cpuset_nodemask_valid_mems_allowed(&policy->nodes)) > > > return &policy->nodes; > > > > > > return NULL > > > > > > Even when the MPOL_BIND's nodes is not allowed by cpuset, it will > > > still return NULL (equals all nodes). > > > > > > > Well, I agree policy_nodemask() is really confusing because of the > > shortage of comments and the weird logic. > > > > > From the semantics of allowed_mems_nr(), I think it does get changed > > > a little by b27abaccf8e8. And to enforce the 'strict' semantic for > > > 'allowed', we may need a more strict nodemask API for it. > > > > > > > Maybe this is a good idea to fix this, e.g. introducing a new helper > > to return the strict allowed nodemask. > > Yep. > > I had another thought to add one global all-zero nodemask, for API like > policy_nodemask(), it has 2 types of return value: > * a nodemask with some bits set > * NULL (means all nodes) > > Here a new type of zero nodemask (a gloabl variable)can be created to > indicate no qualified node. > I know why you want to introduce a gloable zero nidemask. Since we already have a glable nodemask array, namely node_states, instead of returning NULL for the case of all nodes, how about returing node_states[N_ONLINE] for it? And make it return NULL for the case where no nodes are allowed. Any thought? > > > > I haven't checked the actual behavior implications for hugetlb here. Is > > > > MPOL_PREFERRED_MANY even supported for hugetlb? Does this change make it > > > > work? From a quick look this just ignores MPOL_PREFERRED_MANY > > > > completely. > > > > > > IIRC, the hugetlb will hornor MPOL_PREFERRED_MANY. And I can double > > > check and report back if otherwise. > > > > > > > > Fixes: b27abaccf8e8 ("mm/mempolicy: add MPOL_PREFERRED_MANY for multiple preferred nodes") > > > > > Signed-off-by: Muchun Song > > > > > --- > > > > > mm/mempolicy.c | 3 --- > > > > > 1 file changed, 3 deletions(-) > > > > > > > > > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > > > > > index 6c27acb6cd63..4deec7e598c6 100644 > > > > > --- a/mm/mempolicy.c > > > > > +++ b/mm/mempolicy.c > > > > > @@ -1845,9 +1845,6 @@ nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy) > > > > > cpuset_nodemask_valid_mems_allowed(&policy->nodes)) > > > > > return &policy->nodes; > > > > > > > > > > - if (mode == MPOL_PREFERRED_MANY) > > > > > - return &policy->nodes; > > > > > > I think it will make MPOL_PREFERRED_MANY not usable. > > > > > > > Sorry, I didn't got what you mean here. Could you explain more details > > about why it is not usable? > > I thought alloc_pages() will rely on policy_nodemask(), which was wrong > as I forgot the MPOL_PREFERRED_MANY has a dedicated function > alloc_pages_preferred_many() to handle it. Sorry for the confusion. > > Thanks, > Feng > > > Thanks. > > > > > Thanks, > > > Feng > > > > > > > > - > > > > > return NULL; > > > > > } > > > > > > > > > > -- > > > > > 2.11.0 > > > > > > > > -- > > > > Michal Hocko > > > > SUSE Labs > > > > > >