dst.c (4ec93edb14fe5fdee9fae6335f2cbba204627eac) dst.c (c376222960ae91d5ffb9197ee36771aaed1d9f90)
1/*
2 * net/core/dst.c Protocol independent destination cache.
3 *
4 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
5 *
6 */
7
8#include <linux/bitops.h>

--- 15 unchanged lines hidden (view full) ---

24 * entries is protected by dst_lock.
25 * 2) GC is run only from BH context, and is the only remover
26 * of entries.
27 * 3) Entries are added to the garbage list from both BH
28 * and non-BH context, so local BH disabling is needed.
29 * 4) All operations modify state, so a spinlock is used.
30 */
31static struct dst_entry *dst_garbage_list;
1/*
2 * net/core/dst.c Protocol independent destination cache.
3 *
4 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
5 *
6 */
7
8#include <linux/bitops.h>

--- 15 unchanged lines hidden (view full) ---

24 * entries is protected by dst_lock.
25 * 2) GC is run only from BH context, and is the only remover
26 * of entries.
27 * 3) Entries are added to the garbage list from both BH
28 * and non-BH context, so local BH disabling is needed.
29 * 4) All operations modify state, so a spinlock is used.
30 */
31static struct dst_entry *dst_garbage_list;
32#if RT_CACHE_DEBUG >= 2
32#if RT_CACHE_DEBUG >= 2
33static atomic_t dst_total = ATOMIC_INIT(0);
34#endif
35static DEFINE_SPINLOCK(dst_lock);
36
37static unsigned long dst_gc_timer_expires;
38static unsigned long dst_gc_timer_inc = DST_GC_MAX;
39static void dst_run_gc(unsigned long);
40static void ___dst_free(struct dst_entry * dst);

--- 86 unchanged lines hidden (view full) ---

127void * dst_alloc(struct dst_ops * ops)
128{
129 struct dst_entry * dst;
130
131 if (ops->gc && atomic_read(&ops->entries) > ops->gc_thresh) {
132 if (ops->gc())
133 return NULL;
134 }
33static atomic_t dst_total = ATOMIC_INIT(0);
34#endif
35static DEFINE_SPINLOCK(dst_lock);
36
37static unsigned long dst_gc_timer_expires;
38static unsigned long dst_gc_timer_inc = DST_GC_MAX;
39static void dst_run_gc(unsigned long);
40static void ___dst_free(struct dst_entry * dst);

--- 86 unchanged lines hidden (view full) ---

127void * dst_alloc(struct dst_ops * ops)
128{
129 struct dst_entry * dst;
130
131 if (ops->gc && atomic_read(&ops->entries) > ops->gc_thresh) {
132 if (ops->gc())
133 return NULL;
134 }
135 dst = kmem_cache_alloc(ops->kmem_cachep, GFP_ATOMIC);
135 dst = kmem_cache_zalloc(ops->kmem_cachep, GFP_ATOMIC);
136 if (!dst)
137 return NULL;
136 if (!dst)
137 return NULL;
138 memset(dst, 0, ops->entry_size);
139 atomic_set(&dst->__refcnt, 0);
140 dst->ops = ops;
141 dst->lastuse = jiffies;
142 dst->path = dst;
143 dst->input = dst_discard_in;
144 dst->output = dst_discard_out;
138 atomic_set(&dst->__refcnt, 0);
139 dst->ops = ops;
140 dst->lastuse = jiffies;
141 dst->path = dst;
142 dst->input = dst_discard_in;
143 dst->output = dst_discard_out;
145#if RT_CACHE_DEBUG >= 2
144#if RT_CACHE_DEBUG >= 2
146 atomic_inc(&dst_total);
147#endif
148 atomic_inc(&ops->entries);
149 return dst;
150}
151
152static void ___dst_free(struct dst_entry * dst)
153{

--- 44 unchanged lines hidden (view full) ---

198 }
199
200 atomic_dec(&dst->ops->entries);
201
202 if (dst->ops->destroy)
203 dst->ops->destroy(dst);
204 if (dst->dev)
205 dev_put(dst->dev);
145 atomic_inc(&dst_total);
146#endif
147 atomic_inc(&ops->entries);
148 return dst;
149}
150
151static void ___dst_free(struct dst_entry * dst)
152{

--- 44 unchanged lines hidden (view full) ---

197 }
198
199 atomic_dec(&dst->ops->entries);
200
201 if (dst->ops->destroy)
202 dst->ops->destroy(dst);
203 if (dst->dev)
204 dev_put(dst->dev);
206#if RT_CACHE_DEBUG >= 2
205#if RT_CACHE_DEBUG >= 2
207 atomic_dec(&dst_total);
208#endif
209 kmem_cache_free(dst->ops->kmem_cachep, dst);
210
211 dst = child;
212 if (dst) {
213 int nohash = dst->flags & DST_NOHASH;
214

--- 76 unchanged lines hidden ---
206 atomic_dec(&dst_total);
207#endif
208 kmem_cache_free(dst->ops->kmem_cachep, dst);
209
210 dst = child;
211 if (dst) {
212 int nohash = dst->flags & DST_NOHASH;
213

--- 76 unchanged lines hidden ---