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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D7C0C76196 for ; Sun, 19 Mar 2023 23:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbjCSXeA (ORCPT ); Sun, 19 Mar 2023 19:34:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjCSXdz (ORCPT ); Sun, 19 Mar 2023 19:33:55 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC70E19687; Sun, 19 Mar 2023 16:33:53 -0700 (PDT) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 289A11449; Mon, 20 Mar 2023 00:33:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1679268832; bh=l2p4ZDBneAwEGOLjso6EkHUNvJxzex1xBmjmxf7QRGk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aLcAv49AFw0OYSHbmnljKSRWyI2EloW7N3ryboN/dLV3MR3iF00oAyaxNlPwAjbTA TRmqA5Cwa86orRcNH7geU2YfHVDB4sIM45GO+ZPVBETuvTSCzeVyunEXiZOfr0a/Jr GPXVEd+Pz7pKmMVUVySEGmPANB3jS0kMSWW6MFxo= Date: Mon, 20 Mar 2023 01:33:58 +0200 From: Laurent Pinchart To: Hans Verkuil Cc: David Laight , Benjamin Gaignard , "tfiga@chromium.org" , "m.szyprowski@samsung.com" , "mchehab@kernel.org" , "ming.qian@nxp.com" , "shijie.qin@nxp.com" , "eagle.zhou@nxp.com" , "bin.liu@mediatek.com" , "matthias.bgg@gmail.com" , "angelogioacchino.delregno@collabora.com" , "tiffany.lin@mediatek.com" , "andrew-ct.chen@mediatek.com" , "yunfei.dong@mediatek.com" , "stanimir.k.varbanov@gmail.com" , "quic_vgarodia@quicinc.com" , "agross@kernel.org" , "andersson@kernel.org" , "konrad.dybcio@linaro.org" , "ezequiel@vanguardiasur.com.ar" , "p.zabel@pengutronix.de" , "daniel.almeida@collabora.com" , "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-mediatek@lists.infradead.org" , "linux-arm-msm@vger.kernel.org" , "linux-rockchip@lists.infradead.org" , "kernel@collabora.com" Subject: Re: [RFC 2/4] media: videobuf2: Replace bufs array by a list Message-ID: <20230319233358.GD20234@pendragon.ideasonboard.com> References: <20230313135916.862852-1-benjamin.gaignard@collabora.com> <20230313135916.862852-3-benjamin.gaignard@collabora.com> <20230313181155.GC22646@pendragon.ideasonboard.com> <86df05244d974416903e919d387a0a0b@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans, On Tue, Mar 14, 2023 at 11:42:46AM +0100, Hans Verkuil wrote: > On 3/14/23 11:11, David Laight wrote: > > From: Hans Verkuil > >> Sent: 14 March 2023 08:55 > > ... > >> Why not start with a dynamically allocated array of 32 vb2_buffer pointers? > >> And keep doubling the size (reallocing) whenever more buffers are needed, > >> up to some maximum (1024 would be a good initial value for that, I think). > >> This max could be even a module option. The kernel has IDR and IDA APIs, why not use them instead of reinventing the wheel ? > > I don't know the typical uses (or the code at all). > > But it might be worth having a small array in the structure itself. > > Useful if there are typically always (say) less than 8 buffers. > > For larger sizes use the (IIRC) kmalloc_size() to find the actual > > size of the structure that will be allocate and set the array > > size appropriately. > > The typical usage is that applications allocate N buffers with the > VIDIOC_REQBUFS ioctl, and in most cases that's all they use. Note that once we get DELETE_BUF (or DELETE_BUFS) support I'd like to encourage applications to use the new API, and deprecate REQBUFS (dropping it isn't on my radar, as it would take forever before no userspace uses it anymore). > The > current max is 32 buffers, so allocating that initially (usually > during probe()) will cover all current cases with a single one-time > kzalloc. Pre-allocating for the most common usage patterns is fine with me. > Only if the application wants to allocate more than 32 buffers will > there be a slight overhead. -- Regards, Laurent Pinchart