Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3687525pxb; Sat, 13 Feb 2021 06:06:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfgOb5A2YsQ7rp0feAY6bsF7V1jM6SpruEs+JcazJnDysOlcnnUiSIDJS3T6yr2SZ/vD96 X-Received: by 2002:a17:906:3ac3:: with SMTP id z3mr7564672ejd.449.1613225159356; Sat, 13 Feb 2021 06:05:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613225159; cv=none; d=google.com; s=arc-20160816; b=JBkHDT0zIJiomJNmmwhmb4RZaJcc/JO9c4l0Xwlmy7eQgiBqwHVEE6SB+g8Eu2E9C8 slR6teQZHW3OFJlDiRpMPN75DtyeIVMXYDJ8o9CJ+4ozPWS5W41PllG90NyXMqln0oai oF3kWDTYiIS83WRisBuFQxUYEYvSvhIN7cFWEzTbUitZWaIPzhTKo5n9i7snJj3b84oP uOLh0KG/yRcGWwTg1bjWXUyCjuP/GzlMqIL5ZYKZGBU3I3/dSj7jU5olqtpZSgNAVpo5 XNSfBM4DgQKmayJEnUEB+CFQPM3W9uN9jyFBySjwqA5dfL7Oogzwx+8FSwA9W2aiHzor 9pUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=T6KIeabV5sI7XCFa/PJx1BokACoH/f2hbL4xDuJnHrw=; b=hoohplS95cUmYCX5/8OQKWnW24N7Sl744Er8Z3o2CwdGR1gonNne4Bt/D/4J+pAsy9 +CyvXHU/1OAIoLiu2rr2kEREtRP1itwpFY4iSTzhaG9KNCiBuP8tXTTw0Ty3aINCRnEy SG+vDLoTKCSsKJfwvIibLZacQL6CUSevtD+nbpSLabe4uKrk17R1DMnlN6Vt0UTPywrl YV931voHNBom/Hx+1RBS+eec6GZIeq2S+w2a1oTxpFIr/VQ5maEMygaR13wkWppE0by9 KAG5p+rcLu11qQvW3lA92brwz1a81pQoWfYC6in70RN9GQ7wRZHRuxBs9ugNVQuqMRQg 2wcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=paJxQJHQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si9637784eds.493.2021.02.13.06.04.55; Sat, 13 Feb 2021 06:05:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=paJxQJHQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbhBMN5h (ORCPT + 99 others); Sat, 13 Feb 2021 08:57:37 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:19340 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbhBMN5g (ORCPT ); Sat, 13 Feb 2021 08:57:36 -0500 Date: Sat, 13 Feb 2021 13:56:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1613224611; bh=T6KIeabV5sI7XCFa/PJx1BokACoH/f2hbL4xDuJnHrw=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=paJxQJHQ6QsKrY/FqcS3AXMj5XvUuQ90BRqLHfuUsi9sWtk2cLIaYm+tHM3cNPOXE hWNhJER6x7rJCLYwz7ifoh6QseyWydbnO7bNjI88HMlCcJuxtVZ+MRy4O9mAcI75i9 1xvBPF74nQtOT4vaJUsbWYhFmQTIDt7XTILs8FPjL1Yf3gWTDr7d84paGVEQHkZGbj nB8qpQdsijf1m6XNi4NEDHZTsO4eURX0Aqu3IZ+86+YhUdb0550UMZLqiETXmiV9+P ABbATPXQXpOmD6yhsv6GAC40z5OW4KErtHtpdp2RKfVdek7WuoNsVsV8FccVS7p6gM 9ha3bAL1AC/rA== To: Alexander Duyck From: Alexander Lobakin Cc: Alexander Lobakin , "David S. Miller" , Jakub Kicinski , Jonathan Lemon , Eric Dumazet , Dmitry Vyukov , Willem de Bruijn , Randy Dunlap , Kevin Hao , Pablo Neira Ayuso , Jakub Sitnicki , Marco Elver , Dexuan Cui , Paolo Abeni , Jesper Dangaard Brouer , Alexander Duyck , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Taehee Yoo , Cong Wang , =?utf-8?Q?Bj=C3=B6rn_T=C3=B6pel?= , Miaohe Lin , Guillaume Nault , Yonghong Song , zhudi , Michal Kubecek , Marcelo Ricardo Leitner , Dmitry Safonov <0x7f454c46@gmail.com>, Yang Yingliang , Florian Westphal , Edward Cree , LKML , Netdev Reply-To: Alexander Lobakin Subject: Re: [PATCH v5 net-next 06/11] skbuff: remove __kfree_skb_flush() Message-ID: <20210213135604.86581-1-alobakin@pm.me> In-Reply-To: References: <20210211185220.9753-1-alobakin@pm.me> <20210211185220.9753-7-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Duyck Date: Thu, 11 Feb 2021 19:28:52 -0800 > On Thu, Feb 11, 2021 at 10:57 AM Alexander Lobakin wrote= : > > > > This function isn't much needed as NAPI skb queue gets bulk-freed > > anyway when there's no more room, and even may reduce the efficiency > > of bulk operations. > > It will be even less needed after reusing skb cache on allocation path, > > so remove it and this way lighten network softirqs a bit. > > > > Suggested-by: Eric Dumazet > > Signed-off-by: Alexander Lobakin >=20 > I'm wondering if you have any actual gains to show from this patch? >=20 > The reason why I ask is because the flushing was happening at the end > of the softirq before the system basically gave control back over to > something else. As such there is a good chance for the memory to be > dropped from the cache by the time we come back to it. So it may be > just as expensive if not more so than accessing memory that was just > freed elsewhere and placed in the slab cache. Just retested after readding this function (and changing the logics so it would drop the second half of the cache, like napi_skb_cache_put() does) and got 10 Mbps drawback with napi_build_skb() + napi_gro_receive(). So seems like getting a pointer from an array instead of calling kmem_cache_alloc() is cheaper even if the given object was pulled out of CPU caches. > > --- > > include/linux/skbuff.h | 1 - > > net/core/dev.c | 7 +------ > > net/core/skbuff.c | 12 ------------ > > 3 files changed, 1 insertion(+), 19 deletions(-) > > > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > > index 0a4e91a2f873..0e0707296098 100644 > > --- a/include/linux/skbuff.h > > +++ b/include/linux/skbuff.h > > @@ -2919,7 +2919,6 @@ static inline struct sk_buff *napi_alloc_skb(stru= ct napi_struct *napi, > > } > > void napi_consume_skb(struct sk_buff *skb, int budget); > > > > -void __kfree_skb_flush(void); > > void __kfree_skb_defer(struct sk_buff *skb); > > > > /** > > diff --git a/net/core/dev.c b/net/core/dev.c > > index 321d41a110e7..4154d4683bb9 100644 > > --- a/net/core/dev.c > > +++ b/net/core/dev.c > > @@ -4944,8 +4944,6 @@ static __latent_entropy void net_tx_action(struct= softirq_action *h) > > else > > __kfree_skb_defer(skb); > > } > > - > > - __kfree_skb_flush(); > > } > > > > if (sd->output_queue) { > > @@ -7012,7 +7010,6 @@ static int napi_threaded_poll(void *data) > > __napi_poll(napi, &repoll); > > netpoll_poll_unlock(have); > > > > - __kfree_skb_flush(); > > local_bh_enable(); > > > > if (!repoll) >=20 > So it looks like this is the one exception to my comment above. Here > we should probably be adding a "if (!repoll)" before calling > __kfree_skb_flush(). >=20 > > @@ -7042,7 +7039,7 @@ static __latent_entropy void net_rx_action(struct= softirq_action *h) > > > > if (list_empty(&list)) { > > if (!sd_has_rps_ipi_waiting(sd) && list_empty(&= repoll)) > > - goto out; > > + return; > > break; > > } > > > > @@ -7069,8 +7066,6 @@ static __latent_entropy void net_rx_action(struct= softirq_action *h) > > __raise_softirq_irqoff(NET_RX_SOFTIRQ); > > > > net_rps_action_and_irq_enable(sd); > > -out: > > - __kfree_skb_flush(); > > } > > > > struct netdev_adjacent { > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > index 1c6f6ef70339..4be2bb969535 100644 > > --- a/net/core/skbuff.c > > +++ b/net/core/skbuff.c > > @@ -838,18 +838,6 @@ void __consume_stateless_skb(struct sk_buff *skb) > > kfree_skbmem(skb); > > } > > > > -void __kfree_skb_flush(void) > > -{ > > - struct napi_alloc_cache *nc =3D this_cpu_ptr(&napi_alloc_cache)= ; > > - > > - /* flush skb_cache if containing objects */ > > - if (nc->skb_count) { > > - kmem_cache_free_bulk(skbuff_head_cache, nc->skb_count, > > - nc->skb_cache); > > - nc->skb_count =3D 0; > > - } > > -} > > - > > static inline void _kfree_skb_defer(struct sk_buff *skb) > > { > > struct napi_alloc_cache *nc =3D this_cpu_ptr(&napi_alloc_cache)= ; > > -- > > 2.30.1 Al