Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp333436pxy; Wed, 21 Apr 2021 04:18:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUGupOAVdvR4D87XsZgXbsNVNmBV2c83MpPCHGtQplbeRTQR4cOPC9pZVN2053IUiCStMk X-Received: by 2002:a17:90a:9b86:: with SMTP id g6mr4169952pjp.216.1619003891858; Wed, 21 Apr 2021 04:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619003891; cv=none; d=google.com; s=arc-20160816; b=yQsv8xNWK/p//WUacaqt5Y0Rh5DnhrrXp1Z3r1xhJinwUhBd2/RZBki/rewkVp4vht EbIdrAfECSLHbWrHMtQ/wCWw1PkhfLwg8NNZE1ZVuTVzgEvPJhfpdvv201lw5FyfmHOn uDRxFBv9nE72HP2ffsB1SaHjY95WYIfwOFDEhvyOpcSec0FjXLUgsUfqyfyf/FinK6oL 5M066ZWxt5CB1J/PNtM4iGIphqmNfk6eQvcTfRRdOJm3pSARDB9tJeqzWPmVaYagRbdE Vy4RATqD0mz5hOD6Di4fxK6tasvIOSaX8ORWDOZCPlqLMYznOLYQBJm4WtZDchygPBO5 JbBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KTcOC/wq14K4jvcGjobMJQkY4UR5EvlZWWMMmYOurXw=; b=KsMXC4x1pfx061Ijj6hUBS/a7dFcpjY87UROJ8znAknvPdU+/uzz2IETnMCKz2Mvz7 T/TPJL3w9B96gCZajMtoalC3+IJkQyEaMRsYZM5hdvDXtsVrJJhrhXA73hEDNIKk7Vyb ohb6mGQt7UA3KfWM6iChWtmJZIQ7cHQ9AWtcAAQhK5DZr3Ia2yqedfbuiylcsc7jEzTu qDhmJ4iC2kA4XFOHd4Vkqw3hmsMhYhgin/uGFoxiuzJfau7MeBUbUlI/f7XAhT4InXnV WL1U57uhHQKVnB2jyh5ED+PflGzmnUFLFRp4vbJb6kVj7n8J0zbpp8+KoB20QIY72mPn AL2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="A1J/u8MP"; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 144si1941131pfx.180.2021.04.21.04.17.59; Wed, 21 Apr 2021 04:18:11 -0700 (PDT) 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=@suse.com header.s=susede1 header.b="A1J/u8MP"; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234461AbhDUIuV (ORCPT + 99 others); Wed, 21 Apr 2021 04:50:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:41702 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbhDUIuV (ORCPT ); Wed, 21 Apr 2021 04:50:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1618994987; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KTcOC/wq14K4jvcGjobMJQkY4UR5EvlZWWMMmYOurXw=; b=A1J/u8MPGeNdJ7k7m+Tii4ybAdkIzcqRn7pi9mD0uZ2cv7vc0fO3h2MyulXiUxWfGOAmfn nZlLefsjTz2mCYIMpVT2CPpu6DsHm/rx+973gpuEgmTSOI11RsPt03Ovk/QVwMviy5RcBh JSa+vzOfx/3QSSBQ7LvmO/hKjj8hj0c= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 52782B176; Wed, 21 Apr 2021 08:49:47 +0000 (UTC) Date: Wed, 21 Apr 2021 10:49:46 +0200 From: Michal Hocko To: David Hildenbrand Cc: Oscar Salvador , Andrew Morton , Anshuman Khandual , Pavel Tatashin , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 4/8] mm,memory_hotplug: Allocate memmap from the added memory range Message-ID: References: <20210416112411.9826-1-osalvador@suse.de> <20210416112411.9826-5-osalvador@suse.de> <20210421081546.GD22456@linux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 21-04-21 10:44:38, David Hildenbrand wrote: > On 21.04.21 10:39, Michal Hocko wrote: > > On Wed 21-04-21 10:15:46, Oscar Salvador wrote: > > > On Tue, Apr 20, 2021 at 12:56:03PM +0200, Michal Hocko wrote: > > [...] > > > > necessary. Using two different iteration styles is also hurting the code > > > > readability. I would go with the following > > > > for (pfn = start_pfn; pfn < end_pfn; ) { > > > > unsigned long order = min(MAX_ORDER - 1UL, __ffs(pfn)); > > > > > > > > while (start + (1UL << order) > end_pfn) > > > > order--; > > > > (*online_page_callback)(pfn_to_page(pfn), pageblock_order); > > > > pfn += 1 << order; > > > > } > > > > > > > > which is what __free_pages_memory does already. > > > > > > this is kinda what I used to have in the early versions, but it was agreed > > > with David to split it in two loops to make it explicit. > > > I can go back to that if it is preferred. > > > > Not that I would insist but I find it better to use common constructs > > when it doesn't hurt readability. The order evaluation can be even done > > in a trivial helper. > > > > > > > + if (memmap_on_memory) { > > > > > + nr_vmemmap_pages = walk_memory_blocks(start, size, NULL, > > > > > + get_nr_vmemmap_pages_cb); > > > > > + if (nr_vmemmap_pages) { > > > > > + if (size != memory_block_size_bytes()) { > > > > > + pr_warn("Refuse to remove %#llx - %#llx," > > > > > + "wrong granularity\n", > > > > > + start, start + size); > > > > > + return -EINVAL; > > > > > + } > > > > > + > > > > > + /* > > > > > + * Let remove_pmd_table->free_hugepage_table do the > > > > > + * right thing if we used vmem_altmap when hot-adding > > > > > + * the range. > > > > > + */ > > > > > + mhp_altmap.alloc = nr_vmemmap_pages; > > > > > + altmap = &mhp_altmap; > > > > > + } > > > > > + } > > > > > + > > > > > /* remove memmap entry */ > > > > > firmware_map_remove(start, start + size, "System RAM"); > > > > > > > > I have to say I still dislike this and I would just wrap it inside out > > > > and do the operation from within walk_memory_blocks but I will not > > > > insist. > > > > > > I have to confess I forgot about the details of that dicussion, as we were > > > quite focused on decoupling vmemmap pages from {online,offline} interface. > > > Would you mind elaborating a bit more? > > > > As I've said I will not insist and this can be done in the follow up. > > You are iterating over memory blocks just to refuse to do an operation > > which can be split to several memory blocks. See > > http://lkml.kernel.org/r/YFtPxH0CT5QZsnR1@dhcp22.suse.cz and follow > > walk_memory_blocks(start, size, NULL, remove_memory_block_cb) > > > > We'll have to be careful in general when removing memory in different > granularity than it was added, especially calling arch_remove_memory() in > smaller granularity than it was added via arch_add_memory(). We might fail > to tear down the direct map, imagine having mapped a 1GiB page but decide to > remove individual 128 MiB chunks -- that won't work and the direct map would > currently remain. Agreed but I am not referring to arbitrary hotremove path. All I am pointing at is to split up to memory blocks and do the same kind of work on each separately. Partial failures might turn out to be more tricky and as I've said I do not insist on doing that right now but it is a bit weird to outright fail the operation even when in fact there are more blocks to be hot removed in once. -- Michal Hocko SUSE Labs