From 6ea9bfbc1783e58e8f23bcfd29772042ab7c71ae Mon Sep 17 00:00:00 2001 From: Aleksey Baulin Date: Sun, 2 Aug 2015 22:58:56 +0300 Subject: [PATCH] Set the kernel as an extra user of SKBs that are sent out. This should be used in conjunction with the kernel patch. The patch makes sure that SKBs in socket's TX path are freed with kfree_skb() and not __kfree_skb(). kfree_skb() pays attention to the number of users SKB currently has, whereas __kfree_skb() frees SKBs unconditionally. With these two patches together SKBs can be freed safely at any time. --- tempesta_fw/sock.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tempesta_fw/sock.c b/tempesta_fw/sock.c index a37774a8f..b60dd3124 100644 --- a/tempesta_fw/sock.c +++ b/tempesta_fw/sock.c @@ -167,6 +167,19 @@ ss_send(struct sock *sk, const SsSkbList *skb_list) SS_DBG("%s:%d entail skb=%p data_len=%u len=%u\n", __FUNCTION__, __LINE__, skb, skb->data_len, skb->len); + /* + * When SKBs are removed from socket's receive queue and + * passed to Tempesta, control over these SKBs is passed + * from kernel to Tempesta as well. Tempesta becomes the + * sole owner of these SKBs. When these SKBs are sent out + * to a client or a backend by Tempesta, the kernel becomes + * an extra owner of the SKBs in addition to Tempesta. + * To account for that it's necessary to increment SKB's + * count of users so that SKBs are not freed from under + * Tempesta or from under the kernel. + */ + skb_get(skb); + skb_entail(sk, skb); tcb->end_seq += skb->len;