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=-4.0 required=3.0 tests=MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 A06BAC43331 for ; Thu, 2 Apr 2020 17:24:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5A95820757 for ; Thu, 2 Apr 2020 17:24:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A95820757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 100198E000A; Thu, 2 Apr 2020 13:24:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AF208E0007; Thu, 2 Apr 2020 13:24:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB9288E000A; Thu, 2 Apr 2020 13:24:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id D49868E0007 for ; Thu, 2 Apr 2020 13:24:07 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 88C48612C for ; Thu, 2 Apr 2020 17:24:07 +0000 (UTC) X-FDA: 76663588134.12.light34_23f8012cce10f X-HE-Tag: light34_23f8012cce10f X-Filterd-Recvd-Size: 7956 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 2 Apr 2020 17:24:07 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id c7so5184386wrx.5 for ; Thu, 02 Apr 2020 10:24:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=gaMt57vPOGEf104iF+Okoz30/leVUnWlYWQaZv9joEs=; b=amb01Ilvf1pCEVaFjPHNwE/OeXpHGFRdiPQ9RSS/YjvyqMQhHEyKTwBwa8yd/2nXnr tWg7nSlstn5cuG6ZZsQpvCmD3rLm6+aoKFvy+ehNalgV5xQThE6LTmNUAZ2JTkWUesO3 3fN2gK89MKsoWwVk/ycdbUqjK3xolwm9YMH/xHJqNU0S2w6qUNeqD1aJrgzN7TlNI8gP /+KJQPLfjxBYamyiYl2/lgyB8tRdv63W4Q25VbhSE3gXAsCUH5xn/0GR1mZ2eobtGF3g 4DfT92+Bevw+emVp0MsAQREuGpHWbOuQ8eI3knd2jJpXr7HLDVRK5XRlcMHnANpLF9Fs EVJA== X-Gm-Message-State: AGi0PuZG8SKFuP22/TDGeeXYMlDXuxJWRb/Z99M+izPywM1cr2jhExwg 0MWhbofNi7RgeBzLFC1/x2w= X-Google-Smtp-Source: APiQypJS5BBtet99zjncxG5VPVNNr9mscplYuCzxjsRdatXKvNHcZ1fWM/moVUdNiy2BoQkZZNFs0g== X-Received: by 2002:a5d:4e03:: with SMTP id p3mr4440369wrt.408.1585848246012; Thu, 02 Apr 2020 10:24:06 -0700 (PDT) Received: from localhost (ip-37-188-180-223.eurotel.cz. [37.188.180.223]) by smtp.gmail.com with ESMTPSA id 195sm8083093wmb.8.2020.04.02.10.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 10:24:05 -0700 (PDT) Date: Thu, 2 Apr 2020 19:24:04 +0200 From: Michal Hocko To: Vlastimil Babka Cc: Roman Gushchin , Aslan Bakirov , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com, riel@surriel.com, hannes@cmpxchg.org Subject: Re: [PATCH 2/2] mm: hugetlb: Use node interface of cma Message-ID: <20200402172404.GV22681@dhcp22.suse.cz> References: <20200326212718.3798742-1-aslan@fb.com> <20200326212718.3798742-2-aslan@fb.com> <20200327080610.GV27965@dhcp22.suse.cz> <20200327144155.GA194089@carbon.DHCP.thefacebook.com> <20200327151339.GF10449@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu 02-04-20 17:20:01, Vlastimil Babka wrote: [...] > FWIW, for review purposes, this is Roman's patch with all followups from > mmotm/next (hopefully didn't miss any) and then squashed with patch 2/2 from > this thread. It can be applied like this: > > - checkout v5.6 > - apply patch 1/2 from this thread > - apply below Thanks! > ----8<---- > >From dc10a593f2b8dfc7be920b4b088a8d55068fc6bc Mon Sep 17 00:00:00 2001 > From: Roman Gushchin > Date: Thu, 2 Apr 2020 13:49:04 +1100 > Subject: [PATCH] mm: hugetlb: optionally allocate gigantic hugepages using cma > > Commit 944d9fec8d7a ("hugetlb: add support for gigantic page allocation at > runtime") has added the run-time allocation of gigantic pages. However it > actually works only at early stages of the system loading, when the > majority of memory is free. After some time the memory gets fragmented by > non-movable pages, so the chances to find a contiguous 1 GB block are > getting close to zero. Even dropping caches manually doesn't help a lot. > > At large scale rebooting servers in order to allocate gigantic hugepages > is quite expensive and complex. At the same time keeping some constant > percentage of memory in reserved hugepages even if the workload isn't > using it is a big waste: not all workloads can benefit from using 1 GB > pages. > > The following solution can solve the problem: > 1) On boot time a dedicated cma area* is reserved. The size is passed > as a kernel argument. > 2) Run-time allocations of gigantic hugepages are performed using the > cma allocator and the dedicated cma area > > In this case gigantic hugepages can be allocated successfully with a high > probability, however the memory isn't completely wasted if nobody is using > 1GB hugepages: it can be used for pagecache, anon memory, THPs, etc. > > * On a multi-node machine a per-node cma area is allocated on each node. > Following gigantic hugetlb allocation are using the first available > numa node if the mask isn't specified by a user. > > Usage: > 1) configure the kernel to allocate a cma area for hugetlb allocations: > pass hugetlb_cma=10G as a kernel argument > > 2) allocate hugetlb pages as usual, e.g. > echo 10 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages > > If the option isn't enabled or the allocation of the cma area failed, > the current behavior of the system is preserved. > > x86 and arm-64 are covered by this patch, other architectures can be > trivially added later. > > Link: http://lkml.kernel.org/r/20200311220920.2487528-1-guro@fb.com > Signed-off-by: Roman Gushchin > Tested-by: Andreas Schaufler > Cc: Michal Hocko > Cc: Rik van Riel > Cc: Andreas Schaufler > Cc: Mike Kravetz > Cc: Joonsoo Kim > Signed-off-by: Andrew Morton > Signed-off-by: Stephen Rothwell > > mm: hugetlb: Use node interface of cma > > With introduction of numa node interface for CMA, this patch is for using that > interface for allocating memory on numa nodes if NUMA is configured. > This will be more efficient and cleaner because first, instead of iterating > mem range of each numa node, cma_declare_contigueous_nid() will do > its own address finding if we pass 0 for both min_pfn and max_pfn, > second, it can also handle caseswhere NUMA is not configured > by passing NUMA_NO_NODE as an argument. > > In addition, checking if desired size of memory is available or not, > is happening in cma_declare_contiguous_nid() because base and > limit will be determined there, since 0(any) for base and > 0(any) for limit is passed as argument to the function. > > Signed-off-by: Aslan Bakirov > Acked-by: Roman Gushchin Minor nit below. For the squashed version feel free to add Acked-by: Michal Hocko > --- > .../admin-guide/kernel-parameters.txt | 7 ++ > arch/arm64/mm/init.c | 6 ++ > arch/x86/kernel/setup.c | 4 + > include/linux/hugetlb.h | 8 ++ > mm/hugetlb.c | 98 +++++++++++++++++++ > 5 files changed, 123 insertions(+) > [...] > + reserved = 0; > + for_each_node_state(nid, N_ONLINE) { > + int res; > + > + size = min(per_node, hugetlb_cma_size - reserved); > + size = round_up(size, PAGE_SIZE << order); > + > + > +#ifndef CONFIG_NUMA > + nid = NUMA_NO_NODE > +#endif This can be dropped. UMA will simply use node 0 and the memblock allocator will just do the right thing. > + res = cma_declare_contiguous_nid(0, size, > + 0, > + PAGE_SIZE << order, > + 0, false, > + "hugetlb", &hugetlb_cma[nid], nid); > + > + if (res) { > + pr_warn("%s: reservation failed: err %d, node %d\n", > + __func__, res, nid); > + break; > + } > + > + reserved += size; > + pr_info("hugetlb_cma: reserved %lu MiB on node %d\n", > + size / SZ_1M, nid); > + > + if (reserved >= hugetlb_cma_size) > + break; > + } > +} > + > +#endif /* CONFIG_CMA */ > -- > 2.26.0 -- Michal Hocko SUSE Labs