From patchwork Mon Apr 4 13:41:37 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: 12800267 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 D6AFAC433EF for ; Mon, 4 Apr 2022 13:43:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 973BC6B0075; Mon, 4 Apr 2022 09:42:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 922086B0078; Mon, 4 Apr 2022 09:42:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EB086B007B; Mon, 4 Apr 2022 09:42:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 70C0D6B0075 for ; Mon, 4 Apr 2022 09:42:09 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 26E2E183B95BE for ; Mon, 4 Apr 2022 13:41:59 +0000 (UTC) X-FDA: 79319309958.30.5101569 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf22.hostedemail.com (Postfix) with ESMTP id A7B2BC003D for ; Mon, 4 Apr 2022 13:41:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 820CE1F44928 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1649079717; bh=ZuYFeCaQsdCLMnheFQIhRwZM/6Dp8P5T0ofZ9ffnljU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KWXMRl0zbkAs2k9MO2sK3se2kssklJSRRLwjnVlVMF2s5B7XVFz6mzcz2LV7Xl/he n0YVFG/mwufSjL96TitZEYtxZFEod9tUVbjBU1nnswxXjcxNfroB/+TTamZmuADHyU QlcE8HgoPXk8GUkBEejRSJYIxcvZN5Tds0edRQatDr/sTN1kw8DZ+GVfjmcnKSqnj7 XVw1Wey4ta3441uh2Y1t7HofW0Km7IZIgb7/ybYRu/7Fc+zvRkXM6eW6z0I2TL8hKr eLW2wMlFNovHZ4PXsw52wLjbnfrbj8Vzoi41HOU+HFSsHiGzldaBbjiyV0r5JcwhGj kYxnad75vSmVw== From: Gabriel Krisman Bertazi To: Hugh Dickins , Andrew Morton , Amir Goldstein Cc: Gabriel Krisman Bertazi , kernel@collabora.com, Khazhismel Kumykov , Linux MM , linux-fsdevel Subject: [PATCH RESEND 3/3] shmem: Expose space and accounting error count Date: Mon, 4 Apr 2022 09:41:37 -0400 Message-Id: <20220404134137.26284-4-krisman@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220404134137.26284-1-krisman@collabora.com> References: <20220404134137.26284-1-krisman@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: mztja6fjfxy8qspzoemo7gwn6qfbd7nd Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=KWXMRl0z; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf22.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-Rspamd-Queue-Id: A7B2BC003D X-HE-Tag: 1649079718-782343 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 665d417ba8a8..50d22449d99e 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->s_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->s_kobj, NULL, "space_errors"); shmem_unacct_blocks(info->flags, pages); return false; } @@ -3586,10 +3588,33 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) #endif /* CONFIG_TMPFS */ #if defined(CONFIG_TMPFS) && 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, s_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, s_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);