Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp467207ybd; Wed, 26 Jun 2019 01:03:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWzwzqcBfeUjX4Idkm6ZtbfS5AdgtCqGfAggnR7X4PayNJLez4dsRjTVWmBGSkiP5YeHdn X-Received: by 2002:a63:6011:: with SMTP id u17mr1637298pgb.117.1561536214324; Wed, 26 Jun 2019 01:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561536214; cv=none; d=google.com; s=arc-20160816; b=xtnjOsccDLgsiCJWotRAYtf+Ext4dupTJ54ReiEjYkXuMDG0l85QnZlyzm5aeBf0aP Que3DU7BrtclCSn8B1OUl4OmLe7kXorKstkcLP8y4tFmaQSgYS2Y9oClIgWAK2C+xUBj t6bftQ2+u/bv2XQRz/7Cc2iB3nBAmI6U1r/TLTjc2AqOGZ2ddlpgEZBxLqEP3KZ1Giyf ViZLHR5jpUTCiONIeoEc6f3j5anKHujB5bhEv6qZNCxT45g0NNkkMaXJqBj5zMzrL0YP 1pUX6dpWzcxM1l7GndKUb70/Ht1sjVCqpqhtj5OesA/LzxtqHZSgCIaLePkU4OPRPRbd lCnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=gLQmNGRKhgDSh87aiQC+vUId2aguDdMo2Z0NCImkn3A=; b=Ay46ogGHrG1Vw8FV82Ogjx/ux3HWZ0DXytxf8EtQx2N1b4pcbkF9dehYyXtG+AxMtV dV7cda8t8LZS6fBxReAEw658J21dMdsIjDUw83t/QMWgfp2hf3ofL725m/GGn55LoAgw Cev4+9rHDWIRd3sD9mJyHEnL7MnNxub1apvCfgY1Of6pTrIiyZMsoVK/uf3nNYHfZX0T wlVA7N4pYQKkQcw2+NkZm05x9UfBZ1VERHUVsnKuox3I8p2qHcXAdmDiNRniQ/P2Laqt 6+yPCLGXv1x8/Zxyy3BE2gRi8CSVDUDsjPSALdcU7x97gLYln2fsfzQx5cKe5WiRi9oo UaIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z22si15362035pgh.458.2019.06.26.01.03.15; Wed, 26 Jun 2019 01:03:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726653AbfFZIDJ (ORCPT + 99 others); Wed, 26 Jun 2019 04:03:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:53806 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726242AbfFZIDI (ORCPT ); Wed, 26 Jun 2019 04:03:08 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 16173AE20; Wed, 26 Jun 2019 08:03:07 +0000 (UTC) Date: Wed, 26 Jun 2019 10:03:03 +0200 From: Oscar Salvador To: David Hildenbrand Cc: akpm@linux-foundation.org, mhocko@suse.com, dan.j.williams@intel.com, pasha.tatashin@soleen.com, Jonathan.Cameron@huawei.com, anshuman.khandual@arm.com, vbabka@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/5] Allocate memmap from hotadded memory Message-ID: <20190626080249.GA30863@linux> References: <20190625075227.15193-1-osalvador@suse.de> <2ebfbd36-11bd-9576-e373-2964c458185b@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2ebfbd36-11bd-9576-e373-2964c458185b@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 25, 2019 at 10:25:48AM +0200, David Hildenbrand wrote: > > [Coverletter] > > > > This is another step to make memory hotplug more usable. The primary > > goal of this patchset is to reduce memory overhead of the hot-added > > memory (at least for SPARSEMEM_VMEMMAP memory model). The current way we use > > to populate memmap (struct page array) has two main drawbacks: First off, thanks for looking into this :-) > > Mental note: How will it be handled if a caller specifies "Allocate > memmap from hotadded memory", but we are running under SPARSEMEM where > we can't do this. In add_memory_resource(), we have a call to mhp_check_correct_flags(), which is in charge of checking if the flags passed are compliant with our configuration among other things. It also checks if both flags were passed (_MEMBLOCK|_DEVICE). If a) any of the flags were specified and we are not on CONFIG_SPARSEMEM_VMEMMAP, b) the flags are colliding with each other or c) the flags just do not make sense, we print out a warning and drop the flags to 0, so we just ignore them. I just realized that I can adjust the check even more (something for the next version). But to answer your question, flags are ignored under !CONFIG_SPARSEMEM_VMEMMAP. > > > > > a) it consumes an additional memory until the hotadded memory itself is > > onlined and > > b) memmap might end up on a different numa node which is especially true > > for movable_node configuration. > > > > a) it is a problem especially for memory hotplug based memory "ballooning" > > solutions when the delay between physical memory hotplug and the > > onlining can lead to OOM and that led to introduction of hacks like auto > > onlining (see 31bc3858ea3e ("memory-hotplug: add automatic onlining > > policy for the newly added memory")). > > > > b) can have performance drawbacks. > > > > Another minor case is that I have seen hot-add operations failing on archs > > because they were running out of order-x pages. > > E.g On powerpc, in certain configurations, we use order-8 pages, > > and given 64KB base pagesize, that is 16MB. > > If we run out of those, we just fail the operation and we cannot add > > more memory. > > At least for SPARSEMEM, we fallback to vmalloc() to work around this > issue. I haven't looked into the populate_section_memmap() internals > yet. Can you point me at the code that performs this allocation? Yes, on SPARSEMEM we first try to allocate the pages physical configuous, and then fallback to vmalloc. This is because on CONFIG_SPARSEMEM memory model, the translations pfn_to_page/ page_to_pfn do not expect the memory to be contiguous. But that is not the case on CONFIG_SPARSEMEM_VMEMMAP. We do expect the memory to be physical contigous there, that is why a simply pfn_to_page/page_to_pfn is a matter of adding/substracting vmemmap/pfn. Powerpc code is at: https://elixir.bootlin.com/linux/v5.2-rc6/source/arch/powerpc/mm/init_64.c#L175 > So, assuming we add_memory(1GB, MHP_MEMMAP_DEVICE) and then > remove_memory(128MB) of the added memory, this will work? No, MHP_MEMMAP_DEVICE is meant to be used when hot-adding and hot-removing work in the same granularity. This is because all memmap pages will be stored at the beginning of the memory range. Allowing hot-removing in a different granularity on MHP_MEMMAP_DEVICE would imply a lot of extra work. For example, we would have to parse the vmemmap-head of the hot-removed range, and punch a hole in there to clear the vmemmap pages, and then be very carefull when deleting those pagetables. So I followed Michal's advice, and I decided to let the caller specify if he either wants to allocate per memory block or per hot-added range(device). Where per memory block, allows us to do: add_memory(1GB, MHP_MEMMAP_MEMBLOCK) remove_memory(128MB) > add_memory(8GB, MHP_MEMMAP_DEVICE) > > For 8GB, we will need exactly 128MB of memmap if I did the math right. > So exactly one section. This section will still be marked as being > online (although not pages on it are actually online)? Yap, 8GB will fill the first section with vmemmap pages. It will be marked as online, yes. This is not to diverge too much from what we have right now, and starting treat some sections different than others. E.g: Early sections that are used for memmap pages on early boot stage. > > > > What we do is that since when we hot-remove a memory-range, sections are being > > removed sequentially, we wait until we hit the last section, and then we free > > the hole range to vmemmap_free backwards. > > We know that it is the last section because in every pass we > > decrease head->_refcount, and when it reaches 0, we got our last section. > > > > We also have to be careful about those pages during online and offline > > operations. They are simply skipped, so online will keep them > > reserved and so unusable for any other purpose and offline ignores them > > so they do not block the offline operation. > > I assume that they will still be dumped normally by user space. (as they > are described by a "memory resource" and not PG_Offline) They are PG_Reserved. Anyway, you mean by crash-tool? -- Oscar Salvador SUSE L3