BBS水木清华站∶精华区
发信人: mephisto (梦菲斯特*大宝宝), 信区: Linux
标 题: Re: 看过源码的高手解释一下?
发信站: BBS 水木清华站 (Thu Dec 14 17:26:29 2000)
I am pretty sure I have send you mail about this. Havn't you get that?
【 在 lightofstar (star) 的大作中提到: 】
∶ void kfree_skbmem(struct sk_buff *skb)
∶ {
∶ if (!skb->cloned || atomic_dec_and_test(skb_datarefp(skb)))
∶ kfree(skb->head);
∶ kmem_cache_free(skbuff_head_cache, skb);
∶ atomic_dec(&net_skbcount);
∶ }
∶ extern __inline__ atomic_t *skb_datarefp(struct sk_buff *skb)
∶ {
∶ return (atomic_t *)(skb->end);
∶ }
∶ 第一个函数调用了第二个函数,那么假如skb_cloned == 1时,
∶ 什么时候才能执行 kfree(skb->head)??
when *(skb->end) == 1, atomic_dec_and_test(..)return TRUE.
Then release.
∶ skb_end本身指的是数据部分的结尾,分配sk_buff时是个定值。
Exactly.
Here is the trick, skb_end is pointer to data end bound.
Kernel use the next mem as a reference counter.
data->[ the buffer ]
end --->
[reference counter]
Because they need the reference counter go with the data, not the
skb_buff, skb_buff might release earlyer than the data.
skb_clone()
{
...
atomic_inc(skb_datarefp(skb));
...
}
alloc_skb()
{
...
atomic_set(skb_datarefp(skb),1);
...
}
∶ 调用atomic_dec_and_test处理它,能够减少数据部分的引用次数吗?
∶ 当数据部分被两个sk_buff共享时,什么时候才是真正的释放了数据区?
when the counter dec to 0 ;-)
--
约塞连怀疑地摇了摇头,拒绝接受丹比的劝告."当我抬起来时,我看到人们全在设法赚钱.我
看不见天堂,看不见圣人,也看不见天使.我只看见人们利用每一次正当的冲动和每一场人类
的悲剧大把大把地捞钱."
※ 来源:·BBS 水木清华站 smth.org·[FROM: 211.99.241.146]
BBS水木清华站∶精华区