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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88291C433FE for ; Mon, 31 Jan 2022 11:40:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 053826B0074; Mon, 31 Jan 2022 06:40:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1EFD6B0075; Mon, 31 Jan 2022 06:40:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D98976B0078; Mon, 31 Jan 2022 06:40:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id C538C6B0074 for ; Mon, 31 Jan 2022 06:40:31 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6DA0D95AF8 for ; Mon, 31 Jan 2022 11:40:31 +0000 (UTC) X-FDA: 79090389462.12.864C254 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id EEA5440004 for ; Mon, 31 Jan 2022 11:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643629230; 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=ogH8tr5MmhLoSwHbiS34920WI1vsm1WsqaDgKI7Z30c=; b=Wflj/33jwsO29B0Y0Y2b/ZEiZ1MCcwoTn70ELmGAQAN6aPZmuQL5yhPThGFwK1vZ8dDGN1 jGp+S6719CJwqsO4uUw2H3A0C0H31Jgt6uRJe76clV+RNL9gM+gtrHd1pFbkaVwejFtrBU EZ/IMGbTLh9ePcLRGkF0WKqnroWSIpg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-FtIdWM83MW-3-RH3jc09kg-1; Mon, 31 Jan 2022 06:40:27 -0500 X-MC-Unique: FtIdWM83MW-3-RH3jc09kg-1 Received: by mail-wr1-f69.google.com with SMTP id i25-20020adfaad9000000b001e01f5804abso2068377wrc.2 for ; Mon, 31 Jan 2022 03:40:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=ogH8tr5MmhLoSwHbiS34920WI1vsm1WsqaDgKI7Z30c=; b=uqKzC5IVnf80+o9tbci4Sw5Hd+IrIjCEuPycOWaRPCtr1I0XoeGpGHJRu2tEWowZaM rUwNIh0vQI3hLu4wFfWTzhON7XWwSqr6IJpBBZI9M4/eR8Evhyo8r9TRjgPR6O7TQJoc vxWXYZkEphWT+XjpFbWzWkZPvIgdtQ5fpta1UlqoFhf/b+mIr1L/tF6HJxDdn8MsHWdF hmey/8JkAz7kPUzgXp9S8yCx9QhBdAOdTOAD1d/VeuJduqvsfertHqvs8g+6j0Sgw5ij OvnOedLGQSJ968boux07UNb5iGKXCYAjmMEZLwDPJQxrWoNAGlUBWTp5OU8f4OVY9knb 5yOA== X-Gm-Message-State: AOAM533bwF9oUGrQR+MxxAwXnk6pGZxHykmJa0GU2zuYvCjquNskmMg5 t5VSABEgoc0TvGob1pr+klxScyiLyrobyg7LEeP5GSj/abpNHCpn9uqbBsx6UMe8CdEIs7+s5LP TLMna50OLgi0= X-Received: by 2002:adf:ec88:: with SMTP id z8mr16622995wrn.451.1643629226094; Mon, 31 Jan 2022 03:40:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJ8j4HMMvBrlazNr+erVXlYYgB0uAMFAO9IPuslT9L8r/fxEe19qSF8JXMWQWKAX8XvbQPdQ== X-Received: by 2002:adf:ec88:: with SMTP id z8mr16622972wrn.451.1643629225838; Mon, 31 Jan 2022 03:40:25 -0800 (PST) Received: from ?IPV6:2003:cb:c709:b200:f007:5a26:32e7:8ef5? (p200300cbc709b200f0075a2632e78ef5.dip0.t-ipconnect.de. [2003:cb:c709:b200:f007:5a26:32e7:8ef5]) by smtp.gmail.com with ESMTPSA id g4sm12997018wrd.111.2022.01.31.03.40.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jan 2022 03:40:25 -0800 (PST) Message-ID: <5788c8f5-8c2a-45c1-c374-1bf87c189c86@redhat.com> Date: Mon, 31 Jan 2022 12:40:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 To: Oscar Salvador Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , "Rafael J. Wysocki" , Greg Kroah-Hartman , Michal Hocko , Rafael Parra References: <20220128152620.168715-1-david@redhat.com> <20220128152620.168715-3-david@redhat.com> <20220131112909.GB18027@linux> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1 2/2] drivers/base/memory: determine and store zone for single-zone memory blocks In-Reply-To: <20220131112909.GB18027@linux> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: EEA5440004 X-Rspam-User: nil Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Wflj/33j"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf12.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: 5jcgbo17fr6we9ugohdjz53rq57ao6nt X-Rspamd-Server: rspam08 X-HE-Tag: 1643629230-997514 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 31.01.22 12:29, Oscar Salvador wrote: > On Fri, Jan 28, 2022 at 04:26:20PM +0100, David Hildenbrand wrote: >> For memory hot(un)plug, we only really care about memory blocks that: >> * span a single zone (and, thereby, a single node) >> * are completely System RAM (IOW, no holes, no ZONE_DEVICE) >> If one of these conditions is not met, we reject memory offlining. >> Hotplugged memory blocks (starting out offline), always meet both >> conditions. Thanks for the review Oscar! > > This has been always hard for me to follow, so bear with me. > > I remember we changed the memory-hotplug policy, not long ago, wrt. > what we can online/offline so we could get rid of certain assumptions like > "there are no holes in this memblock, so it can go" etc. Yes, end of 2019 via c5e79ef561b0 ("mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes"). > > AFAIR, we can only offline if the memory > > 1) belongs to a single node ("which is always the case for > hotplugged-memory, boot memory is trickier") > 2) does not have any holes > 3) spans a single zone > > These are the only requeriments we have atm, right? The most prominent core requirements, yes, leaving memory notifiers out of the picture. 3) implies 1) as zones are per-node. > > By default, hotplugged memory already complies with they all three, > only in case of ZONE_DEVICE stuff we might violate 2) and 3). > >> There are three scenarios to handle: > ... > ... > >> @@ -225,6 +226,9 @@ static int memory_block_offline(struct memory_block *mem) >> unsigned long nr_vmemmap_pages = mem->nr_vmemmap_pages; >> int ret; >> >> + if (!mem->zone) >> + return -EBUSY; > > Should not we return -EINVAL? I mean, -EBUSY reads like this might be a > temporary error which might get fixed later on, but that isn't the case. > >> @@ -234,7 +238,7 @@ static int memory_block_offline(struct memory_block *mem) >> -nr_vmemmap_pages); >> >> ret = offline_pages(start_pfn + nr_vmemmap_pages, >> - nr_pages - nr_vmemmap_pages, mem->group); >> + nr_pages - nr_vmemmap_pages, mem->zone, mem->group); > > Why not passing the node as well? The zone implies the node, and the prototype now matches the one of online_pages(). So if we'd ever want to change that we should do it for both functions, but I don't necessarily see the need for it. > >> +static struct zone *early_node_zone_for_memory_block(struct memory_block *mem, >> + int nid) >> +{ >> + const unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); >> + const unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; >> + struct zone *zone, *matching_zone = NULL; >> + pg_data_t *pgdat = NODE_DATA(nid); > > I was about to complain because in init_memory_block() you call > early_node_zone_for_memory_block() with nid == NUMA_NODE_NODE, but then > I saw that NODE_DATA on !CONFIG_NUMA falls to contig_page_data. > So, I guess we cannot really reach this on CONFIG_NUMA machines with nid > being NUMA_NO_NODE, right? (do we want to add a check just in case?) > Yes, on CONFIG_NUMA this is only called via memory_block_set_nid(). memory_block_set_nid() is only available with CONFIG_NUMA and calling memory_block_set_nid() with NUMA_NO_NODE would be a BUG. (before sending this out I even had a BUG_ON() in memory_block_set_nid() to verify that, but I removed it because BUG_ON's are frowned-upon.) -- Thanks, David / dhildenb