Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2776784rdb; Wed, 15 Nov 2023 10:07:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYT2k81tCBDBbPx3psMRZHBBJTLCLGdsjZqkU8JXsZNkI1GvuFkuQxAivZHFg7hKnucqNX X-Received: by 2002:a17:90b:1a89:b0:283:2805:7c7f with SMTP id ng9-20020a17090b1a8900b0028328057c7fmr8916958pjb.0.1700071654204; Wed, 15 Nov 2023 10:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700071654; cv=none; d=google.com; s=arc-20160816; b=ycYxClo/6gozDk/9p56PWNu8uRuX92gm4y31Ax6jSnNq9C6WurAs3YfZqhmsqD7fwA Fh0UoECwkL/NwZioixinOR0brJfpsIfyKt/io3vxQ004vHa5uPdoaZFWoZ5WhZ1OXrv4 yBeLYxFphqTFHpZblK+Da8sKITMYv4na1niftlAHNQUbaETJo6VYqRIkqLcVlBEoCG46 imTkn1GhYVaYueiAW8edyBWwe8ktXmh+NNrySjDN1ZzLArSPBzQf7ejEuSmwtnXRxHTr CeLnHDHkikht+wYmWs8A4Q00pMZkY0DjFkSSktaForoIvbBOGmm8Ltu28Tf6OzsGTNGp GiAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=237jqdz3sNQ/lMkcIJ++z3uG+l/JTotWsahyw09GVyw=; fh=tyyQaih5D8glEhhLy2ShZ3M5aIllraoBu5zVDuA0b7Y=; b=gfFaDSkHdOoA5YHrJvWn0TX1LBWkKX0bKxchy1cUkYEY+XzLylcLH2rD3bZfPesZeg oKjWHDnu/2kJBfq497x96qWp69xFUYdXSq8OwE26Xn+ngC87jFG9wNVTSTy46Z/iQfbU 0c5H18dZMQo4BQIQh/eeuClwFro+GFbtbUK2PODfeAHReia7HVsCiiQPR84bpQF2L/N6 EpuZC7bHPcFvZKGlo0hgVpmg9mABQslBuSMjrTSsEfSo9V1EVIyYeZbGp/uAERyXezfA dOU48OCp7q949CBKlETvLMtCxUh/0F10i+HtD0B301cagL6/NTP2kOdHFrOSCEzmmvj8 DrUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q9mSL6RO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q7-20020a17090aa00700b0027491bac826si220762pjp.140.2023.11.15.10.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 10:07:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q9mSL6RO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B1D1A8061369; Wed, 15 Nov 2023 10:07:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229630AbjKOSH2 (ORCPT + 99 others); Wed, 15 Nov 2023 13:07:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjKOSH1 (ORCPT ); Wed, 15 Nov 2023 13:07:27 -0500 Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6641A4 for ; Wed, 15 Nov 2023 10:07:23 -0800 (PST) Received: by mail-vs1-xe2b.google.com with SMTP id ada2fe7eead31-45f3b583ce9so707514137.0 for ; Wed, 15 Nov 2023 10:07:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700071643; x=1700676443; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=237jqdz3sNQ/lMkcIJ++z3uG+l/JTotWsahyw09GVyw=; b=Q9mSL6RObvk6NyMJ1igdQ8hfCosR6lmrelkQbqqR+H+GnmVt59tRWJw+AjOk0PR/Pz D6wVNaD7HHExG9FLMFuxKw2ciFODZyAGHVgdOw/97eG3koqiQnvz+zxmnEbliXMXekub y59fkRzHXu5tm+oHa0gMKewrmCAxTcM+uqST3xDY/8zc32h5IOazcIJlwx0R3zXJcODO 1thEyHdOuEGc4HYsx9Wrub9C5Jw9noT49u0nZwC/ngaF9aZzVjFbIMxioWk09SE0lTgz Y2Rvb4onBis5vLb1e2tIPxbOanq/IjLJ2SfL4fxyz/6CvkvfkCWHtd1lkUyuIgAVJa9T MxpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700071643; x=1700676443; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=237jqdz3sNQ/lMkcIJ++z3uG+l/JTotWsahyw09GVyw=; b=AghWmVZCQ/mTv+2D+43ahXJtfR5kXU+SrSbnRC9UItLF4IV7NdbilCOo7Oq59qkhKz UvimMGKtxzuZWa9Ux0gQPiKDGG81LDYDug6IpPgMi00zSDgAKsXgjid9HN0WAFFzfUbP n6x4aawCNDlSrtkKsanpaX9psLzQ6iSjor+MIPk8Wxmp7d0fS4tq8UkoZ7FajWGOVTkA t9KzziqYAf6ytLCwgE5XzcE0U313FfSL5u1H8UUUESW/HqHXhK+I4Jqo0XeqSOfrnR9H CS+eLHDKbfiT9KGlVIHjS2R6Tmq0WZZdyjmMr5Z47RskUJlGnFzhPoV0IfaPWnBZt0ca 2Zrg== X-Gm-Message-State: AOJu0YymHbuTr2T1+X9fqXqQU1tZNUKhhwzUD6/W6SlB3rIXXyAPoFmb 3hJzSSMS5X4XXrA7f4+sXEuVEE+oPgUslbYeI6Zx2w== X-Received: by 2002:a05:6102:5c5:b0:452:6d82:56e3 with SMTP id v5-20020a05610205c500b004526d8256e3mr4378226vsf.6.1700071642710; Wed, 15 Nov 2023 10:07:22 -0800 (PST) MIME-Version: 1.0 References: <20231113130041.58124-1-linyunsheng@huawei.com> <20231113130041.58124-4-linyunsheng@huawei.com> <20231113180554.1d1c6b1a@kernel.org> <0c39bd57-5d67-3255-9da2-3f3194ee5a66@huawei.com> <3ff54a20-7e5f-562a-ca2e-b078cc4b4120@huawei.com> <6553954141762_1245c529423@willemb.c.googlers.com.notmuch> <8b7d25eb-1f10-3e37-8753-92b42da3fb34@huawei.com> In-Reply-To: <8b7d25eb-1f10-3e37-8753-92b42da3fb34@huawei.com> From: Mina Almasry Date: Wed, 15 Nov 2023 10:07:11 -0800 Message-ID: Subject: Re: [PATCH RFC 3/8] memory-provider: dmabuf devmem memory provider To: Yunsheng Lin Cc: Willem de Bruijn , Jakub Kicinski , davem@davemloft.net, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn , Kaiyuan Zhang , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet , =?UTF-8?Q?Christian_K=C3=B6nig?= , Jason Gunthorpe , Matthew Wilcox , Linux-MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 10:07:32 -0800 (PST) On Wed, Nov 15, 2023 at 1:29=E2=80=AFAM Yunsheng Lin wrote: > > On 2023/11/14 23:41, Willem de Bruijn wrote: > >> > >> I am not sure dma-buf maintainer's concern is still there with this pa= tchset. > >> > >> Whatever name you calling it for the struct, however you arrange each = field > >> in the struct, some metadata is always needed for dmabuf to intergrate= into > >> page pool. > >> > >> If the above is true, why not utilize the 'struct page' to have more u= nified > >> handling? > > > > My understanding is that there is a general preference to simplify stru= ct > > page, and at the least not move in the other direction by overloading t= he > > struct in new ways. > > As my understanding, the new struct is just mirroring the struct page poo= l > is already using, see: > https://elixir.free-electrons.com/linux/v6.7-rc1/source/include/linux/mm_= types.h#L119 > > If there is simplifying to the struct page_pool is using, I think the new > stuct the devmem memory provider is using can adjust accordingly. > > As a matter of fact, I think the way 'struct page' for devmem is decouple= d > from mm subsystem may provide a way to simplify or decoupled the already > existing 'struct page' used in netstack from mm subsystem, before this > patchset, it seems we have the below types of 'struct page': > 1. page allocated in the netstack using page pool. > 2. page allocated in the netstack using buddy allocator. > 3. page allocated in other subsystem and passed to the netstack, such as > zcopy or spliced page? > > If we can decouple 'struct page' for devmem from mm subsystem, we may be = able > to decouple the above 'struct page' from mm subsystem one by one. > > > > > If using struct page for something that is not memory, there is ZONE_DE= VICE. > > But using that correctly is non-trivial: > > > > https://lore.kernel.org/all/ZKyZBbKEpmkFkpWV@ziepe.ca/ > > > > Since all we need is a handle that does not leave the network stack, > > a network specific struct like page_pool_iov entirely avoids this issue= . > > Yes, I am agree about the network specific struct. > I am wondering if we can make the struct more generic if we want to > intergrate it into page_pool and use it in net stack. > > > RFC v3 seems like a good simplification over RFC v1 in that regard to m= e. > > I was also pleasantly surprised how minimal the change to the users of > > skb_frag_t actually proved to be. > > Yes, I am agreed about that too. Maybe we can make it simpler by using > a more abstract struct as page_pool, and utilize some features of > page_pool too. > > For example, from the page_pool doc, page_pool have fast cache and > ptr-ring cache as below, but if napi_frag_unref() call > page_pool_page_put_many() and return the dmabuf chunk directly to > gen_pool in the memory provider, then it seems we are bypassing the > below caches in the page_pool. > I think you're just misunderstanding the code. The page recycling works with my patchset. napi_frag_unref() calls napi_pp_put_page() if recycle =3D=3D true, and that works the same with devmem as with regular pages. If recycle =3D=3D false, we call page_pool_page_put_many() which will call put_page() for regular pages and page_pool_iov_put_many() for devmem pages. So, the memory recycling works exactly the same as before with devmem as with regular pages. In my tests I do see the devmem being recycled correctly. We are not bypassing any caches. > +------------------+ > | Driver | > +------------------+ > ^ > | > | > | > v > +--------------------------------------------+ > | request memory | > +--------------------------------------------+ > ^ ^ > | | > | Pool empty | Pool has entries > | | > v v > +-----------------------+ +------------------------+ > | alloc (and map) pages | | get page from cache | > +-----------------------+ +------------------------+ > ^ ^ > | | > | cache available | No entries, re= fill > | | from ptr-ring > | | > v v > +-----------------+ +------------------+ > | Fast cache | | ptr-ring cache | > +-----------------+ +------------------+ > > > > > > . > > --=20 Thanks, Mina