Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp248581pxy; Wed, 21 Apr 2021 01:57:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvEx/GaDjyasUEShGonLwHfSLWq88C0LTsCgdelnis4qCbRcJWcEaJc4St9+SLIcV7LIZt X-Received: by 2002:a17:902:ec84:b029:ea:b28d:e53e with SMTP id x4-20020a170902ec84b02900eab28de53emr32173169plg.77.1618995446291; Wed, 21 Apr 2021 01:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618995446; cv=none; d=google.com; s=arc-20160816; b=ghkJK9WzU91yNzY73NRUTYZzhw75zLpF7vNh8rvF9phShtXHDFIkXOuHD6kS3tqaHv eyrjdAKL1XMZAkufkYt8N7Vewjl4akVVg1k4EQJoo89BDLiAdHVp5PoN31S+x7Ppn7SC mgvmCvUWYzMeRt+c2PsXoRdJ9PQjp5puAghohi73vp3yzhsnb0VUWyTw+QsfbhB63tNZ 25gIF4F/9SWO/ZM6aMPjXWnj2KXirs6c9lL7YKTVyA3HoXLUvTsv5J88EWNkCmBz9VBi 4e6JNYzdJjvHuOQXFpeuGnqVdwZN75XH0M2wPsNwpN/+z/YdXviEWyuZa3k0pVmVJ/Hs 1K2A== 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=gw6HYqbnkEiPHn0aOFHVdg1JNHJNPqDuI/KUq2+VNGc=; b=Ztg28IRCIhoYTqm6LyPlYjZ9mPbDJlZbADtsActh2jRbw9fm2rwEdpAtf+X9mhuksI 0iK0rjHPyOjVeDChFlnWOkdKM8E5S1mx6KV1L6JPgVm3Z27tPJHPtcR2Q+lcu9HI6gPy OgtS6mdfdBxxXt4HCWt9JC/iGRw4UWxx2Wvlw0J9RXBdb+vvGwJp9p02kIpx7utkmuAH Dt/90dpbnH0OG4ezWN0oV0OsIclUnsxcZKXT85SrGs8euthohsVDXAuT9EbtoLP5cer1 CO8gLp7qY5zdMg5GuNYiOpdvgmjWGRGUWrtdb3rqkSiU+h4GcwTweX1nnRIzGZg3K+pr QgcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=acH8fpQD; 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 m186si1782148pfb.145.2021.04.21.01.57.14; Wed, 21 Apr 2021 01:57:26 -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=acH8fpQD; 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 S236076AbhDUIjv (ORCPT + 99 others); Wed, 21 Apr 2021 04:39:51 -0400 Received: from mx2.suse.de ([195.135.220.15]:34590 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230250AbhDUIjv (ORCPT ); Wed, 21 Apr 2021 04:39:51 -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=1618994357; 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=gw6HYqbnkEiPHn0aOFHVdg1JNHJNPqDuI/KUq2+VNGc=; b=acH8fpQDYTnpf/3diOHmqm81+fUNhW4cxcdnsjR03KiaAqk+RXeW3lYiG2XQtB5xnk1u5O bSYO/tpoIbenZC4+JbPRmJIfaeUXGeti/+QySMKcmUJfbjp8OImj4CcY27Ah+qOAhGKIj3 mKcRghZiQ6sk3phfFRPCYXS0TWtfbEs= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 65021B0B6; Wed, 21 Apr 2021 08:39:17 +0000 (UTC) Date: Wed, 21 Apr 2021 10:39:16 +0200 From: Michal Hocko To: Oscar Salvador Cc: Andrew Morton , David Hildenbrand , 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: <20210421081546.GD22456@linux> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- Michal Hocko SUSE Labs