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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 80709C433E0 for ; Thu, 28 Jan 2021 13:09:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E0ADC64DD8 for ; Thu, 28 Jan 2021 13:09:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0ADC64DD8 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 6AC686B0072; Thu, 28 Jan 2021 08:09:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 635796B0073; Thu, 28 Jan 2021 08:09:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D75C6B0074; Thu, 28 Jan 2021 08:09:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 33C086B0072 for ; Thu, 28 Jan 2021 08:09:16 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E6FB0181AC9C6 for ; Thu, 28 Jan 2021 13:09:15 +0000 (UTC) X-FDA: 77755214670.16.leg34_2d0943d2759f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 62E2B100E6917 for ; Thu, 28 Jan 2021 13:09:15 +0000 (UTC) X-HE-Tag: leg34_2d0943d2759f X-Filterd-Recvd-Size: 8666 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 Jan 2021 13:09:14 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id lw17so4751929pjb.0 for ; Thu, 28 Jan 2021 05:09:12 -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=wV6oz0k6223jz7bAL5Zk8NtAtXo6+ezaMn2fhP1oIYw=; b=LC3TkXKy3vn5GvO4Kf87XAOF7u+IP4qG3NOTmirr40/P/+XPyRG5SDdGc0xFE1cHzH x5korc+db7u6Jg0h5ILb8wHVnJPZoRTCcjqqufpBVYaBcu3M97Nxel7VCt5w/FlLY1eW HZ6M99/NpP2WRtl2d6UH0ByzCBG86H0E2YucVJ4Q2EXwE3VgBpnDydWwZtoo4c8vWi8/ RvIlU+znzcboc0Yh8QxfNNH8UbjIWjr1OkTDbxt3PU3UmW2PclQszMys1ZSv8glvYbk6 OWaYKN3NgoDEUUFpXKZFEoFBIGnGUHi87LSDbF5nBI9fPA1TJ7gs+avJKhwjP02wdMgh U//g== 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=wV6oz0k6223jz7bAL5Zk8NtAtXo6+ezaMn2fhP1oIYw=; b=RBpb6DszO4O0ee3BqdFb5XKfMR+zSBHm4nHOfD9bhIEpC6zcT94aWKRCAk2C6XHL6L PEH6+nG33KpbYKwUasWDWuuyx8jKykH55ubIaSmd9+nKMRDYTn8CBPLNa0MQYOX8eIE7 LJ9ieTc8Ag9LlNHCYXBcI2Qaz1jqdjZyK8y2+7irogEnu/tSnSQ4cC8Z0wl078okok0J V9oVyq0PcZTSY2fcGN7HK5vTOu85pWGKMpihN4mFeG/B39gZpgxV4tqxN2/0kxKGh+WQ kt2a9/0O2Okc0V2nNcLU5enlvLBZxuTCyWiRysnzAPx0LGZTlyatFf5fNfMOgJ70YedQ qXag== X-Gm-Message-State: AOAM530ieV5Gu6D7FjqlYZUOIhn+lsTQrUJRkxRvj3HX6uu4IZxkqYQK ujrI4tytQDGRv/NOoZCuezgkITK+rpkpfWs6hCez4g== X-Google-Smtp-Source: ABdhPJyufgziyJlqzFS90vCqlwRzjRmjfQIf+qHC8gEyNqlz6n+25WRZktQ7hAQucfD1mMlI+eOC+QOtDcYv/xXSLn8= X-Received: by 2002:a17:90a:808a:: with SMTP id c10mr11001877pjn.229.1611839351754; Thu, 28 Jan 2021 05:09:11 -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 21:08:35 +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 Thu, Jan 28, 2021 at 8:37 PM Muchun Song wrote: > > 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. ^^ Sorry. Here "free" should be "optimize". > 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 > >