[PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled

Barry Song posted 1 patch 1 month, 1 week ago
fs/erofs/fileio.c | 2 ++
fs/erofs/zdata.c  | 6 +++++-
2 files changed, 7 insertions(+), 1 deletion(-)
[PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled
Posted by Barry Song 1 month, 1 week ago
From: Barry Song <v-songbaohua@oppo.com>

When a folio has never been zero-filled, mark it as mappedtodisk
to allow other software components to recognize and utilize the
flag.

Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
 fs/erofs/fileio.c | 2 ++
 fs/erofs/zdata.c  | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/fileio.c b/fs/erofs/fileio.c
index 3af96b1e2c2a..aa4cb438ea95 100644
--- a/fs/erofs/fileio.c
+++ b/fs/erofs/fileio.c
@@ -88,6 +88,7 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
 	struct erofs_map_blocks *map = &io->map;
 	unsigned int cur = 0, end = folio_size(folio), len, attached = 0;
 	loff_t pos = folio_pos(folio), ofs;
+	bool fully_mapped = true;
 	struct iov_iter iter;
 	struct bio_vec bv;
 	int err = 0;
@@ -124,6 +125,7 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
 			erofs_put_metabuf(&buf);
 		} else if (!(map->m_flags & EROFS_MAP_MAPPED)) {
 			folio_zero_segment(folio, cur, cur + len);
+			fully_mapped = false;
 			attached = 0;
 		} else {
 			if (io->rq && (map->m_pa + ofs != io->dev.m_pa ||
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 8936790618c6..0158de4f3d95 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -926,7 +926,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
 	const loff_t offset = folio_pos(folio);
 	const unsigned int bs = i_blocksize(inode);
 	unsigned int end = folio_size(folio), split = 0, cur, pgs;
-	bool tight, excl;
+	bool tight, excl, fully_mapped = true;
 	int err = 0;
 
 	tight = (bs == PAGE_SIZE);
@@ -949,6 +949,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
 
 		if (!(map->m_flags & EROFS_MAP_MAPPED)) {
 			folio_zero_segment(folio, cur, end);
+			fully_mapped = false;
 			tight = false;
 		} else if (map->m_flags & EROFS_MAP_FRAGMENT) {
 			erofs_off_t fpos = offset + cur - map->m_la;
@@ -1009,6 +1010,9 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
 			tight = (bs == PAGE_SIZE);
 		}
 	} while ((end = cur) > 0);
+
+	if (fully_mapped)
+		folio_set_mappedtodisk(folio);
 	erofs_onlinefolio_end(folio, err);
 	return err;
 }
-- 
2.39.3 (Apple Git-146)
Re: [PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled
Posted by Gao Xiang 1 month, 1 week ago
Hi Barry,

On 2024/10/17 15:43, Barry Song wrote:
> From: Barry Song <v-songbaohua@oppo.com>
> 
> When a folio has never been zero-filled, mark it as mappedtodisk
> to allow other software components to recognize and utilize the
> flag.
> 
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>

Thanks for this!

It looks good to me as an improvement as long as PG_mappedtodisk
is long-term lived and useful to users.

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

> ---
>   fs/erofs/fileio.c | 2 ++
>   fs/erofs/zdata.c  | 6 +++++-
>   2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/fileio.c b/fs/erofs/fileio.c
> index 3af96b1e2c2a..aa4cb438ea95 100644
> --- a/fs/erofs/fileio.c
> +++ b/fs/erofs/fileio.c
> @@ -88,6 +88,7 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
>   	struct erofs_map_blocks *map = &io->map;
>   	unsigned int cur = 0, end = folio_size(folio), len, attached = 0;
>   	loff_t pos = folio_pos(folio), ofs;
> +	bool fully_mapped = true;
>   	struct iov_iter iter;
>   	struct bio_vec bv;
>   	int err = 0;
> @@ -124,6 +125,7 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
>   			erofs_put_metabuf(&buf);
>   		} else if (!(map->m_flags & EROFS_MAP_MAPPED)) {
>   			folio_zero_segment(folio, cur, cur + len);
> +			fully_mapped = false;
>   			attached = 0;
>   		} else {
>   			if (io->rq && (map->m_pa + ofs != io->dev.m_pa ||
> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
> index 8936790618c6..0158de4f3d95 100644
> --- a/fs/erofs/zdata.c
> +++ b/fs/erofs/zdata.c
> @@ -926,7 +926,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
>   	const loff_t offset = folio_pos(folio);
>   	const unsigned int bs = i_blocksize(inode);
>   	unsigned int end = folio_size(folio), split = 0, cur, pgs;
> -	bool tight, excl;
> +	bool tight, excl, fully_mapped = true;
>   	int err = 0;
>   
>   	tight = (bs == PAGE_SIZE);
> @@ -949,6 +949,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
>   
>   		if (!(map->m_flags & EROFS_MAP_MAPPED)) {
>   			folio_zero_segment(folio, cur, end);
> +			fully_mapped = false;
>   			tight = false;
>   		} else if (map->m_flags & EROFS_MAP_FRAGMENT) {
>   			erofs_off_t fpos = offset + cur - map->m_la;
> @@ -1009,6 +1010,9 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
>   			tight = (bs == PAGE_SIZE);
>   		}
>   	} while ((end = cur) > 0);
> +
> +	if (fully_mapped)
> +		folio_set_mappedtodisk(folio);
>   	erofs_onlinefolio_end(folio, err);
>   	return err;
>   }
Re: [PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled
Posted by Gao Xiang 1 month, 1 week ago

On 2024/10/17 15:58, Gao Xiang wrote:
> Hi Barry,
> 
> On 2024/10/17 15:43, Barry Song wrote:
>> From: Barry Song <v-songbaohua@oppo.com>
>>
>> When a folio has never been zero-filled, mark it as mappedtodisk
>> to allow other software components to recognize and utilize the
>> flag.
>>
>> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> 
> Thanks for this!
> 
> It looks good to me as an improvement as long as PG_mappedtodisk
> is long-term lived and useful to users.
> 
> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

BTW, I wonder if iomap supports this since uncompressed EROFS
relies on iomap paths...

Thanks,
Gao Xiang
Re: [PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled
Posted by Barry Song 1 month, 1 week ago
On Thu, Oct 17, 2024 at 9:00 PM Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
>
>
>
> On 2024/10/17 15:58, Gao Xiang wrote:
> > Hi Barry,
> >
> > On 2024/10/17 15:43, Barry Song wrote:
> >> From: Barry Song <v-songbaohua@oppo.com>
> >>
> >> When a folio has never been zero-filled, mark it as mappedtodisk
> >> to allow other software components to recognize and utilize the
> >> flag.
> >>
> >> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> >
> > Thanks for this!
> >
> > It looks good to me as an improvement as long as PG_mappedtodisk
> > is long-term lived and useful to users.
> >
> > Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>

thanks!

> BTW, I wonder if iomap supports this since uncompressed EROFS
> relies on iomap paths...

In the core layer, I only see fs/buffer.c's block_read_full_folio()
and fs/mpage.c's mpage_readahead() and mpage_readahead()
supporting this. I haven't found any code in iomap that sets the
flag.

I guess erofs doesn't call the above functions for non-compressed
files?

>
> Thanks,
> Gao Xiang

Barry
Re: [PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled
Posted by Gao Xiang 1 month, 1 week ago

On 2024/10/17 16:09, Barry Song wrote:
> On Thu, Oct 17, 2024 at 9:00 PM Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
>>
>>
>>
>> On 2024/10/17 15:58, Gao Xiang wrote:
>>> Hi Barry,
>>>
>>> On 2024/10/17 15:43, Barry Song wrote:
>>>> From: Barry Song <v-songbaohua@oppo.com>
>>>>
>>>> When a folio has never been zero-filled, mark it as mappedtodisk
>>>> to allow other software components to recognize and utilize the
>>>> flag.
>>>>
>>>> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
>>>
>>> Thanks for this!
>>>
>>> It looks good to me as an improvement as long as PG_mappedtodisk
>>> is long-term lived and useful to users.
>>>
>>> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>>
> 
> thanks!
> 
>> BTW, I wonder if iomap supports this since uncompressed EROFS
>> relies on iomap paths...
> 
> In the core layer, I only see fs/buffer.c's block_read_full_folio()
> and fs/mpage.c's mpage_readahead() and mpage_readahead()
> supporting this. I haven't found any code in iomap that sets the
> flag.
> 
> I guess erofs doesn't call the above functions for non-compressed
> files?

mpage are obsoleted interfaces (of course EROFS could use
them instead, see my backport to centos 7 [1]), and iomap
is used for recent unencoded I/O use cases.

It would be better to add support for iomap too, but I guess
PG_mappedtodisk has very few users in the upstream kernel,
so they might ask for further use cases tho ;-)

Thanks,
Gao Xiang

[1] https://github.com/erofs/kmod-erofs/blob/main/src/data.c#L249

> 
>>
>> Thanks,
>> Gao Xiang
> 
> Barry