Skip to contentSkip to conversation

fs: erofs: support PG_mappedtodisk flag for folios with zero-filled

RFC PATCH In review Barry Song 3 participants 6 messages Oct 17, 2024 – Oct 20, 2024 EROFS file system

lore
Share & tools
lore

Barry Song

author
#0 lore raw

RFC PATCH 1/1 fs: erofs: support PG_mappedtodisk flag for folios with zero-filled

From: Barry Song <[email protected]>

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

---
 fs/erofs/fileio.c | 2 ++
 fs/erofs/zdata.c  | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
fs/erofs/fileio.c +2 -0
index 3af96b1e2c2a..aa4cb438ea95 100644
@@ -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 ||
fs/erofs/zdata.c +5 -1
index 8936790618c6..0158de4f3d95 100644
@@ -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;
 }
Signature · 1 line
2.39.3 (Apple Git-146)
Reviewed-by on v1 1/1
#1 lore raw

Hi Barry,

Quoted 7 lines · Barry Song

From: Barry Song <[email protected]>

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

Thanks for this!

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

Thanks,
Gao Xiang

Quoted 56 lines
---
  fs/erofs/fileio.c | 2 ++
  fs/erofs/zdata.c  | 6 +++++-
  2 files changed, 7 insertions(+), 1 deletion(-)
fs/erofs/fileio.c +2 -0
index 3af96b1e2c2a..aa4cb438ea95 100644
@@ -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 ||
fs/erofs/zdata.c +5 -1
index 8936790618c6..0158de4f3d95 100644
@@ -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 lore raw
Quoted 9 lines · Gao Xiang

Hi Barry,

Quoted 6 lines · Barry Song

From: Barry Song <[email protected]>

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

Quoted 8 lines
Quoted 1 line

Thanks for this!

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

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

Thanks,
Gao Xiang

author
#3 lore raw
Quoted 13 lines · Gao Xiang
Quoted 9 lines · Gao Xiang

Hi Barry,

Quoted 6 lines · Barry Song

From: Barry Song <[email protected]>

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

Quoted 9 lines
Quoted 8 lines
Quoted 1 line

Thanks for this!

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

thanks!

Quoted 2 lines

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?

Quoted 3 lines

Thanks,
Gao Xiang

Barry

#4 lore raw
Quoted 29 lines · Barry Song
Quoted 13 lines · Gao Xiang
Quoted 9 lines · Gao Xiang

Hi Barry,

Quoted 6 lines · Barry Song

From: Barry Song <[email protected]>

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

Quoted 9 lines
Quoted 8 lines
Quoted 1 line

Thanks for this!

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

thanks!

Quoted 2 lines

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

Quoted 7 lines

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

Quoted 6 lines
Quoted 4 lines

Thanks,
Gao Xiang

Barry

#5 lore raw
In reply to Barry Song
kernel test robot noticed the following build warnings:

Hi Barry,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on xiang-erofs/dev-test]
[also build test WARNING on xiang-erofs/dev xiang-erofs/fixes linus/master v6.12-rc3 next-20241018] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Barry-Song/fs-erofs-support-PG_mappedtodisk-flag-for-folios-with-zero-filled/20241017-154545
base:   https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
patch link:    https://lore.kernel.org/r/20241017074346.35284-1-21cnbao%40gmail.com
patch subject: [PATCH RFC] fs: erofs: support PG_mappedtodisk flag for folios with zero-filled
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20241020/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241020/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

fs/erofs/fileio.c: In function 'erofs_fileio_scan_folio':

>> fs/erofs/fileio.c:91:14: warning: variable 'fully_mapped' set but not used [-Wunused-but-set-variable]
      91 |         bool fully_mapped = true;
         |              ^~~~~~~~~~~~

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for MODVERSIONS
Depends on [n]: MODULES [=y] && !COMPILE_TEST [=y]
Selected by [y]:
- RANDSTRUCT_FULL [=y] && (CC_HAS_RANDSTRUCT [=n] || GCC_PLUGINS [=y]) && MODULES [=y]
WARNING: unmet direct dependencies detected for GET_FREE_REGION
Depends on [n]: SPARSEMEM [=n]
Selected by [m]:
- RESOURCE_KUNIT_TEST [=m] && RUNTIME_TESTING_MENU [=y] && KUNIT [=m]

vim +/fully_mapped +91 fs/erofs/fileio.c

    84	
    85	static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
    86	{
    87		struct inode *inode = folio_inode(folio);
    88		struct erofs_map_blocks *map = &io->map;
    89		unsigned int cur = 0, end = folio_size(folio), len, attached = 0;
    90		loff_t pos = folio_pos(folio), ofs;
  > 91		bool fully_mapped = true;
    92		struct iov_iter iter;
    93		struct bio_vec bv;
    94		int err = 0;
    95	
    96		erofs_onlinefolio_init(folio);
    97		while (cur < end) {
    98			if (!in_range(pos + cur, map->m_la, map->m_llen)) {
    99				map->m_la = pos + cur;

100 map->m_llen = end - cur;
101 err = erofs_map_blocks(inode, map);
102 if (err)
103 break;
104 }
105
106 ofs = folio_pos(folio) + cur - map->m_la;
107 len = min_t(loff_t, map->m_llen - ofs, end - cur);
108 if (map->m_flags & EROFS_MAP_META) {
109 struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
110 void *src;
111
112 src = erofs_read_metabuf(&buf, inode->i_sb,
113 map->m_pa + ofs, EROFS_KMAP);
114 if (IS_ERR(src)) {
115 err = PTR_ERR(src);
116 break;
117 }
118 bvec_set_folio(&bv, folio, len, cur);
119 iov_iter_bvec(&iter, ITER_DEST, &bv, 1, len);
120 if (copy_to_iter(src, len, &iter) != len) {
121 erofs_put_metabuf(&buf);
122 err = -EIO;
123 break;
124 }
125 erofs_put_metabuf(&buf);
126 } else if (!(map->m_flags & EROFS_MAP_MAPPED)) {
127 folio_zero_segment(folio, cur, cur + len);
128 fully_mapped = false;
129 attached = 0;
130 } else {
131 if (io->rq && (map->m_pa + ofs != io->dev.m_pa ||
132 map->m_deviceid != io->dev.m_deviceid)) {
133 io_retry:
134 erofs_fileio_rq_submit(io->rq);
135 io->rq = NULL;
136 }
137
138 if (!io->rq) {
139 io->dev = (struct erofs_map_dev) {
140 .m_pa = io->map.m_pa + ofs,
141 .m_deviceid = io->map.m_deviceid,
142 };
143 err = erofs_map_dev(inode->i_sb, &io->dev);
144 if (err)
145 break;
146 io->rq = erofs_fileio_rq_alloc(&io->dev);
147 io->rq->bio.bi_iter.bi_sector = io->dev.m_pa >> 9;
148 attached = 0;
149 }
150 if (!attached++)
151 erofs_onlinefolio_split(folio);
152 if (!bio_add_folio(&io->rq->bio, folio, len, cur))
153 goto io_retry;
154 io->dev.m_pa += len;
155 }
156 cur += len;
157 }
158 erofs_onlinefolio_end(folio, err);
159 return err;
160 }
161

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki