public inbox for [email protected]
 help / color / mirror / Atom feed
From: Stefan Roesch <[email protected]>
To: [email protected], Jens Axboe <[email protected]>
Cc: [email protected], [email protected],
	[email protected], [email protected]
Subject: Re: [PATCH v1 01/10] btrfs: implement a nowait option for tree searches
Date: Wed, 7 Sep 2022 17:29:25 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAL3q7H6GLm+hbcJP5Mc0mjyFcWX-8wGD9LVJeYUE6HmgoZK1Vg@mail.gmail.com>



On 9/2/22 8:04 AM, Filipe Manana wrote:
> > 
> On Fri, Sep 2, 2022 at 3:57 PM Jens Axboe <[email protected]> wrote:
>>
>> On 9/2/22 8:48 AM, Filipe Manana wrote:
>>> On Fri, Sep 2, 2022 at 12:01 AM Stefan Roesch <[email protected]> wrote:
>>>>
>>>> From: Josef Bacik <[email protected]>
>>>>
>>>> For NOWAIT IOCB's we'll need a way to tell search to not wait on locks
>>>> or anything.  Accomplish this by adding a path->nowait flag that will
>>>> use trylocks and skip reading of metadata, returning -EWOULDBLOCK in
>>>> either of these cases.  For now we only need this for reads, so only the
>>>> read side is handled.  Add an ASSERT() to catch anybody trying to use
>>>> this for writes so they know they'll have to implement the write side.
>>>>
>>>> Signed-off-by: Josef Bacik <[email protected]>
>>>> Signed-off-by: Stefan Roesch <[email protected]>
>>>> ---
>>>>  fs/btrfs/ctree.c   | 39 ++++++++++++++++++++++++++++++++++++---
>>>>  fs/btrfs/ctree.h   |  1 +
>>>>  fs/btrfs/locking.c | 23 +++++++++++++++++++++++
>>>>  fs/btrfs/locking.h |  1 +
>>>>  4 files changed, 61 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
>>>> index ebfa35fe1c38..052c768b2297 100644
>>>> --- a/fs/btrfs/ctree.c
>>>> +++ b/fs/btrfs/ctree.c
>>>> @@ -1447,6 +1447,11 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
>>>>                         return 0;
>>>>                 }
>>>>
>>>> +               if (p->nowait) {
>>>> +                       free_extent_buffer(tmp);
>>>> +                       return -EWOULDBLOCK;
>>>> +               }
>>>> +
>>>>                 if (unlock_up)
>>>>                         btrfs_unlock_up_safe(p, level + 1);
>>>>
>>>> @@ -1467,6 +1472,8 @@ read_block_for_search(struct btrfs_root *root, struct btrfs_path *p,
>>>>                         ret = -EAGAIN;
>>>>
>>>>                 goto out;
>>>> +       } else if (p->nowait) {
>>>> +               return -EWOULDBLOCK;
>>>>         }
>>>>
>>>>         if (unlock_up) {
>>>> @@ -1634,7 +1641,13 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
>>>>                  * We don't know the level of the root node until we actually
>>>>                  * have it read locked
>>>>                  */
>>>> -               b = btrfs_read_lock_root_node(root);
>>>> +               if (p->nowait) {
>>>> +                       b = btrfs_try_read_lock_root_node(root);
>>>> +                       if (IS_ERR(b))
>>>> +                               return b;
>>>> +               } else {
>>>> +                       b = btrfs_read_lock_root_node(root);
>>>> +               }
>>>>                 level = btrfs_header_level(b);
>>>>                 if (level > write_lock_level)
>>>>                         goto out;
>>>> @@ -1910,6 +1923,13 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
>>>>         WARN_ON(p->nodes[0] != NULL);
>>>>         BUG_ON(!cow && ins_len);
>>>>
>>>> +       /*
>>>> +        * For now only allow nowait for read only operations.  There's no
>>>> +        * strict reason why we can't, we just only need it for reads so I'm
>>>> +        * only implementing it for reads right now.
>>>> +        */
>>>> +       ASSERT(!p->nowait || !cow);
>>>> +
>>>>         if (ins_len < 0) {
>>>>                 lowest_unlock = 2;
>>>>
>>>> @@ -1936,7 +1956,12 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
>>>>
>>>>         if (p->need_commit_sem) {
>>>>                 ASSERT(p->search_commit_root);
>>>> -               down_read(&fs_info->commit_root_sem);
>>>> +               if (p->nowait) {
>>>> +                       if (!down_read_trylock(&fs_info->commit_root_sem))
>>>> +                               return -EAGAIN;
>>>
>>> Why EAGAIN here and everywhere else EWOULDBLOCK? See below.
>>
>> Is EWOULDBLOCK ever different from EAGAIN? But it should be used
>> consistently, EAGAIN would be the return of choice for that.
> 
> Oh right, EWOULDBLOCK is defined as EAGAIN, same values.
> It would be best to use the same everywhere, avoiding confusion...
> 

I changed it to EAGAIN in the patch series.
>>
>> --
>> Jens Axboe
> 
> 
> 

  reply	other threads:[~2022-09-08  0:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01 22:58 [PATCH v1 00/10] io-uring/btrfs: support async buffered writes Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 01/10] btrfs: implement a nowait option for tree searches Stefan Roesch
2022-09-02 14:48   ` Filipe Manana
2022-09-02 14:57     ` Jens Axboe
2022-09-02 15:04       ` Filipe Manana
2022-09-08  0:29         ` Stefan Roesch [this message]
2022-09-08  0:28     ` Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 02/10] btrfs: make can_nocow_extent nowait compatible Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 03/10] btrfs: add the ability to use NO_FLUSH for data reservations Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 04/10] btrfs: add btrfs_try_lock_ordered_range Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 05/10] btrfs: make btrfs_check_nocow_lock nowait compatible Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 06/10] btrfs: make prepare_pages " Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 07/10] btrfs: make lock_and_cleanup_extent_if_need " Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 08/10] btrfs: btrfs: plumb NOWAIT through the write path Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 09/10] btrfs: make balance_dirty_pages nowait compatible Stefan Roesch
2022-09-02 14:34   ` kernel test robot
2022-09-02 14:43     ` Jens Axboe
2022-09-08  0:26       ` Stefan Roesch
2022-09-01 22:58 ` [PATCH v1 10/10] btrfs: enable nowait async buffered writes Stefan Roesch

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox