mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi Zhiling <chizhiling@163.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: John Garry <john.g.garry@oracle.com>,
	Dave Chinner <david@fromorbit.com>,
	djwong@kernel.org, cem@kernel.org, linux-xfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, Chi Zhiling <chizhiling@kylinos.cn>
Subject: Re: [PATCH] xfs: Remove i_rwsem lock in buffered read
Date: Thu, 9 Jan 2025 20:10:27 +0800	[thread overview]
Message-ID: <90e5f9b4-eb1d-4d63-ba22-4a1f564b2ccf@163.com> (raw)
In-Reply-To: <CAOQ4uxje241QhUeNe=V8KKY+5a27eYd2dc3s+OiCXMPW5WZyPQ@mail.gmail.com>

On 2025/1/9 18:25, Amir Goldstein wrote:
>>> One more thing I should mention.
>>> You do not need to wait for atomic large writes patches to land.
>>> There is nothing stopping you from implementing the suggested
>>> solution based on the xfs code already in master (v6.13-rc1),
>>> which has support for the RWF_ATOMIC flag for writes.
> 
> Only I missed the fact that there is not yet a plan to support
> atomic buffered writes :-/

I think it's necessary to support atomic buffered writes.

> 
>>>
>>> It just means that the API will not be usable for applications that
>>> want to do IO larger than block size, but concurrent read/write
>>                                 ^
>> To be precise, this is the page size, not the block size, right?
>>
> 
> fs block size:
> 
>          if (iocb->ki_flags & IOCB_ATOMIC) {
>                  /*
>                   * Currently only atomic writing of a single FS block is
>                   * supported. It would be possible to atomic write smaller than
>                   * a FS block, but there is no requirement to support this.
>                   * Note that iomap also does not support this yet.
>                   */
>                  if (ocount != ip->i_mount->m_sb.sb_blocksize)
>                          return -EINVAL;
>                  ret = generic_atomic_write_valid(iocb, from);
>                  if (ret)
>                          return ret;
>          }

Uh, okay, maybe I didn't understand it very accurately. I thought
you were talking about buffered IO. I was quite curious as to why
you mentioned block size in the context of buffered IO.

