Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7462126imu; Thu, 31 Jan 2019 10:28:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IYRvXqhzERFoDUMvpI5+h84sv6vudWprDInrWoJ6BCPxXlMCy4ErhGNZmXndzUzQ2SfONBU X-Received: by 2002:a62:e012:: with SMTP id f18mr3175580pfh.119.1548959319529; Thu, 31 Jan 2019 10:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548959319; cv=none; d=google.com; s=arc-20160816; b=l5Nd2ByB8sZblOXAkTRQO9LjSkCS4aaXD7HXnU7C/i97NUWSxt/E/VQ96YY2eOjkKc 7Y3cf37HNf4pXxUK6bHpMCg3x4ufdfcqzKeUoyk2kRZc9WVpSMTDn3ELDra3YvtpHFsL U6XqwQqT8iglJqKRx5nnbgfu4w4H49NL0TBD755ipB4Hf4xggcoBGeY8xwfeCGSl39Qb kqQQxkxt2HE6Q6PlUvpBHTIiICqYSwLFoO5ZPRpaJ9QfLFZTmQJTvLLsFaaDNxLM+VEi Jbbg8RixHXkrWpywSbsGrl1s9IJgh//LF5vI+CKM60pdbHOalCwNSl/CViSRIcEtPKuh 5H5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date; bh=dg3mBrNdMWFHz8JEefcHhd5gsNZ9D2YeroUPecIEZWQ=; b=dmuPa3Cp+cJXGyOShqIzoYITZd9ua/AlSzE4w7d8W35h+WJw1upeksOKQTLrvx3OZJ BD9z/iKxeFKVX/bm074ndzwl4g8QULM69lPMTww8eVF3scODMwpOOXmge5pAZWMOCSuu 4I/hKJUGxt7VIEL/pqdh48IEPtTM5BUxDOxETpMKQ0sit1FpW/YuYa0rCpjtCXjoVMTc km435l5m95R1JNynUOZNzu9aw8ag/8NPB5iRZvVVPgNk3pT8+vher2Fms5DotteH/+uZ /WIHkHKVcFqvO+CqthfIEMKSFtLUxbOzuq/qUYX78ww6jMdn8NnStZUBSwN4745Kc7vY ziHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6si5039396plp.429.2019.01.31.10.28.23; Thu, 31 Jan 2019 10:28:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727101AbfAaSO2 (ORCPT + 99 others); Thu, 31 Jan 2019 13:14:28 -0500 Received: from mx2.suse.de ([195.135.220.15]:54890 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725730AbfAaSO2 (ORCPT ); Thu, 31 Jan 2019 13:14:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A65B4ACA8; Thu, 31 Jan 2019 18:14:26 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 0C88DDA7D6; Thu, 31 Jan 2019 19:13:51 +0100 (CET) Date: Thu, 31 Jan 2019 19:13:51 +0100 From: David Sterba To: Dennis Zhou Cc: David Sterba , Josef Bacik , Chris Mason , Omar Sandoval , Nick Terrell , kernel-team@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Omar Sandoval Subject: Re: [PATCH 11/11] btrfs: add zstd compression level support Message-ID: <20190131181351.GN2900@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Dennis Zhou , David Sterba , Josef Bacik , Chris Mason , Omar Sandoval , Nick Terrell , kernel-team@fb.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Omar Sandoval References: <20190128212437.11597-1-dennis@kernel.org> <20190128212437.11597-12-dennis@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190128212437.11597-12-dennis@kernel.org> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 28, 2019 at 04:24:37PM -0500, Dennis Zhou wrote: > As mentioned above, a requirement that differs zstd from zlib is that > higher levels of compression require more memory. To manage this, each > compression level has its own queue of workspaces. A global LRU is used > to help with reclaim. To guarantee forward progress, a max level > workspace is preallocated and hidden from the LRU. > > When getting a workspace, it uses a bitmap to identify the levels that > are populated and scans up. If it finds a workspace that is greater than > it, it uses it, but does not update the last_used time and the > corresponding place in the LRU. This provides a mechanism to decrease > memory utilization as we only keep around workspaces that are sized > appropriately for the in use compression levels. > > By knowing which compression levels have available workspaces, we can > recycle rather than always create new workspaces as well as take > advantage of the preallocated max level for forward progress. If we hit > memory pressure, we sleep on the max level workspace. We continue to > rescan in case we can use a smaller workspace, but eventually should be > able to obtain the max level workspace or allocate one again should > memory pressure subside. The memory requirement for decompression is the > same as level 1, and therefore can use any of available workspace. > > The number of workspaces is bound by an upper limit of the workqueue's > limit which currently is 2 (percpu limit). Second, a reclaim timer is > used to free inactive/improperly sized workspaces. The reclaim timer is > set to 67s to avoid colliding with transaction commit (every 30s) and > attempts to reclaim any unused workspace older than 45s. > --- a/fs/btrfs/zstd.c > +++ b/fs/btrfs/zstd.c > #define ZSTD_BTRFS_MAX_WINDOWLOG 17 > #define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG) > #define ZSTD_BTRFS_DEFAULT_LEVEL 3 > +#define ZSTD_BTRFS_MAX_LEVEL 15 > +#define ZSTD_BTRFS_RECLAIM_NS (45 * NSEC_PER_SEC) > +/* 67s to avoid clashing with transaction commit (every 30s) */ > +#define ZSTD_BTRFS_RECLAIM_JIFFIES (67 * HZ) I think you can copy the relevant part of changelog here to explain the logic of the levels and reclaim as it's scattered over several functions. The description would give a nice overview in one place.