Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6458944rwb; Mon, 5 Dec 2022 12:40:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6FmC0o4w5ZPM4amayBCpk7K1WoIuL4exc2lLRK1lqGZKG1Ugm+kQYAY41Vmf+zx8qt20c0 X-Received: by 2002:aa7:9acb:0:b0:577:1f5f:cc28 with SMTP id x11-20020aa79acb000000b005771f5fcc28mr3101934pfp.16.1670272800940; Mon, 05 Dec 2022 12:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670272800; cv=none; d=google.com; s=arc-20160816; b=eWWIu2NJjWTy8uKjrFGYsx3/wl01CvElXuS/rsuFLkRPmRAtznaWfIstqPcGZOrvHf /8mY1+cD6iHX0aUZNjxyAVGm0107V0ItDtVQUw81WSZLzzdKrigIBQj2gIMblhx2G1eW acVYGiDzwkggE9fjUPl7FyUhp6wm8ENU5aMshNeii59i/myJRGbsSi/RuVQPR1AnQkDX BgcKu/H4IuNzmpviFHDFbg/40x+mihMS6cuCGX9jYaTu3VzBoOSXVdXqrVx78YFIpFrH MKZyJ/yBUIu915dYIfkckFra0sGpXTFdgiDarb7M+BvzMIQLTca/k4T0TnwG691unxAa xdDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=RpLG6FuUPyOMHlETTijxTvENKLCXTVEl0Lq8W8zjYLQ=; b=T/IVEMoTYiXHTbwjAECI56fhdXb/zxSVs25x6Fo8B+LIv0V7kNPOHIJJryXGIPniyu yOz6Hw1bdIPX4tiLx9rHMP69nmR4p9HYjn9FddKb/HFX+XAImGI/J8thJoEF4UiyX55f SmnCY4NTn0Iji3TnirYyXez+UL440ag0tYJNQKWqys014fYBBrxCF0NxW6uCWnzt7rVS vqnI3/WZDgMx1vwGIlXa+lEfHgN1JhWcB1PG5DY+xbBnHh/zEUsnu5j7T1JjCN6hlSFw QIOp4egXoyykgkG9d7SBztxTdyF6QBBhj3dILU3gAGPb1VVSjdxWU5JABtQyRzSAvn+z 4scA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=RKqDLauS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ix17-20020a170902f81100b00174b83659fasi14362403plb.502.2022.12.05.12.39.50; Mon, 05 Dec 2022 12:40:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cybernetics.com header.s=mail header.b=RKqDLauS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cybernetics.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232119AbiLES5t (ORCPT + 80 others); Mon, 5 Dec 2022 13:57:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232965AbiLES5n (ORCPT ); Mon, 5 Dec 2022 13:57:43 -0500 X-Greylist: delayed 3018 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 05 Dec 2022 10:57:37 PST Received: from mail.cybernetics.com (mail.cybernetics.com [173.71.130.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 280D4F62 for ; Mon, 5 Dec 2022 10:57:35 -0800 (PST) X-ASG-Debug-ID: 1670263636-1cf43916c221f840001-xx1T2L 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-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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