From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 DEB1EC433E0 for ; Thu, 28 Jan 2021 12:38:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 23FD464DCE for ; Thu, 28 Jan 2021 12:38:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23FD464DCE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 32C006B0005; Thu, 28 Jan 2021 07:38:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B4716B0006; Thu, 28 Jan 2021 07:38:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17DB16B006C; Thu, 28 Jan 2021 07:38:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F06D56B0005 for ; Thu, 28 Jan 2021 07:38:23 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id ACDA48249980 for ; Thu, 28 Jan 2021 12:38:23 +0000 (UTC) X-FDA: 77755136886.22.hand09_4702cb42759f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 8062F18038E6B for ; Thu, 28 Jan 2021 12:38:23 +0000 (UTC) X-HE-Tag: hand09_4702cb42759f X-Filterd-Recvd-Size: 8256 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 Jan 2021 12:38:22 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id f63so3889314pfa.13 for ; Thu, 28 Jan 2021 04:38:19 -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=rv3Z+2W8zWGnUq5IIol2WfBkFX4YawmKcJQN0vERwmdSOWCi9VsNWK5Wsu2DqpS72u hnOunspHaXKitLU2Cw2Lp3xYa3RC9sfVk8wqiZunwa6VsSBjmjWXSaXO37LeA98cezQZ vg0l6xvTp64RCMY3jS/s6WC9qDHzN88DLZP1kVekO9BP10jGbVeYsE3rXVqRj2Y3vWD8 6bGOF6vODjfYcUoXloS2SuK+n4vzAeADZd+BH5e3fGME+U2BlnLtggbEvQNKOVg/7m0P 7EcaeXtCA2ZJMwXLewRG6xhMfxR7ZkVn5+QQqgva480auv1Q+CLPytZ+q/UrluGht0E/ LlWg== X-Gm-Message-State: AOAM533MKYQS1k02V0JJqzIc5wHzxc/Jy3EX/wCsg5wEJlREJ4TwbSAw 3GPBPI2+aiwG/XXLK9icsUno9lCOhHPQbbZeN6FMgQ== X-Google-Smtp-Source: ABdhPJyw1u0Xr3B5Tu98ZrHbYMZERXsgmC0lR2sLTrtGK6j+NRKrFU5g/BHrH5XrtlG5N0b0Kqx1Q95yjO3O+N/Ejxk= 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" 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 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 >