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 4FB54C433F5 for ; Tue, 31 May 2022 21:56:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3AD06B0071; Tue, 31 May 2022 17:56:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CED056B0073; Tue, 31 May 2022 17:56:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD6DF6B0074; Tue, 31 May 2022 17:56:04 -0400 (EDT) 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 AF3C06B0071 for ; Tue, 31 May 2022 17:56:04 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 828FF33B4A for ; Tue, 31 May 2022 21:56:04 +0000 (UTC) X-FDA: 79527396648.14.13798CE Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 0578AA003D for ; Tue, 31 May 2022 21:55:40 +0000 (UTC) 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 0032C23A; Tue, 31 May 2022 14:56:03 -0700 (PDT) Received: from [10.57.81.38] (unknown [10.57.81.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8C7883F66F; Tue, 31 May 2022 14:56:01 -0700 (PDT) Message-ID: <417bd608-0eeb-b3a0-31e3-8e241ab75e59@arm.com> Date: Tue, 31 May 2022 22:55:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 04/10] dmapool: improve accuracy of debug statistics Content-Language: en-GB To: Tony Battersby , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Tony Lindgren , Andy Shevchenko , Matthew Wilcox , iommu@lists.linux-foundation.org, Keith Busch , kernel-team@fb.com References: <9b08ab7c-b80b-527d-9adf-7716b0868fbc@cybernetics.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf15.hostedemail.com: domain of robin.murphy@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=robin.murphy@arm.com X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0578AA003D X-Stat-Signature: gt151soq743whci4brak9zx1rop9fxsx X-HE-Tag: 1654034140-683876 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: On 2022-05-31 20:52, Tony Battersby wrote: > On 5/31/22 15:48, Robin Murphy wrote: >> On 2022-05-31 19:17, Tony Battersby wrote: >> >>> pool->name, blocks, >>> - (size_t) pages * >>> - (pool->allocation / pool->size), >>> + (size_t) pages * pool->blks_per_alloc, >>> pool->size, pages); >>> size -= temp; >>> next += temp; >>> @@ -168,6 +168,9 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev, >>> retval->size = size; >>> retval->boundary = boundary; >>> retval->allocation = allocation; >>> + retval->blks_per_alloc = >>> + (allocation / boundary) * (boundary / size) + >>> + (allocation % boundary) / size; >> Do we really need to store this? Sure, 4 divisions (which could possibly >> be fewer given the constraints on boundary) isn't the absolute cheapest >> calculation, but I still can't imagine anyone would be polling sysfs >> stats hard enough to even notice. >> > The stored value is also used in patch #5, in more performance-critical > code, although only when debug is enabled. Ah, fair enough. On second look I think 64-bit systems could effectively store this for free anyway, if patch #2 moved "size" down past "dev" in struct dma_pool, such that blks_per_alloc then ends up padding out the hole again. FWIW the mathematician in me also now can't help seeing the algebraic reduction to at least "(allocation + (allocation % boundary)) / size", but is now too tired to reason about the power-of-two constraints and whether the intermediate integer truncations matter... Cheers, Robin.