erofs: fix memory leak of LZMA global compressed deduplication
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 7 Sep 2023 05:05:42 +0000 (13:05 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 11 Sep 2023 00:03:32 +0000 (08:03 +0800)
When stressing microLZMA EROFS images with the new global compressed
deduplication feature enabled (`-Ededupe`), I found some short-lived
temporary pages weren't properly released, which could slowly cause
unexpected OOMs hours later.

Let's fix it now (LZ4 and DEFLATE don't have this issue.)

Fixes: 5c2a64252c5d ("erofs: introduce partial-referenced pclusters")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230907050542.97152-1-hsiangkao@linux.alibaba.com
fs/erofs/decompressor_lzma.c

index 73091fb..dee10d2 100644 (file)
@@ -217,9 +217,12 @@ again:
                        strm->buf.out_size = min_t(u32, outlen,
                                                   PAGE_SIZE - pageofs);
                        outlen -= strm->buf.out_size;
-                       if (!rq->out[no] && rq->fillgaps)       /* deduped */
+                       if (!rq->out[no] && rq->fillgaps) {     /* deduped */
                                rq->out[no] = erofs_allocpage(pagepool,
                                                GFP_KERNEL | __GFP_NOFAIL);
+                               set_page_private(rq->out[no],
+                                                Z_EROFS_SHORTLIVED_PAGE);
+                       }
                        if (rq->out[no])
                                strm->buf.out = kmap(rq->out[no]) + pageofs;
                        pageofs = 0;