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 X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC4B3C47092 for ; Tue, 1 Jun 2021 11:29:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F1BD861057 for ; Tue, 1 Jun 2021 11:29:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1BD861057 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 68CF06B00BC; Tue, 1 Jun 2021 07:29:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 664366B00BE; Tue, 1 Jun 2021 07:29:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52B006B00BF; Tue, 1 Jun 2021 07:29:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 1FD856B00BC for ; Tue, 1 Jun 2021 07:29:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id ADDF5B9F3 for ; Tue, 1 Jun 2021 11:29:27 +0000 (UTC) X-FDA: 78204934374.19.F367E4B Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf25.hostedemail.com (Postfix) with ESMTP id 535EB6000578 for ; Tue, 1 Jun 2021 11:29:14 +0000 (UTC) IronPort-SDR: FS6AmTB0djx4N4ztoaZu4IMLeiuijf6bawFIAeDk6XDToopQlBSgwr1zCgi4Ile6yo9I+NrRF8 Arlfd0Naz2sQ== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="224800782" X-IronPort-AV: E=Sophos;i="5.83,239,1616482800"; d="scan'208";a="224800782" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2021 04:29:25 -0700 IronPort-SDR: LCr6PBFbfXLyRnlYGo22DaUt3W583aCmAc5Xg6BimLd/avK9YTqir8+Bgx027AUorMEdwvf3CF Pth/dFGeAyiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,239,1616482800"; d="scan'208";a="479244076" Received: from shbuild999.sh.intel.com (HELO localhost) ([10.239.147.94]) by orsmga001.jf.intel.com with ESMTP; 01 Jun 2021 04:29:21 -0700 Date: Tue, 1 Jun 2021 19:29:20 +0800 From: Feng Tang To: Michal Hocko Cc: linux-mm@kvack.org, Andrew Morton , David Rientjes , Dave Hansen , Ben Widawsky , linux-kernel@vger.kernel.org, Andrea Arcangeli , Mel Gorman , Mike Kravetz , Randy Dunlap , Vlastimil Babka , Andi Kleen , Dan Williams , ying.huang@intel.com Subject: Re: [v3 PATCH 2/3] mm/mempolicy: don't handle MPOL_LOCAL like a fake MPOL_PREFERRED policy Message-ID: <20210601112920.GB80730@shbuild999.sh.intel.com> References: <1622469956-82897-1-git-send-email-feng.tang@intel.com> <1622469956-82897-3-git-send-email-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Rspamd-Queue-Id: 535EB6000578 Authentication-Results: imf25.hostedemail.com; dkim=none; spf=none (imf25.hostedemail.com: domain of feng.tang@intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=feng.tang@intel.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) X-Rspamd-Server: rspam03 X-Stat-Signature: gycg15nis6rc6iykjwak875yzcwsikne X-HE-Tag: 1622546954-389219 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, Jun 01, 2021 at 10:44:39AM +0200, Michal Hocko wrote: > On Mon 31-05-21 22:05:55, Feng Tang wrote: > > MPOL_LOCAL policy has been setup as a real policy, but it is still > > handled like a faked POL_PREFERRED policy with one internal > > MPOL_F_LOCAL flag bit set, and there are many places having to > > judge the real 'prefer' or the 'local' policy, which are quite > > confusing. > > > > In current code, there are 4 cases that MPOL_LOCAL are used: > > 1. user specifies 'local' policy > > 2. user specifies 'prefer' policy, but with empty nodemask > > 3. system 'default' policy is used > > 4. 'prefer' policy + valid 'preferred' node with MPOL_F_STATIC_NODES > > flag set, and when it is 'rebind' to a nodemask which doesn't > > contains the 'preferred' node, it will perform as 'local' policy > > > > So make 'local' a real policy instead of a fake 'prefer' one, and > > kill MPOL_F_LOCAL bit, which can greatly reduce the confusion for > > code reading. > > > > For case 4, the logic of mpol_rebind_preferred() is confusing, as > > Michal Hocko pointed out: > > > > " > > I do believe that rebinding preferred policy is just bogus and > > it should be dropped altogether on the ground that a preference > > is a mere hint from userspace where to start the allocation. > > Unless I am missing something cpusets will be always authoritative > > for the final placement. The preferred node just acts as a starting > > point and it should be really preserved when cpusets changes. > > Otherwise we have a very subtle behavior corner cases. > > " > > So dump all the tricky transformation between 'prefer' and 'local', > > and just record the new nodemask of rebinding. > > > > Suggested-by: Michal Hocko > > Signed-off-by: Feng Tang > > I like this very much! It simplifies a tricky code and also a very > dubious behavior. I would like to hear from others whether there might > be some userspace depending on this obscure behavior though. One never > knows... > > Some more notes/questions below > > [...] > > @@ -239,25 +240,19 @@ static int mpol_set_nodemask(struct mempolicy *pol, > > cpuset_current_mems_allowed, node_states[N_MEMORY]); > > > > VM_BUG_ON(!nodes); > > - if (pol->mode == MPOL_PREFERRED && nodes_empty(*nodes)) > > - nodes = NULL; /* explicit local allocation */ > > - else { > > - if (pol->flags & MPOL_F_RELATIVE_NODES) > > - mpol_relative_nodemask(&nsc->mask2, nodes, &nsc->mask1); > > - else > > - nodes_and(nsc->mask2, *nodes, nsc->mask1); > > > > - if (mpol_store_user_nodemask(pol)) > > - pol->w.user_nodemask = *nodes; > > - else > > - pol->w.cpuset_mems_allowed = > > - cpuset_current_mems_allowed; > > - } > > + if (pol->flags & MPOL_F_RELATIVE_NODES) > > + mpol_relative_nodemask(&nsc->mask2, nodes, &nsc->mask1); > > + else > > + nodes_and(nsc->mask2, *nodes, nsc->mask1); > > Maybe I've just got lost here but why don't you need to check for the > local policy anymore? mpol_new will take care of the MPOL_PREFERRED && > nodes_empty special but why do we want/need all this for a local policy > at all? You are right that 'local' policy doesn't need this, it should just return in the early port of this function, like 'default' policy, which can remove the useless nop mpol_new_local(). > > > > - if (nodes) > > - ret = mpol_ops[pol->mode].create(pol, &nsc->mask2); > > + if (mpol_store_user_nodemask(pol)) > > + pol->w.user_nodemask = *nodes; > > else > > - ret = mpol_ops[pol->mode].create(pol, NULL); > > + pol->w.cpuset_mems_allowed = > > + cpuset_current_mems_allowed; > > please use a single line. This is just harder to read. You will cross > the line limit but readability should be preferred here. Will change. Thanks, Feng > [...] > > I haven't spotted anything else. > -- > Michal Hocko > SUSE Labs