Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp202473pxb; Thu, 14 Jan 2021 03:51:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPDDhOrfyEXlGzo/mw7WBl1TSVJSeiz/JmVfPDNi98/v5gkEoJRJCcWkD31oRiA7a4pzea X-Received: by 2002:a17:906:7215:: with SMTP id m21mr4908107ejk.248.1610625113396; Thu, 14 Jan 2021 03:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610625113; cv=none; d=google.com; s=arc-20160816; b=1LFJ/BVf0uGsfoLh3SGsGOavp8NuFZVd8d0qmFuXUD0LjrHcmxm3ulDv07HBq2IcCP yir7TJYOmvu1NyQJuSf+k4DC6Y+mYvHxE9OktPTBZj+Dod4Z5sL3KB67HjC1+yXcO0zT dQOb/MekZKWpc8HvP6KAcb8Cirjxb1mvT6gn+2g289BaB3Y2OSDBE9yi857QJ1bQPzKt WEtdvtDQCjf9NyPgu8eL97OA+dzcEdAuxCcyxHawTdjMAPbhdEP7+J2fHajpfqmh2A3f 1/OSwucGeiMjTF+RC4tHs8ezC9LN4nB/CVvjWFPYiSSvsWWPyBUkQcr6LiFmluErpcF7 Wtow== 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=P7zlk5pCQoka+PfAC4PASpL+4y3UpC4S531KyERmJBw=; b=E5vceSVCMqIWZ/OCgg9rw3Gt7526jUxEAa6RFyHypmnF65OLWGJsyCz3spbJYgHe8F eioHY/7BOQlx2/+PIGznQ3vP3akUgUJjNZk50t8hyD7LNkfjALT7haReUtPQVHPZeVSW eROKLK8ODT2+WyAe3u8ePi2SGpmob/7oTlznNhooQH+excZA59wS8MArWfps72vGUOqh nhNtHTq1IkhtT167YkKHqpT+mGt0thnpwZzySWDZF5/WouqiCWv/S60ZHa8HUb8ZB5Tw FDxySDF8Mx/ZhCsOhGrHWu/iCBn7bV5KvmSMTmZ5v4RWvZR8THV/GyYI6trAxPAMJiIQ e9DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ZE8P/VZ6"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a27si2281929ejc.18.2021.01.14.03.51.26; Thu, 14 Jan 2021 03:51:53 -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=@google.com header.s=20161025 header.b="ZE8P/VZ6"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727172AbhANLsZ (ORCPT + 99 others); Thu, 14 Jan 2021 06:48:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbhANLsY (ORCPT ); Thu, 14 Jan 2021 06:48:24 -0500 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53161C061573 for ; Thu, 14 Jan 2021 03:47:44 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id 2so3226732qtt.10 for ; Thu, 14 Jan 2021 03:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P7zlk5pCQoka+PfAC4PASpL+4y3UpC4S531KyERmJBw=; b=ZE8P/VZ6aVPsnkQTxgeSqK8AyML44NMzDst0EI1a5EwxVjEG3WX6b3T9rqmCYMQYWS xYw/cL8ivjt7sGzbDt2MACulsAVKMMxkgZlYmgW6A8xYBjEoTUy+h87qnd/Shm0y60VW WsyQr3WfvGYI8svK+Mg0TNHtOLNELvq1s1B4ZzbbGOz4as+8ZtNM9pwYYKNb/tVPrTWZ PkmrendVFVTg5TVPBPgecFxchLJcdglXxECYFHSeIl0ZV/DrGiSLeeDHuuTMtDNYdemJ E0+lRkPrhwGw1yph75b5pbbMV7Jw91GPqn1x8osuxymPHYrz+jED0UzLyT8xjUKd9blf 4/FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P7zlk5pCQoka+PfAC4PASpL+4y3UpC4S531KyERmJBw=; b=fq+YrFMyh4XIaxFC6oK7zk+qTgFSC2DsoeiDRE1hCtGufNQbOJCfFS3G7D4d6KpS7I YzEDx4ge2V3jdk4eKjlrORLbbZeLYWAuolCBxKOiqUY+nWEG4/PHlN+M0gDzhwBiSZnt Ju1vRNVEkCzP90cwKTAcHWORcHorCuXYM9EWxvytwhYEiAAPcvibDOlQwDCTjs2REvL2 EM38AxhBLiW92kO6qYKot1qGvtWq9YD+gZcxRqsX4qrFS1hbPP714r6pmbodjhG1dka9 p82SvoULqsBfyQ0YtzuxiPi9H3+FXk7rpWWzUpYAms8BxV7REgIFx/TQr/jQ+4AHSrmS koYg== X-Gm-Message-State: AOAM533EOf/nTTUfJuBBvAL+Cn67yn0xrs1WaxWk1peS5qiPSJF5AhC6 rAxwdFwtw0mztZWjBgFlUNtsVy3WRr19ZbV/jsu7HQ== X-Received: by 2002:ac8:4e1c:: with SMTP id c28mr6662207qtw.67.1610624863289; Thu, 14 Jan 2021 03:47:43 -0800 (PST) MIME-Version: 1.0 References: <20210113133523.39205-1-alobakin@pm.me> <20210113133635.39402-1-alobakin@pm.me> <20210113133635.39402-2-alobakin@pm.me> <20210114114046.7272-1-alobakin@pm.me> In-Reply-To: <20210114114046.7272-1-alobakin@pm.me> From: Dmitry Vyukov Date: Thu, 14 Jan 2021 12:47:31 +0100 Message-ID: Subject: Re: [PATCH v2 net-next 2/3] skbuff: (re)use NAPI skb cache on allocation path To: Alexander Lobakin Cc: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Edward Cree , Jonathan Lemon , Willem de Bruijn , Miaohe Lin , Steffen Klassert , Guillaume Nault , Yadu Kishore , Al Viro , netdev , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 14, 2021 at 12:41 PM Alexander Lobakin wrote: > > From: Eric Dumazet > Date: Wed, 13 Jan 2021 15:36:05 +0100 > > > On Wed, Jan 13, 2021 at 2:37 PM Alexander Lobakin wrote: > >> > >> Instead of calling kmem_cache_alloc() every time when building a NAPI > >> skb, (re)use skbuff_heads from napi_alloc_cache.skb_cache. Previously > >> this cache was only used for bulk-freeing skbuff_heads consumed via > >> napi_consume_skb() or __kfree_skb_defer(). > >> > >> Typical path is: > >> - skb is queued for freeing from driver or stack, its skbuff_head > >> goes into the cache instead of immediate freeing; > >> - driver or stack requests NAPI skb allocation, an skbuff_head is > >> taken from the cache instead of allocation. > >> > >> Corner cases: > >> - if it's empty on skb allocation, bulk-allocate the first half; > >> - if it's full on skb consuming, bulk-wipe the second half. > >> > >> Also try to balance its size after completing network softirqs > >> (__kfree_skb_flush()). > > > > I do not see the point of doing this rebalance (especially if we do not change > > its name describing its purpose more accurately). > > > > For moderate load, we will have a reduced bulk size (typically one or two). > > Number of skbs in the cache is in [0, 64[ , there is really no risk of > > letting skbs there for a long period of time. > > (32 * sizeof(sk_buff) = 8192) > > I would personally get rid of this function completely. > > When I had a cache of 128 entries, I had worse results without this > function. But seems like I forgot to retest when I switched to the > original size of 64. > I also thought about removing this function entirely, will test. > > > Also it seems you missed my KASAN support request ? > > I guess this is a matter of using kasan_unpoison_range(), we can ask for help. > > I saw your request, but don't see a reason for doing this. > We are not caching already freed skbuff_heads. They don't get > kmem_cache_freed before getting into local cache. KASAN poisons > them no earlier than at kmem_cache_free() (or did I miss someting?). > heads being cached just get rid of all references and at the moment > of dropping to the cache they are pretty the same as if they were > allocated. KASAN should not report false positives in this case. But I think Eric meant preventing false negatives. If we kmalloc 17 bytes, KASAN will detect out-of-bounds accesses beyond these 17 bytes. But we put that data into 128-byte blocks, KASAN will miss out-of-bounds accesses beyond 17 bytes up to 128 bytes. The same holds for "logical" use-after-frees when object is free, but not freed into slab. An important custom cache should use annotations like kasan_poison_object_data/kasan_unpoison_range.