From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 051571FECDC for ; Fri, 17 Jan 2025 12:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737118621; cv=none; b=B56MvaXMjQtC//7CpRgC4X50t/axvdsDexmBZXe/2voGW4oqd68RiL9ZkaPlwPRL5C4pIYoEDoRpcvqxYCFaELJ44OuTtyu1dZBxN2P0WCoPkJ/2QOmDVZBMKD0Ob/EYcBcodCA++7/uBaWyqBgfYJ8OK25unq/FP7dFdvfLvm8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737118621; c=relaxed/simple; bh=aTVho8AOByn1YepMWxN84zHPjm3oXGLDzyOU12rA3sQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=IszbE9I9aNdyGcV6iTRQnGC1PZXPJDp9ZhghD0k0QLygBGxfQwAX4dklCGZ5YW6cw4SWHE7yaVTktCDt4vb2/5LBZwKA0HlLJq5oZpC9r9IrkgYNoNkvb8xODu7wRWQlz9fGfeWMDLvoO45UHz5OQpvy1X0RQgmJ4mm7Ml6XD98= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ep/c6L0/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ep/c6L0/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737118619; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ljy9OBJQv1xjgRSfCuYEuq1WMWKhZpYM5ej1GNWwrgg=; b=ep/c6L0/xnr3ZIqRD+QdesG2qfKC2Wj5Ti8L5RACd9gjQhsgYDLtQMOibHTejJGxrorpTE Vx+9VW9z5eKI7JjBOlLGn3Wlvb4L9YPMKCsazZ/FOkFftMR3i8ghoTZJv8UjgBcNLLeVsN pKJ0yHexafkiexwtm6atDRw1hAEdFCY= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-aLhV8DJMMfqFvPJU5RNKjQ-1; Fri, 17 Jan 2025 07:56:57 -0500 X-MC-Unique: aLhV8DJMMfqFvPJU5RNKjQ-1 X-Mimecast-MFC-AGG-ID: aLhV8DJMMfqFvPJU5RNKjQ Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ab397fff5a3so36552566b.1 for ; Fri, 17 Jan 2025 04:56:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737118616; x=1737723416; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ljy9OBJQv1xjgRSfCuYEuq1WMWKhZpYM5ej1GNWwrgg=; b=ds4nc2UnkuLc9Hr40hah8dwMRQW1yymM9dn8R+qU0mkbCca/mXdUYCsahaAC126Csj /rmHOnU1Jxjwq5N+Tp23PMVo5m7OBbAYhoqOoVY1wjUpXU0JmSPf58Q07yGy/awRRbwQ 2qhoYweGijrWiR0I229C9xJcO63w2mF+iUZGpPywhGU1Au5zQUpzyL0bTgKDDxJ1i07C DsVjeN9VQaQvKMGSg4CuGhNRXuvFnhsI+rYV+tSU1DVKtdY7Upk3qNMm+ZlehRQ+lOgA LeGbB9inLCDGFZIeMgx6OFvBXRTIjIiDRBgEJk5fa+btKBG0Z6BbA8gWq/qzbqFTz6C1 RqVg== X-Forwarded-Encrypted: i=1; AJvYcCXV5XDl/Mt+CkUdis7JEeL9FZEFAs2tONxKcNpW7aTlQB2P6IeSDTVvPo4i28aGVwx7fUco9xZTyWevkyM=@vger.kernel.org X-Gm-Message-State: AOJu0YxHJDoWdjTYUGQ/Q1+9eliB7w1MK25zNFgQV+qCSVKZnUm1sqvp MtqcNGR63x5u8Tn2B1XeBvDiykoLNJ6rem3NzEJV+cYM3EhEO2vWovHIl2PidHOcnKw8dkYHK5M K+7BVKT7ofFRk8OUyKKjfFGneUcxeqiiwuKzNThZHwI09cVdi3tjEtkpocSbspw== X-Gm-Gg: ASbGnct827+7vquLrpJTi8xZ8PiOmwaCtXRoZb4y0nngv5OJ4hjQrr2VIEclOGXA5cE JWttu3tl7clOXHXsSOL+3YbGP7iIPxy646Zpv8RrpI2acHh1NZdaxsFLOeNR67LNbmstbvoj2NN jV9GcohRVVd56hUBUjoVbBRmGcFFefE8yhwj8H+/Yp3rpHNn3kZF5U8/i4KRUA4WBBDMhgygl7k wdHW0NjgoFifNiSPCgXY46ePgLW6r+oVp18N6imXdqbmua6rYbokSW9z8Vy1Fc5USFZLK7oVY11 0Tuf3A== X-Received: by 2002:a17:907:7dab:b0:aa5:1d68:1f43 with SMTP id a640c23a62f3a-ab38cc5cfd4mr198273966b.11.1737118616479; Fri, 17 Jan 2025 04:56:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxaKgdK7JoJbBu6MZvil0YKC/KT9C4PJcYlKIm/WK2Gh3c/UvTHSx0h4SJ3YHwYv67jGcLwA== X-Received: by 2002:a17:907:7dab:b0:aa5:1d68:1f43 with SMTP id a640c23a62f3a-ab38cc5cfd4mr198270766b.11.1737118615950; Fri, 17 Jan 2025 04:56:55 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384c60746sm167663966b.4.2025.01.17.04.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 04:56:55 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 9851D17E7871; Fri, 17 Jan 2025 13:56:54 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Alexander Lobakin , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Lorenzo Bianconi , Daniel Xu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , John Fastabend , Jesper Dangaard Brouer , Martin KaFai Lau , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v3 5/8] net: skbuff: introduce napi_skb_cache_get_bulk() In-Reply-To: <20250115151901.2063909-6-aleksander.lobakin@intel.com> References: <20250115151901.2063909-1-aleksander.lobakin@intel.com> <20250115151901.2063909-6-aleksander.lobakin@intel.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Fri, 17 Jan 2025 13:56:54 +0100 Message-ID: <877c6toay1.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Alexander Lobakin writes: > Add a function to get an array of skbs from the NAPI percpu cache. > It's supposed to be a drop-in replacement for > kmem_cache_alloc_bulk(skbuff_head_cache, GFP_ATOMIC) and > xdp_alloc_skb_bulk(GFP_ATOMIC). The difference (apart from the > requirement to call it only from the BH) is that it tries to use > as many NAPI cache entries for skbs as possible, and allocate new > ones only if needed. > > The logic is as follows: > > * there is enough skbs in the cache: decache them and return to the > caller; > * not enough: try refilling the cache first. If there is now enough > skbs, return; > * still not enough: try allocating skbs directly to the output array > with %GFP_ZERO, maybe we'll be able to get some. If there's now > enough, return; > * still not enough: return as many as we were able to obtain. > > Most of times, if called from the NAPI polling loop, the first one will > be true, sometimes (rarely) the second one. The third and the fourth -- > only under heavy memory pressure. > It can save significant amounts of CPU cycles if there are GRO cycles > and/or Tx completion cycles (anything that descends to > napi_skb_cache_put()) happening on this CPU. > > Signed-off-by: Alexander Lobakin > Tested-by: Daniel Xu Neat idea! Reviewed-by: Toke H=C3=B8iland-J=C3=B8rgensen