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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F4E4C47258 for ; Wed, 31 Jan 2024 14:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/C2D5DcVzagIlw0t9P8JtFw1Y09i1OQ56DajFChFr2c=; b=KZ/CT+dMbRjdV5 aVG8Dk3PQXGSbvajwnYvpSlJFzz7qr8AxjgAZ2bTl9Ae1FifDcBeBgVVfQc2G1FSOQaJm556hudGr fQqDwaD03ZiF9Zf+yYLzR7TDDoufVgBMGjXZMB+6gMzKLzwyHQgZ8gXYgwqggUsXmDb9XW8JGgD95 qJwde3XPRluuqmA8E6zptacXFYpdUHyhfjE4OLP7uB/w0l2+2Zp7aJzAyIR9Qrm6a0FZM2bdOXbtN 1h+Ng9lFQ+qahFg0LB+XvqRtcyjivsjMndLs7o81kmGJUFKxn5utSISlXmQuOmsq3z6EMpGVb6Jyr jSrfuTYff0vRqg/4uzcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVBQF-00000003qNN-3BmO; Wed, 31 Jan 2024 14:18:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVBQC-00000003qLv-3ABb for linux-arm-kernel@lists.infradead.org; Wed, 31 Jan 2024 14:18:38 +0000 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_061836_918667_77C6CCED X-CRM114-Status: GOOD ( 37.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel