From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94E7C18E3A for ; Tue, 31 Oct 2023 10:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hk2W83bI" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3A683 for ; Tue, 31 Oct 2023 03:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698747199; 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:autocrypt:autocrypt; bh=pAQbrfQoIJNOhnUYvPhPLxk1gl1ZWcaKec9dUXNoa30=; b=hk2W83bI/qnflL+5MNQMs+7zjJpp4veTjLC+jiJVvrmhusfSoQyBwkSyMdOnNvq4vRqi5+ MDd376Mxa22EYz7mM1R+fHy4sAjVmR8xHWC+/vpC+nB0YFI8LVCNF1pS4sOLNNMq7WfbKb Dn1tkF6fr6pkD0QS4PJGGtotQ1+C1Mg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-OnW9_TK7OLKcXwMKFcS68A-1; Tue, 31 Oct 2023 06:13:17 -0400 X-MC-Unique: OnW9_TK7OLKcXwMKFcS68A-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-408524e2368so38408945e9.0 for ; Tue, 31 Oct 2023 03:13:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698747196; x=1699351996; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pAQbrfQoIJNOhnUYvPhPLxk1gl1ZWcaKec9dUXNoa30=; b=MWQCLRGoqLBzToz8Jumj4WSrCLF4/jYNPZw84a1ii9wcYmVHlcuT90A94C7KhrsJNF 4/xm2LAtKh8dCZAUYwINRSYKCiJP6L9yDwiK7PkxKH7AA47LF7BJc+1/cD5D3+mL3Vhy AsXSE0UOzgiXBKKjye2dR2giLGUs84X3GsRvZUrKNO3csXDb0YV+esubaAUyETkhQLpd eI2sSkIg6HKNTiW0q5oXF6dfWyARU7xSEfe/CNWsk97XMgkONURhVpKRZALDX/YQMjpo Fkh0csBRGyjj0/r73Xs+3iOY4iUEJ9mRFZckGUbUQAVXB/mdYwI+rBmDtY+S7coOSyMT WA5w== X-Gm-Message-State: AOJu0Yz82JmYLFYFxLi75Q5eRjuNG7hfX7Ex9OP873ZHGzS1xtpKzkmc yyuaAeaQCpI/r1LagiIlNI27HLe7uRG/7pWjmBpwNlJq7CuKQsnofQ6C5qCNmTxXfShUq6gJWGK yqwIi2m5gixQdQYyQ3ulq X-Received: by 2002:a05:600c:4449:b0:408:4120:bab7 with SMTP id v9-20020a05600c444900b004084120bab7mr10499392wmn.15.1698747196431; Tue, 31 Oct 2023 03:13:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHevO5e8NbNMxyxVt2qma4vR7VuBnZ4MDfKV72pDE/YGANv/bYJg45/F0IcpscecHYnjWYxuQ== X-Received: by 2002:a05:600c:4449:b0:408:4120:bab7 with SMTP id v9-20020a05600c444900b004084120bab7mr10499373wmn.15.1698747195965; Tue, 31 Oct 2023 03:13:15 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:8f00:43b0:1107:57d2:28ee? (p200300cbc7078f0043b0110757d228ee.dip0.t-ipconnect.de. [2003:cb:c707:8f00:43b0:1107:57d2:28ee]) by smtp.gmail.com with ESMTPSA id fb12-20020a05600c520c00b00405d9a950a2sm1281801wmb.28.2023.10.31.03.13.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Oct 2023 03:13:15 -0700 (PDT) Message-ID: Date: Tue, 31 Oct 2023 11:13:14 +0100 Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 2/3] mm/memory_hotplug: split memmap_on_memory requests across memblocks To: "Verma, Vishal L" , "Williams, Dan J" , "Jiang, Dave" , "osalvador@suse.de" , "akpm@linux-foundation.org" Cc: "dave.hansen@linux.intel.com" , "Huang, Ying" , "linux-mm@kvack.org" , "aneesh.kumar@linux.ibm.com" , "linux-kernel@vger.kernel.org" , "linux-cxl@vger.kernel.org" , "Hocko, Michal" , "nvdimm@lists.linux.dev" , "jmoyer@redhat.com" , "Jonathan.Cameron@Huawei.com" References: <20231025-vv-kmem_memmap-v7-0-4a76d7652df5@intel.com> <20231025-vv-kmem_memmap-v7-2-4a76d7652df5@intel.com> <4df63333-de57-4a58-a110-77b4fdfa6a9e@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM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5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== 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; format=flowed Content-Transfer-Encoding: 8bit On 31.10.23 03:14, Verma, Vishal L wrote: > On Mon, 2023-10-30 at 11:20 +0100, David Hildenbrand wrote: >> On 26.10.23 00:44, Vishal Verma wrote: >>> > [..] > >>> @@ -2146,11 +2186,69 @@ void try_offline_node(int nid) >>>   } >>>   EXPORT_SYMBOL(try_offline_node); >>> >>> -static int __ref try_remove_memory(u64 start, u64 size) >>> +static void __ref remove_memory_blocks_and_altmaps(u64 start, u64 size) >>>   { >>> -       struct memory_block *mem; >>> -       int rc = 0, nid = NUMA_NO_NODE; >>> +       unsigned long memblock_size = memory_block_size_bytes(); >>>         struct vmem_altmap *altmap = NULL; >>> +       struct memory_block *mem; >>> +       u64 cur_start; >>> +       int rc; >>> + >>> +       /* >>> +        * For memmap_on_memory, the altmaps could have been added on >>> +        * a per-memblock basis. Loop through the entire range if so, >>> +        * and remove each memblock and its altmap. >>> +        */ >> >> /* >>   * altmaps where added on a per-memblock basis; we have to process >>   * each individual memory block. >>   */ >> >>> +       for (cur_start = start; cur_start < start + size; >>> +            cur_start += memblock_size) { >>> +               rc = walk_memory_blocks(cur_start, memblock_size, &mem, >>> +                                       test_has_altmap_cb); >>> +               if (rc) { >>> +                       altmap = mem->altmap; >>> +                       /* >>> +                        * Mark altmap NULL so that we can add a debug >>> +                        * check on memblock free. >>> +                        */ >>> +                       mem->altmap = NULL; >>> +               } >> >> Simpler (especially, we know that there must be an altmap): >> >> mem = find_memory_block(pfn_to_section_nr(cur_start)); >> altmap = mem->altmap; >> mem->altmap = NULL; >> >> I think we might be able to remove test_has_altmap_cb() then. >> >>> + >>> +               remove_memory_block_devices(cur_start, memblock_size); >>> + >>> +               arch_remove_memory(cur_start, memblock_size, altmap); >>> + >>> +               /* Verify that all vmemmap pages have actually been freed. */ >>> +               if (altmap) { >> >> There must be an altmap, so this can be done unconditionally. > > Hi David, Hi! > > All other comments make sense, making those changes now. > > However for this one, does the WARN() below go away then? > > I was wondering if maybe arch_remove_memory() is responsible for > freeing the altmap here, and at this stage we're just checking if that > happened. If it didn't WARN and then free it. I think that has to stay, to make sure arch_remove_memory() did the right thing and we don't -- by BUG -- still have some altmap pages in use after they should have been completely freed. > > I drilled down the path, and I don't see altmap actually getting freed > in vmem_altmap_free(), but I wasn't sure if was meant > to free it as altmap->alloc went down to 0. vmem_altmap_free() does the "altmap->alloc -= nr_pfns", which is called when arch_remove_memory() frees the vmemmap pages and detects that they actually come from the altmap reserve and not from the buddy/earlyboot allocator. Freeing an altmap is just unaccounting it in the altmap structure; and here we make sure that we are actually back down to 0 and don't have some weird altmap freeing BUG in arch_remove_memory(). -- Cheers, David / dhildenb