Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3671878pxj; Tue, 1 Jun 2021 10:28:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4EOJvkyHPwJvJ4lDkJv2Mm5ePT2bgvXcz7WJ1jUhTQmz/oFbXwH69BnW7iSejOlxbA/TO X-Received: by 2002:a05:6e02:20ea:: with SMTP id q10mr7160930ilv.42.1622568500400; Tue, 01 Jun 2021 10:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622568500; cv=none; d=google.com; s=arc-20160816; b=mNsr0/1Rz6ZMo04d63+ZLyXCNzNTwRCjsk2u7cuk7mzpKOd+qywysPgAY6uUDOnQVv /XX+wfxdZcsjAiEd2phkElbFpWVCIFkCBX6nlrjSxRJ9a9OyNlPnWPljEHD/IC6xXFTK 5iEQJGw3K9aft5T2dTUJGHet6Ysem9l4eucqRFVXJvTmJlHO1/4g9W/i8erCD6+q1hno kfhn/UugOcOA/5/6bn/1/1S7cqBDbt26F0UT0JkPDwzSL5BaFGE6EN1hPHnILI6VtgEH Q0rk6OoiNb2cOSZ4ohAv1Zp6Bh5ZlSH+brWiFcQfSW8rLbwucRwzxh9Iu5VJWFWH4Nz2 2Xgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CVtD8+2EeI7vRgzMp4Y2UcnmlVyMw5K+d6QHOgj8YWo=; b=L1+WLoRCp4rUP5UvpTdHKlPn+pMQeQZvdcAJvv7/BnukB0qJfVb0M0fXuNtIgALA2h 9iYmWGKyK4/dAcUjfVbFSNE42rcYZrp1F7hMA2nx13imcegDOoqzgiEAuluP3AiEKMCX npV+LojMiU+Zdr8C65fe/M/yKAlJEBpoaUSxrbtjaby0JO4tfkn2S2ZOM+2oBbwL/pyJ fYe/6MaSXf34LY9Iprm3SoACisGjo3Fgo0wD/072cyJ3aEjsIv5dQ2NRS88X/nCbSMgm Eo7YGzYhO7X09SpyVt0eWXPs1rjmNG3xW7UgQZzL4M0xVwZqXbt5UAeupbEHc3fZbMbY 7w3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=db4Y7WsH; 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 p37si15598768jal.126.2021.06.01.10.28.06; Tue, 01 Jun 2021 10:28:20 -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=k20201202 header.b=db4Y7WsH; 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 S234009AbhFAR3G (ORCPT + 99 others); Tue, 1 Jun 2021 13:29:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbhFAR3F (ORCPT ); Tue, 1 Jun 2021 13:29:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 079ED610C9; Tue, 1 Jun 2021 17:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622568444; bh=d3z7mELUiviyWH2sfxC5chscv7M4jzF7oXqo/a1kRQI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=db4Y7WsHGKcOdwzlMPjNRTTJXmRwHCDdvAjDKSGqQaBowzUCWkghMSSwnM/+Gy9K+ WuwXaNK3B7cigZzPHect96xAova/FMwubqaPootoqm8p69C3Tpfc0loFIJFE7BgH0c bg1mFb7UxyFR9Yfvke2Sp1OgByq42ZddKInTDv2dXjkbv43U6S3+3Kd0SOr18tjDxu Nmg15aIUIST0GtLJ4EfYQEyPtnnRTVBYowoi2u/9zhR7N3u30/fNQVYwQYommK0g6P 7dPPxkCh/em1xSm5ZVGqpq3l/3jvxlAvo6IWq6EjKq1D/9uaXu26SWP3zwD4hHj+Px XymYkL0lwgBbw== Date: Tue, 1 Jun 2021 10:27:22 -0700 From: Jaegeuk Kim To: Chao Yu Cc: Chao Yu , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH v6] f2fs: compress: add compress_inode to cache compressed blocks Message-ID: References: <20210520115150.4718-1-chao@kernel.org> <2c4db877-b5e6-1139-98b5-be2d9e7872be@kernel.org> <5140516c-e4c6-fd6a-69b2-7566c903cb53@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/01, Jaegeuk Kim wrote: > On 05/26, Chao Yu wrote: > > On 2021/5/26 21:26, Jaegeuk Kim wrote: > > > On 05/26, Chao Yu wrote: > > > > On 2021/5/25 22:01, Jaegeuk Kim wrote: > > > > > On 05/25, Chao Yu wrote: > > > > > > On 2021/5/25 21:02, Jaegeuk Kim wrote: > > > > > > > On 05/25, Jaegeuk Kim wrote: > > > > > > > > On 05/25, Chao Yu wrote: > > > > > > > > > Also, and queue this? > > > > > > > > > > > > > > > > Easy to get this? > > > > > > > > > > > > > > need GFP_NOFS? > > > > > > > > > > > > Not sure, I use __GFP_IO intentionally here to avoid __GFP_RECLAIM from > > > > > > GFP_NOFS, because in low memory case, I don't want to instead page cache > > > > > > of normal file with page cache of sbi->compress_inode. > > > > > > > > > > > > What is memory size in your vm? > > > > > > > > > > 4GB. If I set GFP_NOFS, I don't see the error anymore, at least. > > > > > > > > I applied below patch and don't see the warning message anymore. > > > > > > > > --- > > > > fs/f2fs/compress.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > > > > index 701dd0f6f4ec..ed5b7fabc604 100644 > > > > --- a/fs/f2fs/compress.c > > > > +++ b/fs/f2fs/compress.c > > > > @@ -1703,7 +1703,7 @@ void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, > > > > avail_ram = si.totalram - si.totalhigh; > > > > > > > > /* free memory is lower than watermark, deny caching compress page */ > > > > - if (free_ram <= sbi->compress_watermark / 100 * avail_ram) > > > > This is buggy, because sbi->compress_watermark equals to 20, so that > > sbi->compress_watermark / 100 * avail_ram always be zero... > > > > After this change, if free ram is lower, we may just skip caching > > compressed blocks here. > > Can we move this in f2fs_available_free_memory()? Testing this. --- fs/f2fs/compress.c | 14 +------------- fs/f2fs/node.c | 11 ++++++++++- fs/f2fs/node.h | 1 + 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 9fd62a0a646b..455561826c7d 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1688,8 +1688,6 @@ void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, { struct page *cpage; int ret; - struct sysinfo si; - unsigned long free_ram, avail_ram; if (!test_opt(sbi, COMPRESS_CACHE)) return; @@ -1697,17 +1695,7 @@ void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, if (!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE_READ)) return; - si_meminfo(&si); - free_ram = si.freeram; - avail_ram = si.totalram - si.totalhigh; - - /* free memory is lower than watermark, deny caching compress page */ - if (free_ram <= sbi->compress_watermark / 100 * avail_ram) - return; - - /* cached page count exceed threshold, deny caching compress page */ - if (COMPRESS_MAPPING(sbi)->nrpages >= - free_ram / 100 * sbi->compress_percent) + if (!f2fs_available_free_memory(sbi, COMPRESS_PAGE)) return; cpage = find_get_page(COMPRESS_MAPPING(sbi), blkaddr); diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 3a8f7afa5059..67093416ce9c 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -45,7 +45,7 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) struct f2fs_nm_info *nm_i = NM_I(sbi); struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; struct sysinfo val; - unsigned long avail_ram; + unsigned long avail_ram, free_ram; unsigned long mem_size = 0; bool res = false; @@ -56,6 +56,7 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) /* only uses low memory */ avail_ram = val.totalram - val.totalhigh; + free_ram = val.freeram; /* * give 25%, 25%, 50%, 50%, 50% memory for each components respectively @@ -97,6 +98,14 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) mem_size = (atomic_read(&dcc->discard_cmd_cnt) * sizeof(struct discard_cmd)) >> PAGE_SHIFT; res = mem_size < (avail_ram * nm_i->ram_thresh / 100); + } else if (type == COMPRESS_PAGE) { + /* + * free memory is lower than watermark or cached page count + * exceed threshold, deny caching compress page. + */ + res = (free_ram > avail_ram * sbi->compress_watermark / 100) && + (COMPRESS_MAPPING(sbi)->nrpages < + free_ram * sbi->compress_percent / 100); } else { if (!sbi->sb->s_bdi->wb.dirty_exceeded) return true; diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index d85e8659cfda..84d45385d1f2 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -148,6 +148,7 @@ enum mem_type { EXTENT_CACHE, /* indicates extent cache */ INMEM_PAGES, /* indicates inmemory pages */ DISCARD_CACHE, /* indicates memory of cached discard cmds */ + COMPRESS_PAGE, /* indicates memory of cached compressed pages */ BASE_CHECK, /* check kernel status */ }; -- 2.32.0.rc0.204.g9fa02ecfa5-goog