From: Ioannis Angelakopoulos <iangelak@fb.com>
To: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>,
"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH v2 3/5] btrfs: Add lockdep models for the transaction states wait events
Date: Wed, 20 Jul 2022 17:39:48 +0000 [thread overview]
Message-ID: <e495c510-fb46-774b-a5ac-461c97ed9b02@fb.com> (raw)
In-Reply-To: <a71f27ea-9d2b-f44b-2222-b9f35949a944@dorminy.me>
On 7/20/22 7:47 AM, Sweet Tea Dorminy wrote:
>
>
> On 7/19/22 00:09, Ioannis Angelakopoulos wrote:
>> Add a lockdep annotation for the transaction states that have wait
>> events; 1) TRANS_STATE_COMMIT_START, 2) TRANS_STATE_UNBLOCKED, 3)
>> TRANS_STATE_SUPER_COMMITTED, and 4) TRANS_STATE_COMPLETED in
>> fs/btrfs/transaction.c.
>>
>> With the exception of the lockdep annotation for TRANS_STATE_COMMIT_START
>> the transaction thread has to acquire the lockdep maps for the
>> transaction
>> states as reader after the lockdep map for num_writers is released so
>> that
>> lockdep does not complain.
>
> "acquire the lockdep maps for the transaction states as reader ..." took
> a couple readings for me to grasp. Maybe "get a notional read lock on
> the transaction state only after releasing the notional lock on
> num_writers, as lockdep requires locks to be acquired/released in
> [somehow]". (I don't know how lockdep complains, but I think saying why
> in this commit message would help me understand the 'why' better.)
>
I will make the comment here or the one below more detailed. Yes it has
to do with the lock ordering. As it is, the thread has first acquired
the btrfs_trans_num_writers lock. In case it acquired the state locks
before releasing the btrfs_trans_num_writers lock, it would first
release the btrfs_trans_num_writers lock and then the state locks. Thus
lockdep would complain about a potential deadlock, since locks should be
released in the reverse order they are acquired.
>> @@ -2323,6 +2344,15 @@ int btrfs_commit_transaction(struct
>> btrfs_trans_handle *trans)
>> wait_event(cur_trans->writer_wait,
>> atomic_read(&cur_trans->num_writers) == 1);
>> + /*
>> + * Make lockdep happy by acquiring the state locks after
>> + * btrfs_trans_num_writers is released.
>> + */
>
> Same sort of comment here: elaborating on why it makes lockdep happy
> would help me understand this better.
next prev parent reply other threads:[~2022-07-20 17:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 4:09 [PATCH v2 0/5] btrfs: Annotate wait events with lockdep Ioannis Angelakopoulos
2022-07-19 4:09 ` [PATCH v2 1/5] btrfs: Add a lockdep model for the num_writers wait event Ioannis Angelakopoulos
2022-07-20 14:46 ` Josef Bacik
2022-07-20 14:47 ` Sweet Tea Dorminy
2022-07-20 17:12 ` Ioannis Angelakopoulos
2022-07-19 4:09 ` [PATCH v2 2/5] btrfs: Add a lockdep model for the num_extwriters " Ioannis Angelakopoulos
2022-07-20 14:46 ` Josef Bacik
2022-07-19 4:09 ` [PATCH v2 3/5] btrfs: Add lockdep models for the transaction states wait events Ioannis Angelakopoulos
2022-07-20 14:47 ` Sweet Tea Dorminy
2022-07-20 17:39 ` Ioannis Angelakopoulos [this message]
2022-07-20 14:48 ` Josef Bacik
2022-07-20 17:49 ` Ioannis Angelakopoulos
2022-07-19 4:09 ` [PATCH v2 4/5] btrfs: Add a lockdep model for the pending_ordered wait event Ioannis Angelakopoulos
2022-07-20 14:48 ` Josef Bacik
2022-07-19 4:10 ` [PATCH v2 5/5] btrfs: Add a lockdep model for the ordered extents " Ioannis Angelakopoulos
2022-07-20 14:50 ` Josef Bacik
2022-07-20 14:47 ` [PATCH v2 0/5] btrfs: Annotate wait events with lockdep Sweet Tea Dorminy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e495c510-fb46-774b-a5ac-461c97ed9b02@fb.com \
--to=iangelak@fb.com \
--cc=Kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=sweettea-kernel@dorminy.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.