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 CE5FEC3DA61 for ; Wed, 24 Jul 2024 19:49:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B4686B0088; Wed, 24 Jul 2024 15:49:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 563AD6B0089; Wed, 24 Jul 2024 15:49:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 451F06B008A; Wed, 24 Jul 2024 15:49:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 263816B0088 for ; Wed, 24 Jul 2024 15:49:09 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CA2E440B69 for ; Wed, 24 Jul 2024 19:49:08 +0000 (UTC) X-FDA: 82375684776.02.76CF37A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf12.hostedemail.com (Postfix) with ESMTP id 9817140010 for ; Wed, 24 Jul 2024 19:49:06 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Hz7riYQD; dmarc=none; spf=pass (imf12.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721850493; 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:dkim-signature; bh=bKaymvWd+2YEzVFAAsqY1lXeEDQaGzeOwBv90it87ow=; b=bw95gKFee3vEUHLyq5ZeGArhcN2VEtwAR5iq0NzBX5zBJKZLldA+qQkWrXu9WbYcbpb+CC 5+0oXZo/a8Ll+P4fvN8I/JfW/ARmIUFEglTdLgFT+rNiF+61/kW8StwIYbaXdJHLZhaBJJ c/crSxB/292vG10CcCbHjeXn2Vh4Wfo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721850493; a=rsa-sha256; cv=none; b=lytCjz3bC04/vX2x/yY551QIb0//rm9AqAi94LHOWBNTx7S6oryP5zogg+O1WOqQALPyCz 4sYczc5h55rScEBqKNsSzxpBaJGS6Q4BhAO7c0xJTD7EvEmmCoop4ooPxDEqHqRzTL2KHD diD4R2uJFJeTlkmVjYCpjRTKT48VY5Y= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Hz7riYQD; dmarc=none; spf=pass (imf12.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id D1D02CE1295; Wed, 24 Jul 2024 19:49:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09B3DC32781; Wed, 24 Jul 2024 19:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1721850541; bh=bAuv2q706kZUid9jIKKfKkE9lJuGodK9LcIf+XB9LZc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Hz7riYQDSUckkaoEJSrhSqPMUslc5x+b5z+sD7AjssqmaKHe6VjXcXrLNayo5E+XC wN8y4Hn2EJkG8qmhQwrFdZK248kaA33AHYa2dYNbxTq4TJKRU2XeIxdNVWy1fM2mQo C201sS5RnU+N93dseoF/bxPSriFDOnRV+/ykKL9k= Date: Wed, 24 Jul 2024 12:48:45 -0700 From: Andrew Morton To: Frank van der Linden Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/cma: export total and free number of pages for CMA areas Message-Id: <20240724124845.614c03ad39f8af3729cebee6@linux-foundation.org> In-Reply-To: <20240709163053.2514760-1-fvdl@google.com> References: <20240709163053.2514760-1-fvdl@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9817140010 X-Stat-Signature: 3556kpw1fh9ejzotekbri96r9epceres X-Rspam-User: X-HE-Tag: 1721850546-203205 X-HE-Meta: U2FsdGVkX1/ltublVGiYJEbQSeQZjjAo/ncX8uLhKrTIjBHOrSo7Bsyt9orgAc+rvs0Ny65lLSs8guEpjLyD0Dll4Gy+PkWGQ9B5tSIFFF0MOhu+1AlNtmuKu7XjPeZp9IWWCVailYptstwXysbx10HD/4GtzmA9yrq0VNTtmqpM3glSbGoPk9hQNjMysrqjsadhVXkZPzHwev1zUBZM6HE+083bchKBwbno1WYeKZk4zyK8jc7POw0ALJU+GyC4EIAQKlYsr7IQCMkkj/RITxk73PGOV+BEXEv9aOjm+mKbrg9/MSIZB5UWLAY8UBD1Uxyi95TEeHmcYYJMsb9pgHPGOwyyiHvnXoS4DQ/EyJo/nm+0gkZTrc2NQLcd0XPQW7pH/5kkSvRQGh8ISgqWJ+pHfY88TRhk8kWcU4F2B11yWdGUc8kT+EmRgokw5WVTemictAUXcZnKuLf1s5Cn8FTxuJTGbFHxcvafzsgmZTzPAFphGUPz6EWK4SrGl7ShsNYs7E2vxuwfTkBcfq3i2hDtEY3vFW+q8ljM+kl3Ai1Ij7pwh/c3bYJHmfeqaY6NkTot88ea/6KVGnIZGwYCxvwIqotjqITRzOgIKrbBOHuvF1F2oweUlcgozL3jubWP97np1LnQFcO22fsuYTKUx594Vs/LLzwayz8qgOFqYjMgSJm4Qi3eZc4I3TVEM1zii67/VotAfZ1DZWX3xzqTd/Cn8pjdUoLn5evtssPMDqNsRRtC7OkoVyG9GwlhPz6GknowqVuSPmN9OQDDgzSQG6vFULRVAL982o+ykDZvYskYDrSDDYVnZRLf4uDL7guIAKncO0Pwtkp/rUGjNg/tlUU1S00ypJ5mqWsgQaT4m2JXS/Rowiy4P0Jd8W+wJP5KAYHOg2tVhChlFcu3bE2rY0ecTBieV3BTm40yvwFVMpNIYoMQTM9DbteTkqTs2hDSDVLna8hIcPorQzn+Yd9 IsGevT7L WjwrYoKo8uXjJxRtpMgwn50SGaylq129lHsykAPs9nzfEICcvMD2AROl95CT44M2vEP8yyfyZK/Mwr0tXQZZ7X1+5a9VUAUy0y+fexe5Bs5rJjlxZtV7cIeJ8AcguAz+N9u90iS1Ve+vWY9chvXyGjqbTxGoAKzhzQUqtbcnmfoRVsd4Gq/Qy7YHhWGqhUdP1m+DsExt1PPNDpBq3TEnWqQw9+SzWCoAZdRkMUnaEg5cD0EB+MFNFzcLzo4cM+fyKCtpHGhXtSg8OmZd+qa5VtZRcFw== 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 Tue, 9 Jul 2024 16:30:53 +0000 Frank van der Linden wrote: > In addition to the number of allocations and releases, system > management software may like to be aware of the size of CMA > areas, and how many pages are available in it. This information > is currently not available, so export it in total_page and > available_pages, respectively. > > The name 'available_pages' was picked over 'free_pages' because > 'free' implies that the pages are unused. But they might not > be, they just haven't been used by cma_alloc > > The number of available pages is tracked regardless of > CONFIG_CMA_SYSFS, allowing for a few minor shortcuts in > the code, avoiding bitmap operations. > > ... > > @@ -382,7 +383,7 @@ static void cma_debug_show_areas(struct cma *cma) > { > unsigned long next_zero_bit, next_set_bit, nr_zero; > unsigned long start = 0; > - unsigned long nr_part, nr_total = 0; > + unsigned long nr_part; > unsigned long nbits = cma_bitmap_maxno(cma); > > spin_lock_irq(&cma->lock); > @@ -394,12 +395,12 @@ static void cma_debug_show_areas(struct cma *cma) > next_set_bit = find_next_bit(cma->bitmap, nbits, next_zero_bit); > nr_zero = next_set_bit - next_zero_bit; > nr_part = nr_zero << cma->order_per_bit; > - pr_cont("%s%lu@%lu", nr_total ? "+" : "", nr_part, > + pr_cont("%s%lu@%lu", start ? "+" : "", nr_part, > next_zero_bit); > - nr_total += nr_part; > start = next_zero_bit + nr_zero; > } Can you please explain the above change? > - pr_cont("=> %lu free of %lu total pages\n", nr_total, cma->count); > + pr_cont("=> %lu free of %lu total pages\n", cma->available_count, > + cma->count); > spin_unlock_irq(&cma->lock); > } > > @@ -446,6 +447,10 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > > for (;;) { > spin_lock_irq(&cma->lock); > + if (count > cma->available_count) { Right here would be a nice place for a comment? > + spin_unlock_irq(&cma->lock); > + break; > + } > bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap, > bitmap_maxno, start, bitmap_count, mask, > offset);