linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tmpfs: Restore functionality of nr_inodes=0
@ 2020-09-02  3:57 Byron Stanoszek
  2020-09-02  4:22 ` Hugh Dickins
  2020-09-02 10:48 ` Chris Down
  0 siblings, 2 replies; 3+ messages in thread
From: Byron Stanoszek @ 2020-09-02  3:57 UTC (permalink / raw)
  To: Hugh Dickins, Andrew Morton, linux-mm, linux-kernel
  Cc: Byron Stanoszek, Chris Down

Commit e809d5f0b5c9 ("tmpfs: per-superblock i_ino support") made changes to
shmem_reserve_inode() in mm/shmem.c, however the original test for
(sbinfo->max_inodes) got dropped. This causes mounting tmpfs with option
nr_inodes=0 to fail:

  # mount -ttmpfs -onr_inodes=0 none /ext0
  mount: /ext0: mount(2) system call failed: Cannot allocate memory.

This patch restores the nr_inodes=0 functionality.

Fixes: e809d5f0b5c9 ("tmpfs: per-superblock i_ino support")
Cc: Chris Down <chris@chrisdown.name>
Signed-off-by: Byron Stanoszek <gandalf@winds.org>
---
 mm/shmem.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 271548ca20f3..8e2b35ba93ad 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -279,11 +279,13 @@ static int shmem_reserve_inode(struct super_block *sb, ino_t *inop)
 
 	if (!(sb->s_flags & SB_KERNMOUNT)) {
 		spin_lock(&sbinfo->stat_lock);
-		if (!sbinfo->free_inodes) {
-			spin_unlock(&sbinfo->stat_lock);
-			return -ENOSPC;
+		if (sbinfo->max_inodes) {
+			if (!sbinfo->free_inodes) {
+				spin_unlock(&sbinfo->stat_lock);
+				return -ENOSPC;
+			}
+			sbinfo->free_inodes--;
 		}
-		sbinfo->free_inodes--;
 		if (inop) {
 			ino = sbinfo->next_ino++;
 			if (unlikely(is_zero_ino(ino)))
-- 
2.28.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tmpfs: Restore functionality of nr_inodes=0
  2020-09-02  3:57 [PATCH] tmpfs: Restore functionality of nr_inodes=0 Byron Stanoszek
@ 2020-09-02  4:22 ` Hugh Dickins
  2020-09-02 10:48 ` Chris Down
  1 sibling, 0 replies; 3+ messages in thread
From: Hugh Dickins @ 2020-09-02  4:22 UTC (permalink / raw)
  To: Byron Stanoszek
  Cc: Hugh Dickins, Andrew Morton, linux-mm, linux-kernel, Chris Down

On Tue, 1 Sep 2020, Byron Stanoszek wrote:

> Commit e809d5f0b5c9 ("tmpfs: per-superblock i_ino support") made changes to
> shmem_reserve_inode() in mm/shmem.c, however the original test for
> (sbinfo->max_inodes) got dropped. This causes mounting tmpfs with option
> nr_inodes=0 to fail:
> 
>   # mount -ttmpfs -onr_inodes=0 none /ext0
>   mount: /ext0: mount(2) system call failed: Cannot allocate memory.
> 
> This patch restores the nr_inodes=0 functionality.
> 
> Fixes: e809d5f0b5c9 ("tmpfs: per-superblock i_ino support")
> Cc: Chris Down <chris@chrisdown.name>
> Signed-off-by: Byron Stanoszek <gandalf@winds.org>

Yikes, thank you Byron, very bad of me not to have spotted that:

Acked-by: Hugh Dickins <hughd@google.com>

I've taken a quick look to see how I missed it: yes, I'd compared
against my own tree, knew I had to come back here sometime to replace
the SB_KERNMOUNT test by a max_inodes test like I had, to restore the
performance of nr_inodes=0; but thought the SB_KERNMOUNT test was good
enough for now - without realizing the effect on the code below it. The
error does seem to be localized just to this block, yes.  Many thanks.

> ---
>  mm/shmem.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 271548ca20f3..8e2b35ba93ad 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -279,11 +279,13 @@ static int shmem_reserve_inode(struct super_block *sb, ino_t *inop)
>  
>  	if (!(sb->s_flags & SB_KERNMOUNT)) {
>  		spin_lock(&sbinfo->stat_lock);
> -		if (!sbinfo->free_inodes) {
> -			spin_unlock(&sbinfo->stat_lock);
> -			return -ENOSPC;
> +		if (sbinfo->max_inodes) {
> +			if (!sbinfo->free_inodes) {
> +				spin_unlock(&sbinfo->stat_lock);
> +				return -ENOSPC;
> +			}
> +			sbinfo->free_inodes--;
>  		}
> -		sbinfo->free_inodes--;
>  		if (inop) {
>  			ino = sbinfo->next_ino++;
>  			if (unlikely(is_zero_ino(ino)))
> -- 
> 2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tmpfs: Restore functionality of nr_inodes=0
  2020-09-02  3:57 [PATCH] tmpfs: Restore functionality of nr_inodes=0 Byron Stanoszek
  2020-09-02  4:22 ` Hugh Dickins
@ 2020-09-02 10:48 ` Chris Down
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Down @ 2020-09-02 10:48 UTC (permalink / raw)
  To: Byron Stanoszek; +Cc: Hugh Dickins, Andrew Morton, linux-mm, linux-kernel

Byron Stanoszek writes:
>Commit e809d5f0b5c9 ("tmpfs: per-superblock i_ino support") made changes to
>shmem_reserve_inode() in mm/shmem.c, however the original test for
>(sbinfo->max_inodes) got dropped. This causes mounting tmpfs with option
>nr_inodes=0 to fail:
>
>  # mount -ttmpfs -onr_inodes=0 none /ext0
>  mount: /ext0: mount(2) system call failed: Cannot allocate memory.
>
>This patch restores the nr_inodes=0 functionality.
>
>Fixes: e809d5f0b5c9 ("tmpfs: per-superblock i_ino support")
>Cc: Chris Down <chris@chrisdown.name>
>Signed-off-by: Byron Stanoszek <gandalf@winds.org>

Acked-by: Chris Down <chris@chrisdown.name>

Thanks, good catch.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-02 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-02  3:57 [PATCH] tmpfs: Restore functionality of nr_inodes=0 Byron Stanoszek
2020-09-02  4:22 ` Hugh Dickins
2020-09-02 10:48 ` Chris Down

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox