2021-03-11 09:02:08

by Sahitya Tummala

[permalink] [raw]
Subject: [PATCH v2] f2fs: allow to change discard policy based on cached discard cmds

With the default DPOLICY_BG discard thread is ioaware, which prevents
the discard thread from issuing the discard commands. On low RAM setups,
it is observed that these discard commands in the cache are consuming
high memory. This patch aims to relax the memory pressure on the system
due to f2fs pending discard cmds by changing the policy to DPOLICY_FORCE
based on the nm_i->ram_thresh configured.

Signed-off-by: Sahitya Tummala <[email protected]>
---
v2:
- by mistake the last else condition was modified, fix it now.

fs/f2fs/node.c | 5 +++++
fs/f2fs/node.h | 1 +
fs/f2fs/segment.c | 3 ++-
3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 3a24423..03d99f9 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -44,6 +44,7 @@ int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
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 mem_size = 0;
@@ -90,6 +91,10 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
/* it allows 20% / total_ram for inmemory pages */
mem_size = get_pages(sbi, F2FS_INMEM_PAGES);
res = mem_size < (val.totalram / 5);
+ } else if (type == DISCARD_CACHE) {
+ 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 (!sbi->sb->s_bdi->wb.dirty_exceeded)
return true;
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index f84541b..7a45c0f 100644
--- a/fs/f2fs/node.h
+++ b/fs/f2fs/node.h
@@ -147,6 +147,7 @@ enum mem_type {
INO_ENTRIES, /* indicates inode entries */
EXTENT_CACHE, /* indicates extent cache */
INMEM_PAGES, /* indicates inmemory pages */
+ DISCARD_CACHE, /* indicates memory of cached discard cmds */
BASE_CHECK, /* check kernel status */
};

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index deca74c..13b3d728 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1773,7 +1773,8 @@ static int issue_discard_thread(void *data)
continue;
}

- if (sbi->gc_mode == GC_URGENT_HIGH)
+ if (sbi->gc_mode == GC_URGENT_HIGH ||
+ !f2fs_available_free_memory(sbi, DISCARD_CACHE))
__init_discard_policy(sbi, &dpolicy, DPOLICY_FORCE, 1);

sb_start_intwrite(sbi->sb);
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


2021-03-11 11:51:21

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH v2] f2fs: allow to change discard policy based on cached discard cmds

On 2021/3/11 16:59, Sahitya Tummala wrote:
> With the default DPOLICY_BG discard thread is ioaware, which prevents
> the discard thread from issuing the discard commands. On low RAM setups,
> it is observed that these discard commands in the cache are consuming
> high memory. This patch aims to relax the memory pressure on the system
> due to f2fs pending discard cmds by changing the policy to DPOLICY_FORCE
> based on the nm_i->ram_thresh configured.
>
> Signed-off-by: Sahitya Tummala <[email protected]>
> ---
> v2:
> - by mistake the last else condition was modified, fix it now.

Oh, yes,

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2021-03-16 11:40:08

by Oliver Sang

[permalink] [raw]
Subject: [f2fs] ab2dbddfd0: BUG:kernel_NULL_pointer_dereference,address



Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: ab2dbddfd064f2078a7099e4d65cce54f5ef5e71 ("[PATCH v2] f2fs: allow to change discard policy based on cached discard cmds")
url: https://github.com/0day-ci/linux/commits/Sahitya-Tummala/f2fs-allow-to-change-discard-policy-based-on-cached-discard-cmds/20210311-170257


in testcase: ltp
version: ltp-x86_64-14c1f76-1_20210315
with following parameters:

disk: 1HDD
fs: f2fs
test: io
ucode: 0x21

test-description: The LTP testsuite contains a collection of tools for testing the Linux kernel and related features.
test-url: http://linux-test-project.github.io/


on test machine: 4 threads Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz with 8G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):



If you fix the issue, kindly add following tag
Reported-by: kernel test robot <[email protected]>


