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 A0255C47DB3 for ; Wed, 31 Jan 2024 14:18:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C3336B00A0; Wed, 31 Jan 2024 09:18:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14EA36B00A3; Wed, 31 Jan 2024 09:18:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F313F6B00A5; Wed, 31 Jan 2024 09:18:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E0FD76B00A0 for ; Wed, 31 Jan 2024 09:18:37 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8801280D52 for ; Wed, 31 Jan 2024 14:18:37 +0000 (UTC) X-FDA: 81739811874.08.79E2B74 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 6353740009 for ; Wed, 31 Jan 2024 14:18:35 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf17.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706710715; 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; bh=GVg/mvySrOpTcWb/qKTVbqu/eDPqB8GJh+95d6mmLIw=; b=h70ei4SD4FTofjlZNPWKsavpzjLrW4moiyKiyUwZ8XT+1OxjFZe5BniAGYmQdD3j9qH29M mTLm4cDNvaHCpO/4p9q/hVv18esc2vWLrnxOy9OCW9oKF/5MziJpt5wXHS+0i96xQY+MgH gS3HEFs/Xb5ft26SUutWs3wXX/AfWVk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf17.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706710715; a=rsa-sha256; cv=none; b=tabjOKD63L6+wO7WnFnDKXHvoq/GamsbF3NtNWMj61Iet/Kejcw/Uo8rMU9lh3wWJ6Q9sm NehhYdivmpOv4y8Dj7SAvYnReACX9NgXkKGaTaQXuavR7q4YprpspLP0TJPkZ+/p7Kk4gF J1Qes/hEp4FvdNL/rDB43V1gClGC4QA= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5F9F4DA7; Wed, 31 Jan 2024 06:19:17 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 150DA3F738; Wed, 31 Jan 2024 06:18:28 -0800 (PST) Date: Wed, 31 Jan 2024 14:18:22 +0000 From: Alexandru Elisei To: Anshuman Khandual Cc: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com, pcc@google.com, steven.price@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH RFC v3 08/35] mm: cma: Introduce cma_alloc_range() Message-ID: References: <20240125164256.4147-1-alexandru.elisei@arm.com> <20240125164256.4147-9-alexandru.elisei@arm.com> <61a3dbb7-25b6-4f49-aa70-9a8aaeb53365@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 6353740009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6w9npqb8uwy3h987qi7cpmokua1pa5dm X-HE-Tag: 1706710715-453505 X-HE-Meta: U2FsdGVkX199Le1DrT62y+udlf85JDui+3k5BX7IkqToEcOh7Xn7D/pkCQ98i/gtzQg3d7KL3KEzR1F+4MC02fGJR0WQNrjs4EeIVPHalEjxGNkzFKQ2pG/ZstXXtqzwZ4wAF0+NB2avsI2MruuI99ASZ+aLUeDuWVyQ65ZvOPuRk3BXMGYxlz0Gw1ALklpQTQz5Z9SBfcZl7gRHqOFNBKJrOZ1Sh3MF9/CgVhc4XsjC/hQZvGVHWAjkZcJ5dssNNXIHfxaHeYR1H47fHoYobSu1IkRq4Y1vLsVTlWnq2f4/1Q2hWKC5wnRS+3sQhIBSpElLkfleFR4JxD38n8ByiqIvj+ueK3sRn2KdguG9lF7BH7shgaHsdZ2wJT4lRVmg27bfuVWPGftaQQZZIGIQGUHnSUCo9G8xPrI5JcX6DbHabKoQzOT6b7rmXERIHRlV1UN5QfSD9Rp08Ibs1dh3nGJa88cwQIWAogtOzFK8PqO8MvHz/Dnxh+o4DbXdbHWasFy7sfpDpejNdMTbrKxU1DMCYBnUnZG1BDyp2qgbk/nSIl3RbdJUzckRFe+8qWW054V1nWTm/x1OltN6totBxdX/c+bM9CzMs40e7uPBzQ2KhMZRfrnqnI0ut91t6CD0EhixgaDzzttN93riiO4iLkrocXnm/EsZ077phL5UAfMDxoh/rXnduFNYyBbN9tJigfZfBUGe/yTUMdte6JarQpNcRvtFlM/sdBzN5HAveRgfqgczWHE5wg8wEdwYgLAxbMOz02uYiY+z0QmD95lytlJrVPquBeMeV0Xnajwk+kASXoD/djMJM4fkUrQGMlv3Vs88llg5HMrUc5P+tmrLA7XLVzVtU6iN9maWkn2BK0LuhtPExDPk7rzF+T1Nm1AxBId5e298AzVbZ3QlQiPueiOWHPYBS1QikM2QEhVM3P5GsKvOAmqEjGxGR43VLAC0LAKNqvO5R+TA9ilM8l6 4oI9fTCw 4pwyfhXyMIBVW8Ch9VdLPJwyRna9EFc7tlB+OW79hT+7kFmFXtJru2OFLuq3+HYUNDEk31rX6vnuLGRUACrlWr9TEq0dHaXaPNU4au553NdnepQtoGKIxCCAp8xvb9rhNet9oQpFXUcwlzyiQZ0PG+y0nHryHhcIxXxjkQc3qQ3ymdZkv/4Jv9ReyC0z7auUl6pd4MccV83k2tQN8ok8LnG0+Y5Hm5WmafODefNUsQo1JIYM= 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: Hi, On Wed, Jan 31, 2024 at 11:54:17AM +0530, Anshuman Khandual wrote: > > > On 1/30/24 17:05, Alexandru Elisei wrote: > > Hi, > > > > On Tue, Jan 30, 2024 at 10:50:00AM +0530, Anshuman Khandual wrote: > >> > >> On 1/25/24 22:12, Alexandru Elisei wrote: > >>> Today, cma_alloc() is used to allocate a contiguous memory region. The > >>> function allows the caller to specify the number of pages to allocate, but > >>> not the starting address. cma_alloc() will walk over the entire CMA region > >>> trying to allocate the first available range of the specified size. > >>> > >>> Introduce cma_alloc_range(), which makes CMA more versatile by allowing the > >>> caller to specify a particular range in the CMA region, defined by the > >>> start pfn and the size. > >>> > >>> arm64 will make use of this function when tag storage management will be > >>> implemented: cma_alloc_range() will be used to reserve the tag storage > >>> associated with a tagged page. > >> Basically, you would like to pass on a preferred start address and the > >> allocation could just fail if a contig range is not available from such > >> a starting address ? > >> > >> Then why not just change cma_alloc() to take a new argument 'start_pfn'. > >> Why create a new but almost similar allocator ? > > I tried doing that, and I gave up because: > > > > - It made cma_alloc() even more complex and hard to follow. > > > > - What value should 'start_pfn' be to tell cma_alloc() that it should be > > ignored? Or, to put it another way, what pfn number is invalid on **all** > > platforms that Linux supports? > > > > I can give it another go if we can come up with an invalid value for > > 'start_pfn'. > > Something negative might work. How about -1/-1UL ? A quick search gives > some instances such as ... > > git grep "pfn == -1" > > mm/mm_init.c: if (*start_pfn == -1UL) > mm/vmscan.c: if (pfn == -1) > mm/vmscan.c: if (pfn == -1) > mm/vmscan.c: if (pfn == -1) > tools/testing/selftests/mm/hugepage-vmemmap.c: if (pfn == -1UL) { > > Could not -1UL be abstracted as common macro MM_INVALID_PFN to be used in > such scenarios including here ? Ah yes, you are right, get_pte_pfn() already uses -1 as an invalid pfn, so I can just use that. Will definitely give it a go on the next iteration, thanks for the suggestion! > > > > >> But then I am wondering why this could not be done in the arm64 platform > >> code itself operating on a CMA area reserved just for tag storage. Unless > >> this new allocator has other usage beyond MTE, this could be implemented > >> in the platform itself. > > I had the same idea in the previous iteration, David Hildenbrand suggested > > this approach [1]. > > > > [1] https://lore.kernel.org/linux-fsdevel/2aafd53f-af1f-45f3-a08c-d11962254315@redhat.com/ > > There are two different cma_alloc() proposals here - including the next > patch i.e mm: cma: Fast track allocating memory when the pages are free > > 1) Augment cma_alloc() or add cma_alloc_range() with start_pfn parameter > 2) Speed up cma_alloc() for small allocation requests when pages are free > > The second one if separated out from this series could be considered on > its own as it will help all existing cma_alloc() callers. The first one > definitely needs an use case as provided in this series. I understand, thanks for the input! Alex