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 C809DC4332F for ; Mon, 5 Dec 2022 18:07:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 503A88E0002; Mon, 5 Dec 2022 13:07:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3E08E0001; Mon, 5 Dec 2022 13:07:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37B0D8E0002; Mon, 5 Dec 2022 13:07:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 284E18E0001 for ; Mon, 5 Dec 2022 13:07:19 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F0116808CD for ; Mon, 5 Dec 2022 18:07:18 +0000 (UTC) X-FDA: 80209034556.03.ABBAE03 Received: from mail.cybernetics.com (mail.cybernetics.com [173.71.130.66]) by imf02.hostedemail.com (Postfix) with ESMTP id 824C780002 for ; Mon, 5 Dec 2022 18:07:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=cybernetics.com header.s=mail header.b=RKqDLauS; spf=pass (imf02.hostedemail.com: domain of "btv1==338c2aab3f6==tonyb@cybernetics.com" designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==338c2aab3f6==tonyb@cybernetics.com"; dmarc=pass (policy=none) header.from=cybernetics.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670263637; 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=RpLG6FuUPyOMHlETTijxTvENKLCXTVEl0Lq8W8zjYLQ=; b=JROFqHfvSCXYczjaeQ+QB6Zqb+Im+H5VhVaW2A8K0Zq02b13xou4kcNLk4Fxa2tj2txEcI 0VOuYRNDQvwp0rTGKT7MSfTMENR7YIEto5rehpj3rDjwWfphK6DnNbNSZHJGajgIkLaCId KTqj+mQdmDtefdkCCl6hVrkSYzRGasY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=cybernetics.com header.s=mail header.b=RKqDLauS; spf=pass (imf02.hostedemail.com: domain of "btv1==338c2aab3f6==tonyb@cybernetics.com" designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==338c2aab3f6==tonyb@cybernetics.com"; dmarc=pass (policy=none) header.from=cybernetics.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670263637; a=rsa-sha256; cv=none; b=5F5B9+HXwb16MZ/oHfjTH81v7adKxyw/vRiGdOIRdMaajA3eS3FeRsBswnfaxWPIudCgZk SwwwVRwmrsXaqbAWw8u/2YuzRpy8Anp/ugghQpCecR2JOpXvYxfKHe6WdvKPX7gMP3lvMd 2R21vGhMuzJr1OCRl31PcOkFO58tng4= X-ASG-Debug-ID: 1670263636-1cf43916c221f840001-v9ZeMO Received: from cybernetics.com ([10.10.4.126]) by mail.cybernetics.com with ESMTP id BowDeQFtfcmWyUgM; Mon, 05 Dec 2022 13:07:16 -0500 (EST) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-ASG-Whitelist: Client DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cybernetics.com; s=mail; bh=RpLG6FuUPyOMHlETTijxTvENKLCXTVEl0Lq8W8zjYLQ=; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc:To: Content-Language:Subject:MIME-Version:Date:Message-ID; b=RKqDLauSxncfqo0oPaW8 hTFWjoaPEZSKJp25k2V2a5MkhjSuOv3zbSOGKYEI4P/ZIUCZuX3ba9F2u0aEVAcwqqWwvXAQjmqRq Hw+ZN6ctq5ADesMMtzdj5uUrIZ6iuPl/5t62o89MDa8WW1OmFCFJTWMJw/7OjEdvev4hOHO8Dk= Received: from [10.157.2.224] (HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 7.1.1) with ESMTPS id 12356546; Mon, 05 Dec 2022 13:07:16 -0500 Message-ID: <8fc56daf-7f8d-b62b-b6bf-4da4ca87ea20@cybernetics.com> Date: Mon, 5 Dec 2022 13:07:15 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH 11/11] dmapool: link blocks across pages Content-Language: en-US X-ASG-Orig-Subj: Re: [PATCH 11/11] dmapool: link blocks across pages To: Keith Busch , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Cc: Keith Busch References: <20221205145937.54367-1-kbusch@meta.com> <20221205145937.54367-12-kbusch@meta.com> From: Tony Battersby In-Reply-To: <20221205145937.54367-12-kbusch@meta.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: UNKNOWN[10.10.4.126] X-Barracuda-Start-Time: 1670263636 X-Barracuda-URL: https://10.10.4.122:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-Scan-Msg-Size: 2390 X-Stat-Signature: w9qorjopjeo55hxh3cp6aiwhmdwdsbz6 X-Rspam-User: X-Spamd-Result: default: False [-4.42 / 9.00]; BAYES_HAM(-3.82)[94.50%]; DMARC_POLICY_ALLOW(-0.50)[cybernetics.com,none]; FORGED_SENDER(0.30)[tonyb@cybernetics.com,btv1==338c2aab3f6==tonyb@cybernetics.com]; R_SPF_ALLOW(-0.20)[+a:mail.cybernetics.com]; R_DKIM_ALLOW(-0.20)[cybernetics.com:s=mail]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[cybernetics.com:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; FROM_NEQ_ENVFROM(0.00)[tonyb@cybernetics.com,btv1==338c2aab3f6==tonyb@cybernetics.com]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 824C780002 X-Rspamd-Server: rspam06 X-HE-Tag: 1670263637-805048 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 12/5/22 09:59, Keith Busch wrote: > From: Keith Busch > > The allocated dmapool pages are never freed for the lifetime of the > pool. There is no need for the two level list+stack lookup for finding a > free block since nothing is ever removed from the list. Just use a > simple stack, reducing time complexity to constant. > > The implementation inserts the stack linking elements and the dma handle > of the block within itself when freed. This means the smallest possible > dmapool block is increased to at most 16 bytes to accomodate these > fields, but there are no exisiting users requesting a dma pool smaller > than that anyway. Great work! I notice that the comment at the top of dmapool.c describes the old design ("Free blocks are tracked in an unsorted singly-linked list of free blocks within the page."), so you need to delete or update that part of the comment. > struct dma_pool { /* the pool */ > struct list_head page_list; > spinlock_t lock; > struct device *dev; > + struct dma_block *next_block; > unsigned int size; > unsigned int allocation; > unsigned int boundary; > + unsigned int nr_blocks; > + unsigned int nr_active; > + unsigned int nr_pages; I think nr_blocks, nr_active, and nr_pages should be size_t rather than unsigned int since they count the number of objects in the entire pool, and it would be theoretically possible to allocate more than 2^32 objects. > @@ -199,22 +217,24 @@ EXPORT_SYMBOL(dma_pool_create); > > static void pool_initialise_page(struct dma_pool *pool, struct dma_page *page) > { > - unsigned int offset = 0; > - unsigned int next_boundary = pool->boundary; > - > - page->in_use = 0; > - page->offset = 0; > - do { > - unsigned int next = offset + pool->size; > - if (unlikely((next + pool->size) >= next_boundary)) { > - next = next_boundary; > + unsigned int next_boundary = pool->boundary, offset = 0; > + struct dma_block *block; > + > + while (offset < pool->allocation) { > + if (offset > next_boundary) { This is incorrect.  I believe the correct comparison should be: +    while (offset + pool->size <= pool->allocation) { +        if (offset + pool->size > next_boundary) { That should handle all the weird possible combinations of size, boundary, and allocation. Tony Battersby Cybernetics