Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp701965pxt; Fri, 6 Aug 2021 11:33:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv/XqFfqi9Z7Y0uvtTn/Mqsk7NYI+ZyePoU1ycoS+yzVtGXxIVX45PO3nVtFE89VbUfHXK X-Received: by 2002:a05:6e02:d0c:: with SMTP id g12mr157181ilj.230.1628274793239; Fri, 06 Aug 2021 11:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628274793; cv=none; d=google.com; s=arc-20160816; b=mMfF+k3RJJyflLN+uP3QY8HUSQ+21OEbG9ENcFcDGD7P+sUmKXDVEFfDbkEDEIdHcr CybINadVSmGUoIjI6YkSl02toMrVeVKfpCcyNwgIMhxHJzq4hvhVknBQJZC9L2A5Zla0 R1ln2euUnKKXseOWu9UuHw2bfilU8mTz4LIDM0YIl1jFT7rkiHip9bAp/CxrP0KpnkWF ND4mowaVJ2XgYErvjZUQ8t3xtJl+39WXQ0kZrkQPQFbn4sfVCdUBd3rGgrAGJdMZpMby uSOLCE6zKLzn4pU6zR45JUexjtmcAFwEqJZee5uKf81gWvMTWTrbC4NWc+umXNPz6s/M Jksw== 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=yE3Uk/UgQFDJwZHbh1+RL0Led8QeXNn8UlO09LuvY6U=; b=oHfknDFY0RS8NKYPa0rAcLvQJDhmtO6lJ0CONyWUyhzBZsfhwpez3tcN8r9TTPbtls beZd2kN0smQAQA3eI1xGKHudz9rJ0QW7/VxtEUgZLq6BB1xvUlXPRuNUjsHPMsiAHUlW gQ2HMQ2gQdTV3bi58FkL7xmqvmk2PF9+V/AF+P3LQd/XgrAyPG/Lk448hlDICvGlFbA/ VV1R7mB0MyZvU9qrYZIbpG2cKzNPAoLO3pdvTYbABgSzEhbO/KKMHn4ew5srqXX5HVK/ wO3YAaKwiEsMKVqKaW9laB7dIJtB8J4hFvkIAuZrQeZSzHgSy3Ptx3qM4r7I/ntsmSmq ut3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fiYr6g9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si10530367ilu.13.2021.08.06.11.33.01; Fri, 06 Aug 2021 11:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fiYr6g9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344064AbhHFNgK (ORCPT + 99 others); Fri, 6 Aug 2021 09:36:10 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:51718 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233838AbhHFNgI (ORCPT ); Fri, 6 Aug 2021 09:36:08 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 1290A21F91; Fri, 6 Aug 2021 13:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1628256952; 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=yE3Uk/UgQFDJwZHbh1+RL0Led8QeXNn8UlO09LuvY6U=; b=fiYr6g9t/DoJEyJF5CFB7zTZUyIAEfgvQ/bWOoomvQ4cGuOm9BM6a2tDqReI/4GvbSMXuZ hXyEDfPhJC34DRxbHFUjvKgZaGd/Qk9KAGxh6nbL2qjiWAsY6XnWHy2GyolEy2kSm8Ydtg 6yYynAI7nKqmXwjrE37BErnSRIGMhnc= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D35C5A3B8A; Fri, 6 Aug 2021 13:35:51 +0000 (UTC) Date: Fri, 6 Aug 2021 15:35:48 +0200 From: Michal Hocko To: Feng Tang Cc: linux-mm@kvack.org, Andrew Morton , David Rientjes , Dave Hansen , Ben Widawsky , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Andrea Arcangeli , Mel Gorman , Mike Kravetz , Randy Dunlap , Vlastimil Babka , Andi Kleen , Dan Williams , ying.huang@intel.com Subject: Re: [PATCH v7 3/5] mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY Message-ID: References: <1627970362-61305-1-git-send-email-feng.tang@intel.com> <1627970362-61305-4-git-send-email-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1627970362-61305-4-git-send-email-feng.tang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 03-08-21 13:59:20, Feng Tang wrote: > From: Ben Widawsky > > Implement the missing huge page allocation functionality while obeying > the preferred node semantics. This is similar to the implementation > for general page allocation, as it uses a fallback mechanism to try > multiple preferred nodes first, and then all other nodes. > > [akpm: fix compling issue when merging with other hugetlb patch] > [Thanks to 0day bot for catching the missing #ifdef CONFIG_NUMA issue] > Link: https://lore.kernel.org/r/20200630212517.308045-12-ben.widawsky@intel.com > Suggested-by: Michal Hocko > Signed-off-by: Ben Widawsky > Co-developed-by: Feng Tang > Signed-off-by: Feng Tang ifdefery is just ugly as hell. One way to get rid of that would be to provide a mpol_is_preferred_many() wrapper and hide the CONFIG_NUMA in mempolicy.h. I haven't checked but this might help to remove some other ifdefery as well. I especially dislike the label hidden in the ifdef. You can get rid of that by checking the page for NULL. > --- > mm/hugetlb.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 95714fb28150..9279f6d478d9 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1166,7 +1166,20 @@ static struct page *dequeue_huge_page_vma(struct hstate *h, > > gfp_mask = htlb_alloc_mask(h); > nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask); > +#ifdef CONFIG_NUMA > + if (mpol->mode == MPOL_PREFERRED_MANY) { > + page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask); > + if (page) > + goto check_reserve; > + /* Fallback to all nodes */ > + nodemask = NULL; > + } > +#endif > page = dequeue_huge_page_nodemask(h, gfp_mask, nid, nodemask); > + > +#ifdef CONFIG_NUMA > +check_reserve: > +#endif > if (page && !avoid_reserve && vma_has_reserves(vma, chg)) { > SetHPageRestoreReserve(page); > h->resv_huge_pages--; > @@ -2147,6 +2160,21 @@ struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h, > nodemask_t *nodemask; > > nid = huge_node(vma, addr, gfp_mask, &mpol, &nodemask); > +#ifdef CONFIG_NUMA > + if (mpol->mode == MPOL_PREFERRED_MANY) { > + gfp_t gfp = gfp_mask | __GFP_NOWARN; > + > + gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); > + page = alloc_surplus_huge_page(h, gfp, nid, nodemask, false); > + if (page) { > + mpol_cond_put(mpol); > + return page; > + } > + > + /* Fallback to all nodes */ > + nodemask = NULL; > + } > +#endif > page = alloc_surplus_huge_page(h, gfp_mask, nid, nodemask, false); > mpol_cond_put(mpol); > > -- > 2.14.1 -- Michal Hocko SUSE Labs