Re: [PATCH 1/6] lib: Implement range locks

From: Jan Kara
Date: Mon Feb 04 2013 - 11:41:48 EST


On Thu 31-01-13 15:57:26, Andrew Morton wrote:
> On Thu, 31 Jan 2013 22:49:49 +0100
> Jan Kara <jack@xxxxxxx> wrote:
>
> > Implement range locking using interval tree.
> >
> > ...
> >
> > +void range_lock(struct range_lock_tree *tree, struct range_lock *lock)
> > +{
> > + struct interval_tree_node *node;
> > + unsigned long flags;
> > +
> > + spin_lock_irqsave(&tree->lock, flags);
> > + node = interval_tree_iter_first(&tree->root, lock->node.start,
> > + lock->node.last);
> > + while (node) {
> > + lock->blocking_ranges++;
> > + node = interval_tree_iter_next(node, lock->node.start,
> > + lock->node.last);
> > + }
> > + interval_tree_insert(&lock->node, &tree->root);
> > + /* Do we need to go to sleep? */
> > + while (lock->blocking_ranges) {
> > + lock->task = current;
> > + __set_current_state(TASK_UNINTERRUPTIBLE);
> > + spin_unlock_irqrestore(&tree->lock, flags);
> > + schedule();
> > + spin_lock_irqsave(&tree->lock, flags);
> > + }
> > + spin_unlock_irqrestore(&tree->lock, flags);
> > +}
> >
> > ...
> >
> > +void range_unlock(struct range_lock_tree *tree, struct range_lock *lock)
> > +{
> > + struct interval_tree_node *node;
> > + unsigned long flags;
> > +
> > + spin_lock_irqsave(&tree->lock, flags);
> > + interval_tree_remove(&lock->node, &tree->root);
> > + node = interval_tree_iter_first(&tree->root, lock->node.start,
> > + lock->node.last);
> > + while (node) {
> > + range_lock_unblock((struct range_lock *)node);
> > + node = interval_tree_iter_next(node, lock->node.start,
> > + lock->node.last);
> > + }
> > + spin_unlock_irqrestore(&tree->lock, flags);
> > +}
>
> What are the worst-case interrupt-off durations here?
Good question. In theory, it could be relatively long, e.g. when there
are lots of DIOs in flight against a range which is locked. I'll do some
measurements to get some idea.

> I note that the new exported functions in this patchset are
> refreshingly free of documentation ;)
They are *so* obvious ;) Point taken... Thanks for review.

Honza
--
Jan Kara <jack@xxxxxxx>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/