Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2638446rdh; Mon, 30 Oct 2023 03:26:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJjiVL/e88WvPbY/FystWmHsMWTeoxDsjSJXzp/EsBv4jQ2U3DfwiVoyqVHgqlDvphCRRG X-Received: by 2002:a17:90b:190c:b0:27c:e062:c464 with SMTP id mp12-20020a17090b190c00b0027ce062c464mr8918449pjb.37.1698661571833; Mon, 30 Oct 2023 03:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698661571; cv=none; d=google.com; s=arc-20160816; b=s29yIQqJFa10H6q5ep4Mw6yp1oFLU4E0XNzDdtBD+raznaT0pcdmXs6PvkLDuSLIqI N7VT+rbSI1/xlXavXRrJ8bNV6jNxHX3NRD29P7k8oPxtY/gM5V0aCl/+qt7hmhhvvWaD 4KBJBUovj2oYxA5GgokZec/mvwQcJhooDimiPfOhEKQEQwZnbNs4Kevlo0Q/wCK/mARm vTXr5rinJTEEuDg8mlHgHX3YQPtZauPFzDE8pBh2gTFrzp7Q8dFKbubTIuw+t3OPC/Kf O46Cvlw/5PnYx0QyzfMaynQjkPhMrcOAEmUpaO+vI9iZsBFfIJgbD+MwpYzov9xUn/BI Dopg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=5LK3NrzkfOof1kZmFIFKBX84P630qta/Emok9ahJO90=; fh=1y1w3Z2I2TvbAb3XHQdUPt2+yXy/gePQGCzeWbR7iKg=; b=S7TYE7n8n84Dw/jheLNB9GS/+HQo7bLA/qp+SbrqbQdzWRotpGqk5Ot5VEAeyh3GUo uot+8DkTMv8t86mhBHaVHPPPDYAsjr66Zfc1TAjHRyKCWsbMQcX3RQke5gbU4GZbKwdB dGqFClCBROALyaE01dMP+gq0PNE0//WudstGQxwDFgEhLR06t+NpvycmIrcLxg3KwSyF ITrDsBMJZf/UpOzD/aShpvLeqIY0nlZ0i6xLn0wWReVQRjGmWRd+DRKBp3KMFAR/azYr CIal2LFGq9CN4GW/YZvY33P6F5nH/1iRsgkHt8LA6tjxI/5qUXg8l89Q1GmUWGnWXUZm FVtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YgIVxBYg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id gm21-20020a17090b101500b002800c14f2e1si4061354pjb.89.2023.10.30.03.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 03:26:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YgIVxBYg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 62BC6806655C; Mon, 30 Oct 2023 03:25:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232954AbjJ3KY6 (ORCPT + 99 others); Mon, 30 Oct 2023 06:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233036AbjJ3KY1 (ORCPT ); Mon, 30 Oct 2023 06:24:27 -0400 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 D50D72688 for ; Mon, 30 Oct 2023 03:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698661226; 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=5LK3NrzkfOof1kZmFIFKBX84P630qta/Emok9ahJO90=; b=YgIVxBYgQmqTy355E7S4mbLHObXkjCTVbDAxVIKpBHcOXzY3zClYYoSeHp2yx1Rh1c4ycw hfDk6eOMZUyHsvOYHsSf0SeWcIqpZIj99ORLng35nEKs0CWQjBNAHp0PvHKTdB0UXXAu1d ZOCvb1tbgjM+Ipu60tx+p2MrqFHOtfc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-66H6pjoLN5GAUF-ikUDe7Q-1; Mon, 30 Oct 2023 06:20:24 -0400 X-MC-Unique: 66H6pjoLN5GAUF-ikUDe7Q-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40837aa4a58so29218605e9.0 for ; Mon, 30 Oct 2023 03:20:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698661223; x=1699266023; 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=5LK3NrzkfOof1kZmFIFKBX84P630qta/Emok9ahJO90=; b=OJVi8HtAMRhNDtcvSS4fvAqWnI/2wrJ8/I/DHxIWoDysTWzrHxXQY2erRGa0q4itkL bhY1QMUdNtaasus5lYt/XZjJNyYt8BPzqN2FAMQXe5meHbcYMRaaIJITepjgqM5x+/Uw 5SoMvKUlYmYTqBVbz76tCyOKgsNVwVu5akh6Ga3W9FpEg7bkfphWyZtddgW/6aUXE6lF 818A+sCT/W3sBnCgc+SJLaGUe1cbz0NqNFDg6tMabFQMRUzwuPg+FWHDWZkvvjvKcewN rNIaeUsSfCCvHoJQRs9F/gIFLWjK1A8okIIIYWkkKS2xJzzAoOWW4KwRYQn1wpEtGzPA d5QQ== X-Gm-Message-State: AOJu0YzPE4dfBie0JmzdIh5eZiSMdf2TPPEe8UR7JPhGJQAjrhd5BbR5 3cxtwtkMFQJzTgSMFNlss6CMlpjez4QevAJ4CnxGpJ0x3LKJtJgXBIO9H+3CxMbovehmGW7AO8e 1jFW6FeJhY1GyAOeZnIHdrlNU X-Received: by 2002:a05:600c:3201:b0:407:73fc:6818 with SMTP id r1-20020a05600c320100b0040773fc6818mr15618889wmp.2.1698661223492; Mon, 30 Oct 2023 03:20:23 -0700 (PDT) X-Received: by 2002:a05:600c:3201:b0:407:73fc:6818 with SMTP id r1-20020a05600c320100b0040773fc6818mr15618860wmp.2.1698661223050; Mon, 30 Oct 2023 03:20:23 -0700 (PDT) Received: from ?IPV6:2003:cb:c73c:f800:7df6:a2c9:652e:c799? (p200300cbc73cf8007df6a2c9652ec799.dip0.t-ipconnect.de. [2003:cb:c73c:f800:7df6:a2c9:652e:c799]) by smtp.gmail.com with ESMTPSA id m11-20020a05600c4f4b00b0040651505684sm8840526wmq.29.2023.10.30.03.20.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Oct 2023 03:20:22 -0700 (PDT) Message-ID: <4df63333-de57-4a58-a110-77b4fdfa6a9e@redhat.com> Date: Mon, 30 Oct 2023 11:20:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 2/3] mm/memory_hotplug: split memmap_on_memory requests across memblocks Content-Language: en-US To: Vishal Verma , Andrew Morton , Oscar Salvador , Dan Williams , Dave Jiang Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Huang Ying , Dave Hansen , "Aneesh Kumar K.V" , Michal Hocko , Jonathan Cameron , Jeff Moyer References: <20231025-vv-kmem_memmap-v7-0-4a76d7652df5@intel.com> <20231025-vv-kmem_memmap-v7-2-4a76d7652df5@intel.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/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoP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zTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20231025-vv-kmem_memmap-v7-2-4a76d7652df5@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 30 Oct 2023 03:25:14 -0700 (PDT) On 26.10.23 00:44, Vishal Verma wrote: > The MHP_MEMMAP_ON_MEMORY flag for hotplugged memory is restricted to > 'memblock_size' chunks of memory being added. Adding a larger span of > memory precludes memmap_on_memory semantics. > > For users of hotplug such as kmem, large amounts of memory might get > added from the CXL subsystem. In some cases, this amount may exceed the > available 'main memory' to store the memmap for the memory being added. > In this case, it is useful to have a way to place the memmap on the > memory being added, even if it means splitting the addition into > memblock-sized chunks. > > Change add_memory_resource() to loop over memblock-sized chunks of > memory if caller requested memmap_on_memory, and if other conditions for > it are met. Teach try_remove_memory() to also expect that a memory > range being removed might have been split up into memblock sized chunks, > and to loop through those as needed. > > This does preclude being able to use PUD mappings in the direct map; a > proposal to how this could be optimized in the future is laid out > here[1]. Almost there, I think :) > > +static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group, > + u64 start, u64 size) > +{ > + unsigned long memblock_size = memory_block_size_bytes(); > + u64 cur_start; > + int ret; > + > + for (cur_start = start; cur_start < start + size; > + cur_start += memblock_size) { > + struct mhp_params params = { .pgprot = > + pgprot_mhp(PAGE_KERNEL) }; > + struct vmem_altmap mhp_altmap = { > + .base_pfn = PHYS_PFN(cur_start), > + .end_pfn = PHYS_PFN(cur_start + memblock_size - 1), > + }; > + > + mhp_altmap.free = memory_block_memmap_on_memory_pages(); > + params.altmap = kmemdup(&mhp_altmap, sizeof(struct vmem_altmap), > + GFP_KERNEL); > + if (!params.altmap) > + return -ENOMEM; Best to cleanup here instead of handling it in the caller [as noted by Vishal, we might not be doing that yet]. Using remove_memory_blocks_and_altmaps() on the fully processed range sounds reasonable. maybe something like ret = arch_add_memory(nid, cur_start, memblock_size, ¶ms); if (ret) { kfree(params.altmap); goto out; } ret = create_memory_block_devices(cur_start, memblock_size, params.altmap, group); if (ret) { arch_remove_memory(cur_start, memblock_size, NULL); kfree(params.altmap); goto out; } if (ret && cur_start != start) remove_memory_blocks_and_altmaps(start, cur_start - start); return ret; > + > + /* call arch's memory hotadd */ > + ret = arch_add_memory(nid, cur_start, memblock_size, ¶ms); > + if (ret < 0) { > + kfree(params.altmap); > + return ret; > + } > + > + /* create memory block devices after memory was added */ > + ret = create_memory_block_devices(cur_start, memblock_size, > + params.altmap, group); > + if (ret) { > + arch_remove_memory(cur_start, memblock_size, NULL); > + kfree(params.altmap); > + return ret; > + } > + } > + > + return 0; > +} > + [...] > static int check_cpu_on_node(int nid) > { > int cpu; > @@ -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. > + WARN(altmap->alloc, "Altmap not fully unmapped"); > + kfree(altmap); > + } > + } > +} -- Cheers, David / dhildenb