[ 38.378402] BUG: kernel NULL pointer dereference, address: 0000000000000010
[ 38.378526] #PF: supervisor read access in kernel mode
[ 38.378610] #PF: error_code(0x0000) - not-present page
[ 38.378694] PGD 0 P4D 0
[ 38.378739] Oops: 0000 [#1] SMP PTI
[ 38.378799] CPU: 2 PID: 2436 Comm: f2fs_discard-8: Not tainted 5.12.0-rc2-00001-gab2dbddfd064 #1
[ 38.378940] Hardware name: Hewlett-Packard p6-1451cx/2ADA, BIOS 8.15 02/05/2013
[ 38.379057] RIP: 0010:f2fs_available_free_memory (kbuild/src/consumer/fs/f2fs/node.c:96) f2fs
[ 38.379237] Code: 04 00 00 48 0f af d6 48 be c3 f5 28 5c 8f c2 f5 28 48 c1 ea 02 48 89 d0 48 f7 e6 48 c1 ea 03 48 39 ca 0f 97 c0 e9 af fe ff ff <41> 8b 54 24 10 49 63 8d 94 20 00 00 48 0f af d6 48 be c3 f5 28 5c
All code
========
0: 04 00 add $0x0,%al
2: 00 48 0f add %cl,0xf(%rax)
5: af scas %es:(%rdi),%eax
6: d6 (bad)
7: 48 be c3 f5 28 5c 8f movabs $0x28f5c28f5c28f5c3,%rsi
e: c2 f5 28
11: 48 c1 ea 02 shr $0x2,%rdx
15: 48 89 d0 mov %rdx,%rax
18: 48 f7 e6 mul %rsi
1b: 48 c1 ea 03 shr $0x3,%rdx
1f: 48 39 ca cmp %rcx,%rdx
22: 0f 97 c0 seta %al
25: e9 af fe ff ff jmpq 0xfffffffffffffed9
2a:* 41 8b 54 24 10 mov 0x10(%r12),%edx <-- trapping instruction
2f: 49 63 8d 94 20 00 00 movslq 0x2094(%r13),%rcx
36: 48 0f af d6 imul %rsi,%rdx
3a: 48 rex.W
3b: be c3 f5 28 5c mov $0x5c28f5c3,%esi

Code starting with the faulting instruction
===========================================
0: 41 8b 54 24 10 mov 0x10(%r12),%edx
5: 49 63 8d 94 20 00 00 movslq 0x2094(%r13),%rcx
c: 48 0f af d6 imul %rsi,%rdx
10: 48 rex.W
11: be c3 f5 28 5c mov $0x5c28f5c3,%esi
[ 38.379531] RSP: 0018:ffffc900006f3dd8 EFLAGS: 00010246
[ 38.379617] RAX: 0000000000000106 RBX: ffff888213317000 RCX: 00000000001e9c8c
[ 38.379731] RDX: ffff88810c84b430 RSI: 00000000001e9c8c RDI: ffff88810c84b540
[ 38.379844] RBP: 0000000000000006 R08: 0000000000000106 R09: ffff88821fb2bc58
[ 38.379958] R10: 000000000000032e R11: ffff88821fb2a144 R12: 0000000000000000
[ 38.380071] R13: ffff88820b7e4000 R14: 000000000000ea60 R15: 0000000000000000
[ 38.380185] FS: 0000000000000000(0000) GS:ffff88821fb00000(0000) knlGS:0000000000000000
[ 38.380315] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 38.380408] CR2: 0000000000000010 CR3: 000000021e00a003 CR4: 00000000001706e0
[ 38.380522] Call Trace:
[ 38.380619] ? del_timer_sync (kbuild/src/consumer/kernel/time/timer.c:1394)
[ 38.380686] ? prepare_to_wait_event (kbuild/src/consumer/kernel/sched/wait.c:323 (discriminator 15))
[ 38.380762] ? __next_timer_interrupt (kbuild/src/consumer/kernel/time/timer.c:1816)
[ 38.380841] issue_discard_thread (kbuild/src/consumer/fs/f2fs/segment.c:1759 (discriminator 1)) f2fs
[ 38.380937] ? finish_wait (kbuild/src/consumer/kernel/sched/wait.c:403)
[ 38.380997] ? __issue_discard_cmd (kbuild/src/consumer/fs/f2fs/segment.c:1722) f2fs
[ 38.381094] kthread (kbuild/src/consumer/kernel/kthread.c:292)
[ 38.381151] ? kthread_park (kbuild/src/consumer/kernel/kthread.c:245)
[ 38.381213] ret_from_fork (kbuild/src/consumer/arch/x86/entry/entry_64.S:300)
[ 38.381276] Modules linked in: dm_mod f2fs netconsole btrfs blake2b_generic xor zstd_compress raid6_pq libcrc32c sd_mod t10_pi sg intel_rapl_msr intel_rapl_common i915 x86_pkg_temp_thermal intel_powerclamp coretemp intel_gtt crct10dif_pclmul crc32_pclmul drm_kms_helper crc32c_intel usb_storage ghash_clmulni_intel syscopyarea rapl ahci libahci sysfillrect sysimgblt fb_sys_fops ipmi_devintf ipmi_msghandler intel_cstate drm libata intel_uncore mei_me mei video ip_tables
[ 38.381939] CR2: 0000000000000010
[ 38.381996] ---[ end trace d47b1e3f3cb425e8 ]---
[ 38.382072] RIP: 0010:f2fs_available_free_memory (kbuild/src/consumer/fs/f2fs/node.c:96) f2fs
[ 38.382188] Code: 04 00 00 48 0f af d6 48 be c3 f5 28 5c 8f c2 f5 28 48 c1 ea 02 48 89 d0 48 f7 e6 48 c1 ea 03 48 39 ca 0f 97 c0 e9 af fe ff ff <41> 8b 54 24 10 49 63 8d 94 20 00 00 48 0f af d6 48 be c3 f5 28 5c
All code
========
0: 04 00 add $0x0,%al
2: 00 48 0f add %cl,0xf(%rax)
5: af scas %es:(%rdi),%eax
6: d6 (bad)
7: 48 be c3 f5 28 5c 8f movabs $0x28f5c28f5c28f5c3,%rsi
e: c2 f5 28
11: 48 c1 ea 02 shr $0x2,%rdx
15: 48 89 d0 mov %rdx,%rax
18: 48 f7 e6 mul %rsi
1b: 48 c1 ea 03 shr $0x3,%rdx
1f: 48 39 ca cmp %rcx,%rdx
22: 0f 97 c0 seta %al
25: e9 af fe ff ff jmpq 0xfffffffffffffed9
2a:* 41 8b 54 24 10 mov 0x10(%r12),%edx <-- trapping instruction
2f: 49 63 8d 94 20 00 00 movslq 0x2094(%r13),%rcx
36: 48 0f af d6 imul %rsi,%rdx
3a: 48 rex.W
3b: be c3 f5 28 5c mov $0x5c28f5c3,%esi

Code starting with the faulting instruction
===========================================
0: 41 8b 54 24 10 mov 0x10(%r12),%edx
5: 49 63 8d 94 20 00 00 movslq 0x2094(%r13),%rcx
c: 48 0f af d6 imul %rsi,%rdx
10: 48 rex.W
11: be c3 f5 28 5c mov $0x5c28f5c3,%esi


To reproduce:

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp install job.yaml # job file is attached in this email
bin/lkp split-job --compatible job.yaml
bin/lkp run compatible-job.yaml



---
0DAY/LKP+ Test Infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation

Thanks,
Oliver Sang


Attachments:
(No filename) (6.83 kB)
config-5.12.0-rc2-00001-gab2dbddfd064 (175.56 kB)
job-script (5.87 kB)
dmesg.xz (1.74 kB)
job.yaml (4.60 kB)
Download all attachments