From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FBBBC433B4 for ; Wed, 21 Apr 2021 08:49:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E4D616142B for ; Wed, 21 Apr 2021 08:49:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4D616142B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 67D0A6B006E; Wed, 21 Apr 2021 04:49:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 653A96B0070; Wed, 21 Apr 2021 04:49:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51BA66B0071; Wed, 21 Apr 2021 04:49:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 363956B006E for ; Wed, 21 Apr 2021 04:49:49 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id ED19818079ED8 for ; Wed, 21 Apr 2021 08:49:48 +0000 (UTC) X-FDA: 78055751256.15.3B6224C Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf16.hostedemail.com (Postfix) with ESMTP id 8827380192DA for ; Wed, 21 Apr 2021 08:49:47 +0000 (UTC) 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: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8827380192DA X-Stat-Signature: rjcq35cpdqsx9ctg4bx4jdo3jkosiohr Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618994987-276989 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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