> 
>>> performance of 4K IO could be improved already.
>>
>> Great, which means that IO operations aligned within a single page
>> can be executed concurrently, because the folio lock already
>> provides atomicity guarantees.
>>
>> If the write does not exceed the boundary of a page, we can
>> downgrade the iolock to XFS_IOLOCK_SHARED. It seems to be safe
>> and will not change the current behavior.
>>
>> --- a/fs/xfs/xfs_file.c
>> +++ b/fs/xfs/xfs_file.c
>> @@ -454,6 +454,11 @@ xfs_file_write_checks(
>>           if (error)
>>                   return error;
>>
>> +       if ( iocb->ki_pos >> PAGE_SHIFT == (iocb->ki_pos + count) >>
>> PAGE_SHIFT) {
>> +               *iolock = XFS_IOLOCK_SHARED;
>> +       }
>> +
>>           /*
>>            * For changing security info in file_remove_privs() we need
>> i_rwsem
>>            * exclusively.
>>
> 
> I think that may be possible, but you should do it in the buffered write
> code as the patch below.
> xfs_file_write_checks() is called from code paths like
> xfs_file_dio_write_unaligned() where you should not demote to shared lock.

Wow, thank you for the reminder. This is the prototype of the patch.
I might need to consider more scenarios and conduct testing before
sending the patch.


> 
> 
>>>
>>> It's possible that all you need to do is:
>>>
>>> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
>>> index c488ae26b23d0..2542f15496488 100644
>>> --- a/fs/xfs/xfs_file.c
>>> +++ b/fs/xfs/xfs_file.c
>>> @@ -777,9 +777,10 @@ xfs_file_buffered_write(
>>>           ssize_t                 ret;
>>>           bool                    cleared_space = false;
>>>           unsigned int            iolock;
>>> +       bool                    atomic_write = iocb->ki_flags & IOCB_ATOMIC;
>>>
>>>    write_retry:
>>> -       iolock = XFS_IOLOCK_EXCL;
>>> +       iolock = atomic_write ? XFS_IOLOCK_SHARED : XFS_IOLOCK_EXCL;
>>>           ret = xfs_ilock_iocb(iocb, iolock);
>>> --
>>>
>>> xfs_file_write_checks() afterwards already takes care of promoting
>>> XFS_IOLOCK_SHARED to XFS_IOLOCK_EXCL for extending writes.
>>
>> Yeah, for writes that exceed the PAGE boundary, we can also promote
>> the lock to XFS_IOLOCK_EXCL. Otherwise, I am concerned that it may
>> lead to old data being retained in the file.
>>
>> For example, two processes writing four pages of data to the same area.
>>
>> process A           process B
>> --------------------------------
>> write AA--
>> <sleep>
>>                       new write BBBB
>> write --AA
>>
>> The final data is BBAA.
>>
> 
> What is the use case for which you are trying to fix performance?
> Is it a use case with single block IO? if not then it does not help to implement
> a partial solution for single block size IO.

I want to improve the UnixBench score for XFS. UnixBench uses buffered
IO for testing, including both single-threaded and multi-threaded tests.
Additionally, the IO size tested in UnixBench is below 4K, so this will
be very helpful.


Thanks,
Chi Zhiling


  reply	other threads:[~2025-01-09 12:11 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-26  6:16 Chi Zhiling
2024-12-26 21:50 ` Dave Chinner
2024-12-28  7:37   ` Chi Zhiling
2024-12-28 22:17     ` Dave Chinner
2024-12-30  2:42       ` Chi Zhiling
2025-01-07 12:13         ` Amir Goldstein
2025-01-07 17:12           ` Christoph Hellwig
2025-01-08  7:43           ` Chi Zhiling
2025-01-08 11:33             ` Amir Goldstein
2025-01-08 11:45               ` Amir Goldstein
2025-01-08 12:15               ` John Garry
2025-01-09 10:07                 ` Amir Goldstein
2025-01-09 12:40                   ` John Garry
2025-01-09  8:37               ` Chi Zhiling
2025-01-09 10:25                 ` Amir Goldstein
2025-01-09 12:10                   ` Chi Zhiling [this message]
2025-01-09 12:25                     ` John Garry
2025-01-08 17:35             ` Darrick J. Wong
2025-01-09 23:28               ` Dave Chinner
2025-01-10  1:31                 ` Chi Zhiling
2025-01-10 17:07                 ` Amir Goldstein
2025-01-12 10:05                   ` Chi Zhiling
2025-01-13  2:44                     ` Darrick J. Wong
2025-01-13  5:59                       ` Chi Zhiling
2025-01-13 13:40                       ` Brian Foster
2025-01-13 16:19                         ` Darrick J. Wong
2025-01-15  5:55                         ` Christoph Hellwig
2025-01-15 21:41                           ` Dave Chinner
2025-01-16  4:36                             ` Christoph Hellwig
2025-01-17 22:20                               ` Dave Chinner
2025-01-16 14:23                             ` Brian Foster
2025-01-17 13:27                             ` Amir Goldstein
2025-01-17 22:19                               ` Dave Chinner
2025-01-18 13:03                                 ` Amir Goldstein
2025-01-20  5:11                                   ` Dave Chinner
2025-01-22  6:08                                 ` Christoph Hellwig
2025-01-22 23:35                                   ` Dave Chinner
2025-01-17 16:12                             ` Chi Zhiling
2025-01-24  7:57                             ` Chi Zhiling
2025-01-27 20:49                               ` Dave Chinner
2025-01-28  5:15                                 ` Christoph Hellwig
2025-01-28 21:23                                   ` David Laight
2025-01-29  0:59                                   ` Dave Chinner
2025-01-29  5:20                                     ` Christoph Hellwig
2025-02-10  1:44                                 ` Chi Zhiling
2025-01-14  0:09                   ` Dave Chinner
2025-01-25  8:43           ` Jinliang Zheng
2025-01-25 14:14             ` Amir Goldstein
2025-06-20 14:03   ` Jinliang Zheng

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=90e5f9b4-eb1d-4d63-ba22-4a1f564b2ccf@163.com \
    --to=chizhiling@163.com \
    --cc=amir73il@gmail.com \
    --cc=cem@kernel.org \
    --cc=chizhiling@kylinos.cn \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=john.g.garry@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®