Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp186792ybj; Mon, 4 May 2020 18:58:20 -0700 (PDT) X-Google-Smtp-Source: APiQypKDi4Uw6kIDG9xXJ/oIKhYu2zVrdTPOldZfrsJQDUMJpAYjH4FDajGt1IjIXIuKHvksjFCo X-Received: by 2002:aa7:de0b:: with SMTP id h11mr712495edv.133.1588643899988; Mon, 04 May 2020 18:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588643899; cv=none; d=google.com; s=arc-20160816; b=FYkYwu7Y0T7ik5pZuLq04XL0NGGuZX7uPiZC2gFdr5Zgb+wFVOUI+TzVkJKQllKqP5 MIIxpU5PsmOv/La1Y7vAm4kulvWALRmVaxeRowbtPQGvnLn5ghZZ3dA4TBprwy9/mNiI dKTILSNb4Y2c96SeHNJ5xK8DPYFouIV7tp0hSB8z43EV+7V8RR4GhDDeWBsyag9qXxEW /lyt7R2T6Eecrra99UOUBs2aPKsvVL0olwrqA68JnsyKIqGqdeJpCWL5AntOeshQqrLe MEWnisli33695N4i+3H9ZqTDVSBT4IdvMyJGgGc6kQskcv4zJSsPFsNjC0hmGaWuKGVu kAww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:to:subject :dkim-signature; bh=pqerY56arna1M2JGw2cM4hBelT9rXqN+vlbSgD2rZU0=; b=e7q68PfHS5+wdlSDmzt6llELX5jiXkWke0s1RPIyi18SrPFlBwrxlhqWhVt5ZZjJX6 GBnh82Gs4BUtIXxE+uV5LSi6YL/V5+doMT+S8Iw1wnQCNupKh6VKq8RC9i3ID7QIoW5l IZKEXAA20bHPePUEU/vavZMAL7+Fj5KpnCAcT75aGyOhp6oEaaylDo38HaLQaCNFnyyr dWmbBs7Mr7FNX9qGehqbflph8PguuqV+urOU4wJC+1DM3x8hHRltDNuI5PS5w00GEVeY hzjttsWKH0oR83n8miyEWUhF++KDX2UiZj4NYGC/jjPWd7mFuTv77xor2h6Z8D4VIA45 h6og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A40hyaPi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si408281edr.198.2020.05.04.18.57.56; Mon, 04 May 2020 18:58:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A40hyaPi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727899AbgEEBwx (ORCPT + 99 others); Mon, 4 May 2020 21:52:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:54322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726482AbgEEBwx (ORCPT ); Mon, 4 May 2020 21:52:53 -0400 Received: from [192.168.0.107] (unknown [58.213.210.203]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66A34206C0; Tue, 5 May 2020 01:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588643572; bh=otlpl9kgwwzoyQGAsBIJNT4k36SElcRlfWNTe5IWlao=; h=Subject:To:References:From:Date:In-Reply-To:From; b=A40hyaPiyapzdGNG+jUJHa7VQ2T3Wjwrtw1OVfzgaDIfxIXeSTgA43oQ7r2Xbo4Ug SIC9g4ead+0Dv1uTmRsYZSLckqfSOPyHEMdOsg/iV4oMLuWBuxyZXCNw8uE5pl6l6h YsCiuNUTKhUjb0B6zitn1PKycvYpt3DcrwUGbaE0= Subject: Re: [f2fs-dev] [PATCH] f2fs: change maximum zstd compression buffer size To: Jaegeuk Kim , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com References: <20200504143039.155644-1-jaegeuk@kernel.org> From: Chao Yu Message-ID: <7177aab9-630e-e077-7005-0023c93134b3@kernel.org> Date: Tue, 5 May 2020 09:52:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20200504143039.155644-1-jaegeuk@kernel.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-5-4 22:30, Jaegeuk Kim wrote: > From: Daeho Jeong > > Current zstd compression buffer size is one page and header size less > than cluster size. By this, zstd compression always succeeds even if > the real compression data is failed to fit into the buffer size, and > eventually reading the cluster returns I/O error with the corrupted > compression data. What's the root cause of this issue? I didn't get it. > > Signed-off-by: Daeho Jeong > --- > fs/f2fs/compress.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 4c7eaeee52336..a9fa8049b295f 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -313,7 +313,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc) > cc->private = workspace; > cc->private2 = stream; > > - cc->clen = cc->rlen - PAGE_SIZE - COMPRESS_HEADER_SIZE; > + cc->clen = ZSTD_compressBound(PAGE_SIZE << cc->log_cluster_size); In my machine, the value is 66572 which is much larger than size of dst buffer, so, in where we can tell the real size of dst buffer to zstd compressor? Otherwise, if compressed data size is larger than dst buffer size, when we flush compressed data into dst buffer, we may suffer overflow. > return 0; > } > > @@ -330,7 +330,7 @@ static int zstd_compress_pages(struct compress_ctx *cc) > ZSTD_inBuffer inbuf; > ZSTD_outBuffer outbuf; > int src_size = cc->rlen; > - int dst_size = src_size - PAGE_SIZE - COMPRESS_HEADER_SIZE; > + int dst_size = cc->clen; > int ret; > > inbuf.pos = 0; >