Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp283722pxy; Wed, 21 Apr 2021 02:57:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs1GRJqLgWI9QxYje7sDdhyL+tmdRO7YSfSHFW4sLQyJKPpvI3nlzc3WY9QPIOirLa6mMw X-Received: by 2002:a17:906:d8c:: with SMTP id m12mr32456441eji.347.1618999077066; Wed, 21 Apr 2021 02:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618999077; cv=none; d=google.com; s=arc-20160816; b=gt5oqW/w+oGrPLYx6NWOfO9DEYkUCDi+ZtPyJ8448W7ajzeRfE7/pKu95lFdZ7tmZJ 2JKqWcnSsbAfrgVWKnRiryPxwWyYHTKO7QYOmaWp9UrZ1XVz/b+XhkmTwr8Z9+UHNS3g +nv/4qbMN3yq+g4tc+K2uaNGQVhdgvb7TE+DZG7SFy6RNWzgMsDn1EM23xM6TvkFugl4 nEb4gIdV1k1g0eU4mWBauHJjz92YBbjoFn0pDjx2R5Zl/i8RcvgeTjwcSvZq8UT9UCTz Do4rhjZTfKedlBmXNKuzvbdCxwOi/fvcchXWvK8b38JOwcTxxJayrV+s2Npg7yURWWSr 8vOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=bcu+wrxn0FqEovyk3sgh/f7CXEAiST4+EaHgahYx5jU=; b=DDDQHtXa27ZL3JjImwtl3qaD8ueDcPf95V1L5fvuvZq6Guft5UtztD81CdPMK/WAnX Ls7CMR78ED4qEOG1PD/i1XsNq6acaHQSt/JhATHDDXE4YD/4hf9NzczZAhcaaPL5nIMh rtokmMpzJcNYRA560r9kK2rhoE5oJCRTGSoIKHMBL2wjC03sVEhl4h+4qEWoEAP/Ikcg eUkchC2pNUVzN5EWDOcLy/tA4gmnT28J9cGA1Zbd2x//oc/nrBcvDMB3R3Nw/tlcE4ID 0WUvtr5rNzRLVotgS1ZSd019Y7K6ZuD+TBYwZxsw1/tYtWXG8cZiitAj8JEQv1WAxRzL jnnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="G75aNtI/"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si1346006ejm.291.2021.04.21.02.57.34; Wed, 21 Apr 2021 02:57:57 -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=@redhat.com header.s=mimecast20190719 header.b="G75aNtI/"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237459AbhDUIp2 (ORCPT + 99 others); Wed, 21 Apr 2021 04:45:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45018 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237440AbhDUIp1 (ORCPT ); Wed, 21 Apr 2021 04:45:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618994693; 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; bh=bcu+wrxn0FqEovyk3sgh/f7CXEAiST4+EaHgahYx5jU=; b=G75aNtI/AT9JjLU0qrjoofMRDBtHOJEPEHfgPX57qkyiMzsP60Tj873lSqSBdRprIoBqvv GyiQ7wmhFHokVa0uyiqUbQjAYN/EVGspl4CGRFjCebbUizTFItVjAoAifQYwDerk2LGbns mKUbe2xYcQJD5lJ1YiA8ASUbFhhVlZA= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-551-EZFgsCQfMoGCuLAJhQ6uPg-1; Wed, 21 Apr 2021 04:44:41 -0400 X-MC-Unique: EZFgsCQfMoGCuLAJhQ6uPg-1 Received: by mail-ed1-f69.google.com with SMTP id c13-20020a05640227cdb0290385526e5de5so4581264ede.21 for ; Wed, 21 Apr 2021 01:44:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=bcu+wrxn0FqEovyk3sgh/f7CXEAiST4+EaHgahYx5jU=; b=r/yN9Y5Cfi52qFCtljVP/yKL2jUh7uBFHrjK3mHit87+RlKWqvccZI0EbQviXsYxgz 4yRMZf5X4HkA7D9Qb9SqmXVBqeY5kZ4nPqfWFNJDYVwonHIahsHwbkBN9d52sFVFOSX0 ISQiYhVbdPUCQ0GiJ63ELEiBnm1MNcJKs85q5clRHg+TQz7PHWFo2Ubpt6xfJx7yg1PK DCxXerwNW8ENt6kCi4tgx90QtoMRnOZNKj3FL33m3IfhDWSxg0hkdGqgaOv9mBmbKvQQ BS/Vn+prNZvcfIouubg3rnwXXdbYYyy0Dt+OTDTkcVo/u2q5IEfNMJyFCXOw7uTqPY1q Xppw== X-Gm-Message-State: AOAM531cFJGoOf8nUn5UHLG12n58nC4zU7huxSbV5cvrcrIDt7ZdeTdx wrEva/OLGoOVF8HBLpzuy4k+xvQwYXN/z7hI7sZIr2CNZSW0+YCpPP2BLpDMGSo3bAYP1Jr+2Cf 8e/LUfsoC1KQ61jA9OJ+VHeKeqcVO9+SDRDakgHUgRAh3Yg6YACX3ONHL5W+H7q/kEWYmPtgV X-Received: by 2002:a17:907:1b11:: with SMTP id mp17mr12776379ejc.1.1618994679864; Wed, 21 Apr 2021 01:44:39 -0700 (PDT) X-Received: by 2002:a17:907:1b11:: with SMTP id mp17mr12776357ejc.1.1618994679589; Wed, 21 Apr 2021 01:44:39 -0700 (PDT) Received: from [192.168.3.132] (p5b0c64b8.dip0.t-ipconnect.de. [91.12.100.184]) by smtp.gmail.com with ESMTPSA id c19sm2271296edu.20.2021.04.21.01.44.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Apr 2021 01:44:39 -0700 (PDT) Subject: Re: [PATCH v9 4/8] mm,memory_hotplug: Allocate memmap from the added memory range To: Michal Hocko , Oscar Salvador Cc: Andrew Morton , Anshuman Khandual , Pavel Tatashin , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210416112411.9826-1-osalvador@suse.de> <20210416112411.9826-5-osalvador@suse.de> <20210421081546.GD22456@linux> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Wed, 21 Apr 2021 10:44:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. So this should be handled separately in the future. -- Thanks, David / dhildenb