Skip to contentSkip to conversation

erofs: fix memory leak on short-lived bounced pages

PATCH Superseded Gao Xiang 3 participants 4 messages Nov 28, 2023 – Dec 14, 2023 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: fix memory leak on short-lived bounced pages

Both MicroLZMA and DEFLATE algorithms can use short-lived pages on demand for overlap inplace I/O decompression.

However, those short-lived pages are actually added to be->decompressed_pages. Thus, it should be checked instead of pcl->compressed_bvecs.

The LZ4 algorithm doesn't work like this, so it won't be impacted.

Fixes 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")
---
 fs/erofs/zdata.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/erofs/zdata.c +2 -3
index a7e6847f6f8f..e5e44f926692 100644
@@ -1309,12 +1309,11 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 		put_page(page);
 	} else {
 		for (i = 0; i < pclusterpages; ++i) {
-			page = pcl->compressed_bvecs[i].page;
+			/* consider shortlived pages added when decompressing */
+			page = be->decompressed_pages[i];
 
 			if (erofs_page_is_managed(sbi, page))
 				continue;
-
-			/* recycle all individual short-lived pages */
 			(void)z_erofs_put_shortlivedpage(be->pagepool, page);
 			WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
 		}
Signature · 1 line
2.39.3
author
#1 lore raw

PATCH v2 1/1 erofs: fix memory leak on short-lived bounced pages

Both MicroLZMA and DEFLATE algorithms can use short-lived pages on demand for overlap inplace I/O decompression.

However, those short-lived pages are actually added to be->compressed_pages. Thus, it should be checked instead of pcl->compressed_bvecs.

The LZ4 algorithm doesn't work like this, so it won't be impacted.

Fixes 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")

---
v2:
- should be be->compressed_pages.

 fs/erofs/zdata.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/erofs/zdata.c +2 -3
index a7e6847f6f8f..a33cd6757f98 100644
@@ -1309,12 +1309,11 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 		put_page(page);
 	} else {
 		for (i = 0; i < pclusterpages; ++i) {
-			page = pcl->compressed_bvecs[i].page;
+			/* consider shortlived pages added when decompressing */
+			page = be->compressed_pages[i];
 
 			if (erofs_page_is_managed(sbi, page))
 				continue;
-
-			/* recycle all individual short-lived pages */
 			(void)z_erofs_put_shortlivedpage(be->pagepool, page);
 			WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
 		}
Signature · 1 line
2.39.3
reviewer Reviewed-by on v2 1/1
#2 lore raw
Quoted 11 lines · On Wed, 29 Nov 2023 02:04:31 +0800 Gao Xiang <[email protected]>…

Both MicroLZMA and DEFLATE algorithms can use short-lived pages on demand for overlap inplace I/O decompression.

However, those short-lived pages are actually added to be->compressed_pages. Thus, it should be checked instead of pcl->compressed_bvecs.

The LZ4 algorithm doesn't work like this, so it won't be impacted.

Fixes 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")
maintainer Reviewed-by on v2 1/1
#3 lore raw
In reply to Gao Xiang
Quoted 11 lines · Gao Xiang

Both MicroLZMA and DEFLATE algorithms can use short-lived pages on demand for overlap inplace I/O decompression.

However, those short-lived pages are actually added to be->compressed_pages. Thus, it should be checked instead of pcl->compressed_bvecs.

The LZ4 algorithm doesn't work like this, so it won't be impacted.

Fixes 67139e36d970 ("erofs: introduce `z_erofs_parse_in_bvecs'")

Thanks,