]> git.proxmox.com Git - mirror_spl.git/commit - module/spl/spl-taskq.c
Swap taskq_ent_t with taskqid_t in taskq_thread_t
authorPrakash Surya <surya1@llnl.gov>
Fri, 16 Dec 2011 17:44:31 +0000 (09:44 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 16 Dec 2011 21:26:54 +0000 (13:26 -0800)
commite7e5f78e7bf6dc86337483f4d9f01becc017d185
tree36355eabeffff2829fe1aff8c3ac879c33168861
parentc2dceb5cd5221f7e1bde915218f5d2cf69920959
Swap taskq_ent_t with taskqid_t in taskq_thread_t

The taskq_t's active thread list is sorted based on its
tqt_ent->tqent_id field. The list is kept sorted solely by inserting
new taskq_thread_t's in their correct sorted location; no other
means is used. This means that once inserted, if a taskq_thread_t's
tqt_ent->tqent_id field changes, the list runs the risk of no
longer being sorted.

Prior to the introduction of the taskq_dispatch_prealloc() interface,
this was not a problem as a taskq_ent_t actively being serviced under
the old interface should always have a static tqent_id field. Thus,
once the taskq_thread_t is added to the taskq_t's active thread list,
the taskq_thread_t's tqt_ent->tqent_id field would remain constant.

Now, this is no longer the case. Currently, if using the
taskq_dispatch_prealloc() interface, any given taskq_ent_t actively
being serviced _may_ have its tqent_id value incremented. This happens
when the preallocated taskq_ent_t structure is recursively dispatched.
Thus, a taskq_thread_t could potentially have its tqt_ent->tqent_id
field silently modified from under its feet. If this were to happen
to a taskq_thread_t on a taskq_t's active thread list, this would
compromise the integrity of the order of the list (as the list
_may_ no longer be sorted).

To get around this, the taskq_thread_t's taskq_ent_t pointer was
replaced with its own static copy of the tqent_id. So, as a taskq_ent_t
is pulled off of the taskq_t's pending list, a static copy of its
tqent_id is made and this copy is used to sort the active thread
list. Using a static copy is key in ensuring the integrity of the
order of the active thread list. Even if the underlying taskq_ent_t
is recursively dispatched (as has its tqent_id modified), this
static copy stored inside the taskq_thread_t will remain constant.

Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #71
include/sys/taskq.h
module/spl/spl-taskq.c