Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp564690ybj; Thu, 7 May 2020 02:20:38 -0700 (PDT) X-Google-Smtp-Source: APiQypKv3DE7/HCB7Ayi6F2unDJtiqj+zhf5bQ781QqBLkfXaaM2q/R3rCg1fqq7reC76T8on+oA X-Received: by 2002:a17:906:a2d3:: with SMTP id by19mr11318809ejb.370.1588843238620; Thu, 07 May 2020 02:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588843238; cv=none; d=google.com; s=arc-20160816; b=FODrJaTTZoMi2sWJHVkdUztcuBqg6Ur1kuFvllHXxP8NSPIjVNJwJP7eimGrNLE6tb Bw0piixVHSplIjrU0udzQHoqxCg8TcxyRSWNRRE9uJTqk+xxWgcXnU2PkP6rJIb7XN4G 5VOTIs/AjkBr/Gsg6PTPHnkdaCchkLKhD4MWn2dIIVF8lK0Y9tolSGyJF+/VhV7UioRR rm3WeJIyKkZkOP6dQ9JconiEa7/Uirfz/+zwQ4KKosBymTSYzVp34UQApEF4/2I3F7I0 8B0Lx4xx+bW40RPRd8K+9qiw5C1jIuhU5upGz/8amgzX4CEpJC2T0vu7G7ckcDWchkni m7BQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Gqn4Nt1775FJeFyZB84NoRj3maesSKyLaBb0Fz7dhdk=; b=fb2Xj3ntcYbKUPRPTISX43/VDLgLFnUphJiqF8sFPFsX/3yWqKVZNW5pNHJKoGnS9a opH3melh94ieXcHqEWRBJJKrDvU2iAZbbXnmJ60obYxBtmz4f/U1cQtjf9nVxAHf3s18 OV5NpCH401S/l5yEwZiLAuAW11/aHZb0ReGrKSlVCo1XW2HZUf0Hp1wIlfmpZ/lYmcFU ZgZK/o5ZLmBCJXEkLJNHTgZN/gNmbvV/r8PbFkr+TvvjJ6q8JZomqaZMNG06XOFKYZyD Ghma2RaV0feJnZ6sY3jvD+d1dzGlAVg6UHTSPe7NC6ktmLIgpljf//YeWxwM1l899+eL U36g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si2733094edi.76.2020.05.07.02.20.14; Thu, 07 May 2020 02:20:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726572AbgEGJQn (ORCPT + 99 others); Thu, 7 May 2020 05:16:43 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57202 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726476AbgEGJQm (ORCPT ); Thu, 7 May 2020 05:16:42 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3ABD85AD673B3CE51DB3; Thu, 7 May 2020 17:16:40 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.207) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 7 May 2020 17:16:38 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs: change maximum zstd compression buffer size To: Jaegeuk Kim CC: Chao Yu , , , References: <20200504143039.155644-1-jaegeuk@kernel.org> <7177aab9-630e-e077-7005-0023c93134b3@kernel.org> <20200505230559.GA203407@google.com> <9aaeac5e-4511-5c81-653c-23a85b3c335a@huawei.com> <20200506145608.GD107238@google.com> From: Chao Yu Message-ID: <357d5a28-5163-c52d-2a7d-c6162b56e1cb@huawei.com> Date: Thu, 7 May 2020 17:16:36 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200506145608.GD107238@google.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/5/6 22:56, Jaegeuk Kim wrote: > On 05/06, Chao Yu wrote: >> On 2020/5/6 7:05, Jaegeuk Kim wrote: >>> On 05/05, 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); >>>> >>>> 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. >>> >>> Could you give it a try compress_log_size=2 and check decompression works? >> >> I tried some samples before submitting the patch, did you encounter app's data >> corruption when using zstd algorithm? If so, let me check this issue. > > Daeho reported: > 1. cp -a src_file comp_dir/dst_file (comp_dir is a directory for compression) > 2. sync comp_dir/dst_file > 3. echo 3 > /proc/sys/vm/drop_caches > 4. cat comp_dir/dst_file > dump (it returns I/O error depending on the file). * ZSTD_endStream() to complete the flush. It returns the number of bytes left * in the internal buffer and must be called until it returns 0. It looks we need to check return value of ZSTD_endStream() to see whether dst buffer has enough space to store all compressed data. Thanks, > >> >> Thanks, >> >>> >>>> >>>>> 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 >>> . >>> > . >