All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.com>
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 <krisman@collabora.com>,
	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	[thread overview]
Message-ID: <20211116220742.584975-2-krisman@collabora.com> (raw)
In-Reply-To: <20211116220742.584975-1-krisman@collabora.com>

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 <krisman@collabora.com>
---
 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
-- 
2.33.0



  reply	other threads:[~2021-11-16 22:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 22:07 [PATCH 0/2] shmem: Notify user space when file system is full Gabriel Krisman Bertazi
2021-11-16 22:07 ` Gabriel Krisman Bertazi [this message]
2021-11-16 22:07 ` [PATCH 2/2] shmem: Trigger FS_ERROR notification " Gabriel Krisman Bertazi
2021-11-17  9:00 ` [PATCH 0/2] shmem: Notify user space " Amir Goldstein
2022-01-11  1:57   ` Gabriel Krisman Bertazi
2022-01-11  7:50     ` Amir Goldstein
2022-01-12  3:19       ` Gabriel Krisman Bertazi
2022-01-12  5:59         ` Amir Goldstein
2022-01-14 20:17           ` Gabriel Krisman Bertazi
2022-01-14 22:16             ` Khazhy Kumykov
2022-01-15 11:30               ` Amir Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116220742.584975-2-krisman@collabora.com \
    --to=krisman@collabora.com \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=hughd@google.com \
    --cc=jack@suse.com \
    --cc=kernel@collabora.com \
    --cc=khazhy@google.com \
    --cc=linux-mm@kvack.org \
    --cc=repnop@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.