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 D1D45C00144 for ; Tue, 2 Aug 2022 03:43:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 541686B0071; Mon, 1 Aug 2022 23:43:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CA146B0072; Mon, 1 Aug 2022 23:43:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 343288E0001; Mon, 1 Aug 2022 23:43:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1F3A06B0071 for ; Mon, 1 Aug 2022 23:43:00 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F34671A0CE7 for ; Tue, 2 Aug 2022 03:42:59 +0000 (UTC) X-FDA: 79753256478.18.F976B23 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf15.hostedemail.com (Postfix) with ESMTP id B6CC9A0046 for ; Tue, 2 Aug 2022 03:42:58 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id t2-20020a17090a4e4200b001f21572f3a4so14101105pjl.0 for ; Mon, 01 Aug 2022 20:42:58 -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=KJxuIb+FvWHlHrYgvDT8WOgL3C6VVylvpOvbAr0onVs=; b=5dhI05Ua0LfWPG4hwhI0FJOGPXb3H6lRbM8R3NXqkI1kYApGSZLULohK0IjJArtt8e LUFO7egf+mCm5nKEDxQ25yHmwwj/Zw6lriuWgF05/4a4AF3esBdhLkt9zm53wJ26rD7P RBVP8h4ubR9TL3qrWeyAHPHYVAsmd7M2wcwVPEVZHlQexefQBL4+MBLjry1LJVaY7wff fbOGCSRLwRlYUFpu3z6dzlThHZEPn4Nf3WcW8Mj3FJCKbdhx8qNUbX/N4h4oeReligS/ eBf75Qc5Qgr0+jQ0px+pZ3e9vVp/PMsNG60wI8SMQqAQAAEYfnn4JssW6Xb6ur895sKu heGA== 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=KJxuIb+FvWHlHrYgvDT8WOgL3C6VVylvpOvbAr0onVs=; b=RGCneHEQ/IGzGCr3pNicDKbuG96IQ4sMELCMTtj9xh4ueEcb7puSVol9pvbYAqNAa2 iy/ccEYADQfVFgx5cfvkAkAjL9wJ3UDQlVzVSiuovKopPaPFYr2o1jjP4cYYfYtm7uYk dHvJNWfxYxbnEHoGODF2s1yQs01pmikM8M3hIb1b0su7/ioN4TMXvz+a+8AE3TP8bn6l QQQrn7cmgzxLuAA5f5XZyQzSRyXaITOgeRXcr9tASqCvj+PooW9X/C4IUE3WDIQ/bvY/ caKd63Z1smzywbPuZe73StoUMcDm9o1KO5o/isrUaU8Djy/yATxPHBmL3m5RHKmza3L+ jvTw== X-Gm-Message-State: ACgBeo0jBDlsqnkb2J4TDYKOrbfhYWpueaR7myyIM+SwMSngeQ1QEJl2 tnI/dPHoGh4W7Hj5BFndqZnxk5gxAca5GzSB X-Google-Smtp-Source: AA6agR4H+BzoFmhRfPdcu5yxoYuwlVlavAWMsxSDrvOQFvQpX7wNxhlU7dRAGin/2LZz+iGVNeSP+Q== X-Received: by 2002:a17:902:aa98:b0:16c:d74d:fe6c with SMTP id d24-20020a170902aa9800b0016cd74dfe6cmr20044603plr.134.1659411777534; Mon, 01 Aug 2022 20:42:57 -0700 (PDT) Received: from localhost ([139.177.225.233]) by smtp.gmail.com with ESMTPSA id e5-20020a170902784500b0016d3d907146sm5638827pln.191.2022.08.01.20.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 20:42:56 -0700 (PDT) Date: Tue, 2 Aug 2022 11:42:52 +0800 From: Muchun Song To: Feng Tang Cc: Michal Hocko , "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-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5dhI05Ua; spf=pass (imf15.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659411779; a=rsa-sha256; cv=none; b=S8oaZ6LxfnFJ4h+bT/+5oxDt5sJprtbbRco8io+jVrSX6NJXQtJMv/itKHeaIWJ13hiZel 3ecHjE2K7rhuNtj29qm/xgc5Om//clF1Ejkj5V59TrXGNrX56DtMfiHdh5AouPnSQ9SKPT F8L9Cd9KfDsOMVpSZ3q20mcaKf5XrRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659411779; 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=KJxuIb+FvWHlHrYgvDT8WOgL3C6VVylvpOvbAr0onVs=; b=lcgLdWUDt0Q/c17Uj0nrn36X3DgRlDIXgL5b8o2ow7ZPhEuSOFwukgKetGHwUvcqpI+jgt 0LJ4P1jg3zyps6DXmJXXHzu0ysW10fVBhWacBxN9d62EIkLit6iZGwpsNvb4uWzQkCsIQT sZLEGNQaZX83YMsnIE17HyrXWrlg2bA= X-Stat-Signature: m9n79anhsj7mffac6i71ip7x6pnabpqx X-Rspamd-Queue-Id: B6CC9A0046 X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5dhI05Ua; spf=pass (imf15.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1659411778-671266 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 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. > > 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? Thanks. > Thanks, > Feng > > > > - > > > return NULL; > > > } > > > > > > -- > > > 2.11.0 > > > > -- > > Michal Hocko > > SUSE Labs >