Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp196358ybj; Mon, 4 May 2020 19:11:19 -0700 (PDT) X-Google-Smtp-Source: APiQypKzUH33H0pfsspqh6M/zQ5YNFSIPlArG+bHNLOUaVc2BGgz4N/PQhQga4TIH4v35mTQ3dib X-Received: by 2002:a17:906:55c4:: with SMTP id z4mr567507ejp.353.1588644679232; Mon, 04 May 2020 19:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588644679; cv=none; d=google.com; s=arc-20160816; b=hH/pQzrJ2UQpzd+APQuXlmOZZLstJP9AKT8Ggidtu06VsK4kJr/857Gg1WRvzWvg93 r7FGS1+Yp1T+vjr76Y0zQDfNpQ7U3B1JlP4nxRJO5C9p0MZOgQxK1YaDHKsB5Z0vYdEh /I/i7n9QvGd+4Hy5AwICoHjtsSEjxpbPPH/cWmJHtdAtJr1ojX1htiT4NRRO6B1qr2rW xe0YX389WvHS1flo7N2uISIi3aI7Ed/bojESicPmuZkTAa/N3VghhVmh+Soy//3aAwiK V9PNYK3QIb9jeACHU4+SkE6JH1l3RYr6aXp6jJQoDM4QVz+ra3W5Huner48c1fek5lDW z74w== 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=MkL3QhofGSlLa+UEfqgb99bJ6h+2kfZnPZoDW1sRSKI=; b=i4E08kl9rq/t5Pz4PzT5LgVNSY8En1P5KtYMOcIyzmIQvnKZFni+QMQxQS2yhhZhgF WimkAQbhqok9KrjEtB1BArm5347tl2bIozXM72sxGzbVR5uM25zioDd1Ohaqw++gVErq YL+r4tw2F/X0qv49JQHZdPbWdk7DWy5A/sIvEl8NQXoDbfp7Eq7SM48PSb+kBwUhk6ng 9OTVwHxEEFj6x0myqmfgy+d4UeQSmBZX1DY67wnSRJzltQAMrSlx3IM4AB0vBvvY69cv kwSFY4chXas959LrqywtsWUtpTLL0X3yoKCnjPHbiv8Urax5i8VX5uwXSMm/0u2bIyo4 h4dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fMN8n8tR; 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 n24si190794ejs.457.2020.05.04.19.10.56; Mon, 04 May 2020 19:11: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=fMN8n8tR; 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 S1728035AbgEECIp (ORCPT + 99 others); Mon, 4 May 2020 22:08:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726449AbgEECIp (ORCPT ); Mon, 4 May 2020 22:08:45 -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 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= 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> <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> 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-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