From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98263C3A5A9 for ; Tue, 5 May 2020 02:08:54 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 67D72206D7; Tue, 5 May 2020 02:08:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="PYX9cDXp"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="CCcN/zOZ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="fMN8n8tR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67D72206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jVn0w-00005w-0v; Tue, 05 May 2020 02:08:54 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVn0u-00005h-KX for linux-f2fs-devel@lists.sourceforge.net; Tue, 05 May 2020 02:08:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:To:Subject:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=MkL3QhofGSlLa+UEfqgb99bJ6h+2kfZnPZoDW1sRSKI=; b=PYX9cDXpqV5lGTT0qY6PxlxuoZ XNnQwDNpF1iXI7mKvLJA5Nvb1190SeO5FvSsDXlWRLjZUT5oRC4+NTeompbwFonyFrlV3PEkqjEUs qcqHPD0oFHwi4yixvMwagVIH+pD+yXvaD4WAXZS+8odMt7/kFk4br0qjFD3dze3Yt5X4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MkL3QhofGSlLa+UEfqgb99bJ6h+2kfZnPZoDW1sRSKI=; b=CCcN/zOZ3Ua5oGWxDnhzm0Wu0V oTBA2qgqoagY38Sc1m0J5gl0fUzBFEinoEbC+GIaO0zNZd1oRuC4NIupTohQ98CW7oU8S+ZBR+BQR UZ5ASa62pWWqo/ZSnq6vAXWXn452BMtd1+90BFfS1jQ+q4vidVRb1RtfFfYjxgzUSkw4=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jVn0s-007gp5-NM for linux-f2fs-devel@lists.sourceforge.net; Tue, 05 May 2020 02:08:52 +0000 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 96F2F206D7; Tue, 5 May 2020 02:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588644525; bh=WA4NF4Zrsn/AZscHkiK0AuxGMzZiCnAsbzhY8KUi4w0=; h=Subject:To:References:From:Date:In-Reply-To:From; b=fMN8n8tRQXf1Xn4ZeO8JjyvlKub1XKr/IMBo7ozbkZDKaAMKH29LkrAWe0quuLyIM Orp6jaTKVFgbxlOCLm+liNy9gek39BAcEW2E82h3Cjj7RJYcH0NiWAw8jLZFDuGtQK qtMDBUCKIlx0o3D2eh15JtbooNKPgRjm4TWNW7I0= 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> <7177aab9-630e-e077-7005-0023c93134b3@kernel.org> From: Chao Yu Message-ID: <5dadaf04-ef9e-f6a8-c132-8fa072e8e6fe@kernel.org> Date: Tue, 5 May 2020 10:08:37 +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: <7177aab9-630e-e077-7005-0023c93134b3@kernel.org> X-Headers-End: 1jVn0s-007gp5-NM Subject: Re: [f2fs-dev] [PATCH] f2fs: change maximum zstd compression buffer size X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 2020-5-5 9:52, Chao Yu wrote: > 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); Max size of intermediate buffer has been set as below? - zstd_init_compress_ctx - params = ZSTD_getParams(F2FS_ZSTD_DEFAULT_CLEVEL, cc->rlen, 0) - ZSTD_CStreamWorkspaceBound(params.cParams) - outBuffSize = ZSTD_compressBound(blockSize) + 1; - workspace_size = ... + outBuffSize + ... - workspace = f2fs_kvmalloc(workspace_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; >> > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel