Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1198088pxf; Fri, 12 Mar 2021 04:27:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwQIYXdL3zDQv2U+R1cHUDtPe2SIiV0gNMC8dlVhWcFsIkoNDB3khSQigx5VHmVKLAjdd4 X-Received: by 2002:aa7:d4ca:: with SMTP id t10mr13644754edr.388.1615552046862; Fri, 12 Mar 2021 04:27:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615552046; cv=none; d=google.com; s=arc-20160816; b=EONw4zXsYjHSy7AbbACYl0GYlZJ3ANI2f6wAECxfAPE5BNsEsRpfdJgFmXDBZyb+kt 3gOeBQNKSVW0AyesNL5weRmCCKkXdeRRWgvFhAmewatqsVHWDWLZw/dTLwIz6zBN3kpP klK8Kv0nu4KNfhpB2KH/e6uvW9cpmVq7jnRSGEb2cfNkcyNx9ucgjxL7DVn0KY1xjFoh H+GELWLsJM/saJJ2ntU2AGM/iS+tmQagVWNFNUC6xulrkbJM0w+H4d23hS6GPADqA6c6 hahZBrpphItdLup83li1xw9o03pxBPjO3mYL1hOJOfv/3en25spKNNQXjdy5lV7DAka0 6BdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=heFiHRJ+yDXxsvP4FofmW3y6eiqEITqgGlgBBBwjlWI=; b=03/m8aYi0sBrRmhyCakEWf8rZrXDH7STTsShcuGldVya9SmTAdbg/bD+YiTakNGou6 BKHLwk7oTdzJekkWaDlm5X6XHphYZ9d3Iy9wVxZNOlocclEQaTY42ABH7NSnnmAgUhdS 3+X8Vba3gv3wd2bYXTDpee5MVP/1WAS2xkTrjXBMeUXn85PPBlso7WujfmBQBNOKbxLK fG9sZQWO8Z2WYIusg/1wK1PfWZmVaOj9SqXr6SFKg9IvAT34B4NoWDRVu6AKmbLn+WxA WLIni5f6MqmdTuMBHFLNHZqBkY8yiVEQSpuIjkOPoMd4dqWJLUJs6ChYwC+Cr6xkGYvo fYZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rc85kEb4; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q9si3808360edd.324.2021.03.12.04.27.03; Fri, 12 Mar 2021 04:27:26 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=rc85kEb4; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbhCLM0J (ORCPT + 99 others); Fri, 12 Mar 2021 07:26:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbhCLMZj (ORCPT ); Fri, 12 Mar 2021 07:25:39 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7742C061574 for ; Fri, 12 Mar 2021 04:25:38 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id lr10-20020a17090b4b8ab02900dd61b95c5eso8426376pjb.4 for ; Fri, 12 Mar 2021 04:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=heFiHRJ+yDXxsvP4FofmW3y6eiqEITqgGlgBBBwjlWI=; b=rc85kEb472JL3UTVxb/VSg9CshQzVlWaps9ym3rGDLm9Kev+oXifXhdSNATALoko3r T/EPPKN33y8081b0eCP/BJJ0FdwQI1Q+En1+BKnnzH1Qcd3saEaQiEtmSzO74NIffsYk CRw/rN+q/3p7OFTnPletzuXHCNFIE6UMvuNSEqARRu8mf7g+ZrCzDfJBV+RyAAViSmHw 4GIx+mopjgpqdJ+uALQcKr7eU5sNaI/6Q05JMw7b0TJyYwA8PfigWJPDzwq8YLRU1qYC bxgE3wdxwiwt8bfzTfnpuUljLtcP5bqEbRAdRFxmbpPz1/QnqV8CHlWTFKXKdwIgpag2 16yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=heFiHRJ+yDXxsvP4FofmW3y6eiqEITqgGlgBBBwjlWI=; b=Ah3zj07sPEcXr9VhqTu8lI4RwEpaVw0Kre8CNF3szkFgyZ23X3PBKSIxYrJkJGoA0v XjZzV8cHenKxOHe0j+44TfKmAkGyhafyuHpq4Sqwuf76QLnkJCvkLljS0eC8eFlTT2A+ hLl8knHqFlYNwfQ/X8vE4CTBQenzfN4dF37n38CgnLEEatUfIdCcsLrfGq1lWVGBQQ7U ilySJa1DBy7I1SfeivTzUAG7RAjLkIt+t1XN7tBCFlLtq3FTWQeXXvXxWH2Q3Uj2BwyT 1NqFLclYBiUE4U7zDeDgYW0BXWxMcAKcmiretzzFi+IhXMDsqkWS7ATaJGxDE0eYTxBo hL6A== X-Gm-Message-State: AOAM5310IO8lIlRE1tK09+wdYbzG7FiRJhg4bhBgAfJ+6otqJo2ZFEM6 snighFZVhQxxuBAAt3Ty9b+bU9Hv8XQ= X-Received: by 2002:a17:90a:bd97:: with SMTP id z23mr14381546pjr.189.1615551938111; Fri, 12 Mar 2021 04:25:38 -0800 (PST) Received: from daehojeong1.seo.corp.google.com ([2401:fa00:d:11:addc:c0e1:9aed:6202]) by smtp.gmail.com with ESMTPSA id iq6sm2208956pjb.31.2021.03.12.04.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 04:25:37 -0800 (PST) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH v4] f2fs: add sysfs nodes to get runtime compression stat Date: Fri, 12 Mar 2021 21:25:31 +0900 Message-Id: <20210312122531.2717093-1-daeho43@gmail.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daeho Jeong I've added new sysfs nodes to show runtime compression stat since mount. compr_written_block - show the block count written after compression compr_saved_block - show the saved block count with compression compr_new_inode - show the count of inode newly enabled for compression Signed-off-by: Daeho Jeong --- v2: thanks to kernel test robot , fixed compile issue related to kernel config v3: changed sysfs nodes' names and made them runtime stat, not persistent on disk v4: changed sysfs nodes' desctiption --- Documentation/ABI/testing/sysfs-fs-f2fs | 24 ++++++++++ fs/f2fs/compress.c | 1 + fs/f2fs/f2fs.h | 19 ++++++++ fs/f2fs/super.c | 7 +++ fs/f2fs/sysfs.c | 58 +++++++++++++++++++++++++ 5 files changed, 109 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index cbeac1bebe2f..ddd4bd6116fc 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -409,3 +409,27 @@ Description: Give a way to change checkpoint merge daemon's io priority. I/O priority "3". We can select the class between "rt" and "be", and set the I/O priority within valid range of it. "," delimiter is necessary in between I/O class and priority number. + +What: /sys/fs/f2fs//compr_written_block +Date: March 2021 +Contact: "Daeho Jeong" +Description: Show the block count written after compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs//compr_saved_block +Date: March 2021 +Contact: "Daeho Jeong" +Description: Show the saved block count with compression since mount. Note + that when the compressed blocks are deleted, this count doesn't + decrease. If you write "0" here, you can initialize + compr_written_block and compr_saved_block to "0". + +What: /sys/fs/f2fs//compr_new_inode +Date: March 2021 +Contact: "Daeho Jeong" +Description: Show the count of inode newly enabled for compression since mount. + Note that when the compression is disabled for the files, this count + doesn't decrease. If you write "0" here, you can initialize + compr_new_inode to "0". diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 77fa342de38f..3c9d797dbdd6 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1353,6 +1353,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, if (fio.compr_blocks) f2fs_i_compr_blocks_update(inode, fio.compr_blocks - 1, false); f2fs_i_compr_blocks_update(inode, cc->nr_cpages, true); + add_compr_block_stat(inode, cc->nr_cpages); set_inode_flag(cc->inode, FI_APPEND_WRITE); if (cc->cluster_idx == 0) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e2d302ae3a46..2c989f8caf05 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1623,6 +1623,11 @@ struct f2fs_sb_info { #ifdef CONFIG_F2FS_FS_COMPRESSION struct kmem_cache *page_array_slab; /* page array entry */ unsigned int page_array_slab_size; /* default page array slab size */ + + /* For runtime compression statistics */ + atomic64_t compr_written_block; + atomic64_t compr_saved_block; + atomic_t compr_new_inode; #endif }; @@ -3955,6 +3960,18 @@ int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); int __init f2fs_init_compress_cache(void); void f2fs_destroy_compress_cache(void); +#define inc_compr_inode_stat(inode) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + atomic_inc(&sbi->compr_new_inode); \ + } while (0) +#define add_compr_block_stat(inode, blocks) \ + do { \ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ + int diff = F2FS_I(inode)->i_cluster_size - blocks; \ + atomic64_add(blocks, &sbi->compr_written_block); \ + atomic64_add(diff, &sbi->compr_saved_block); \ + } while (0) #else static inline bool f2fs_is_compressed_page(struct page *page) { return false; } static inline bool f2fs_is_compress_backend_ready(struct inode *inode) @@ -3983,6 +4000,7 @@ static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } static inline int __init f2fs_init_compress_cache(void) { return 0; } static inline void f2fs_destroy_compress_cache(void) { } +#define inc_compr_inode_stat(inode) do { } while (0) #endif static inline void set_compress_context(struct inode *inode) @@ -4006,6 +4024,7 @@ static inline void set_compress_context(struct inode *inode) F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; set_inode_flag(inode, FI_COMPRESSED_FILE); stat_inc_compr_inode(inode); + inc_compr_inode_stat(inode); f2fs_mark_inode_dirty_sync(inode, true); } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 7069793752f1..88d9ecdee8d3 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3260,6 +3260,13 @@ static void init_sb_info(struct f2fs_sb_info *sbi) init_rwsem(&sbi->sb_lock); init_rwsem(&sbi->pin_sem); + +#ifdef CONFIG_F2FS_FS_COMPRESSION + /* For runtime compression statistics */ + atomic64_set(&sbi->compr_written_block, 0); + atomic64_set(&sbi->compr_saved_block, 0); + atomic_set(&sbi->compr_new_inode, 0); +#endif } static int init_percpu_info(struct f2fs_sb_info *sbi) diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index e38a7f6921dd..2b6e5e6e1286 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -282,6 +282,38 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a, return len; } +#ifdef CONFIG_F2FS_FS_COMPRESSION + if (!strcmp(a->attr.name, "compr_written_block")) { + u64 bcount; + int len; + + bcount = atomic64_read(&sbi->compr_written_block); + + len = scnprintf(buf, PAGE_SIZE, "%llu\n", bcount); + return len; + } + + if (!strcmp(a->attr.name, "compr_saved_block")) { + u64 bcount; + int len; + + bcount = atomic64_read(&sbi->compr_saved_block); + + len = scnprintf(buf, PAGE_SIZE, "%llu\n", bcount); + return len; + } + + if (!strcmp(a->attr.name, "compr_new_inode")) { + u32 icount; + int len; + + icount = atomic_read(&sbi->compr_new_inode); + + len = scnprintf(buf, PAGE_SIZE, "%u\n", icount); + return len; + } +#endif + ui = (unsigned int *)(ptr + a->offset); return sprintf(buf, "%u\n", *ui); @@ -458,6 +490,24 @@ static ssize_t __sbi_store(struct f2fs_attr *a, return count; } +#ifdef CONFIG_F2FS_FS_COMPRESSION + if (!strcmp(a->attr.name, "compr_written_block") || + !strcmp(a->attr.name, "compr_saved_block")) { + if (t != 0) + return -EINVAL; + atomic64_set(&sbi->compr_written_block, 0); + atomic64_set(&sbi->compr_saved_block, 0); + return count; + } + + if (!strcmp(a->attr.name, "compr_new_inode")) { + if (t != 0) + return -EINVAL; + atomic_set(&sbi->compr_new_inode, 0); + return count; + } +#endif + *ui = (unsigned int)t; return count; @@ -668,6 +718,9 @@ F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD); #ifdef CONFIG_F2FS_FS_COMPRESSION F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION); +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block); +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block); +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode); #endif #define ATTR_LIST(name) (&f2fs_attr_##name.attr) @@ -730,6 +783,11 @@ static struct attribute *f2fs_attrs[] = { ATTR_LIST(moved_blocks_foreground), ATTR_LIST(moved_blocks_background), ATTR_LIST(avg_vblocks), +#endif +#ifdef CONFIG_F2FS_FS_COMPRESSION + ATTR_LIST(compr_written_block), + ATTR_LIST(compr_saved_block), + ATTR_LIST(compr_new_inode), #endif NULL, }; -- 2.31.0.rc2.261.g7f71774620-goog