Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp300247imn; Wed, 3 Aug 2022 04:30:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR7WgBNvO8+FSDR1iKQ5qBzyEIn4LxAn0X88FVkFH5BgUHma+GaTqIDcKTATDcGhoB6DSFVN X-Received: by 2002:a05:6402:50c9:b0:43e:42b0:f84a with SMTP id h9-20020a05640250c900b0043e42b0f84amr2397631edb.72.1659526245819; Wed, 03 Aug 2022 04:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659526245; cv=none; d=google.com; s=arc-20160816; b=IBP0AgWBWqVnF+c/XVwmuObnbDKcfc6HwAg6ILLTHsLuV6ulHwfaMx/zbsYwmcHiBf l4k7N8KgPx3sr4r3svNMJcSkzVMO2l9NNWCXKVSOLp893l1hrXqG5d6Cpkq71ez/ldER 1cEtFJwcCO4MppbOAdYnJ+dMDcBOgA+k0/zTBrnqBf+4u4tcOvvuGwBc1+nuq5W7DBrC ZYln7rKEt0psgNixEh13gB1HuFcIBaf0e43+9jik08AX6hOup74hgFnnU3Ky5NbcqjI3 FtG2nSh3A76ZEXRiwgPwmfzloSnTVZlcay9zUgKH13PeeyGzGApc7OtAE+s730YLef6g M9CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8dYSp9FkxWYhq7shbNgnFFdDe+YIHT7/x9Ijr1mix0I=; b=dVyia519c8k5umg97I9AJf2Sv8iVKWsUVlS5NSNti7czJecvDeS6xlTR3J2dg9A7P3 rwrYS62vmFzX8FrKlIaTxIeIezxGJcohbCL/ZVcPfwz0W9RJQ/AcUvWvhWL43eQPMQMC cJuFomATPRM5fMscm8beEZSmf2vCm8OuoninKzPNnUhPXdEiOu8DVZKH08WJSD7D8OyP faVRuuOrNl7wzNGXS/uZPWadN/ese97zR3ZG95erCB2hY8in3xyd+N89neQxvw63a0lw gTNbuWZuxNL0ebSnNPRLjAkVebQif79mt2GPzjb5+sj/TISAlfQ/5tzd6kT8kLqhCWPY MIDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fcYHHTuq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv9-20020a17090760c900b007307c26f6ddsi8535316ejc.995.2022.08.03.04.30.18; Wed, 03 Aug 2022 04:30:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fcYHHTuq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235645AbiHCL3E (ORCPT + 99 others); Wed, 3 Aug 2022 07:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231781AbiHCL3D (ORCPT ); Wed, 3 Aug 2022 07:29:03 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B711427B14 for ; Wed, 3 Aug 2022 04:29:01 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5FDC533FC5; Wed, 3 Aug 2022 11:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1659526140; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8dYSp9FkxWYhq7shbNgnFFdDe+YIHT7/x9Ijr1mix0I=; b=fcYHHTuqTlfgxJZcvyxGKgTu1VnPjFXTOUt52Ni4Bw7g85QoBmSi4vKwbJPKPNXDrCdZra cplMKPt/0pFTe9HQlH6cvsO98tf3NZ6XHPh9IufME2nCHwRwCP1bfXB1qDcSNfbpwLG+fx xnnm2nF/mGmZl3fwq5oA261sUfGmXRU= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3CA2913A94; Wed, 3 Aug 2022 11:29:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RYNeDPxb6mIyQgAAMHmgww (envelope-from ); Wed, 03 Aug 2022 11:29:00 +0000 Date: Wed, 3 Aug 2022 13:28:59 +0200 From: Michal Hocko To: Feng Tang Cc: Muchun Song , "akpm@linux-foundation.org" , "bwidawsk@kernel.org" , "dave.hansen@linux.intel.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Mike Kravetz Subject: Re: [PATCH] mm: mempolicy: fix policy_nodemask() for MPOL_PREFERRED_MANY case Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 04-08-22 01:14:32, Feng Tang wrote: [...] > Ok, I change it as below: Wouldn't it be better to make this allowed_mems_nr specific to be explicit about the intention? Not that I feel strongly about that. > --- > mm/hugetlb.c | 28 +++++++++++++++++++++++----- > 1 file changed, 23 insertions(+), 5 deletions(-) Not even compile tested include/linux/mempolicy.h | 12 ------------ mm/hugetlb.c | 24 ++++++++++++++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index 668389b4b53d..e38b0ef20b8b 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -151,13 +151,6 @@ extern bool mempolicy_in_oom_domain(struct task_struct *tsk, const nodemask_t *mask); extern nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy); -static inline nodemask_t *policy_nodemask_current(gfp_t gfp) -{ - struct mempolicy *mpol = get_task_policy(current); - - return policy_nodemask(gfp, mpol); -} - extern unsigned int mempolicy_slab_node(void); extern enum zone_type policy_zone; @@ -294,11 +287,6 @@ static inline void mpol_put_task_policy(struct task_struct *task) { } -static inline nodemask_t *policy_nodemask_current(gfp_t gfp) -{ - return NULL; -} - static inline bool mpol_is_preferred_many(struct mempolicy *pol) { return false; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a18c071c294e..6cacbc9b15a1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4330,18 +4330,34 @@ static int __init default_hugepagesz_setup(char *s) } __setup("default_hugepagesz=", default_hugepagesz_setup); +struct mempolicy *policy_mbind_nodemask(gfp_t gfp) +{ +#ifdef CONFIG_MEMPOLICY + struct mempolicy *mpol = get_task_policy(current); + + /* + * only enforce MBIND which overlaps with cpuset policy (from policy_nodemask) + * specifically for hugetlb case + */ + if (mpol->mode == MPOL_BIND && + (apply_policy_zone(mpol, gfp_zone(gfp)) && + cpuset_nodemask_valid_mems_allowed(&policy->nodes)) + return &mpol->nodes; +#endif + return NULL; +} + static unsigned int allowed_mems_nr(struct hstate *h) { int node; unsigned int nr = 0; - nodemask_t *mpol_allowed; + nodemask_t *mbind_nodemask; unsigned int *array = h->free_huge_pages_node; gfp_t gfp_mask = htlb_alloc_mask(h); - mpol_allowed = policy_nodemask_current(gfp_mask); - + mbind_nodemask = policy_mbind_nodemask(gfp_mask); for_each_node_mask(node, cpuset_current_mems_allowed) { - if (!mpol_allowed || node_isset(node, *mpol_allowed)) + if (!mbind_nodemask || node_isset(node, *mbind_nodemask)) nr += array[node]; } -- Michal Hocko SUSE Labs