From patchwork Mon Apr 18 21:37:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 12817129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33B33C433EF for ; Mon, 18 Apr 2022 21:37:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2BAC8D0022; Mon, 18 Apr 2022 17:37:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DB258D001A; Mon, 18 Apr 2022 17:37:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A2DC8D0022; Mon, 18 Apr 2022 17:37:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 7A8EC8D001A for ; Mon, 18 Apr 2022 17:37:24 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 3FD168043E for ; Mon, 18 Apr 2022 21:37:24 +0000 (UTC) X-FDA: 79371311208.04.CE9DCA6 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf04.hostedemail.com (Postfix) with ESMTP id A2BDB4000B for ; Mon, 18 Apr 2022 21:37:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 721EB1F41D3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650317842; bh=zfBsf2RUnAkmYRtu6lmk/b8dTq1cQYpREmaCwhUzUEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WAWUs7vw4rAUaK44h9j1spxZtioK1PD5dBNKcpMrBFLUfZtnXiyERNuSmsGNTgifP qXynn0eWhQhDs6NqUV1p/vW3vZTm6MsMKpZEGWXERcAiHNf+HTmsdVfjUn4WqC4QcM 8wGPp5ECkEQiq1QbyZnqu8NPoSsGr8GZauB/p9I7NyYyB5+8uat2QvFKDFofKiss4Q vC/B3RIy8nxVLuLa9SviblUvj9vHucP8c8PBoa0WIVJpUFUodYw3JVxgJY4rGcwI4M 5W8ALr9v1cClZWFab9exNQ/FDKFXXMAshyWEb/2aqVcWfojuOs0d8/wgeRyvpAUYF6 VBWTg6uDa9D5w== From: Gabriel Krisman Bertazi To: hughd@google.com, akpm@linux-foundation.org, amir73il@gmail.com Cc: viro@zeniv.linux.org.uk, Gabriel Krisman Bertazi , kernel@collabora.com, Khazhismel Kumykov , Linux MM , linux-fsdevel Subject: [PATCH v3 1/3] shmem: Keep track of out-of-memory and out-of-space errors Date: Mon, 18 Apr 2022 17:37:11 -0400 Message-Id: <20220418213713.273050-2-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220418213713.273050-1-krisman@collabora.com> References: <20220418213713.273050-1-krisman@collabora.com> MIME-Version: 1.0 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=WAWUs7vw; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf04.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A2BDB4000B X-Stat-Signature: w4jnkezuhcpt1sam44x56jkd6benw58g X-HE-Tag: 1650317843-98130 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Keep a per-sb counter of failed shmem allocations for ENOMEM/ENOSPC to be reported on sysfs. The sysfs support is done separately on a later patch. Signed-off-by: Gabriel Krisman Bertazi --- include/linux/shmem_fs.h | 3 +++ mm/shmem.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index e65b80ed09e7..1a7cd9ea9107 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -44,6 +44,9 @@ struct shmem_sb_info { spinlock_t shrinklist_lock; /* Protects shrinklist */ struct list_head shrinklist; /* List of shinkable inodes */ unsigned long shrinklist_len; /* Length of shrinklist */ + + unsigned long acct_errors; + unsigned long space_errors; }; static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index a09b29ec2b45..c350fa0a0fff 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -212,8 +212,10 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); - if (shmem_acct_block(info->flags, pages)) + if (shmem_acct_block(info->flags, pages)) { + sbinfo->acct_errors += 1; return false; + } if (sbinfo->max_blocks) { if (percpu_counter_compare(&sbinfo->used_blocks, @@ -225,6 +227,7 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) return true; unacct: + sbinfo->space_errors += 1; shmem_unacct_blocks(info->flags, pages); return false; } From patchwork Mon Apr 18 21:37:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 12817130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A5AEC433F5 for ; Mon, 18 Apr 2022 21:37:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B14F8D0023; Mon, 18 Apr 2022 17:37:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 264A08D001A; Mon, 18 Apr 2022 17:37:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DBEB8D0023; Mon, 18 Apr 2022 17:37:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id EC32F8D001A for ; Mon, 18 Apr 2022 17:37:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id B4407606BC for ; Mon, 18 Apr 2022 21:37:27 +0000 (UTC) X-FDA: 79371311334.18.A1D3158 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf23.hostedemail.com (Postfix) with ESMTP id 44DD3140008 for ; Mon, 18 Apr 2022 21:37:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 2117C1F419FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650317846; bh=Y+ucbxeR+Qi5rPHrBhvrhU/yGHcw5E2wDEXDS0A6lTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L9CgekMQMobPNA/RLWz4ovzCY0yGOFDl8V/g4lc9S1gl6ccLy58WhtNDUHuyHD+G8 radeF2PEzd4xCBi5HHl1lCBjoeedo8GWRvo51FZNxcn5zc+K0BmiRgTS2IeCzoVuvl mDRyqXT/ncSV7XbRUyDfvlFQnZ72jx0MswnjYCYm9xzktnAn2D1xFYBnL64E0qP1RK 3CkGxjPCu1ATn8HNruvg5o3QWnuHdaX/4kTh3aNhh80iqog4DljGeSoOlGLV6ON94i 4qeLSFi0N7r6iqPOm1rmU395Ck9GR7XAe+rZo8wHjUZjhfHhlPTja3Ww3Ohzf4gIg1 5wk4el4Dr96Qw== From: Gabriel Krisman Bertazi To: hughd@google.com, akpm@linux-foundation.org, amir73il@gmail.com Cc: viro@zeniv.linux.org.uk, Gabriel Krisman Bertazi , kernel@collabora.com, Khazhismel Kumykov , Linux MM , linux-fsdevel Subject: [PATCH v3 2/3] shmem: Introduce /sys/fs/tmpfs support Date: Mon, 18 Apr 2022 17:37:12 -0400 Message-Id: <20220418213713.273050-3-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220418213713.273050-1-krisman@collabora.com> References: <20220418213713.273050-1-krisman@collabora.com> MIME-Version: 1.0 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=L9CgekMQ; spf=pass (imf23.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com; dmarc=pass (policy=none) header.from=collabora.com X-Stat-Signature: 4bp1fh4nryn4ijw6yc3eeg1wu5zpsycd X-Rspamd-Queue-Id: 44DD3140008 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650317847-978014 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In order to expose tmpfs statistics on sysfs, add the boilerplate code to create the /sys/fs/tmpfs structure. As suggested on a previous review, this uses the minor as the volume directory in /sys/fs/. This takes care of not exposing SB_NOUSER mounts. I don't think we have a usecase for showing them and, since they don't appear elsewhere, they might be confusing to users. Signed-off-by: Gabriel Krisman Bertazi Reported-by: kernel test robot Reported-by: Dan Carpenter --- Changes since v2: - Use kobject to release sbinfo (Viro) Changes since v1: - Use minor instead of fsid for directory in sysfs. (Amir) --- include/linux/shmem_fs.h | 2 ++ mm/shmem.c | 46 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 1a7cd9ea9107..6c1f3a4b8c46 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -47,6 +47,8 @@ struct shmem_sb_info { unsigned long acct_errors; unsigned long space_errors; + + struct kobject kobj; }; static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index c350fa0a0fff..8fe4a22e83a6 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -250,6 +250,7 @@ static const struct inode_operations shmem_dir_inode_operations; static const struct inode_operations shmem_special_inode_operations; static const struct vm_operations_struct shmem_vm_ops; static struct file_system_type shmem_fs_type; +static struct kobject *shmem_root; bool vma_is_shmem(struct vm_area_struct *vma) { @@ -3582,17 +3583,44 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) return 0; } +#if defined(CONFIG_SYSFS) +#define TMPFS_SB_ATTR_RO(name) \ + static struct kobj_attribute tmpfs_sb_attr_##name = __ATTR_RO(name) + +static struct attribute *tmpfs_attrs[] = { + NULL +}; +ATTRIBUTE_GROUPS(tmpfs); +#endif /* CONFIG_SYSFS */ + #endif /* CONFIG_TMPFS */ -static void shmem_put_super(struct super_block *sb) +static void tmpfs_sb_release(struct kobject *kobj) { - struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + struct shmem_sb_info *sbinfo = + container_of(kobj, struct shmem_sb_info, kobj); free_percpu(sbinfo->ino_batch); percpu_counter_destroy(&sbinfo->used_blocks); mpol_put(sbinfo->mpol); kfree(sbinfo); +} + +static struct kobj_type tmpfs_sb_ktype = { +#if defined(CONFIG_TMPFS) && defined(CONFIG_SYSFS) + .default_groups = tmpfs_groups, +#endif + .sysfs_ops = &kobj_sysfs_ops, + .release = tmpfs_sb_release, +}; + +static void shmem_put_super(struct super_block *sb) +{ + struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + sb->s_fs_info = NULL; + + kobject_put(&sbinfo->kobj); } static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) @@ -3608,6 +3636,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) return -ENOMEM; sb->s_fs_info = sbinfo; + kobject_init(&sbinfo->kobj, &tmpfs_sb_ktype); #ifdef CONFIG_TMPFS /* @@ -3673,6 +3702,11 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_root = d_make_root(inode); if (!sb->s_root) goto failed; + + if (!(sb->s_flags & SB_NOUSER) && + kobject_add(&sbinfo->kobj, shmem_root, "%d", MINOR(sb->s_dev))) + goto failed; + return 0; failed: @@ -3889,11 +3923,15 @@ int __init shmem_init(void) goto out2; } + shmem_root = kobject_create_and_add("tmpfs", fs_kobj); + if (!shmem_root) + goto out1; + shm_mnt = kern_mount(&shmem_fs_type); if (IS_ERR(shm_mnt)) { error = PTR_ERR(shm_mnt); pr_err("Could not kern_mount tmpfs\n"); - goto out1; + goto put_kobj; } #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -3904,6 +3942,8 @@ int __init shmem_init(void) #endif return 0; +put_kobj: + kobject_put(shmem_root); out1: unregister_filesystem(&shmem_fs_type); out2: From patchwork Mon Apr 18 21:37:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 12817131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D17AFC433EF for ; Mon, 18 Apr 2022 21:37:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C0FB8D0024; Mon, 18 Apr 2022 17:37:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 547748D001A; Mon, 18 Apr 2022 17:37:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E8058D0024; Mon, 18 Apr 2022 17:37:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 2DEB98D001A for ; Mon, 18 Apr 2022 17:37:31 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F30B5246D9 for ; Mon, 18 Apr 2022 21:37:30 +0000 (UTC) X-FDA: 79371311460.05.EA13F2F Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf02.hostedemail.com (Postfix) with ESMTP id 80EC18000C for ; Mon, 18 Apr 2022 21:37:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 50DD11F41A0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650317849; bh=GYECkxCByzaOM41HzDyvIHL8brH7A+F886nTQDaIBIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bP+AZTJ2AO1MTsrZvoI7YCLQR55xXNgN/onPzok9ZwDu3pRPGvKiTAVExakDe/H/1 s9bHl/qImPN12s+ovALL0e5KBxnKMx0sv2ElEMxL1ICOVPicOsYqo7YVLV9hnGWf+e Kbr7D1JwzaKr6KTl38sJ75FLDMH0m9D1ZBo4rY0jWwiNo5MHoRDNvaEqVaaUhaW/mg mQUUn6Lu6tyCGEn+e6HgEyTASMHNTnu0JfeQgwqtMyybQSK4gPQmHyb3QH3j/8pmaQ nGdo5b943LsozlDXjsA+ugy9jf6MZv78fW8V4iQqR27B4rFG1ReyEZdUiI7KnXWGOH DnvGr7u2klyyg== From: Gabriel Krisman Bertazi To: hughd@google.com, akpm@linux-foundation.org, amir73il@gmail.com Cc: viro@zeniv.linux.org.uk, Gabriel Krisman Bertazi , kernel@collabora.com, Khazhismel Kumykov , Linux MM , linux-fsdevel Subject: [PATCH v3 3/3] shmem: Expose space and accounting error count Date: Mon, 18 Apr 2022 17:37:13 -0400 Message-Id: <20220418213713.273050-4-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220418213713.273050-1-krisman@collabora.com> References: <20220418213713.273050-1-krisman@collabora.com> MIME-Version: 1.0 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=bP+AZTJ2; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf02.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 80EC18000C X-Stat-Signature: p4o5bjne5q836qkjntjtoh5grmuooh63 X-HE-Tag: 1650317850-504043 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Exposing these shmem counters through sysfs is particularly useful for container provisioning, to allow administrators to differentiate between insufficiently provisioned fs size vs. running out of memory. Suggested-by: Amir Goldstein Suggested-by: Khazhy Kumykov Signed-off-by: Gabriel Krisman Bertazi --- Documentation/ABI/testing/sysfs-fs-tmpfs | 13 ++++++++++++ mm/shmem.c | 25 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-fs-tmpfs diff --git a/Documentation/ABI/testing/sysfs-fs-tmpfs b/Documentation/ABI/testing/sysfs-fs-tmpfs new file mode 100644 index 000000000000..d32b90949710 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-fs-tmpfs @@ -0,0 +1,13 @@ +What: /sys/fs/tmpfs//acct_errors +Date: March 2022 +Contact: "Gabriel Krisman Bertazi" +Description: + Track the number of IO errors caused by lack of memory to + perform the allocation of a tmpfs block. + +What: /sys/fs/tmpfs//space_errors +Date: March 2022 +Contact: "Gabriel Krisman Bertazi" +Description: + Track the number of IO errors caused by lack of space + in the filesystem to perform the allocation of a tmpfs block. diff --git a/mm/shmem.c b/mm/shmem.c index 8fe4a22e83a6..5c665b955ceb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -214,6 +214,7 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) if (shmem_acct_block(info->flags, pages)) { sbinfo->acct_errors += 1; + sysfs_notify(&sbinfo->kobj, NULL, "acct_errors"); return false; } @@ -228,6 +229,7 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) unacct: sbinfo->space_errors += 1; + sysfs_notify(&sbinfo->kobj, NULL, "space_errors"); shmem_unacct_blocks(info->flags, pages); return false; } @@ -3584,10 +3586,33 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) } #if defined(CONFIG_SYSFS) +static ssize_t acct_errors_show(struct kobject *kobj, + struct kobj_attribute *attr, char *page) +{ + struct shmem_sb_info *sbinfo = + container_of(kobj, struct shmem_sb_info, kobj); + + return sysfs_emit(page, "%lu\n", sbinfo->acct_errors); +} + +static ssize_t space_errors_show(struct kobject *kobj, + struct kobj_attribute *attr, char *page) +{ + struct shmem_sb_info *sbinfo = + container_of(kobj, struct shmem_sb_info, kobj); + + return sysfs_emit(page, "%lu\n", sbinfo->space_errors); +} + #define TMPFS_SB_ATTR_RO(name) \ static struct kobj_attribute tmpfs_sb_attr_##name = __ATTR_RO(name) +TMPFS_SB_ATTR_RO(acct_errors); +TMPFS_SB_ATTR_RO(space_errors); + static struct attribute *tmpfs_attrs[] = { + &tmpfs_sb_attr_acct_errors.attr, + &tmpfs_sb_attr_space_errors.attr, NULL }; ATTRIBUTE_GROUPS(tmpfs);