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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BE36C43334 for ; Thu, 16 Jun 2022 07:21:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6A4C6B0072; Thu, 16 Jun 2022 03:21:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B19D56B0073; Thu, 16 Jun 2022 03:21:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BA358D0001; Thu, 16 Jun 2022 03:21:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8E0686B0072 for ; Thu, 16 Jun 2022 03:21:40 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5DBD2213D7 for ; Thu, 16 Jun 2022 07:21:40 +0000 (UTC) X-FDA: 79583253960.10.DBE9C44 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id ED5FEC007A for ; Thu, 16 Jun 2022 07:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655364099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BmKGnuktFvztcVSafDwftRNZMdy1HHQkqyAtAvqCv2M=; b=ey4hXQOLOtvuKJwI420i3r3d8IGovESa+aitn74MkSxucY2gkiUMu0n5G5Hz3bFh2UzZZe dsVNaArbbhuNEXkaiR8FeEWbvBs7rmDP0pAXRHli0EFob+0+MBH5gcAN/G5/3TNHuq9/n5 23HdyIcEz/s0s8+UZHngMYNB947NLIg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-DwOfLBXvMiGoUNSDqo1Esw-1; Thu, 16 Jun 2022 03:21:38 -0400 X-MC-Unique: DwOfLBXvMiGoUNSDqo1Esw-1 Received: by mail-wr1-f72.google.com with SMTP id u18-20020adfb212000000b0021855847651so62935wra.6 for ; Thu, 16 Jun 2022 00:21:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=BmKGnuktFvztcVSafDwftRNZMdy1HHQkqyAtAvqCv2M=; b=JT+7RcLEn4cbA8jHuiKaWSUKCdgU/87xVHDuAJuW/5JcbDc8+r6iwbqJ/jl9LxQg4H GvyqNH/cOjXMTkASRFPcU7qokV8r4IAEwwWfem+EDzD7yvIX2TEeWa6tPTwpqVuJaSv7 3pv21DvAP4Slk1RqW4qyaenNDHslS56lYMb4byLSjdhjPJlmoajOGERwGzx2s2t2dSvw XLqqUbnRYHAUOafn9PW+ko1OG6R+icgiqz+/wUldoT86HgmyrZ8qZ/fkfqClONwczb/I nNUiL/sKHhUf2piMhTPhF+8bzMsoCQFXVYrLDb70OQS39roXwHmPPzz+aX1idT8Ha7ts zoCg== X-Gm-Message-State: AJIora9d9CBc0cccPnlISGyDJnmhjSzxkgLGt1cgcm6aT/Ikv9+pqcoY f0al9i01muKk0raSvTfh1xH1QX0qT86ydJJQ4N5TUzl+NhtoXA2ChmbVS32T9TB2jzliv8PO4EK qACuD9Kwd9WQ= X-Received: by 2002:a5d:584c:0:b0:218:4e98:770a with SMTP id i12-20020a5d584c000000b002184e98770amr3205377wrf.271.1655364096977; Thu, 16 Jun 2022 00:21:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sCHqyHd8fBXb2/1perTt3JC0gqX+eoIPsBJarFVdNDwHFuc2T2urts+Aswd2WJYMkghrY7ow== X-Received: by 2002:a5d:584c:0:b0:218:4e98:770a with SMTP id i12-20020a5d584c000000b002184e98770amr3205359wrf.271.1655364096688; Thu, 16 Jun 2022 00:21:36 -0700 (PDT) Received: from ?IPV6:2003:cb:c70b:2d00:73d7:5fab:cc8a:e48c? (p200300cbc70b2d0073d75fabcc8ae48c.dip0.t-ipconnect.de. [2003:cb:c70b:2d00:73d7:5fab:cc8a:e48c]) by smtp.gmail.com with ESMTPSA id t2-20020a1c4602000000b0039db60fa340sm4809654wma.33.2022.06.16.00.21.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Jun 2022 00:21:36 -0700 (PDT) Message-ID: Date: Thu, 16 Jun 2022 09:21:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v2 2/2] mm: memory_hotplug: introduce SECTION_CANNOT_OPTIMIZE_VMEMMAP To: Muchun Song Cc: corbet@lwn.net, akpm@linux-foundation.org, paulmck@kernel.org, mike.kravetz@oracle.com, osalvador@suse.de, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, smuchun@gmail.com References: <20220520025538.21144-1-songmuchun@bytedance.com> <20220520025538.21144-3-songmuchun@bytedance.com> <53024884-0182-df5f-9ca2-00652c64ce36@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655364100; a=rsa-sha256; cv=none; b=yIopSnLvVM12PkXN0g+hKCYe31Ehhl/Lf4P06KEK1rJmlBpoRzxnJ1nni6Pu2XpU3a4zQI TwudVTkSQe7IYtqQ8GnMfugtgKFGU8qAF+y0iXCy8Gme8z+X09+g3X8NhCTWgB3RYV3Rg5 K3iAFOgZ7VCQVFtPurMrNxlZjocL0B0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ey4hXQOL; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf10.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655364100; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BmKGnuktFvztcVSafDwftRNZMdy1HHQkqyAtAvqCv2M=; b=n2wXqjqQReTxmgT5wveYIynZAbSpceZTqhWjdtgc5OKMxzUDVKTkpEBpnmxA7eGG4xtz/s gaB4BdLx/7ECAyMSEiZrZ+IYnU8Pv75XqPfu6cr711SuNtwDsdXZ6MrNGZxzjzMWeuRKNs iFB3vbycvvuux31qhtbFMAHlRzofZSc= X-Rspamd-Queue-Id: ED5FEC007A X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ey4hXQOL; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf10.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam06 X-Stat-Signature: rp7z36ooob939bf5a8h8oi8sc1nn7uyr X-HE-Tag: 1655364099-114298 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 16.06.22 04:45, Muchun Song wrote: > On Wed, Jun 15, 2022 at 11:51:49AM +0200, David Hildenbrand wrote: >> On 20.05.22 04:55, Muchun Song wrote: >>> For now, the feature of hugetlb_free_vmemmap is not compatible with the >>> feature of memory_hotplug.memmap_on_memory, and hugetlb_free_vmemmap >>> takes precedence over memory_hotplug.memmap_on_memory. However, someone >>> wants to make memory_hotplug.memmap_on_memory takes precedence over >>> hugetlb_free_vmemmap since memmap_on_memory makes it more likely to >>> succeed memory hotplug in close-to-OOM situations. So the decision >>> of making hugetlb_free_vmemmap take precedence is not wise and elegant. >>> The proper approach is to have hugetlb_vmemmap.c do the check whether >>> the section which the HugeTLB pages belong to can be optimized. If >>> the section's vmemmap pages are allocated from the added memory block >>> itself, hugetlb_free_vmemmap should refuse to optimize the vmemmap, >>> otherwise, do the optimization. Then both kernel parameters are >>> compatible. So this patch introduces SECTION_CANNOT_OPTIMIZE_VMEMMAP >>> to indicate whether the section could be optimized. >>> >> >> In theory, we have that information stored in the relevant memory block, >> but I assume that lookup in the xarray + locking is impractical. >> >> I wonder if we can derive that information simply from the vmemmap pages >> themselves, because *drumroll* >> >> For one vmemmap page (the first one), the vmemmap corresponds to itself >> -- what?! >> >> >> [ hotplugged memory ] >> [ memmap ][ usable memory ] >> | | | >> ^--- | | >> ^------- | >> ^---------------------- >> >> The memmap of the first page of hotplugged memory falls onto itself. >> We'd have to derive from actual "usable memory" that condition. >> >> >> We currently support memmap_on_memory memory only within fixed-size >> memory blocks. So "hotplugged memory" is guaranteed to be aligned to >> memory_block_size_bytes() and the size is memory_block_size_bytes(). >> >> If we'd have a page falling into usbale memory, we'd simply lookup the >> first page and test if the vmemmap maps to itself. >> > > I think this can work. Should we use this approach in next version? > Either that or more preferable, flagging the vmemmap pages eventually. That's might be future proof. >> >> Of course, once we'd support variable-sized memory blocks, it would be >> different. >> >> >> An easier/future-proof approach might simply be flagging the vmemmap >> pages as being special. We reuse page flags for that, which don't have >> semantics yet (i.e., PG_reserved indicates a boot-time allocation via >> memblock). >> > > I think you mean flag vmemmap pages' struct page as PG_reserved if it > can be optimized, right? When the vmemmap pages are allocated in > hugetlb_vmemmap_alloc(), is it valid to flag them as PG_reserved (they > are allocated from buddy allocator not memblock)? > Sorry I wasn't clear. I'd flag them with some other not-yet-used-for-vmemmap-pages flag. Reusing PG_reserved could result in trouble. -- Thanks, David / dhildenb