Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp73952pxb; Sun, 15 Aug 2021 23:44:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx88i/iKgdkITVDhHMmrwJ85C9Y7A3BPsryZeGW7IIvW95d2ooWOIlhSFe2bGtFYEcBlxQj X-Received: by 2002:a5d:9617:: with SMTP id w23mr11403804iol.115.1629096272029; Sun, 15 Aug 2021 23:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629096272; cv=none; d=google.com; s=arc-20160816; b=uLxvEiFXGnIMjiUvHK/bOP3YOTkaTLB6qp4oH0MPQlLK7KxU/NNo7baBmt9JVsAqwQ JUmYdxA0Pi3Os03grDxPCd817WU55vfgJWRfTglW8lP6x5uPfsV2yHMfdnzMBjOTJ9jZ onE4vhzW9GgMlhGlu01ZL6tTCLCG+EDzidvWCvQSJ0eEqdv7XZ/df0EFThX41ThUqMqX PzanI/1EMgQchyodaOm5jqzGZ8Ri8h6o24tNoH4IwlGgNQh238+NTCvoVicuIIrBs5kU 3nRKCAoXhXlbQ5j54MXnjTHNas2WPS3O9fOET3qGK4JgdlXUHfYN9hs54m8trx55iGOn HfnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Fq3zC6TxrJ7wnET3ctJ9AEVAzp2Vf4zNH2VUOyMj2T8=; b=I3s92/bURlSsKcaDHV3rBT99C2lihQKDW5vssO2dIBe6fSXvWTKU+6Ytn0vwUlmSOh tPkZxxlpC9+MUjedpymx+mrsMo7LtDWRVQn4T2EFX4fbWRjL2N/KVTbIhBQC7uA/s87W lJVf8veFhlXOBxzZ/gcu1ErH6a28lDKv1Gd6EnzN3thuySGNx5okN8hluYY7ivcKusDB j5rWSpwmqDa2QbEYvgkkNvLb6wP+z6rzlXifjiGY5EqfN2lJXP3lff5XdcqeduFBq0DE S7MutCzhg96D8M3hcwNPZeo+XHTAGExnmMM41PxCgVBHNEqZ7P8XjINbtirCvO0N4YIq HAXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gFQi9ted; 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 y17si15140083iov.62.2021.08.15.23.44.20; Sun, 15 Aug 2021 23:44:32 -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=gFQi9ted; 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 S233373AbhHPGm0 (ORCPT + 99 others); Mon, 16 Aug 2021 02:42:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230442AbhHPGmT (ORCPT ); Mon, 16 Aug 2021 02:42:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C1C4361A51; Mon, 16 Aug 2021 06:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629096108; bh=O8dpjKa3LoFhx1uZWjgWVWjFUc5corw5KPdK4GWHD80=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=gFQi9tedmh5BXSbzTqAybSYyXPQPQiC+RwW62EAbwkAFZJAozqqXviXot5x11Rmr2 F04A4gAqonO8y7aLbYYknMhgQSNmgUXZMakrU+1OEnF36bIkzoUCAM5nn7cc26Jyig Zccsd6+u3RAQqbFeIw9Q3JSXoqJd2SNf1XgkD6UvCk6KUcP5UCqDnOShBw2Ep5LCVe /CXRcMx+Jo20gM4kLPsa/nwZbwRY80h9SPFS0WrnQBowBTelvV9sW5eQHRSgu7JyHy 8XaUnCoMlIfod3zCqehpbZulwoTQIcuCPcDG7CfOS/G/cSFhI12QUkqNTXiwB0ZISr Ab25LR2V1n4RA== Subject: Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs//fsck_stack node To: =?UTF-8?B?5p2O5oms6Z+s?= , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: From: Chao Yu Message-ID: <2692c9c0-bb9f-0dd2-f0ca-6abb89e34c47@kernel.org> Date: Mon, 16 Aug 2021 14:41:46 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/8/16 12:02, 李扬韬 wrote: > HI Chao, >>> SBI_NEED_FSCK is an indicator that fsck.f2fs needs to be triggered, >>> this flag is set in too many places. For some scenes that are not very >>> reproducible, adding stack information will help locate the problem. >>> >>> Let's record all fsck stack history, I added F2FS_FSCK_STACK_TRACE >>> configuration options and sysfs nodes. After opening the configuration >>> options and enabling the node, it will start recording. The recorded >>> stack information will not be clear, and we can get information form >>> kernel log. >>> >>> Signed-off-by: Yangtao Li >>> --- >>> Documentation/ABI/testing/sysfs-fs-f2fs | 7 ++++ >>> fs/f2fs/Kconfig | 10 ++++++ >>> fs/f2fs/f2fs.h | 45 +++++++++++++++++++++++++ >>> fs/f2fs/sysfs.c | 27 +++++++++++++++ >>> 4 files changed, 89 insertions(+) >>> >>> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs >>> index ef4b9218ae1e..047c398093cf 100644 >>> --- a/Documentation/ABI/testing/sysfs-fs-f2fs >>> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs >>> @@ -493,3 +493,10 @@ Contact: "Chao Yu" >>> Description: When ATGC is on, it controls age threshold to bypass GCing young >>> candidates whose age is not beyond the threshold, by default it was >>> initialized as 604800 seconds (equals to 7 days). >>> + >>> +What: /sys/fs/f2fs//fsck_stack >>> +Date: August 2021 >>> +Contact: "Yangtao Li" >>> +Description: Controls to enable/disable fsck stack trace, you can get stack >>> + information from kernel log. Note that the recorded stack information >>> + will not be cleared. >> >> Again, please don't add this into sysfs. Oh, I missed to check the details... > > I added this node, part of the idea is to trigger the export of stack information. > There is no information transmitted through sysfs here, but the record of the stack is switched on and off. > If don't export this information through procfs and sysfs, is there a more appropriate way? Well, I doubt why we should export stack info via proc/sysfs node or sysfs switch. Those info will always be needed to troubleshoot issues no matter in user or eng version of Android, can we just print them directly into kernel message... what I concern is we may lost the bug scene due to no one can help to trigger dmesg printing via sysfs. Jaegeuk, thoughts? > >> >>> diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig >>> index 7669de7b49ce..f451e567e4a8 100644 >>> --- a/fs/f2fs/Kconfig >>> +++ b/fs/f2fs/Kconfig >>> @@ -135,3 +135,13 @@ config F2FS_FS_LZORLE >>> default y >>> help >>> Support LZO-RLE compress algorithm, if unsure, say Y. >>> + >>> +config F2FS_FSCK_STACK_TRACE >> >> I don't think we need another config to wrap this functionality, may be we >> can use F2FS_CHECK_FS instead. > > OK. > >> >>> + bool "F2FS fsck stack information record" >>> + depends on F2FS_FS >>> + depends on STACKDEPOT >>> + default y >>> + help >>> + Support printing out fsck stack history. With this, you have to >>> + turn on "fsck_stack" sysfs node. Then you can get information >>> + from kernel log. >>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>> index ee8eb33e2c25..b2d1d1a5a3fc 100644 >>> --- a/fs/f2fs/f2fs.h >>> +++ b/fs/f2fs/f2fs.h >>> @@ -24,6 +24,8 @@ >>> #include >>> #include >>> #include >>> +#include >>> +#include >>> >>> #include >>> #include >>> @@ -117,6 +119,8 @@ typedef u32 nid_t; >>> >>> #define COMPRESS_EXT_NUM 16 >>> >>> +#define FSCK_STACK_DEPTH 64 >> >> 16? > > OK. > >> >>> + >>> struct f2fs_mount_info { >>> unsigned int opt; >>> int write_io_size_bits; /* Write IO size bits */ >>> @@ -1748,6 +1752,11 @@ struct f2fs_sb_info { >>> unsigned int compress_watermark; /* cache page watermark */ >>> atomic_t compress_page_hit; /* cache hit count */ >>> #endif >>> +#ifdef CONFIG_F2FS_FSCK_STACK_TRACE >>> + depot_stack_handle_t *fsck_stack_history; >>> + unsigned int fsck_count; >>> + bool fsck_stack; >> >> IMO, all bug_on()s are corner cases, and catching those stacks won't cost >> much, so we can just use CONFIG_XXX to enable/disable this feature. > > F2FS_CHECK_FS ? > >> >>> +#endif >>> }; >>> >>> struct f2fs_private_dio { >>> @@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) >>> return sbi->node_inode->i_mapping; >>> } >>> >>> +#ifdef CONFIG_F2FS_FSCK_STACK_TRACE >>> +static void fsck_stack_trace(struct f2fs_sb_info *sbi) >>> +{ >>> + unsigned long entries[FSCK_STACK_DEPTH]; >>> + depot_stack_handle_t stack, *new; >>> + unsigned int nr_entries; >>> + int i; >>> + >>> + if (!sbi->fsck_stack) >>> + return; >>> + >>> + nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0); >>> + nr_entries = filter_irq_stacks(entries, nr_entries); >>> + stack = stack_depot_save(entries, nr_entries, GFP_KERNEL); >>> + if (!stack) >>> + return; >>> + >>> + /* Try to find an existing entry for this backtrace */ >>> + for (i = 0; i < sbi->fsck_count; i++) >>> + if (sbi->fsck_stack_history[i] == stack) >>> + return; >>> + >>> + new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) * >>> + sizeof(*sbi->fsck_stack_history), GFP_KERNEL); >>> + if (!new) >>> + return; >>> + >>> + sbi->fsck_stack_history = new; >>> + sbi->fsck_stack_history[sbi->fsck_count++] = stack; >> >> It will case memory leak after f2fs module exits. > > So let's enable this feature when f2fs is not a module and enable F2FS_CHECK_FS. I mean it needs to free .fsck_stack_history during umount(). Thanks, > >> >>> +} >>> +#endif >>> + >>> static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) >>> { >>> return test_bit(type, &sbi->s_flag); >>> @@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) >>> static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) >>> { >>> set_bit(type, &sbi->s_flag); >>> +#ifdef CONFIG_F2FS_FSCK_STACK_TRACE >>> + if (unlikely(type == SBI_NEED_FSCK)) >>> + fsck_stack_trace(sbi); >>> +#endif >>> } >>> >>> static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) >>> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c >>> index 204de4c2c818..4e786bb797e7 100644 >>> --- a/fs/f2fs/sysfs.c >>> +++ b/fs/f2fs/sysfs.c >>> @@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a, >>> if (!strcmp(a->attr.name, "compr_new_inode")) >>> return sysfs_emit(buf, "%u\n", sbi->compr_new_inode); >>> #endif >>> +#ifdef CONFIG_F2FS_FSCK_STACK_TRACE >>> + if (!strcmp(a->attr.name, "fsck_stack")) { >>> + unsigned long *entries; >>> + unsigned int nr_entries; >>> + unsigned int i; >>> + int count; >>> + >>> + count = sysfs_emit(buf, "%u\n", sbi->fsck_stack); >>> + if (!sbi->fsck_stack) >>> + return count; >>> + >>> + for (i = 0; i < sbi->fsck_count; i++) { >>> + nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries); >>> + if (!entries) >>> + return count; >>> + stack_trace_print(entries, nr_entries, 0); >>> + } >>> + return count; >>> + } >>> +#endif >>> >>> ui = (unsigned int *)(ptr + a->offset); >>> >>> @@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou >>> F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight); >>> F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold); >>> >>> +#ifdef CONFIG_F2FS_FSCK_STACK_TRACE >>> +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack); >>> +#endif >>> + >>> #define ATTR_LIST(name) (&f2fs_attr_##name.attr) >>> static struct attribute *f2fs_attrs[] = { >>> ATTR_LIST(gc_urgent_sleep_time), >>> @@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = { >>> ATTR_LIST(atgc_candidate_count), >>> ATTR_LIST(atgc_age_weight), >>> ATTR_LIST(atgc_age_threshold), >>> +#ifdef CONFIG_F2FS_FSCK_STACK_TRACE >>> + ATTR_LIST(fsck_stack), >>> +#endif >>> NULL, >>> }; >>> ATTRIBUTE_GROUPS(f2fs); >>> > > Thx, > Yangtao >