From patchwork Tue Nov 16 22:07:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 12623245 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E74AC433EF for ; Tue, 16 Nov 2021 22:08:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4B5563222 for ; Tue, 16 Nov 2021 22:08:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A4B5563222 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 94B916B0072; Tue, 16 Nov 2021 17:08:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FA046B0074; Tue, 16 Nov 2021 17:08:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C1E46B007D; Tue, 16 Nov 2021 17:08:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 6EA196B0072 for ; Tue, 16 Nov 2021 17:08:08 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3908555D60 for ; Tue, 16 Nov 2021 22:07:58 +0000 (UTC) X-FDA: 78816181836.11.6C3C246 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf25.hostedemail.com (Postfix) with ESMTP id 2A553B0001B1 for ; Tue, 16 Nov 2021 22:07:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 879DB1F44E90 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637100476; bh=NA0cdbekL1x62oPHdCMkmMH2XOBcwhAKSdexD6u70Kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SC0ozE3yZVAXaHcomRlInUUHQ32AFtRAi8Y+xzwWta7iHus8VTzSF5V5MjuKNoAor 3qbGNWqdqRUo8kGY7U4YHON9wFSW45QxGIy5p/HkpSrIuV+9zhemb1vZdVjSw9KHIw QF1MalyZoxiLTZqy4icq2hILytQCxpemcLJ6KJ9093/NO69PbKR7rGFsES3txxdTQJ 7mvTgl+UT/t3OOPp9eoUWGZz07UC+lIOcUG5DfKFt3nvkjl+3BWMlx0pOW/jdwkw2Q GIoGI+GzD9/D0mbL2BgIuLoXVKQT1GNh3t2RIj08uJQ3tnm1bxlXa5GOePBVNNr036 Pks0mHW2riCFw== From: Gabriel Krisman Bertazi To: hughd@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, jack@suse.com, amir73il@gmail.com, repnop@google.com, khazhy@google.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH 1/2] shmem: Differentiate cause of blk account error due to lack of space Date: Tue, 16 Nov 2021 17:07:41 -0500 Message-Id: <20211116220742.584975-2-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116220742.584975-1-krisman@collabora.com> References: <20211116220742.584975-1-krisman@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2A553B0001B1 X-Stat-Signature: i1849rqw86ds4rx776phebxzrxetyaaw Authentication-Results: imf25.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=collabora.com header.s=mail header.b=SC0ozE3y; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf25.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-HE-Tag: 1637100464-4623 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 notify userspace when space is running out, split the accounting return codes for the case where we cannot allocate more memory due to memory pressure from the actual case where we are approaching the file system size limit. Signed-off-by: Gabriel Krisman Bertazi --- mm/shmem.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index dc038ce78700..1cdd0253cb7a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -208,13 +208,13 @@ static inline void shmem_unacct_blocks(unsigned long flags, long pages) vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); } -static inline bool shmem_inode_acct_block(struct inode *inode, long pages) +static inline int 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)) - return false; + return -EPERM; if (sbinfo->max_blocks) { if (percpu_counter_compare(&sbinfo->used_blocks, @@ -223,11 +223,11 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) percpu_counter_add(&sbinfo->used_blocks, pages); } - return true; + return 0; unacct: shmem_unacct_blocks(info->flags, pages); - return false; + return -ENOSPC; } static inline void shmem_inode_unacct_blocks(struct inode *inode, long pages) @@ -373,7 +373,7 @@ bool shmem_charge(struct inode *inode, long pages) struct shmem_inode_info *info = SHMEM_I(inode); unsigned long flags; - if (!shmem_inode_acct_block(inode, pages)) + if (shmem_inode_acct_block(inode, pages)) return false; /* nrpages adjustment first, then shmem_recalc_inode() when balanced */ @@ -1595,7 +1595,8 @@ static struct page *shmem_alloc_and_acct_page(gfp_t gfp, huge = false; nr = huge ? HPAGE_PMD_NR : 1; - if (!shmem_inode_acct_block(inode, nr)) + err = shmem_inode_acct_block(inode, nr); + if (err) goto failed; if (huge) @@ -1907,7 +1908,9 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, error = PTR_ERR(page); page = NULL; - if (error != -ENOSPC) + if (error == -EPERM) + error = -ENOSPC; + else if (error != -ENOSPC) goto unlock; /* * Try to reclaim some space by splitting a huge page @@ -2357,7 +2360,7 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, int ret; pgoff_t max_off; - if (!shmem_inode_acct_block(inode, 1)) { + if (shmem_inode_acct_block(inode, 1)) { /* * We may have got a page, returned -ENOENT triggering a retry, * and now we find ourselves with -ENOMEM. Release the page, to From patchwork Tue Nov 16 22:07:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 12623247 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB19BC433F5 for ; Tue, 16 Nov 2021 22:09:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D615611AF for ; Tue, 16 Nov 2021 22:09:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4D615611AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B6CD66B0074; Tue, 16 Nov 2021 17:08:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1D2A6B007D; Tue, 16 Nov 2021 17:08:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E44F6B007E; Tue, 16 Nov 2021 17:08:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 908BE6B0074 for ; Tue, 16 Nov 2021 17:08:12 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 57A787DCB9 for ; Tue, 16 Nov 2021 22:08:02 +0000 (UTC) X-FDA: 78816182004.18.47990D3 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf28.hostedemail.com (Postfix) with ESMTP id 0B02790000BB for ; Tue, 16 Nov 2021 22:08:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id C13F31F44E90 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1637100481; bh=RqMGCc5ANCSX0caOVBCRAi6TG1XH+XSLk0z0lhMYJzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NUVK4h1yNWQ0bn9YXDH/oEj5dL4elNgiiSlB2/K/kwrOHSYZxauHQraYqz7InaTc/ /Nt0LnDve1uXRj0FGia2Cn9vpqLT8Kppb1WmDpDkm5tJyC79oOH1/xf4aE7PrbIC94 vSOrs9bqCmqvOwsyzoHinyeAlZwVsoENV9dPeVml+ezo13EpB4iawt5yW3aZ7rGH2n uUysPPJR0TSorf20lAOJ1/2VJy2NQSJkDE+g1o0N7MLN63O/zk8HBnzhAC0CH+Sy91 FgmJVO1AYgmOb7SN3VxRrSfkQwjwtAa1lXwqgDAWPJZL7cRU9rkJoy6B026LRmGgD3 P84ytBAo763BA== From: Gabriel Krisman Bertazi To: hughd@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, jack@suse.com, amir73il@gmail.com, repnop@google.com, khazhy@google.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH 2/2] shmem: Trigger FS_ERROR notification when file system is full Date: Tue, 16 Nov 2021 17:07:42 -0500 Message-Id: <20211116220742.584975-3-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116220742.584975-1-krisman@collabora.com> References: <20211116220742.584975-1-krisman@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0B02790000BB X-Stat-Signature: jtb8c5keptqnuk1p6t57zj3ksdgi8n1z Authentication-Results: imf28.hostedemail.com; dkim=fail ("headers rsa verify failed") header.d=collabora.com header.s=mail header.b=NUVK4h1y; dmarc=pass (policy=none) header.from=collabora.com; spf=pass (imf28.hostedemail.com: domain of krisman@collabora.com designates 46.235.227.227 as permitted sender) smtp.mailfrom=krisman@collabora.com X-HE-Tag: 1637100481-34431 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: Notify a monitoring application through the new FS_ERROR fsnotify event that the file system is full, allowing a sysadmin or recovery application to start recovery procedures. Signed-off-by: Gabriel Krisman Bertazi --- mm/shmem.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 1cdd0253cb7a..525af77d35f3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -39,6 +39,7 @@ #include #include #include +#include static struct vfsmount *shm_mnt; @@ -1823,6 +1824,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, int error; int once = 0; int alloced = 0; + bool max_blocks_reached = false; if (index > (MAX_LFS_FILESIZE >> PAGE_SHIFT)) return -EFBIG; @@ -1908,9 +1910,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, error = PTR_ERR(page); page = NULL; - if (error == -EPERM) + if (error == -ENOSPC) + max_blocks_reached = true; + else if (error == -EPERM) error = -ENOSPC; - else if (error != -ENOSPC) + else goto unlock; /* * Try to reclaim some space by splitting a huge page @@ -2024,11 +2028,16 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, unlock_page(page); put_page(page); } - if (error == -ENOSPC && !once++) { - spin_lock_irq(&info->lock); - shmem_recalc_inode(inode); - spin_unlock_irq(&info->lock); - goto repeat; + if (error == -ENOSPC) { + if (!once++) { + spin_lock_irq(&info->lock); + shmem_recalc_inode(inode); + spin_unlock_irq(&info->lock); + goto repeat; + } + + if (max_blocks_reached) + fsnotify_sb_error(inode->i_sb, inode, ENOSPC); } if (error == -EEXIST) goto repeat; @@ -2701,6 +2710,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT; /* Try to avoid a swapstorm if len is impossible to satisfy */ if (sbinfo->max_blocks && end - start > sbinfo->max_blocks) { + fsnotify_sb_error(inode->i_sb, inode, ENOSPC); error = -ENOSPC; goto out; }