From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id EE4058E0002 for ; Thu, 17 Jan 2019 15:10:01 -0500 (EST) Received: by mail-qk1-f200.google.com with SMTP id 80so9634570qkd.0 for ; Thu, 17 Jan 2019 12:10:01 -0800 (PST) Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id c83si750qke.5.2019.01.17.12.10.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Jan 2019 12:10:00 -0800 (PST) Subject: Re: [PATCH] hugetlb: allow to free gigantic pages regardless of the configuration References: <20190117183953.5990-1-aghiti@upmem.com> From: Mike Kravetz Message-ID: <5e02e9c1-efd5-fc1e-c658-5a11f6291bcd@oracle.com> Date: Thu, 17 Jan 2019 12:09:11 -0800 MIME-Version: 1.0 In-Reply-To: <20190117183953.5990-1-aghiti@upmem.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Alexandre Ghiti , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Martin Schwidefsky , Heiko Carstens , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, Alexander Viro , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: linux-riscv@lists.infradead.org, hch@infradead.org, Alexandre Ghiti On 1/17/19 10:39 AM, Alexandre Ghiti wrote: > From: Alexandre Ghiti > > On systems without CMA or (MEMORY_ISOLATION && COMPACTION) activated but > that support gigantic pages, boottime reserved gigantic pages can not be > freed at all. This patchs simply enables the possibility to hand back > those pages to memory allocator. > > This commit then renames gigantic_page_supported and > ARCH_HAS_GIGANTIC_PAGE to make them more accurate. Indeed, those values > being false does not mean that the system cannot use gigantic pages: it > just means that runtime allocation of gigantic pages is not supported, > one can still allocate boottime gigantic pages if the architecture supports > it. > > Signed-off-by: Alexandre Ghiti Thank you for doing this! Reviewed-by: Mike Kravetz > --- a/include/linux/gfp.h > +++ b/include/linux/gfp.h > @@ -589,8 +589,8 @@ static inline bool pm_suspended_storage(void) > /* The below functions must be run on a range from a single zone. */ > extern int alloc_contig_range(unsigned long start, unsigned long end, > unsigned migratetype, gfp_t gfp_mask); > -extern void free_contig_range(unsigned long pfn, unsigned nr_pages); > #endif > +extern void free_contig_range(unsigned long pfn, unsigned int nr_pages); I think nr_pages should be an unsigned long in cma_release() and here as well, but that is beyond the scope of this patch. Most callers of cma_release pass in a truncated unsigned long. The truncation is unlikely to cause any issues, just would be nice if types were consistent. I have a patch to do that as part of a contiguous allocation series that I will get back to someday. > @@ -2350,9 +2355,10 @@ static unsigned long set_max_huge_pages(struct hstate *h, unsigned long count, > break; > } > out: > - ret = persistent_huge_pages(h); > + h->max_huge_pages = persistent_huge_pages(h); > spin_unlock(&hugetlb_lock); > - return ret; > + > + return 0; > } > > #define HSTATE_ATTR_RO(_name) \ > @@ -2404,11 +2410,6 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy, > int err; > NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY); > > - if (hstate_is_gigantic(h) && !gigantic_page_supported()) { > - err = -EINVAL; > - goto out; > - } > - > if (nid == NUMA_NO_NODE) { > /* > * global hstate attribute > @@ -2428,7 +2429,9 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy, > } else > nodes_allowed = &node_states[N_MEMORY]; > > - h->max_huge_pages = set_max_huge_pages(h, count, nodes_allowed); > + err = set_max_huge_pages(h, count, nodes_allowed); > + if (err) > + goto out; > > if (nodes_allowed != &node_states[N_MEMORY]) > NODEMASK_FREE(nodes_allowed); Yeah! Those changes causes max_huge_pages to be modified while holding hugetlb_lock as it should be. -- Mike Kravetz