* [PATCH 2.6.20 08/10] nfnetlink_log: shorten instances_lock holding time
@ 2007-02-12 0:40 Michał Mirosław
2007-02-13 12:48 ` Patrick McHardy
0 siblings, 1 reply; 2+ messages in thread
From: Michał Mirosław @ 2007-02-12 0:40 UTC (permalink / raw)
To: netfilter-devel; +Cc: linux-kernel
Shorten instances_lock window at the cost of doing unnecessary work
on the failure case. I don't know if it makes sense actually. ;>
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
--- linux-2.6.20/net/netfilter/nfnetlink_log.c.6 2007-02-11 22:31:19.000000000 +0100
+++ linux-2.6.20/net/netfilter/nfnetlink_log.c 2007-02-11 22:41:18.000000000 +0100
@@ -149,18 +149,14 @@ instance_create(u_int16_t group_num, int
if (!try_module_get(THIS_MODULE)) {
UDEBUG("aborting, could not reference own module (module unloading?)\n");
- goto out_modunload;
- }
-
- write_lock_bh(&instances_lock);
- if (__instance_lookup(group_num)) {
- UDEBUG("aborting, instance already exists\n");
- goto out_unlock;
+ return NULL;
}
inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
- if (!inst)
- goto out_unlock;
+ if (!inst) {
+ module_put(THIS_MODULE);
+ return NULL;
+ }
INIT_HLIST_NODE(&inst->hlist);
spin_lock_init(&inst->lock);
@@ -181,21 +177,25 @@ instance_create(u_int16_t group_num, int
inst->copy_mode = NFULNL_COPY_PACKET;
inst->copy_range = 0xffff;
- hlist_add_head(&inst->hlist,
+ write_lock_bh(&instances_lock);
+
+ if (!__instance_lookup(group_num)) {
+ hlist_add_head(&inst->hlist,
&instance_table[instance_hashfn(group_num)]);
- UDEBUG("newly added node: %p, next=%p\n", &inst->hlist,
- inst->hlist.next);
+ UDEBUG("newly added node: %p, next=%p\n", &inst->hlist,
+ inst->hlist.next);
+ } else {
+ UDEBUG("aborting, instance already exists\n");
+
+ kfree(inst);
+ module_put(THIS_MODULE);
+ inst = NULL;
+ }
write_unlock_bh(&instances_lock);
return inst;
-
-out_unlock:
- write_unlock_bh(&instances_lock);
- module_put(THIS_MODULE);
-out_modunload:
- return NULL;
}
static int __nfulnl_send(struct nfulnl_instance *inst);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2.6.20 08/10] nfnetlink_log: shorten instances_lock holding time
2007-02-12 0:40 [PATCH 2.6.20 08/10] nfnetlink_log: shorten instances_lock holding time Michał Mirosław
@ 2007-02-13 12:48 ` Patrick McHardy
0 siblings, 0 replies; 2+ messages in thread
From: Patrick McHardy @ 2007-02-13 12:48 UTC (permalink / raw)
To: Michał Mirosław; +Cc: netfilter-devel, linux-kernel
Micha³ Miros³aw wrote:
> Shorten instances_lock window at the cost of doing unnecessary work
> on the failure case. I don't know if it makes sense actually. ;>
Not really. Its taking the lock whats expensive and we shouldn't
have contention here.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-02-13 12:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-12 0:40 [PATCH 2.6.20 08/10] nfnetlink_log: shorten instances_lock holding time Michał Mirosław
2007-02-13 12:48 ` Patrick McHardy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.