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 80531D5CCB5 for ; Wed, 30 Oct 2024 14:59:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 129576B009B; Wed, 30 Oct 2024 10:59:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D9CB6B009D; Wed, 30 Oct 2024 10:59:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E957E6B00A1; Wed, 30 Oct 2024 10:59:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C34E56B009B for ; Wed, 30 Oct 2024 10:59:46 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 789E3140AD5 for ; Wed, 30 Oct 2024 14:59:46 +0000 (UTC) X-FDA: 82730577006.25.639D785 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf09.hostedemail.com (Postfix) with ESMTP id 541FF14000B for ; Wed, 30 Oct 2024 14:59:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=lCro446V; dmarc=none; spf=pass (imf09.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.51 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730300329; a=rsa-sha256; cv=none; b=F3qLe3QuEgkIK0qlNkgH+uGfsEjlgeK9IHAAhYhwa3b+FoYSGSIhqu3W/Sp994NSGVOpRE IRhjZt7y6fFVo0GDo6f0fGAuwcugUWzaiKky3tv2e7voe7HFnVNVUCWW2s7e2/rRN010yM 3kqvDROrgks79yEn6H3AeiShInPvUsI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=lCro446V; dmarc=none; spf=pass (imf09.hostedemail.com: domain of gourry@gourry.net designates 209.85.219.51 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730300329; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1CRNigufEv4srYMK7CzZ+n/1hKhvYmg+07IbXIIY6zQ=; b=TdAEN8X6zCBigxR2jQndPwGCq/bvQalIMWw0k7pf0xn+Rr1t+ggju2NjIWniPSXeo+F0+3 dP/aOSyYgJUUqDTOtO4qGN/9eoUnEbUZdz8ZOZZlNKzjPhqicxg21wV9nW604Bl1k6PVKs cpiLDXEU0c3zxQ0iNGKNA98dHwg8aCk= Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6cbd00dd21cso39675446d6.3 for ; Wed, 30 Oct 2024 07:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1730300383; x=1730905183; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1CRNigufEv4srYMK7CzZ+n/1hKhvYmg+07IbXIIY6zQ=; b=lCro446VDYJxv6Jd9qifgxN6IsI8ed8244UtJM6g8w1o0eY+qmQ9i0uiZjktTnM2eZ gmdoeqfraNqdaAW0RAv80vWovcub9IYaW1YxQrt2JyCsj2cwaTQIQ0onr/DbcYkajuMV ZQJVRVkI0LVSaHTf2FvWvsQ94dzQQYEG1DQrLqPxE5RoREgBJYe8XlpLvTVtvIbiOJTw j6is+0Whd3SnE+B6HnYLtYeSG27Q1JkRNADdvh91QAz2HjTW35BZ1fYcpjMHgmKv1Ztm lf/MFRjoCZxBRkiRE9TxBVdVkNC2Cigp35i1q3gF/tJTwPb941YgHf6aZtCR5QGTydFI hbBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730300383; x=1730905183; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1CRNigufEv4srYMK7CzZ+n/1hKhvYmg+07IbXIIY6zQ=; b=LNnwvlA5OfOjCYUsXboNAeMMO4IcLax+qfQbBc5ggkXKVESwGFbXDhLkkRYKqPT1rh CJtvQZBuQoN1/n7FrAT55GADfjX3CWtHBsfrRk0BH3cpsrncNiulzD7lhzuezqhGeFdL P8rxQHCytZ9ocZuCBfMO85AH1vK/NRb/IqIWLAGP7YuP8D8zE2TwgefMfNG1R0jx3S33 X7wpLB4n4CPdr2qtLlgNoXyLj3798kzseyqloCiPSufNcueQ/RTpBotmEP3fPYuK8Sy0 OguRTiIfRj9p50p0/md/Dp2sq81J2BLVvilh9y+loeoi3h6CTQhqcHcCNw1a6naOSffn gcPg== X-Forwarded-Encrypted: i=1; AJvYcCUSpIqV0pe76nwYBKUXwN+nq0fHUrl3+U2m5bNNY6N1MqPDzlr6gJGU/9geX4GzqSNsy/5SmTdIvA==@kvack.org X-Gm-Message-State: AOJu0Yw2CkjxyJipyo5CkR+nEj+sV1H1E0kIbJaZu836INgBypHQaH7F SaNx9jYRNW7h1t7GIxFTsOXLNpdNDkh2WleirPaBZUYVUmoo0taPYwHgiQEt668= X-Google-Smtp-Source: AGHT+IEV7l+Y+OcHF3D5iHR7Q3RlAhw7sBOVYB5E6ILrTizIrARGpPbdx8snNJXXQLRSYzX4Yuru7A== X-Received: by 2002:a0c:f409:0:b0:6cb:c6d2:3567 with SMTP id 6a1803df08f44-6d345fae094mr34561776d6.3.1730300383356; Wed, 30 Oct 2024 07:59:43 -0700 (PDT) Received: from PC2K9PVX.TheFacebook.com (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d179a09498sm52532166d6.93.2024.10.30.07.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 07:59:43 -0700 (PDT) Date: Wed, 30 Oct 2024 10:59:48 -0400 From: Gregory Price To: David Hildenbrand Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, Jonathan.Cameron@huawei.com, dan.j.williams@intel.com, rrichter@amd.com, Terry.Bowman@amd.com, dave.jiang@intel.com, ira.weiny@intel.com, alison.schofield@intel.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, rafael@kernel.org, lenb@kernel.org, osalvador@suse.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, rppt@kernel.org Subject: Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size Message-ID: References: <20241029202041.25334-1-gourry@gourry.net> <20241029202041.25334-2-gourry@gourry.net> <55df76a9-afa3-4dc0-a7f9-ff9b6f139448@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55df76a9-afa3-4dc0-a7f9-ff9b6f139448@redhat.com> X-Rspam-User: X-Rspamd-Queue-Id: 541FF14000B X-Rspamd-Server: rspam01 X-Stat-Signature: 7toecb9uwxwrxhgcyfndrzg5aiuuz1sz X-HE-Tag: 1730300366-466768 X-HE-Meta: U2FsdGVkX1+7mnMbZHFrmA7nXj4S3238340nk+3bsDl+VcDWyo2+YP0r7JLTYReNueYu297tM1cHVMgDVabapS8jAy3pZFaKH/jodpt9mPa46mBJbrb42zS351PlvmcZg6mtY6t6DoV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YXb2m4D8N1XZLTeXpSOqa/p60cHzbS/LsADo86kMJ4sm9iW/swOZesXgx1y4MwIZoTbZ1AIOvVYRay2Kh5k6HqyCtXFtnSf7OjecNiG8WOsdyStWPKSn9xJzcALhNLN7ND/1FuHybw6gKP9qXteQ2ghEkjWcGifRBJ/AeR0EGBZqrh9k1H+V5dvx/5Iys558ul9UCBB5qFBdRNEmiV8P1EThszGR 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: List-Subscribe: List-Unsubscribe: On Wed, Oct 30, 2024 at 11:25:33AM +0100, David Hildenbrand wrote: > On 29.10.24 21:20, Gregory Price wrote: > > Hotplug memory sources may have opinions on what the memblock size > > should be - usually for alignment purposes. For example, CXL memory > > extents can be 256MB with a matching alignment. If this size/alignment > > is smaller than the block size, it can result in stranded capacity. > > > > Implement memory_block_advise_max_size for use prior to allocator init, > > for software to advise the system on the max block size. > > > > Implement memory_block_probe_max_size for use by arch init code to > > calculate the best block size. Use of advice is architecture defined. > > > > The probe value can never change after first probe. Calls to advise > > after probe will return -EBUSY to aid debugging. > > > > On systems without hotplug, always return -ENODEV and 0 respectively. > > > > Suggested-by: Ira Weiny > > Signed-off-by: Gregory Price > > --- > > drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++ > > include/linux/memory.h | 10 +++++++++ > > 2 files changed, 58 insertions(+) > > > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > > index 67858eeb92ed..099a972c52dc 100644 > > --- a/drivers/base/memory.c > > +++ b/drivers/base/memory.c > > @@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev) > > kfree(mem); > > } > > +/** > > + * memory_block_advise_max_size() - advise memory hotplug on the max suggested > > + * block size, usually for alignment. > > + * @size: suggestion for maximum block size. must be aligned on power of 2. > > + * > > + * Early boot software (pre-allocator init) may advise archs on the max block > > + * size. This value can only decrease after initialization, as the intent is > > + * to identify the largest supported alignment for all sources. > > + * > > + * Use of this value is arch-defined, as is min/max block size. > > + * > > + * Return: 0 on success > > + * -EINVAL if size is 0 or not pow2 aligned > > + * -EBUSY if value has already been probed > > + */ > > +static size_t memory_block_advised_sz; > > Nit: if everything is called "size", call this "size" as well. > Mostly shortened here because if (memory_block_advised_sz) memory_block_advised_size = min(size, memory_block_advised_size); is over 80 characters lol. Happy to change if you have strong feelings. > > +static bool memory_block_advised_size_queried; > > +int memory_block_advise_max_size(size_t size) > > Not that memory_block_size_bytes() uses "unsigned long". I don't think it > matters here. Or could it on 32bit? (I assume that code will not really > matter on 32bit) > ack > > +{ > > + if (!size || !is_power_of_2(size)) > > + return -EINVAL; > > + > > + if (memory_block_advised_size_queried) > > + return -EBUSY; > > + > > + if (memory_block_advised_sz) > > + memory_block_advised_sz = min(size, memory_block_advised_sz); > > + else > > + memory_block_advised_sz = size; > > + > > + return 0; > > +} > > + > > +/** > > + * memory_block_advised_max_size() - query advised max hotplug block size. > > + * > > + * After the first call, the value can never change. Callers looking for the > > + * actual block size should use memory_block_size_bytes. This interface is > > + * intended for use by arch-init when initializing the hotplug block size. > > + * > > + * Return: advised size in bytes, or 0 if never set. > > + */ > > +size_t memory_block_advised_max_size(void) > > +{ > > + memory_block_advised_size_queried = true; > > + return memory_block_advised_sz;> +} > > + > > I wonder if both should.could be "__init" ? So they could only be called > from __init ... which sounds like the tight thing to do? > Was thinking the same thing in another thread, will go ahead and change it. > Acked-by: David Hildenbrand > > -- > Cheers, > > David / dhildenb >