mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi Zhiling <chizhiling@163.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Cc: Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>, Zi Yan <ziy@nvidia.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Jan Kara <jack@suse.cz>, Chi Zhiling <chizhiling@kylinos.cn>
Subject: Re: [RFC PATCH 2/4] mm/shmem: use SGP_GET in read operations
Date: Tue, 19 May 2026 14:24:11 +0800	[thread overview]
Message-ID: <4744e5ec-f7ba-4107-8d2f-63bfe419632f@163.com> (raw)
In-Reply-To: <e63962ad-55a9-4521-9f88-fd6be0c80434@linux.alibaba.com>

On 5/19/26 11:06, Baolin Wang wrote:
> On 5/18/26 3:42 PM, Chi Zhiling wrote:
>> On 5/18/26 14:39, Baolin Wang wrote:
>>>
>>>
>>> On 5/15/26 5:47 PM, Chi Zhiling wrote:
>>>> From: Chi Zhiling <chizhiling@kylinos.cn>
>>>>
>>>> Replace SGP_READ with SGP_GET in shmem_file_read_iter(),
>>>> shmem_file_splice_read(), and shmem_get_link(). These functions
>>>> immediately unlock the folio after getting it, making the lock
>>>> acquisition redundant.
>>>>
>>>> Even though folio_lock can protect folio data consistency or prevent
>>>> truncate while holding the lock, these can still happen after unlock.
>>>> Since these functions continue reading data after unlocking, the lock
>>>> does not provide effective protection. The folio reference count is
>>>> what actually prevents reclamation during access, making the lock
>>>> unnecessary.
>>>>
>>>> Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
>>>> ---
>>>
>>> Thanks for your patch. It would be better to squash patch 1 and patch 
>>> 2 into a one commit, so that the usage of the newly introduced flag 
>>> can be easily seen.
>>
>> Hi, Baolin
>>
>> Thanks for your review. I will squash patches 1 and 2 in the next 
>> version, unless v2 is unnecessary :D
>>
>>>
>>>>   mm/shmem.c | 12 +++---------
>>>>   1 file changed, 3 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/mm/shmem.c b/mm/shmem.c
>>>> index ef19968cc51c..767610f78d0d 100644
>>>> --- a/mm/shmem.c
>>>> +++ b/mm/shmem.c
>>>> @@ -3370,15 +3370,13 @@ static ssize_t shmem_file_read_iter(struct 
>>>> kiocb *iocb, struct iov_iter *to)
>>>>               break;
>>>>           index = iocb->ki_pos >> PAGE_SHIFT;
>>>> -        error = shmem_get_folio(inode, index, 0, &folio, SGP_READ);
>>>> +        error = shmem_get_folio(inode, index, 0, &folio, SGP_GET);
>>>>           if (error) {
>>>>               if (error == -EINVAL)
>>>>                   error = 0;
>>>>               break;
>>>>           }
>>>>           if (folio) {
>>>> -            folio_unlock(folio);
>>>> -
>>>
>>> This is incorrect. Since a shmem folio can still be locked if it is 
>>> being swapped in from the swap device.
>>
>> I don't know how I missed that, that's truly a serious bug. Thanks for 
>> pointing that out.
>>
>>>
>>> Essentially, you need to show reviewers the benefit of introducing a 
>>> new flag. In what scenario would you see overhead from locking the 
>>> folio in shmem_get_folio()? And how much performance improvement does 
>>> your patch bring? Data is the easiest way to convince people:)
>>
>> Honestly, this may not bring significant performance improvements in 
>> single thread scenarios.
>>
>> I think the main benefit is that during concurrent reads and writes, 
>> especially when large folio is enabled, there are more chances that 
>> reads and writes occur in the same folio. Removing the folio lock can 
>> prevent read operations from being blocked by write operations.
>>
>> If necessary, I will include the test data in v2.
>>
>> A more important reason is that folio batches are not suitable for 
>> storing locked folios, as this could lead to some issues.
> 
> If this new flag is necessary, please add these explanations to the 
> commit message.
> 
> However, if there's no obvious performance improvement, I'd prefer not 
> to add an unnecessary flag. Also, looking at the implementation of 
> shmem_get_folio_from_batch() in patch 3, couldn't we unlock the folio 
> after shmem_get_folio()?

I have tested single-thread and multi-thread read and write. Only 
concurrent read and write shows some improvement, but dropping the lock 
is not the main target in this patch series, so I will remove the change 
in next version.

Thanks,


  reply	other threads:[~2026-05-19  6:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15  9:46 [RFC PATCH 0/4] mm/shmem: optimize read performance with folio batching Chi Zhiling
2026-05-15  9:46 ` [RFC PATCH 1/4] mm/shmem: add SGP_GET to get unlocked folio Chi Zhiling
2026-05-15  9:47 ` [RFC PATCH 2/4] mm/shmem: use SGP_GET in read operations Chi Zhiling
2026-05-18  6:39   ` Baolin Wang
2026-05-18  7:42     ` Chi Zhiling
2026-05-19  3:06       ` Baolin Wang
2026-05-19  6:24         ` Chi Zhiling [this message]
2026-05-15  9:47 ` [RFC PATCH 3/4] mm/shmem: optimize file read with folio batching Chi Zhiling
2026-05-18  6:57   ` Baolin Wang
2026-05-18  8:05     ` Chi Zhiling
2026-05-19  2:15     ` Chi Zhiling
2026-05-19  3:06       ` Baolin Wang
2026-05-15  9:47 ` [RFC PATCH 4/4] mm/shmem: make SGP_NOALLOC succeed on hole like SGP_READ Chi Zhiling

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=4744e5ec-f7ba-4107-8d2f-63bfe419632f@163.com \
    --to=chizhiling@163.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chizhiling@kylinos.cn \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /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®