From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BCC1C433ED for ; Thu, 1 Apr 2021 17:58:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 568A660FF3 for ; Thu, 1 Apr 2021 17:58:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236700AbhDAR63 (ORCPT ); Thu, 1 Apr 2021 13:58:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51134 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236671AbhDARzF (ORCPT ); Thu, 1 Apr 2021 13:55:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617299703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BgvGAsDOvKMgSVYp7bTtwXKT2hEAIoE+wnLxJq/735A=; b=aFMAmH/HvtdgCqxRtHYA9IbovlkvXsaJDGF/YkIjJnonzvvVCwIhF2LcovHKwG+JTYDG1q 8JnyHhFxx9XxP2Ai2JNYhJwJtn00EUS2xVhWAC+cyf8QCUOnhmnkmlWKtHfZRqA2ZhpdHr FvZ82WeLRBjiBf7KfzlxCN92ta9Z7Qo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-457--NqG1dISMsqr4WjpFbCKrg-1; Thu, 01 Apr 2021 09:51:40 -0400 X-MC-Unique: -NqG1dISMsqr4WjpFbCKrg-1 Received: by mail-wr1-f69.google.com with SMTP id m13so2792904wri.16 for ; Thu, 01 Apr 2021 06:51:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BgvGAsDOvKMgSVYp7bTtwXKT2hEAIoE+wnLxJq/735A=; b=VmoX/dp1/5b8XQ6xQRdEwqDwkK8yl9n24201PvLd5uMvgaAYZ3ghOw9OQbpS944WyI hPxaGXqG3KfRD3wj7Wn8nRpgC4dpi191jejn6YFxx27VBlhJ/m7mqyHumxERTiei8cxU GjlJCcPS0BswWfimQwHGl//tMrFaBO4Y+Po1p5Gjoa5BGQOqlZdrUnRKpvNDWAsVZsIt 3wr8xjGO1IlyEr7zKOth8AHndjzY6Z+F9kDhjChddawiAxrvzk4MJCmKKGZG9vNMe3aN wgj8fY5bDBAFVSGFVjHZaAj/ekSH5KuJqQ0vHaVxGLB62RJ7Io7osFci/0J3XEn1WOHO 23vg== X-Gm-Message-State: AOAM5326egLz5TL3cdepwuDLQhyh4QLM+nBOWKcBjmuzAz9bwNwS5W4k Px+oDgTWqAFYIk4l45FAt638wd+fEZP54e/RIi31bgAT/eJ7kmdzAMY/DFZ+QKYH9cAh+pkKn8h hBbxDAjbspt7eWOjL X-Received: by 2002:a5d:49c7:: with SMTP id t7mr9893792wrs.306.1617285099109; Thu, 01 Apr 2021 06:51:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjzcKwTlfX7x5n4ZvUBoWHuz3RuxDcJMmjlqldM7Dep3TjSjovhSsUYoOEy6gPj4UCFLlfGQ== X-Received: by 2002:a5d:49c7:: with SMTP id t7mr9893772wrs.306.1617285098948; Thu, 01 Apr 2021 06:51:38 -0700 (PDT) Received: from redhat.com ([2a10:800e:f0d3:0:b69b:9fb8:3947:5636]) by smtp.gmail.com with ESMTPSA id 64sm8217047wmz.7.2021.04.01.06.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 06:51:38 -0700 (PDT) Date: Thu, 1 Apr 2021 09:51:34 -0400 From: "Michael S. Tsirkin" To: Eric Dumazet Cc: Xuan Zhuo , Eric Dumazet , netdev , Alexander Duyck , Paolo Abeni , Greg Thelen , "David S . Miller" , Jakub Kicinski , su-lifan@linux.alibaba.com, "dust.li" , Jason Wang Subject: Re: [PATCH net] net: avoid 32 x truesize under-estimation for tiny skbs Message-ID: <20210401094908-mutt-send-email-mst@kernel.org> References: <20210113161819.1155526-1-eric.dumazet@gmail.com> <1617007696.5731978-1-xuanzhuo@linux.alibaba.com> <20210331040405-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Mar 31, 2021 at 10:36:35AM +0200, Eric Dumazet wrote: > On Wed, Mar 31, 2021 at 10:11 AM Michael S. Tsirkin wrote: > > > > On Mon, Mar 29, 2021 at 11:06:09AM +0200, Eric Dumazet wrote: > > > On Mon, Mar 29, 2021 at 10:52 AM Xuan Zhuo wrote: > > > > > > > > On Wed, 13 Jan 2021 08:18:19 -0800, Eric Dumazet wrote: > > > > > From: Eric Dumazet > > > > > > > > > > Both virtio net and napi_get_frags() allocate skbs > > > > > with a very small skb->head > > > > > > > > > > While using page fragments instead of a kmalloc backed skb->head might give > > > > > a small performance improvement in some cases, there is a huge risk of > > > > > under estimating memory usage. > > > > > > > > > > For both GOOD_COPY_LEN and GRO_MAX_HEAD, we can fit at least 32 allocations > > > > > per page (order-3 page in x86), or even 64 on PowerPC > > > > > > > > > > We have been tracking OOM issues on GKE hosts hitting tcp_mem limits > > > > > but consuming far more memory for TCP buffers than instructed in tcp_mem[2] > > > > > > > > > > Even if we force napi_alloc_skb() to only use order-0 pages, the issue > > > > > would still be there on arches with PAGE_SIZE >= 32768 > > > > > > > > > > This patch makes sure that small skb head are kmalloc backed, so that > > > > > other objects in the slab page can be reused instead of being held as long > > > > > as skbs are sitting in socket queues. > > > > > > > > > > Note that we might in the future use the sk_buff napi cache, > > > > > instead of going through a more expensive __alloc_skb() > > > > > > > > > > Another idea would be to use separate page sizes depending > > > > > on the allocated length (to never have more than 4 frags per page) > > > > > > > > > > I would like to thank Greg Thelen for his precious help on this matter, > > > > > analysing crash dumps is always a time consuming task. > > > > > > > > > > > > This patch causes a performance degradation of about 10% in the scenario of > > > > virtio-net + GRO. > > > > > > > > For GRO, there is no way to merge skbs based on frags with this patch, only > > > > frag_list can be used to link skbs. The problem that this cause are that compared > > > > to the GRO package merged into the frags way, the current skb needs to call > > > > kfree_skb_list to release each skb, resulting in performance degradation. > > > > > > > > virtio-net will store some data onto the linear space after receiving it. In > > > > addition to the header, there are also some payloads, so "headlen <= offset" > > > > fails. And skb->head_frag is failing when use kmalloc() for skb->head allocation. > > > > > > > > > > Thanks for the report. > > > > > > There is no way we can make things both fast for existing strategies > > > used by _insert_your_driver > > > and malicious usages of data that can sit for seconds/minutes in socket queues. > > > > > > I think that if you want to gain this 10% back, you have to change > > > virtio_net to meet optimal behavior. > > > > > > Normal drivers make sure to not pull payload in skb->head, only headers. > > > > Hmm we do have hdr_len field, but seem to ignore it on RX. > > Jason do you see any issues with using it for the head len? > > > > I was looking at this code (page_to_skb()) a few minutes ago ;) > > pulling payload would make sense only if can pull of of it (to free the page) > (This is what some drivers implement and call copybreak) right.. I wonder whether it's preferable to always copy as much as fits, or to use hdr_len if it's there? > Even if we do not have an accurate knowledge of header sizes, > it would be better to pull only the Ethernet header and let GRO do the > rest during its dissection. So IIUC what you are saying is we should do more or less if (hdr_len != 0) copy hdr_len ? > Once fixed, virtio_net will reduce by 2x number of frags per skb, > compared to the situation before "net: avoid 32 x truesize > under-estimation for tiny skbs" > > > > > > > Optimal GRO packets are when payload is in page fragments. > > > > > > (I am speaking not only for raw performance, but ability for systems > > > to cope with network outages and sudden increase of memory usage in > > > out of order queues) > > > > > > This has been quite clearly stated in my changelog. > > > > > > Thanks. > > > > > > > > > > int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) > > > > { > > > > struct skb_shared_info *pinfo, *skbinfo = skb_shinfo(skb); > > > > unsigned int offset = skb_gro_offset(skb); > > > > unsigned int headlen = skb_headlen(skb); > > > > > > > > ....... > > > > > > > > if (headlen <= offset) { // virtio-net will fail > > > > ........ // merge by frags > > > > goto done; > > > > } else if (skb->head_frag) { // skb->head_frag is fail when use kmalloc() for skb->head allocation > > > > ........ // merge by frags > > > > goto done; > > > > } > > > > > > > > merge: > > > > ...... > > > > > > > > if (NAPI_GRO_CB(p)->last == p) > > > > skb_shinfo(p)->frag_list = skb; > > > > else > > > > NAPI_GRO_CB(p)->last->next = skb; > > > > > > > > ...... > > > > return 0; > > > > } > > > > > > > > > > > > test cmd: > > > > for i in $(seq 1 4) > > > > do > > > > redis-benchmark -r 10000000 -n 10000000 -t set -d 1024 -c 8 -P 32 -h -p 6379 2>&1 | grep 'per second' & > > > > done > > > > > > > > Reported-by: su-lifan@linux.alibaba.com > > > > > > > > > > > > > > Fixes: fd11a83dd363 ("net: Pull out core bits of __netdev_alloc_skb and add __napi_alloc_skb") > > > > > Signed-off-by: Eric Dumazet > > > > > Cc: Alexander Duyck > > > > > Cc: Paolo Abeni > > > > > Cc: Michael S. Tsirkin > > > > > Cc: Greg Thelen > > > > > --- > > > > > net/core/skbuff.c | 9 +++++++-- > > > > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > > > > index 7626a33cce590e530f36167bd096026916131897..3a8f55a43e6964344df464a27b9b1faa0eb804f3 100644 > > > > > --- a/net/core/skbuff.c > > > > > +++ b/net/core/skbuff.c > > > > > @@ -501,13 +501,17 @@ EXPORT_SYMBOL(__netdev_alloc_skb); > > > > > struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len, > > > > > gfp_t gfp_mask) > > > > > { > > > > > - struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache); > > > > > + struct napi_alloc_cache *nc; > > > > > struct sk_buff *skb; > > > > > void *data; > > > > > > > > > > len += NET_SKB_PAD + NET_IP_ALIGN; > > > > > > > > > > - if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) || > > > > > + /* If requested length is either too small or too big, > > > > > + * we use kmalloc() for skb->head allocation. > > > > > + */ > > > > > + if (len <= SKB_WITH_OVERHEAD(1024) || > > > > > + len > SKB_WITH_OVERHEAD(PAGE_SIZE) || > > > > > (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) { > > > > > skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE); > > > > > if (!skb) > > > > > @@ -515,6 +519,7 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len, > > > > > goto skb_success; > > > > > } > > > > > > > > > > + nc = this_cpu_ptr(&napi_alloc_cache); > > > > > len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); > > > > > len = SKB_DATA_ALIGN(len); > > > > > > > > > > -- > > > > > 2.30.0.284.gd98b1dd5eaa7-goog > > > > > > >