Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2799816rwd; Wed, 14 Jun 2023 07:30:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4pUgnR5zYBMmN2hOmnkiO6oT060hwbDbCQv8/RWvzEhvwyW/GXASdJCkmV6a30e/aRXZdP X-Received: by 2002:a19:5e51:0:b0:4ee:8ff3:c981 with SMTP id z17-20020a195e51000000b004ee8ff3c981mr7498982lfi.10.1686753016630; Wed, 14 Jun 2023 07:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686753016; cv=none; d=google.com; s=arc-20160816; b=wJKtnTJvj87kBMbOtD0lUs0HbfsXE7v4xiVFIk2ZvsxvRBq7x7nPMxi/6tz84tvW6S cZqbIuL7wnUgzB7UtMjI1hsr3r76ZBSNPmyOTGvmsKirw02cFx2RwWLpCZMwnupUn7Vj cSXnp5QfSPsybgBpMGC3FZ6yFBgZCSdEH9kFz+y5w8TJc5nIS0KUDsandUumavdBjrOA ykm+OMQOYzQq0nFzIT5Gtz0FtAXgeK6VNgDSybQFMb7E8ZKP94+CPAXecclxBMp3HYa2 4tDLcQzP5jtD1DcIGBW9B8GdIAElPcu5UM1HAileLyyRlTeH+5StlvckeIiwPdJEsm8g 13BQ== 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=j45S64yVRtWNmXi9+AQpAX/jaYs8Bbc2x/KQu3uuygo=; b=ISJQBDg9e2/xldJxx2yyDbfRfDJL6ZXLQBY5WECRnn+H3UcfZKArweEhJxUfWmQ4RM vejTaQ1vp3VgirnEXcO2DT6z8kU0V6MTmmBCWIG35WMLl6F11yYXunGGQabcs3LcpThc me5LAB5/e/KoCv8K7TKEewE5/G4SKjGtEhcpHyE1Gyo+o2o2zO1gCLviY/xhwcrVrB5Z EAQJST8mfOhsajiPDLnMR1XL3mN7qSkPvtvvKe3Nc9FoWRmeNgQLwf56+/AycUPjI7g3 5yE1CiFpQmL/X+UrqnYfL5vNX3LG6FB0k4Xrb9Bo3c5JsV8X3I/QEQY1JSYZNAQyu+U7 uLtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="lGNA8g/X"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l22-20020a056402029600b005187232e642si2638730edv.87.2023.06.14.07.29.40; Wed, 14 Jun 2023 07:30:16 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b="lGNA8g/X"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245461AbjFNOTL (ORCPT + 99 others); Wed, 14 Jun 2023 10:19:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245495AbjFNOTK (ORCPT ); Wed, 14 Jun 2023 10:19:10 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B10AE10D8; Wed, 14 Jun 2023 07:19:08 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-25e247414d9so340644a91.1; Wed, 14 Jun 2023 07:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686752348; x=1689344348; 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=j45S64yVRtWNmXi9+AQpAX/jaYs8Bbc2x/KQu3uuygo=; b=lGNA8g/XUZhtMjdIGr5d3t83lKAAlZkr5+qkiFZuJ1870yee6pz6Ea/XZpsaogva4h Ie4KxBWdz2y02qLCLW4QTnS35H0IxGzNaR7Z7CZZf7ypBiMIkRyIlI/BjqFWvqYucfiY VBVsFuwHWRgxyL5m5ewLJZTN8xtU4bnccg0j3RSLnrS0qYrpYz5P+SuZvtfz5kNl1Ez8 j6kr7dXOXrn3PibKwXTJNtZ7DsEuPPwxnxLjLoZ0GZD2MlwLZ7DV8qfT9EySXmjKTxP/ pz0FGVN0MzfAQ4HlWrbCSnWvetd4/+0eGik/vTY5zezVtO+K7gEZczhkeY2ha2iWq7km OAbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686752348; x=1689344348; 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=j45S64yVRtWNmXi9+AQpAX/jaYs8Bbc2x/KQu3uuygo=; b=K7muAopsdrXsIGj4x3ZJdrMPN35Nt9zNVxzVM/1hl6fYqhMkvutCvzQNZOx1Bel2hb pCRlalS+X6Tnndlf9EHbUWedxj3LX0CKBJuFiU3NTTDalj9mXdCWW7gcfHOPibH7FN34 +c2Fc19pA7pTWzWfuuMHNZ7qp7Pi7dld6c+qM/TeL9a4Xm6+swHOK0YI9WLReyGCK09/ fEwhFPd2evSH1nA2KdGpt5PnSyL8dGc+qymhFmSmNerUyRb2WxgwfBSlkcRyFH8dkK8R 0t9+oHvypthxKIuorg8eWD+EknumIPdDZDtJvUDbFGvkWoPfcWpfexQF8DEKvrvuG9Ao lW5Q== X-Gm-Message-State: AC+VfDwNqMn+nRESL6CLoh98S0X7XjCww4gJI8NTvqUJJwLa6A0YCFIE lo9QpL4v7zNcK1fgmVyYcZebZnKaIV+UVfJmnfQ= X-Received: by 2002:a17:90b:214:b0:259:17bc:1a3c with SMTP id fy20-20020a17090b021400b0025917bc1a3cmr1385035pjb.7.1686752347917; Wed, 14 Jun 2023 07:19:07 -0700 (PDT) MIME-Version: 1.0 References: <20230609131740.7496-1-linyunsheng@huawei.com> <20230609131740.7496-4-linyunsheng@huawei.com> <36366741-8df2-1137-0dd9-d498d0f770e4@huawei.com> In-Reply-To: <36366741-8df2-1137-0dd9-d498d0f770e4@huawei.com> From: Alexander Duyck Date: Wed, 14 Jun 2023 07:18:31 -0700 Message-ID: Subject: Re: [PATCH net-next v3 3/4] page_pool: introduce page_pool_alloc() API To: Yunsheng Lin Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lorenzo Bianconi , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Tue, Jun 13, 2023 at 8:51=E2=80=AFPM Yunsheng Lin wrote: > > On 2023/6/13 22:36, Alexander Duyck wrote: > > On Fri, Jun 9, 2023 at 6:20=E2=80=AFAM Yunsheng Lin wrote: > > ... > > >> > >> +static inline struct page *page_pool_alloc(struct page_pool *pool, > >> + unsigned int *offset, > >> + unsigned int *size, gfp_t g= fp) > >> +{ > >> + unsigned int max_size =3D PAGE_SIZE << pool->p.order; > >> + struct page *page; > >> + > >> + *size =3D ALIGN(*size, dma_get_cache_alignment()); > >> + > >> + if (WARN_ON(*size > max_size)) > >> + return NULL; > >> + > >> + if ((*size << 1) > max_size || PAGE_POOL_DMA_USE_PP_FRAG_COUNT= ) { > >> + *size =3D max_size; > >> + *offset =3D 0; > >> + return page_pool_alloc_pages(pool, gfp); > >> + } > >> + > >> + page =3D __page_pool_alloc_frag(pool, offset, *size, gfp); > >> + if (unlikely(!page)) > >> + return NULL; > >> + > >> + /* There is very likely not enough space for another frag, so = append the > >> + * remaining size to the current frag to avoid truesize undere= stimate > >> + * problem. > >> + */ > >> + if (pool->frag_offset + *size > max_size) { > >> + *size =3D max_size - *offset; > >> + pool->frag_offset =3D max_size; > >> + } > >> + > > > > Rather than preventing a truesize underestimation this will cause one. > > You are adding memory to the size of the page reserved and not > > accounting for it anywhere as this isn't reported up to the network > > stack. I would suggest dropping this from your patch. > > I was thinking about the driver author reporting it up to the network > stack using the new API as something like below: > > int truesize =3D size; > struct page *page; > int offset; > > page =3D page_pool_dev_alloc(pool, &offset, &truesize); > if (unlikely(!page)) > goto err; > > skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, > offset, size, truesize); > > and similiar handling for *_build_skb() case too. > > Does it make senses for that? or did I miss something obvious here? It is more the fact that you are creating a solution in search of a problem. As I said before most of the drivers will deal with these sorts of issues by just doing the fragmentation themselves or allocating fixed size frags and knowing how it will be divided into the page. If you are going to go down this path then you should have a consumer for the API and fully implement it instead of taking half measures and making truesize underreporting worse by evicting pages earlier.