[PATCH] Make same-process recursive mm_struct access possible

From: David Howells (dhowells@redhat.com)
Date: Thu Sep 20 2001 - 10:24:35 EST


Based on an idea by Andrea Arcangeli, this patch wraps the rw_semaphore on the
mm_struct (to force you to use special locking operations to access it) and
adds a counter to the task_struct (which counts the number of active read
locks you hold on _your_ mm_struct). The four new ops are:

        mm_lock_shared(struct mm_struct *);
        mm_unlock_shared(struct mm_struct *);
        mm_lock_exclusive(struct mm_struct *);
        mm_unlock_exclusive(struct mm_struct *);

 * The exclusive ops map directly to down_write() and up_write().

 * The unlock-shared op decrements the current mm readlock counter if the mm
   unlocked is the current mm; finally it calls up_read().

 * The lock-shared op does one of the following two things:

   * If the mm being locked is the current mm, and if the current readlock
     counter is greater than zero, then it calls down_read_recursive() and
     then increments the current readlock counter.

   * Otherwise, it just calls down_read() and then increments the current
     readlock counter.

down_read_recursive() is a new rw-semaphore operation. It simply adjusts the
semaphore to record an extra active readlock. As specified in the comments
associated with it, it MUST ONLY be called if you know that there is already
an active read lock on the semaphore. Note that it never needs to wait; given
the preconditions for calling it, it knows it can always succeed immediately.

This patch makes no changes to existing rw-semaphore operations. They are
still fair. It simply makes mm_struct locks fair and capable of recursion.

David



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Sep 23 2001 - 21:00:38 EST