diff mbox series

[v1,03/14] mm: add noio support in filemap_get_pages

Message ID 20220214174403.4147994-4-shr@fb.com (mailing list archive)
State New, archived
Headers show
Series Support sync buffered writes for io-uring | expand

Commit Message

Stefan Roesch Feb. 14, 2022, 5:43 p.m. UTC
This adds noio support for async buffered writes in filemap_get_pages.
The idea is to handle the failure gracefully and return -EAGAIN if we
can't get the memory quickly.

Signed-off-by: Stefan Roesch <shr@fb.com>
---
 mm/filemap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Matthew Wilcox Feb. 14, 2022, 6:08 p.m. UTC | #1
On Mon, Feb 14, 2022 at 09:43:52AM -0800, Stefan Roesch wrote:
> This adds noio support for async buffered writes in filemap_get_pages.
> The idea is to handle the failure gracefully and return -EAGAIN if we
> can't get the memory quickly.

But it doesn't return -EAGAIN?

        folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0);
        if (!folio)
                return -ENOMEM;

> Signed-off-by: Stefan Roesch <shr@fb.com>
> ---
>  mm/filemap.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index d2fb817c0845..0ff4278c3961 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2591,10 +2591,15 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
>  		filemap_get_read_batch(mapping, index, last_index, fbatch);
>  	}
>  	if (!folio_batch_count(fbatch)) {
> +		unsigned int pflags;
> +
>  		if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
> -			return -EAGAIN;
> +			pflags = memalloc_noio_save();
>  		err = filemap_create_folio(filp, mapping,
>  				iocb->ki_pos >> PAGE_SHIFT, fbatch);
> +		if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
> +			memalloc_noio_restore(pflags);
> +
>  		if (err == AOP_TRUNCATED_PAGE)
>  			goto retry;
>  		return err;

I would also not expect the memalloc_noio_save/restore calls to be
here.  Surely they should be at the top of the call chain where
IOCB_NOWAIT/IOCB_WAITQ are set?
Matthew Wilcox Feb. 14, 2022, 7:33 p.m. UTC | #2
On Mon, Feb 14, 2022 at 09:43:52AM -0800, Stefan Roesch wrote:
> This adds noio support for async buffered writes in filemap_get_pages.
> The idea is to handle the failure gracefully and return -EAGAIN if we
> can't get the memory quickly.

I don't understand why this helps you.  filemap_get_pages() is for
reads, not writes.
Stefan Roesch Feb. 16, 2022, 6:26 p.m. UTC | #3
This patch will be removed from the next version.

On 2/14/22 11:33 AM, Matthew Wilcox wrote:
> On Mon, Feb 14, 2022 at 09:43:52AM -0800, Stefan Roesch wrote:
>> This adds noio support for async buffered writes in filemap_get_pages.
>> The idea is to handle the failure gracefully and return -EAGAIN if we
>> can't get the memory quickly.
> 
> I don't understand why this helps you.  filemap_get_pages() is for
> reads, not writes.
Stefan Roesch Feb. 16, 2022, 6:27 p.m. UTC | #4
On 2/14/22 10:08 AM, Matthew Wilcox wrote:
> On Mon, Feb 14, 2022 at 09:43:52AM -0800, Stefan Roesch wrote:
>> This adds noio support for async buffered writes in filemap_get_pages.
>> The idea is to handle the failure gracefully and return -EAGAIN if we
>> can't get the memory quickly.
> 
> But it doesn't return -EAGAIN?
> 
>         folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0);
>         if (!folio)
>                 return -ENOMEM;
> 
>> Signed-off-by: Stefan Roesch <shr@fb.com>
>> ---
>>  mm/filemap.c | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index d2fb817c0845..0ff4278c3961 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
>> @@ -2591,10 +2591,15 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
>>  		filemap_get_read_batch(mapping, index, last_index, fbatch);
>>  	}
>>  	if (!folio_batch_count(fbatch)) {
>> +		unsigned int pflags;
>> +
>>  		if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
>> -			return -EAGAIN;
>> +			pflags = memalloc_noio_save();
>>  		err = filemap_create_folio(filp, mapping,
>>  				iocb->ki_pos >> PAGE_SHIFT, fbatch);
>> +		if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
>> +			memalloc_noio_restore(pflags);
>> +
>>  		if (err == AOP_TRUNCATED_PAGE)
>>  			goto retry;
>>  		return err;
> 
> I would also not expect the memalloc_noio_save/restore calls to be
> here.  Surely they should be at the top of the call chain where
> IOCB_NOWAIT/IOCB_WAITQ are set?

This patch will be removed from the next version of the patch series.
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index d2fb817c0845..0ff4278c3961 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2591,10 +2591,15 @@  static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter,
 		filemap_get_read_batch(mapping, index, last_index, fbatch);
 	}
 	if (!folio_batch_count(fbatch)) {
+		unsigned int pflags;
+
 		if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
-			return -EAGAIN;
+			pflags = memalloc_noio_save();
 		err = filemap_create_folio(filp, mapping,
 				iocb->ki_pos >> PAGE_SHIFT, fbatch);
+		if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
+			memalloc_noio_restore(pflags);
+
 		if (err == AOP_TRUNCATED_PAGE)
 			goto retry;
 		return err;