Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp972037pxb; Thu, 28 Jan 2021 05:13:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyh7Z31g762yxLanoLgWpuxmxOq5FXvIxNDP268poMnkFn3aUtAFfICjCkxdCS7YBiN1tHW X-Received: by 2002:a05:6402:3122:: with SMTP id dd2mr13874858edb.262.1611839606638; Thu, 28 Jan 2021 05:13:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611839606; cv=none; d=google.com; s=arc-20160816; b=B8CwLJlBZLvuzDINuZMxRCl6MO81cV5D6M7KNX8AymbekO1Rqw2ZUHuM5mPpZTWhRy Kme2Dya1tLx60+YcxLRL3hVU5fPalzz7FIHHE4duhYYsW8BYxeVTdeLic3kNQDn5oiiN L9G9UDTJDJdBl6JJReDi7AHk2EgGeGK52Sjs7rRli1C/bEQYBcsiZBhnsBJL6J9SNO6d 7rcGFU4gGAqnpTefG7PfYgnkAztWfsCBtxHp33ZRGIbH/RzUJzCvoyeFExvje6pY3UE5 n1flcVgy3VQBQ23AWuHz0okQYESKm/LAfNAZfuOuitjdsNr+psgVCAQo197jYMaQYDsk ZWjw== 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=wV6oz0k6223jz7bAL5Zk8NtAtXo6+ezaMn2fhP1oIYw=; b=Kbfb1ssYC/HlCuqDPx59Lxhp1Y3833fcFHzZyXdwh7y6/3ovEOi/e8UiSpUejw1Unz /7BdxuQrk42z2dgtthe7MtjKtF0YMy124hQg2yprt/iD7LS3z/5mNiR0VMgDlLKBY2BE 0/1KNDKog9kB15soBytf2JeF0GDnmeQnLbxDxv08M5QdU3gDM+4qAbX8NlrbB1x0pzOK NnraCIxn0PKGz2fuAaZjrGNkKuheZUt4XpRc3a74kVlahGNA2ppVyga9GZVluIZeWqg8 BepapoNZNhUxJxPY0BY4Zj4R8aJ/RTjPHsfll2SeJjXXfOhwUpjyMT44bBDrTCxQi3cu D9wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=LC3TkXKy; 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 v3si3106052edr.600.2021.01.28.05.13.01; Thu, 28 Jan 2021 05:13:26 -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=LC3TkXKy; 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 S231882AbhA1NJ4 (ORCPT + 99 others); Thu, 28 Jan 2021 08:09:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231709AbhA1NJx (ORCPT ); Thu, 28 Jan 2021 08:09:53 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3175CC061573 for ; Thu, 28 Jan 2021 05:09:12 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id b17so3298679plz.6 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=I09wQxHTp+Cbxew0+QvUrFhMKduEKzfn/N7aPS02bJuh2SiloRJ9kCu+4ogL7ql1nh CLXEMkmFuWx6Jn2e9mNIAsagFtO0e481J0IBe1Z4dElCQX3yrz6QfSGgRe6jOxvyaOBS 4nPH2b1Pij7P7r6XSOD/ZZ/ULA0Saf1s51hRZujvnWDWX+GjX4b1isp5Yw9+xdHbu+jD A3z8GFQ7qV6lJ0uJu8+gfip+K9MWJgcbkunELKytEuOH1zaQMRvDFwslHD087wEKmf8R XAsG40TkNucZRJEU9ozGW+hyDsPb3YFKFctl28N5mgDRbXAh1SoQ+JkfdngdNhxHyvIx OfPw== X-Gm-Message-State: AOAM531YYzms+VGuTvgKXKXn2MrJ+em61qXOg2SFJRSAh4Dz+HCa/KCs rMyty9u1LDF0MOdZyXmx2mshRPcoScyZXq3pJbxCFA== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > >