From patchwork Fri Oct 25 14:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13850807 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38BC82022E9; Fri, 25 Oct 2024 14:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729866046; cv=none; b=eFRvGO2imeVMkFFMceiZeMfCSDVDeJwmBKmbAI2mEhXR4XzBIfxezFQfxtmp5PFNVbILMpdnwS6HfcdqNF91HAKye5wAnXvB5w/NX0kR1bTdZQYpyS4h984x1SFThN3IqBJfRbikpr7+ibqzVEYfkwTx3LBYG0WizVvrIVPbFA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729866046; c=relaxed/simple; bh=AL33S6aqp2+Me+OST8v16scKbzzI5Wc5/E5yIdnk6Tk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m3O7rZqLbfNQLuN54or+oy7vkqUlD89kPuGIHQlY3GARjSgEu8TaekGFIlwEbrBSFCmXzX4uy+ccHDNpjlwheAAvfZiLngSOdjkYQYbG/W7IzXbnNvJX2FybKygfEkEoXJGz1gIM1Do9m02CPYECzC4adx0wDI+aH/gcDH6tWbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a9a2cdc6f0cso288864766b.2; Fri, 25 Oct 2024 07:20:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729866042; x=1730470842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=57KDVzYSwEIQctNDCcs9zd4Yx9d1EFMi2Kt7CfrtltM=; b=pcppgehPvJCyEXuH0HG/4/b9Ip4ANhnOVvKqCir52M6cTM+zAsQrGnRQ4QEwRqvrKM B7ZZn7db3xu4UMCexZSvosuD/T0b79D6JcgJByn3gERKvSyVxqw1lGRtSgbQypSOKcrq h8DCTiLpEPUnNxhUHIhaGnIFTseQoBDBJZddMVUxdKXHKZa+69QIXi680TWlfRK/6wEN EggEXyThAX33X5EJUF4sI+il0e1ZpNrN9AC+lPdNAbUBmPv7hE5VqCfocEu4/ApnlOAI kDecvF/lfOxqTXoEGmECwquT6GylC8XSGmRW77H9gsV8v7e9fuKkWn+aTAAF/gPodoWE L+cg== X-Forwarded-Encrypted: i=1; AJvYcCWi+rKjSRVhLcbYAONl3pmOF1lXPnkss76/c4Bzs1LIG8cy46HZz5uMijZqcX5nYWVCE5fp8qbc@vger.kernel.org, AJvYcCXCfXp9rZueOpIecF7HRtA2Q+gvx/Apdz8tQQIIim4nXlhZ8W2f31Y1eHUbvIC9wnPT+0IQCVsR7WCfTWQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwC5DNZmob2A+LnDQvluPMv6PAhJlmO7NCVeE15D7Bvux/tzAlb eqrC1gtGgjU9nLxD1Dy/fPqkkfujJgxUCKDmuj2P7huJm5827vir X-Google-Smtp-Source: AGHT+IFUl1d1otlSP2l0kzq0Mxj1GCgb7HSwX85GZgsdLHF2rLlTRyhtRxvX8C8tnkQGmm2HP4J4/g== X-Received: by 2002:a17:907:9484:b0:a9a:597:8cca with SMTP id a640c23a62f3a-a9abf92f3camr977454666b.45.1729866040871; Fri, 25 Oct 2024 07:20:40 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b307b53fcsm76881166b.148.2024.10.25.07.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 07:20:40 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, horms@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com, jiri@resnulli.us, jv@jvosburgh.net, andy@greyhouse.net, aehkn@xenhub.one, Rik van Riel , Al Viro Subject: [PATCH net-next 1/3] net: netpoll: Defer skb_pool population until setup success Date: Fri, 25 Oct 2024 07:20:18 -0700 Message-ID: <20241025142025.3558051-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241025142025.3558051-1-leitao@debian.org> References: <20241025142025.3558051-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The current implementation has a flaw where it populates the skb_pool with 32 SKBs before calling __netpoll_setup(). If the setup fails, the skb_pool buffer will persist indefinitely and never be cleaned up. This change moves the skb_pool population to after the successful completion of __netpoll_setup(), ensuring that the buffers are not unnecessarily retained. Additionally, this modification alleviates rtnl lock pressure by allowing the buffer filling to occur outside of the lock. Signed-off-by: Breno Leitao --- net/core/netpoll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index aa49b92e9194..e83fd8bdce36 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -772,13 +772,13 @@ int netpoll_setup(struct netpoll *np) } } - /* fill up the skb queue */ - refill_skbs(); - err = __netpoll_setup(np, ndev); if (err) goto put; rtnl_unlock(); + + /* fill up the skb queue */ + refill_skbs(); return 0; put: From patchwork Fri Oct 25 14:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13850808 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8C7720BB25; Fri, 25 Oct 2024 14:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729866050; cv=none; b=GA/IXy6szBRmkSnTQpkwiQ3sGYTXKrmTCO3DyVz0twxPDffinFuzk3fwb9MV+1X/SODYWqOelRsWaaqia2V0tSIh5S3cswkdfFMeRlL9R05FXAtV634pkUdAFhCXZFKbsvVNTwbsJ2e3TO7iONtaYBVB7t9ZoEEOXOHgvlAo74I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729866050; c=relaxed/simple; bh=kTXqbVT8/aFlhf2HvwbGxRoLYxDWqQGUVvq6m5IFA4Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QqjXc8vhkqPQ75M8eWpDdNa+QAq8EOL308rkJUgFg0bhgveVDe9HJoy3J4vfXY7qnQJXqM64tunX/6VCKQu0zsT+mr2ROJt4cHoHrzdsCXSbChhhYiXxQCWSP7l2C45Mzf/7e2cwNzNjTwQd4uK9cTu+ZrxzBf7iyfL24BUDBiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a99ea294480so144683566b.2; Fri, 25 Oct 2024 07:20:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729866046; x=1730470846; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ck924se1om31UyjoafpndFOU4rDT4hZQ5rZ/Zwk6iDI=; b=J1QGtHeiDQ9NlCUVrRfgqIwQUggQ8Ebr9oq/uMhr6+PUK1KG9PlIfoDDqD6zTJNLPk 5h/JztzOouOBc8QmbZ0y6reLrU9NYTfjbNLCZsJBGfUIx1wd0uvQjqn7xIJu7A+gZyKH G0cVzC/MWa3qlLOKcq5oAjpJ4QAEEFjPtDIzE/azg+px+TNwm0QZyqALDR69q4hc+JjL Ml46oKF5B+zRNCBBty9syac5J15P2OMQ+boLQ3BYJiiSLE4AQp205CWwvtnfgL8Nm227 7AlDYDYi7zmQQJ1DE+1oPSPhrYBlTID0aYo5caO3v6ONW1i/odi/1tRiaaxoXLRNDeFS wJVQ== X-Forwarded-Encrypted: i=1; AJvYcCV6G+LmCv8LeDDM87463MM+hYcselNoASVE9v40vkle1U5gYZKAHruCokAD4HpAUPkVbT7ZOAGQdmJesbY=@vger.kernel.org, AJvYcCVv7SMrn/UfNGp2s0dXDm05DnC5RMZllWpCNAMqJp+ZuzRJqEVZsXFf/zoEtAIYelU5CwJL0biI@vger.kernel.org X-Gm-Message-State: AOJu0Yxaskdr9qpVkCbwdNReICu56/MBnYWvCa4YsLee0HN+YkzRsmcD Pd0eb+4v9fYQkjouXenkbD/BFrTLgPOYIKdNxMnmTtgOtuV1pM/B X-Google-Smtp-Source: AGHT+IETnJCpvGq9y8Sy6S/Rh8w9SGTLCR33+tk+O1VMx6SYqVv0L4zb0FRLNEe2F/IZtlBQ2LpzrQ== X-Received: by 2002:a05:6402:1956:b0:5c8:8290:47bf with SMTP id 4fb4d7f45d1cf-5cb8b1ea74amr10463758a12.21.1729866046014; Fri, 25 Oct 2024 07:20:46 -0700 (PDT) Received: from localhost (fwdproxy-lla-114.fbsv.net. [2a03:2880:30ff:72::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb6349675sm665994a12.94.2024.10.25.07.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 07:20:44 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, horms@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com, jiri@resnulli.us, jv@jvosburgh.net, andy@greyhouse.net, aehkn@xenhub.one, Rik van Riel , Al Viro Subject: [PATCH net-next 2/3] net: netpoll: Individualize the skb pool Date: Fri, 25 Oct 2024 07:20:19 -0700 Message-ID: <20241025142025.3558051-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241025142025.3558051-1-leitao@debian.org> References: <20241025142025.3558051-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The current implementation of the netpoll system uses a global skb pool, which can lead to inefficient memory usage and waste when targets are disabled or no longer in use. This can result in a significant amount of memory being unnecessarily allocated and retained, potentially causing performance issues and limiting the availability of resources for other system components. Modify the netpoll system to assign a skb pool to each target instead of using a global one. This approach allows for more fine-grained control over memory allocation and deallocation, ensuring that resources are only allocated and retained as needed. Signed-off-by: Breno Leitao --- include/linux/netpoll.h | 1 + net/core/netpoll.c | 29 +++++++++++------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index cd4e28db0cbd..77635b885c18 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -32,6 +32,7 @@ struct netpoll { bool ipv6; u16 local_port, remote_port; u8 remote_mac[ETH_ALEN]; + struct sk_buff_head skb_pool; }; struct netpoll_info { diff --git a/net/core/netpoll.c b/net/core/netpoll.c index e83fd8bdce36..c9a9e37e2d74 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -45,9 +45,6 @@ #define MAX_UDP_CHUNK 1460 #define MAX_SKBS 32 - -static struct sk_buff_head skb_pool; - #define USEC_PER_POLL 50 #define MAX_SKB_SIZE \ @@ -234,20 +231,23 @@ void netpoll_poll_enable(struct net_device *dev) up(&ni->dev_lock); } -static void refill_skbs(void) +static void refill_skbs(struct netpoll *np) { + struct sk_buff_head *skb_pool; struct sk_buff *skb; unsigned long flags; - spin_lock_irqsave(&skb_pool.lock, flags); - while (skb_pool.qlen < MAX_SKBS) { + skb_pool = &np->skb_pool; + + spin_lock_irqsave(&skb_pool->lock, flags); + while (skb_pool->qlen < MAX_SKBS) { skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC); if (!skb) break; - __skb_queue_tail(&skb_pool, skb); + __skb_queue_tail(skb_pool, skb); } - spin_unlock_irqrestore(&skb_pool.lock, flags); + spin_unlock_irqrestore(&skb_pool->lock, flags); } static void zap_completion_queue(void) @@ -284,12 +284,12 @@ static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve) struct sk_buff *skb; zap_completion_queue(); - refill_skbs(); + refill_skbs(np); repeat: skb = alloc_skb(len, GFP_ATOMIC); if (!skb) - skb = skb_dequeue(&skb_pool); + skb = skb_dequeue(&np->skb_pool); if (!skb) { if (++count < 10) { @@ -778,7 +778,7 @@ int netpoll_setup(struct netpoll *np) rtnl_unlock(); /* fill up the skb queue */ - refill_skbs(); + refill_skbs(np); return 0; put: @@ -792,13 +792,6 @@ int netpoll_setup(struct netpoll *np) } EXPORT_SYMBOL(netpoll_setup); -static int __init netpoll_init(void) -{ - skb_queue_head_init(&skb_pool); - return 0; -} -core_initcall(netpoll_init); - static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head) { struct netpoll_info *npinfo = From patchwork Fri Oct 25 14:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13850809 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 441201FB8B3; Fri, 25 Oct 2024 14:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729866053; cv=none; b=Neut3yuDsj1qSyGbYT+fVMsqOu9JACOPkXLVnM97AIpcQEx0Jzo+54qhTHjiLcZ9hZlWRl3rf5jf0NuU4YeohWdRx89HHXBo+JMkyEQxg6NBHhdJd/yN2e3PRqtmuazFDQOB6ABwqYkG5oz4c64w+tdbEpVRD2AhuX8y34TV87w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729866053; c=relaxed/simple; bh=fLsTCSmGp67EjhEnnlAG78/AyL452S+1fsT8cfcmIoM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rDJ8bILx+I2lCbcYYekZfZTb9abZ0jOMdllLUvNMrplLTJ0Xxv8k68gdjAHRM/Er1FObZ+tmXfScrrcuPRLh0w/UtbEZeG4mXTmKNiVL4MV9CsSwmWCREVXwKUMY2jYFEBV795r8rU2+gdYnppi6G5vZvtvp6kQGN9mE8GOaCQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a9a0ec0a94fso289695066b.1; Fri, 25 Oct 2024 07:20:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729866049; x=1730470849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pm3hvhV5IbmS7jee4bd/KcAJkIdb0heegZgnh5CQJLs=; b=rfvndUizzeYBHUldBVqMg4axYiLI/+H4Qq/fVo1MM54rNG6ItC0Q4YL1zperNHbsUw 5ZgW/Q4LU88psfY4nTea6k17rc1WhiPfoiaRGXOD5tMLDLoIFMb1hb7Ad4zWl63DDsCF AMrIXy4TIfRYszu569Ica5cVVDBZGOoKmvwECmL/SBx2R2X6H875YMIGZNaWOFLKQs/K 3GHt+8UfpQk5EN/HArsczmi2S3RCAM095sGSPEPLUE0YzsQz6BsO7KrlD5XyCUoXP68L 8JxgF6teRsCylCLaSslZf+risyXCpOMUtzpJwk1Mj2/6lYfAC0QpnaxGpLAHUz5TQsLq Rq9Q== X-Forwarded-Encrypted: i=1; AJvYcCV/wDfDZsSIauO1xBjIqzn4YuVO/0gWrZ1dqP78npcig8xoTsXTKFKtUextQt9yrSLGdKv06Etz@vger.kernel.org, AJvYcCVBB69CNw/TJBnou4ArSdlDwZYCASEarEVD4E9P2Sts5Qbj3V6QZs7aDEDU6Pr/h3oQ6xJxqTf6CnJAVLY=@vger.kernel.org X-Gm-Message-State: AOJu0YzV/82fLvm86smDHZkWrPcrXCuqxPw2qgLrun35nuo4bYTka3p5 BYGvjJ0+/nbcMzPvRUZ41wUNi+mSzRkOWYGB9zAa/3tsbL597HE/ X-Google-Smtp-Source: AGHT+IFbKqmmKvRLqml79sWrH3UJ8TA84zhLsSg9Rz0Lm0QloNqbwms7CBZXT0VjobG/JIt+Wf6X+w== X-Received: by 2002:a17:907:72ce:b0:a9a:b70:2a7c with SMTP id a640c23a62f3a-a9ad27386f2mr555322766b.25.1729866049488; Fri, 25 Oct 2024 07:20:49 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b32455a83sm76247066b.186.2024.10.25.07.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 07:20:48 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, horms@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com, jiri@resnulli.us, jv@jvosburgh.net, andy@greyhouse.net, aehkn@xenhub.one, Rik van Riel , Al Viro Subject: [PATCH net-next 3/3] net: netpoll: flush skb pool during cleanup Date: Fri, 25 Oct 2024 07:20:20 -0700 Message-ID: <20241025142025.3558051-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241025142025.3558051-1-leitao@debian.org> References: <20241025142025.3558051-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The netpoll subsystem maintains a pool of 32 pre-allocated SKBs per instance, but these SKBs are not freed when the netpoll user is brought down. This leads to memory waste as these buffers remain allocated but unused. Add skb_pool_flush() to properly clean up these SKBs when netconsole is terminated, improving memory efficiency. Signed-off-by: Breno Leitao --- net/core/netpoll.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index c9a9e37e2d74..bf2064d689d5 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -656,6 +656,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) /* last thing to do is link it to the net device structure */ rcu_assign_pointer(ndev->npinfo, npinfo); + skb_queue_head_init(&np->skb_pool); return 0; @@ -809,6 +810,22 @@ static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head) kfree(npinfo); } +static void skb_pool_flush(struct netpoll *np) +{ + struct sk_buff_head *skb_pool; + struct sk_buff *skb; + unsigned long flags; + + skb_pool = &np->skb_pool; + + spin_lock_irqsave(&skb_pool->lock, flags); + while (skb_pool->qlen > 0) { + skb = __skb_dequeue(skb_pool); + kfree_skb(skb); + } + spin_unlock_irqrestore(&skb_pool->lock, flags); +} + void __netpoll_cleanup(struct netpoll *np) { struct netpoll_info *npinfo; @@ -828,6 +845,8 @@ void __netpoll_cleanup(struct netpoll *np) call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info); } else RCU_INIT_POINTER(np->dev->npinfo, NULL); + + skb_pool_flush(np); } EXPORT_SYMBOL_GPL(__netpoll_cleanup);