Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp952101pxb; Thu, 28 Jan 2021 04:42:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4WtQDFRAiEXQjzxiXHKj6KHmTRBqxJi3OTXuMi3u75jArqtNEsCKM9kycfazkDDxWT7Mr X-Received: by 2002:a50:ef0a:: with SMTP id m10mr7085261eds.38.1611837771319; Thu, 28 Jan 2021 04:42:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611837771; cv=none; d=google.com; s=arc-20160816; b=ve9PiVEOefEwxLQ1JlIR+g5T24zdmShbV2ZBqCDZ/SuO0+OPVHnAl26EWxCoiNV5nf loZ4k6D4orqSHi+LQ4kQqDYu/schFJ0sZegTU9YGXQGrFenXZrDy9wssY/KyKccbT/67 kVVtJzJjbc2LQnr4wj1sxChl7U6MW+yK/nHzfdfwlcbgfjBv4jleZdTy2zIWxGMpXASY mR4XdS17mohRUtF9rBOBxR11qZlqsxVv6QEsJuMfTbUbshGAAkamEm4wQWSKEJrS817d WNdSxOpGOmJ4Ti/3MW1OjYFSwKtkxa/XlFECMGhn8ltXw3rhcMnzhhL//BPjGbK83DGT d9Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6WaOltVmRWY4A85dkkyKWm4CB5hPuoSl1c1lXUzFBBo=; b=BoTGPzZCfqVDRlDUbIGw3GrKvfqPpUrXYmkbv4ATEWqSA3ZKpaFIcGWSzdnvmtfem0 9HR6eRxfwBNWXw3jE+4I+6znXFKXAfQkcBh/RLC+LCzPoZGpVGqPYBCBTXWxeSKgJAOL 4uDAcRpXvMd5FQw5xFOyPzOLNY7yWOvujyX9SDnTKrNaZM1EZuKOZwgrDuNXastlSmm1 DFmo7Z8WRwivfjwYgtCrZGAnzP5Eb3RxXIF+31zHmn5wfBSttex/VqLB1HS2j7GdvbkG DU6sIzpPKP6UJrHBTXspMz1OAoGR9prK4LdcVyvGgB1I0kxooTbPHkevi+pFlN9LCTSb M4TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=CtMUy+LG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z21si2415563ejr.63.2021.01.28.04.42.26; Thu, 28 Jan 2021 04:42:51 -0800 (PST) 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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=CtMUy+LG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231220AbhA1MjH (ORCPT + 99 others); Thu, 28 Jan 2021 07:39:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbhA1Mi7 (ORCPT ); Thu, 28 Jan 2021 07:38:59 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E282AC061756 for ; Thu, 28 Jan 2021 04:38:18 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id 11so3908632pfu.4 for ; Thu, 28 Jan 2021 04:38:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6WaOltVmRWY4A85dkkyKWm4CB5hPuoSl1c1lXUzFBBo=; b=CtMUy+LGS6RZ6wo05NIVWOeVZapiGPFCG7S6qJhU2IbnzcVusdLgW/ZbNsskfVWrUN MQywc7znYQ5UERN4AzrEKHe2ItHXgXNU5klDm31oxeP/khbY+vUSQryPVBBIAfEDw/Vv 3gTs3OJ9VpgcBuGYgOcVbeDMqBlEe0o+q3OSkydmSSa0Tv4WpFi3eaD3wE5ZpbL0crjv gcdSagrLpFTsVhn1PVCAnGY9EaYJOiVYJDDn8QKGR432e9cmrI7pxQk3XQYVNmAj5Ajm CgzxOmE5U8+7o8LkzGpeB3UemRiwygv/eyF+McqBGgVLBIXVvJtsjPIFFsjT6R04v3tk hOaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6WaOltVmRWY4A85dkkyKWm4CB5hPuoSl1c1lXUzFBBo=; b=HkFBQHI2W2VcR/zRwjlUzK0CFyOnCV8L3Vzu1hviadPotrtCBGdDuImgZd2kSBszzv s8pnFpIy9xDAgytRx7hK45m+x5//B2W0c/uf9nNM3SC7rrvY3VhppgxxZT23bMs3bNsP gHb+yu6VoBYwy5k+p0ZJeomvRYNSE2Hs8K1OAf+DF1lf4Xa4FwKrcWRSXhBWnu+gHc7B 6oearfXh4JJ260sVH4ofujYWblRGWkV+QCIMiNMok+dkJHWMys3bg/HtVBCH67fkcJHA UPe7wjZW4EUZcfeGk0CNNleVvtJaruD3viVOvL+CezsQBlmPBRewOLLz87WhecI1c/wb Xe3Q== X-Gm-Message-State: AOAM532NXpTb0BAncL7wp9niYxDqZe2WzRNbInX91EBk/b16JZqCiG2Z LvyZzQF+BXYaGG20J8Pc8judQZBTThmKGVLDk8txRQ== X-Received: by 2002:a63:1f21:: with SMTP id f33mr16523781pgf.31.1611837498467; Thu, 28 Jan 2021 04:38:18 -0800 (PST) MIME-Version: 1.0 References: <20210117151053.24600-1-songmuchun@bytedance.com> <20210117151053.24600-6-songmuchun@bytedance.com> <20210126092942.GA10602@linux> <6fe52a7e-ebd8-f5ce-1fcd-5ed6896d3797@redhat.com> <20210126145819.GB16870@linux> <259b9669-0515-01a2-d714-617011f87194@redhat.com> <20210126153448.GA17455@linux> <9475b139-1b33-76c7-ef5c-d43d2ea1dba5@redhat.com> In-Reply-To: From: Muchun Song Date: Thu, 28 Jan 2021 20:37:41 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v13 05/12] mm: hugetlb: allocate the vmemmap pages associated with each HugeTLB page To: David Hildenbrand , Oscar Salvador , Mike Kravetz Cc: Jonathan Corbet , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , Matthew Wilcox , Michal Hocko , "Song Bao Hua (Barry Song)" , =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 6:36 PM David Hildenbrand wrote: > > On 26.01.21 16:56, David Hildenbrand wrote: > > On 26.01.21 16:34, Oscar Salvador wrote: > >> On Tue, Jan 26, 2021 at 04:10:53PM +0100, David Hildenbrand wrote: > >>> The real issue seems to be discarding the vmemmap on any memory that has > >>> movability constraints - CMA and ZONE_MOVABLE; otherwise, as discussed, we > >>> can reuse parts of the thingy we're freeing for the vmemmap. Not that it > >>> would be ideal: that once-a-huge-page thing will never ever be a huge page > >>> again - but if it helps with OOM in corner cases, sure. > >> > >> Yes, that is one way, but I am not sure how hard would it be to implement. > >> Plus the fact that as you pointed out, once that memory is used for vmemmap > >> array, we cannot use it again. > >> Actually, we would fragment the memory eventually? > >> > >>> Possible simplification: don't perform the optimization for now with free > >>> huge pages residing on ZONE_MOVABLE or CMA. Certainly not perfect: what > >>> happens when migrating a huge page from ZONE_NORMAL to (ZONE_MOVABLE|CMA)? > >> > >> But if we do not allow theose pages to be in ZONE_MOVABLE or CMA, there is no > >> point in migrate them, right? > > > > Well, memory unplug "could" still work and migrate them and > > alloc_contig_range() "could in the future" still want to migrate them > > (virtio-mem, gigantic pages, powernv memtrace). Especially, the latter > > two don't work with ZONE_MOVABLE/CMA. But, I mean, it would be fair > > enough to say "there are no guarantees for > > alloc_contig_range()/offline_pages() with ZONE_NORMAL, so we can break > > these use cases when a magic switch is flipped and make these pages > > non-migratable anymore". > > > > I assume compaction doesn't care about huge pages either way, not sure > > about numa balancing etc. > > > > > > However, note that there is a fundamental issue with any approach that > > allocates a significant amount of unmovable memory for user-space > > purposes (excluding CMA allocations for unmovable stuff, CMA is > > special): pairing it with ZONE_MOVABLE becomes very tricky as your user > > space might just end up eating all kernel memory, although the system > > still looks like there is plenty of free memory residing in > > ZONE_MOVABLE. I mentioned that in the context of secretmem in a reduced > > form as well. > > > > We theoretically have that issue with dynamic allocation of gigantic > > pages, but it's something a user explicitly/rarely triggers and it can > > be documented to cause problems well enough. We'll have the same issue > > with GUP+ZONE_MOVABLE that Pavel is fixing right now - but GUP is > > already known to be broken in various ways and that it has to be treated > > in a special way. I'd like to limit the nasty corner cases. > > > > Of course, we could have smart rules like "don't online memory to > > ZONE_MOVABLE automatically when the magic switch is active". That's just > > ugly, but could work. > > > > Extending on that, I just discovered that only x86-64, ppc64, and arm64 > really support hugepage migration. > > Maybe one approach with the "magic switch" really would be to disable > hugepage migration completely in hugepage_migration_supported(), and > consequently making hugepage_movable_supported() always return false. > > Huge pages would never get placed onto ZONE_MOVABLE/CMA and cannot be > migrated. The problem I describe would apply (careful with using > ZONE_MOVABLE), but well, it can at least be documented. Thanks for your explanation. All thinking seems to be introduced by encountering OOM. :-( In order to move forward and free the hugepage. We should add some restrictions below. 1. Only free the hugepage which is allocated from the ZONE_NORMAL. 2. Disable hugepage migration when this feature is enabled. 3. Using GFP_ATOMIC to allocate vmemmap pages firstly (it can reduce memory fragmentation), if it fails, we use part of the hugepage to remap. Hi Oscar, Mike and David H What's your opinion about this? Should we take this approach? Thanks. > > -- > Thanks, > > David / dhildenb >