From: Chao Yu <chao@kernel.org>
To: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Chao Yu <yuchao0@huawei.com>,
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
Date: Thu, 3 Jun 2021 23:55:06 +0800 [thread overview]
Message-ID: <eb52cab7-d9b3-c84b-1c7b-8fee463b06c5@kernel.org> (raw)
In-Reply-To: <YLek7U+BaFvHhz58@google.com>
On 2021/6/2 23:34, Jaegeuk Kim wrote:
> On 06/02, Chao Yu wrote:
>> On 2021/6/2 1:27, Jaegeuk Kim wrote:
>>> 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()?
>>
>> More clean.
>>
>> One comment below:
>>
>>>
>>> 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 >=
>>
>> Need to cover COMPRESS_MAPPING() with CONFIG_F2FS_FS_COMPRESSION.
>
> Added like this.
>
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -99,6 +99,7 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
> sizeof(struct discard_cmd)) >> PAGE_SHIFT;
> res = mem_size < (avail_ram * nm_i->ram_thresh / 100);
> } else if (type == COMPRESS_PAGE) {
> +#ifdef CONFIG_F2FS_FS_COMPRESSION
How about adding free_ram definition and assigment here?
unsigned long free_ram = val.freeram;
Thanks,
> /*
> * free memory is lower than watermark or cached page count
> * exceed threshold, deny caching compress page.
> @@ -106,6 +107,9 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
> res = (free_ram > avail_ram * sbi->compress_watermark / 100) &&
> (COMPRESS_MAPPING(sbi)->nrpages <
> free_ram * sbi->compress_percent / 100);
> +#else
> + res = false;
> +#endif
> } else {
> if (!sbi->sb->s_bdi->wb.dirty_exceeded)
> return true;
>
>>
>> Thanks,
>>
>>> - 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 */
>>> };
>>>
next prev parent reply other threads:[~2021-06-03 15:55 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-20 11:51 [PATCH v6] f2fs: compress: add compress_inode to cache compressed blocks Chao Yu
2021-05-25 11:32 ` Chao Yu
2021-05-25 12:57 ` Jaegeuk Kim
2021-05-25 13:02 ` [f2fs-dev] " Jaegeuk Kim
2021-05-25 13:59 ` Chao Yu
2021-05-25 14:01 ` Jaegeuk Kim
2021-05-26 8:52 ` Chao Yu
2021-05-26 13:26 ` Jaegeuk Kim
2021-05-26 14:54 ` Chao Yu
2021-05-26 15:46 ` Jaegeuk Kim
2021-05-27 1:22 ` Chao Yu
2021-05-27 1:29 ` Jaegeuk Kim
2021-05-27 1:38 ` Chao Yu
2021-05-27 1:41 ` Jaegeuk Kim
2021-05-27 1:58 ` Chao Yu
2021-05-29 7:24 ` Chao Yu
2021-05-29 15:12 ` Jaegeuk Kim
2021-05-31 1:11 ` Chao Yu
2021-06-01 16:06 ` Jaegeuk Kim
2021-06-01 16:14 ` Jaegeuk Kim
2021-06-01 17:27 ` Jaegeuk Kim
2021-06-02 11:49 ` Chao Yu
2021-06-02 15:34 ` Jaegeuk Kim
2021-06-03 15:55 ` Chao Yu [this message]
2021-06-03 16:13 ` Jaegeuk Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eb52cab7-d9b3-c84b-1c7b-8fee463b06c5@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=yuchao0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).