Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5647029rwl; Tue, 4 Apr 2023 01:16:57 -0700 (PDT) X-Google-Smtp-Source: AKy350ZWoDLWxaM64IQeWkZXC/3kJqp2JRk4+o6f+xX7Br6RsusPkTbHO7xhwWCW9UVptTOTcOYI X-Received: by 2002:a17:906:26c4:b0:933:130e:e81a with SMTP id u4-20020a17090626c400b00933130ee81amr17623524ejc.32.1680596217590; Tue, 04 Apr 2023 01:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680596217; cv=none; d=google.com; s=arc-20160816; b=QYDXp7qhL9DkCVuCphGJ0SwEqWZEhVfTfYuDFkxp6R3DB5cNyDv9p8ny5xXFqpLOeF ehSL5Xxk5xYL5s7yhMeygNCpa0qHBP1sCUDOgwt4zzyvcffrt9q5ZntUyP72Pi5CFP6G 0pnqxZp4b+WY+VPwWWKaW/oy/hK+fCZr934fwBGcqRqrbKgNyDDyBwJG7SpaQFwPk2E9 X5wWbo+5D1rA8z1tu6QQ7dPL0sZrFC38f+1CIPUw75QW3sAvssptbqJgcdGiCL6BMDOu qdbOA7D/NqDqYcmIP8Jsdtl8O//64avTQRr+SVbJXRSoelf/a489BDZcyaP9QcFegB9U TjhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7ZWSy31nxZx1PXrJ/a/Nio7iVH3OxfiLHZKduoDBB98=; b=RiTcIp/tsgSKOebjflSsfOCGJV0dAiQK0cW+5Ds5/1bzT3L1xGbO9s20/8KKmxPznz asdL7OMrcwRePCgsQUfmifE0cdTbDuzhPYRd7UL9H1KygZCGnjbzDZONM7lEiYDCQTQA dhGieh9w+j5thQbgcy9Ks8FLEyX2bbFASTLbVUFJIlUKwPf/Jj2oLY7c69+cnzA4jL4O lo2tgx8PTcJ3zFWrral1SZ5ZfoF1pVQAG3ytihoHc62dK0hd7Wok/WIsP1sIT9KUkvYZ 69MuRHSJnVX5NOm9U4gmIIxrqtoMOoMUB8CPUu+ALvsfU00XeGZDOtX7On80tCOckQgA jouQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dectris.com header.s=google header.b=FteqBbAS; 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=dectris.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a170906145100b0094779d354efsi8714109ejc.941.2023.04.04.01.16.32; Tue, 04 Apr 2023 01:16:57 -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=@dectris.com header.s=google header.b=FteqBbAS; 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=dectris.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbjDDIPq (ORCPT + 99 others); Tue, 4 Apr 2023 04:15:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234083AbjDDIPo (ORCPT ); Tue, 4 Apr 2023 04:15:44 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F7C2115 for ; Tue, 4 Apr 2023 01:15:42 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id t10so127011982edd.12 for ; Tue, 04 Apr 2023 01:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dectris.com; s=google; t=1680596141; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7ZWSy31nxZx1PXrJ/a/Nio7iVH3OxfiLHZKduoDBB98=; b=FteqBbAS9GU7d/CcIKLll4vLYKmpQvsOdqlvYAoJwULBBi/Y0on4cacwGnABacI2Fj L/UCNRzfGFcIV7VW99CVyvKbh72ec1sYa6CxTDURk/WHNWrbVN3ecXUuoEk0MEA+x8zC 1ipN/kACbc0hZpVcsf0PRsxHAPm/WvoSbj2Lg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680596141; h=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=7ZWSy31nxZx1PXrJ/a/Nio7iVH3OxfiLHZKduoDBB98=; b=BW38XsdDTeDQ0+HLchiQRCL7zRiA//0yJgj1jMMFZ3G6oo7HbOVzgdFPZhjpMct7xQ O9PmQFmSlCC9/MW1Hf6rMHgsMBXmUePOu3sN8KrT6la90TzUuAESxUWyaBjsVRwz0VrH gFIEZJp6cWK3Ri1BFlFWNQ+iuE1HAgSlgQFl5FdRpIRQSSdTryCUgYt9Esi/NnU7/PyI oDH4FnUEi7sFxcoSLsdz8/7AaFGjgjDpqpzMb8KXRzCuSthhFYGGVsVc6zrPF+rDu0u1 IcsVhCq+sGmEepSDXodlf3oITFMnCU9/AN3i545PP59AUKX9qEye+4uYeQclJ1ZZSftL tXHA== X-Gm-Message-State: AAQBX9ce8Hub4uqmkgHCoQpd3xPLIVYo8rZXgCrKfJJydG7Fa/LdCuNq BgtJ2FiMrH/4sJ+pNI7AQ09fbmIrzztfPOZx69OEog== X-Received: by 2002:a17:906:c197:b0:947:54ef:374 with SMTP id g23-20020a170906c19700b0094754ef0374mr765759ejz.0.1680596140889; Tue, 04 Apr 2023 01:15:40 -0700 (PDT) MIME-Version: 1.0 References: <20230329180502.1884307-1-kal.conley@dectris.com> <20230329180502.1884307-9-kal.conley@dectris.com> In-Reply-To: From: Kal Cutter Conley Date: Tue, 4 Apr 2023 10:20:21 +0200 Message-ID: Subject: Re: [PATCH bpf-next v2 08/10] xsk: Support UMEM chunk_size > PAGE_SIZE To: Magnus Karlsson Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 > Is not the max 64K as you test against XDP_UMEM_MAX_CHUNK_SIZE in > xdp_umem_reg()? The absolute max is 64K. In the case of HPAGE_SIZE < 64K, then it would be HPAGE_SIZE. > > diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h > > index e96a1151ec75..ed88880d4b68 100644 > > --- a/include/net/xdp_sock.h > > +++ b/include/net/xdp_sock.h > > @@ -28,6 +28,9 @@ struct xdp_umem { > > struct user_struct *user; > > refcount_t users; > > u8 flags; > > +#ifdef CONFIG_HUGETLB_PAGE > > Sanity check: have you tried compiling your code without this config set? Yes. The CI does this also on one of the platforms (hence some of the bot errors in v1). > > static int xdp_umem_pin_pages(struct xdp_umem *umem, unsigned long address) > > { > > +#ifdef CONFIG_HUGETLB_PAGE > > Let us try to get rid of most of these #ifdefs sprinkled around the > code. How about hiding this inside xdp_umem_is_hugetlb() and get rid > of these #ifdefs below? Since I believe it is quite uncommon not to > have this config enabled, we could simplify things by always using the > page_size in the pool, for example. And dito for the one in struct > xdp_umem. What do you think? I used #ifdef for `page_size` in the pool for maximum performance when huge pages are disabled. We could also not worry about optimizing this uncommon case though since the performance impact is very small. However, I don't find the #ifdefs excessive either. > > +static void xp_check_dma_contiguity(struct xsk_dma_map *dma_map, u32 page_size) > > { > > - u32 i; > > + u32 stride = page_size >> PAGE_SHIFT; /* in order-0 pages */ > > + u32 i, j; > > > > - for (i = 0; i < dma_map->dma_pages_cnt - 1; i++) { > > - if (dma_map->dma_pages[i] + PAGE_SIZE == dma_map->dma_pages[i + 1]) > > - dma_map->dma_pages[i] |= XSK_NEXT_PG_CONTIG_MASK; > > - else > > - dma_map->dma_pages[i] &= ~XSK_NEXT_PG_CONTIG_MASK; > > + for (i = 0; i + stride < dma_map->dma_pages_cnt;) { > > + if (dma_map->dma_pages[i] + page_size == dma_map->dma_pages[i + stride]) { > > + for (j = 0; j < stride; i++, j++) > > + dma_map->dma_pages[i] |= XSK_NEXT_PG_CONTIG_MASK; > > + } else { > > + for (j = 0; j < stride; i++, j++) > > + dma_map->dma_pages[i] &= ~XSK_NEXT_PG_CONTIG_MASK; > > + } > > Still somewhat too conservative :-). If your page size is large you > will waste a lot of the umem. For the last page mark all the 4K > "pages" that cannot cross the end of the umem due to the max size of a > packet with the XSK_NEXT_PG_CONTIG_MASK bit. So you only need to add > one more for-loop here to mark this, and then adjust the last for-loop > below so it only marks the last bunch of 4K pages at the end of the > umem as not contiguous. I don't understand the issue. The XSK_NEXT_PG_CONTIG_MASK bit is only looked at if the descriptor actually crosses a page boundary. I don't think the current implementation wastes any UMEM.