Skip to contentSkip to conversation

shmem: restore superblock info

PATCH In review Hugh Dickins 2 participants 4 messages Jun 6, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shmem: restore superblock info

To improve shmem scalability, we allowed tmpfs instances which don't need their blocks or inodes limited not to count them, and not to allocate any sbinfo. Which was okay when the only use for the sbinfo was accounting blocks and inodes; but since then a couple of unrelated projects extending tmpfs want to store other data in the sbinfo. Whether either extension reaches mainline is beside the point: I'm guilty of a bad design decision, and should restore sbinfo to make any such future extensions easier.

So, once again allocate a shmem_sb_info for every shmem/tmpfs instance, and now let max_blocks 0 indicate unlimited blocks, and max_inodes 0 unlimited inodes. Brent Casavant verified (many months ago) that this does not perceptibly impact the scalability (since the unlimited sbinfo cacheline is repeatedly accessed but only once dirtied).

And merge shmem_set_size into its sole caller shmem_remount_fs.

---

 Documentation/filesystems/tmpfs.txt |    6 -
 mm/shmem.c                          |  143 +++++++++++++++++-------------------
 2 files changed, 73 insertions(+), 76 deletions(-)
Documentation/filesystems/tmpfs.txt +3 -3
@@ -71,8 +71,8 @@ can be changed on remount.  The size par
 to limit this tmpfs instance to that percentage of your physical RAM:
 the default, when neither size nor nr_blocks is specified, is size=50%
 
-If both nr_blocks (or size) and nr_inodes are set to 0, neither blocks
-nor inodes will be limited in that instance.  It is generally unwise to
+If nr_blocks=0 (or size=0), blocks will not be limited in that instance;
+if nr_inodes=0, inodes will not be limited.  It is generally unwise to
 mount with such options, since it allows any user with write access to
 use up all the memory on the machine; but enhances the scalability of
 that instance in a system with many cpus making intensive use of it.
@@ -97,4 +97,4 @@ RAM/SWAP in 10240 inodes and it is only 
 Author:
    Christoph Rohland <[email protected]>, 1.12.01
 Updated:
-   Hugh Dickins <[email protected]>, 01 September 2004
+   Hugh Dickins <[email protected]>, 13 March 2005
mm/shmem.c +70 -73

248 lines not on this page · raw message

#1 lore raw
Quoted 10 lines · Hugh Dickins
mm/shmem.c +2 -2
@@ -1607,15 +1582,17 @@ static int shmem_statfs(struct super_blo
 	buf->f_type = TMPFS_MAGIC;
 	buf->f_bsize = PAGE_CACHE_SIZE;
 	buf->f_namelen = NAME_MAX;
-	if (sbinfo) {
-		spin_lock(&sbinfo->stat_lock);
+	spin_lock(&sbinfo->stat_lock);
+	if (sbinfo->max_blocks) {
 		buf->f_blocks = sbinfo->max_blocks;
 		buf->f_bavail = buf->f_bfree = sbinfo->free_blocks;

mm/shmem.c static int shmem_statfs(struct super_blo · line 1597

Quoted 10 lines
mm/shmem.c +3 -1
+	}
+	if (sbinfo->max_inodes) {
 		buf->f_files = sbinfo->max_inodes;
 		buf->f_ffree = sbinfo->free_inodes;
-		spin_unlock(&sbinfo->stat_lock);
 	}
 	/* else leave those fields 0 like simple_statfs */
+	spin_unlock(&sbinfo->stat_lock);
 	return 0;
 }

This is the only change I'm at all concerned about.

I'm not sure how frequent statfs operations occur in practice (I suspect infrequently), however simply changing the existing code from "if (sbinfo)" to "if (sbinfo->max_blocks || sbinfo->max_inodes)" would be an appropriate remedy if there is a real problem.

That said, I'm not all that concerned about it, as my fuzzy memory indicates it was the lock/unlock around the statistics updates which caused the primary lock contention.

Brent

Signature · 3 lines
Brent Casavant                          If you had nothing to fear,
[email protected]                        how then could you be brave?
Silicon Graphics, Inc.                    -- Queen Dama, Source Wars
#2 lore raw
Quoted 6 lines · Brent Casavant
Quoted 4 lines · Hugh Dickins
mm/shmem.c +1 -2
@@ -1607,15 +1582,17 @@ static int shmem_statfs(struct super_blo
-	if (sbinfo) {
-		spin_lock(&sbinfo->stat_lock);
+	spin_lock(&sbinfo->stat_lock);

...

Quoted 2 lines

This is the only change I'm at all concerned about.

Thanks for noticing, I hadn't really considered that.

Quoted 2 lines

I'm not sure how frequent statfs operations occur in practice (I suspect infrequently),

Infrequently, yes. I think infrequently to the point of never in the case that concerns you: correct if I'm wrong, someone, but I think there's actually no handle by which user can statfs shm's internal mount.

Quoted 3 lines

however simply changing the existing code from "if (sbinfo)" to "if (sbinfo->max_blocks || sbinfo->max_inodes)" would be an appropriate remedy if there is a real problem.

Hadn't thought of that, yes, can do if there's a real problem.

Quoted 3 lines

That said, I'm not all that concerned about it, as my fuzzy memory indicates it was the lock/unlock around the statistics updates which caused the primary lock contention.

That's right, and certainly this shmem_statfs locking change didn't show up when you retested for me (thank you!) all those months ago.

Hugh

#3 lore raw
Quoted 11 lines · Hugh Dickins
Quoted 6 lines · Brent Casavant
Quoted 4 lines · Hugh Dickins
mm/shmem.c +1 -2
@@ -1607,15 +1582,17 @@ static int shmem_statfs(struct super_blo
-	if (sbinfo) {
-		spin_lock(&sbinfo->stat_lock);
+	spin_lock(&sbinfo->stat_lock);

...

Quoted 2 lines

This is the only change I'm at all concerned about.

Quoted 8 lines

Thanks for noticing, I hadn't really considered that.

Quoted 2 lines

I'm not sure how frequent statfs operations occur in practice (I suspect infrequently),

Infrequently, yes. I think infrequently to the point of never in the case that concerns you: correct if I'm wrong, someone, but I think there's actually no handle by which user can statfs shm's internal mount.

Ah, that's an even better point, which I had failed to consider. Consider my concerns duly nullified. :)

Thanks for CC'ing me on the change.

Brent

Signature · 3 lines
Brent Casavant                          If you had nothing to fear,
[email protected]                        how then could you be brave?
Silicon Graphics, Inc.                    -- Queen Dama, Source Wars