From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CDDE743A3C; Thu, 1 Feb 2024 17:33:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A1F3A42D3F; Thu, 1 Feb 2024 17:33:07 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 8B71840608 for ; Thu, 1 Feb 2024 17:33:06 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id AB40620B2000; Thu, 1 Feb 2024 08:33:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AB40620B2000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1706805185; bh=+qoaDtvAQPFGb0k7ojBFnjH/Py/Y8ytEx4gvkEyUNko=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TUQZPkaTlfVxSf9/pssxKrtKbhdrVvq9JUyvTJuRk2zqsm/BG8TIkiImKzNI0fGXH kTAh4033JehOsrh0h7ji1z4l2RgFIobzO3HSyvr9fdsWY/x5XP718ZVtw+N5H9hW1Q D/MKTsisje6kGVf6pfwpo0HHWiHPeWEA8Pe+pEYM= Date: Thu, 1 Feb 2024 08:33:05 -0800 From: Tyler Retzlaff To: Long Li Cc: Ferruh Yigit , stephen , Andrew Rybchenko , "dev@dpdk.org" Subject: Re: [Patch v2] net/mana: use rte_pktmbuf_alloc_bulk for allocating RX WQEs Message-ID: <20240201163305.GB13514@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1706150562-23248-1-git-send-email-longli@linuxonhyperv.com> <1706577181-27842-1-git-send-email-longli@linuxonhyperv.com> <20240130084352.56971000@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, Feb 01, 2024 at 03:55:55AM +0000, Long Li wrote: > > >> 'mbufs' is temporarily storage for allocated mbuf pointers, why not > > >> allocate if from stack instead, can be faster and easier to manage: > > >> "struct rte_mbuf *mbufs[count]" > > > > > > That would introduce a variable length array. > > > VLA's should be removed, they are not supported on Windows and many > > > security tools flag them. The problem is that it makes the code > > > brittle if count gets huge. > > > > > > But certainly regular calloc() or alloca() would work here. > > > > > > > Most of the existing bulk alloc already uses VLA but I can see the problem it is not > > being supported by Windows. > > > > As this mbuf pointer array is short lived within the function, and being in the fast > > path, I think continuous alloc and free can be prevented, > > > > one option can be to define a fixed size, big enough, array which requires > > additional loop for the cases 'count' size is bigger than array size, > > > > or an array can be allocated by driver init in device specific data ,as we know it > > will be required continuously in the datapath, and it can be freed during device > > close()/uninit(). > > > > I think an fixed size array from stack is easier and can be preferred. > > I sent a v3 of the patch, still using alloc(). > > I found two problems with using a fixed array: > 1. the array size needs to be determined in advance. I don't know what a good number should be. If too big, some of them may be wasted. (and maybe make a bigger mess of CPU cache) If too small, it ends up doing multiple allocations, which is the problem this patch trying to solve. > 2. if makes the code slightly more complex ,but I think 1 is the main problem. > > I think another approach is to use VLA by default, but for Windows use alloc(). a few thoughts on VLAs you may consider. not to be regarded as a strong objection. indications are that standard C will gradually phase out VLAs because they're generally accepted as having been a bad idea. that said compilers that implement them will probably keep them forever. VLAs generate a lot of code relative to just using a more permanent allocation. may not show up in your performance tests but you also may not want it on your hotpath either. mana doesn't currently support windows, are there plans to support windows? if never then i suppose VLAs can be used since all the toolchains you care about have them. though it does raise the bar, cause more work, later refactor, carry regression risk should you change your mind and choose to port to windows. accepting the use of VLAs anywhere in dpdk prohibits general checkpatches and/or compiling with compiler options that detect and flag their inclusion as a part of the CI without having to add exclusion logic for drivers that are allowed to use them. > > Long