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 AB9C8C47258 for ; Wed, 31 Jan 2024 06:24:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2D946B006E; Wed, 31 Jan 2024 01:24:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB7146B0072; Wed, 31 Jan 2024 01:24:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D58366B0075; Wed, 31 Jan 2024 01:24:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C13A86B006E for ; Wed, 31 Jan 2024 01:24:33 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 66BCFC0BD2 for ; Wed, 31 Jan 2024 06:24:33 +0000 (UTC) X-FDA: 81738617226.17.60904AE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 489B480013 for ; Wed, 31 Jan 2024 06:24:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706682271; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PRNifjQgxNoMaMrTeswkgxni/PmWNot+pfvVcxusYGM=; b=QyEaRqky4Q3yUUWC/f24f2M5IxUqMN++3lWqJMoU3GGkPL++VyvFoOX2SMPRPOsBYDlLMC xZuKIZ8uZD3hjikgHjEt47EASklJ9wlP01j2qaRCQVQUwmAkaIWQnfGzoxdkHX5MALWqjM 87E0r/PbEm/eu4RKXfo7Oav3nvVu4Us= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf02.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706682271; a=rsa-sha256; cv=none; b=MwzQayyDeJe/xCWGkrnl7idMaVrtnNxxE3dkD/MDJ4ez66Fme4dO21Xz8XPpaAO3SkDc/M envPwx7U3fLpuQKa9ZWbwlkw+QxteebBeey3Ux4EXxrVVrg963YFQUAKXAVCYX/im+PR/N lEdkG+a/eUYXelESwfYfq5Sa4rWUhzA= 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 C95BCDA7; Tue, 30 Jan 2024 22:25:13 -0800 (PST) Received: from [10.163.41.195] (unknown [10.163.41.195]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 307963F738; Tue, 30 Jan 2024 22:24:18 -0800 (PST) Message-ID: Date: Wed, 31 Jan 2024 11:54:17 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v3 08/35] mm: cma: Introduce cma_alloc_range() Content-Language: en-US To: Alexandru Elisei 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 References: <20240125164256.4147-1-alexandru.elisei@arm.com> <20240125164256.4147-9-alexandru.elisei@arm.com> <61a3dbb7-25b6-4f49-aa70-9a8aaeb53365@arm.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: qaaepqwnjpktho1qmpnyppsfekfnfmqt X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 489B480013 X-HE-Tag: 1706682271-210037 X-HE-Meta: U2FsdGVkX1/TgoyktkSLnXfXWuMS+KumjcuNp7I8xkDbbouRV6hTK8KwXNqtYqOG38JKDG9pTTjrjfE6uBqPsDECD/O4X0eQJaI93jGyE08g6K1/wDcH7+Fc0vX0CQXqYVvsdKAOpkVuDp528VYd8308qRauLqXDUcNcPHEcP4rn6dbfTLZa+7687ncXPeF+Yuf+V2l7NV0IMsNsFGWL8b8PN15YIfaNm7AedITWZvzZ6H0Qw4BtFEDjWaBtk6tcalKITWQtAUOHisboRJEQGvoonnw91jUwTF0WdEmtY4Mr7h2cEhzXgPJI16BWelSHR+SEGdVR+HpzWoOD9Zx3kZxKcwRn/RyU6OLx9neFK8fsNj34CM9k5Qd3fwbKRamvmkvrn6AkxNk2RD4z70eOhQTzZwR7FI0/5jfptoqQw/x5cLDVPvf2jlIHoclWrIFVtMgQlntU7xdprVpWOfV0nslf4pL4kmZZGmDnH/4U76BRe0hKCmaA1v/LLFojo7cjef+0G4TKMCEJskRpWUMIdcZQM8wPZnR3grR2Tlg5SQjbmBI3aQUn5YtLo/x1ra/B880+WziV9dRgvyYBMBa9eV6hRxQ4v4t2qOODge9sb/8KA8EfxbpfqzkoKVTQiCjuElhvornIsFER1szJvhMHhPBLastSvJkC89tifMOLoAxEv/K7yIJI+DMc8VvwpyqujVhCeSaeJYn8B5DKY97WdipdDn6xnsj8kKaSp428Qh67FkULfAHlrVjfL/iFzHdPwNBOuUiae970SLywRvnylbfiCR/IO6I87U6cg10kvAOnYZpv4VvfiFGE5KJtx3sR5K93TIJTMsRkD3oDp2rRV3mavOkNve9gMAz2blFNTK8svx29LUetzta9KCSMqsKDRpO77NMY+l4NQ4TtmTKaR4Cnnwp8WhZD37KGrlkA7clhAxC7Au0+u5mhcaFWkSijWFQ37hD35TiS9/cat2b 9i4NvqfQ tLbKLgO3dZZx3JgEeCDbX4yzcalShdghY8kVIKzEAPLGOgRvpmMx24X/KeNqJ8Y4UoXAJgC3aRIEFH7TQuy/doBp92v+8+5gTGaaKsKmq1vr9VxpWpZZr/BUA9VFyg6KCoBPOAs+VIV+8Dt/a9oiFjy6XA9b1gJSds7Jphf6JFIEQlE1QIO7D6jJN6rdVD5u/6SyA4E1sBAwRFB0KUUpS0HOUudIwZebR36Xsyn026Ex6C0vMxgd5TiXjvjS9U6Sgt2aKEcklgbsrPc41b7w3V+zRfg== 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 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 ? > >> 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.