Skip to contentSkip to conversation

mm: shmem: always support large folios for internal shmem mount

PATCH In review Baolin Wang 3 participants 11 messages Apr 17 – Apr 23

Subsystems (2)
lore
Share & tools
lore

Baolin Wang

author reviewer
#0 lore raw

PATCH v3 1/1 mm: shmem: always support large folios for internal shmem mount

Currently, when shmem mounts are initialized, they only use 'sbinfo->huge' to determine whether the shmem mount supports large folios. However, for anonymous shmem, whether it supports large folios can be dynamically configured via sysfs interfaces, so setting or not setting mapping_set_large_folios() during initialization cannot accurately reflect whether anonymous shmem actually supports large folios, which has already caused some confusion[1].

As discussed with David[2], for anonymous shmem we can treat it as always potentially having large folios. Therefore, always support large folios for the internal shmem mount (e.g., anonymous shmem), and which large order allocations are allowed can be configured dynamically via the 'shmem_enabled' interfaces.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

---
Changes from v2:
- Always support large folios for internal shmem mount, per David.
Changes from v1:
- Update the comments and commit message, per Lance.

---
 mm/shmem.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
mm/shmem.c +11 -2
index 4ecefe02881d..769ef37b1ea9 100644
@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
 	if (sbinfo->noswap)
 		mapping_set_unevictable(inode->i_mapping);
 
-	/* Don't consider 'deny' for emergencies and 'force' for testing */
-	if (sbinfo->huge)
+	/*
+	 * Always support large folios for the internal shmem mount (e.g.,
+	 * anonymous shmem), and which large order allocations are allowed
+	 * can be configured dynamically via the 'shmem_enabled' interfaces.
+	 *
+	 * For tmpfs, honour the 'huge=' mount option to determine whether
+	 * large folios are supported.
+	 *
+	 * Note: don't consider 'deny' for emergencies and 'force' for testing.
+	 */
+	if (sbinfo->huge || (sb->s_flags & SB_KERNMOUNT))
 		mapping_set_large_folios(inode->i_mapping);
 
 	switch (mode & S_IFMT) {
Signature · 1 line
2.47.3
#1 lore raw
Quoted 36 lines · Baolin Wang

Currently, when shmem mounts are initialized, they only use 'sbinfo->huge' to determine whether the shmem mount supports large folios. However, for anonymous shmem, whether it supports large folios can be dynamically configured via sysfs interfaces, so setting or not setting mapping_set_large_folios() during initialization cannot accurately reflect whether anonymous shmem actually supports large folios, which has already caused some confusion[1].

As discussed with David[2], for anonymous shmem we can treat it as always potentially having large folios. Therefore, always support large folios for the internal shmem mount (e.g., anonymous shmem), and which large order allocations are allowed can be configured dynamically via the 'shmem_enabled' interfaces.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

---
Changes from v2:
- Always support large folios for internal shmem mount, per David.
Changes from v1:
- Update the comments and commit message, per Lance.

---
 mm/shmem.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
index 4ecefe02881d..769ef37b1ea9 100644
@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
 	if (sbinfo->noswap)
 		mapping_set_unevictable(inode->i_mapping);
 
-	/* Don't consider 'deny' for emergencies and 'force' for testing */
-	if (sbinfo->huge)
+	/*
+	 * Always support large folios for the internal shmem mount (e.g.,

mm/shmem.c static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, · line 3102

Quoted 10 lines
mm/shmem.c +9 -0
+	 * anonymous shmem), and which large order allocations are allowed
+	 * can be configured dynamically via the 'shmem_enabled' interfaces.
+	 *
+	 * For tmpfs, honour the 'huge=' mount option to determine whether
+	 * large folios are supported.
+	 *
+	 * Note: don't consider 'deny' for emergencies and 'force' for testing.
+	 */
+	if (sbinfo->huge || (sb->s_flags & SB_KERNMOUNT))
 		mapping_set_large_folios(inode->i_mapping);

Two questions from a non-fs person about the semantics here:

a) Can sbinfo->huge be triggered later, for example, through a remount (staring at shmem_reconfigure())

b) Do we cover all cases with the SB_KERNMOUNT where sbinfo->huge cannot be changed later?

Signature · 3 lines
Cheers,

David
author reviewer
#2 lore raw
Quoted 50 lines · David Hildenbrand (Arm)
Quoted 36 lines · Baolin Wang

Currently, when shmem mounts are initialized, they only use 'sbinfo->huge' to determine whether the shmem mount supports large folios. However, for anonymous shmem, whether it supports large folios can be dynamically configured via sysfs interfaces, so setting or not setting mapping_set_large_folios() during initialization cannot accurately reflect whether anonymous shmem actually supports large folios, which has already caused some confusion[1].

As discussed with David[2], for anonymous shmem we can treat it as always potentially having large folios. Therefore, always support large folios for the internal shmem mount (e.g., anonymous shmem), and which large order allocations are allowed can be configured dynamically via the 'shmem_enabled' interfaces.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

---
Changes from v2:
- Always support large folios for internal shmem mount, per David.
Changes from v1:
- Update the comments and commit message, per Lance.

---
  mm/shmem.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
index 4ecefe02881d..769ef37b1ea9 100644
@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
  	if (sbinfo->noswap)
  		mapping_set_unevictable(inode->i_mapping);
 
-	/* Don't consider 'deny' for emergencies and 'force' for testing */
-	if (sbinfo->huge)
+	/*
+	 * Always support large folios for the internal shmem mount (e.g.,

mm/shmem.c static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, · line 3102

Quoted 10 lines
mm/shmem.c +9 -0
+	 * anonymous shmem), and which large order allocations are allowed
+	 * can be configured dynamically via the 'shmem_enabled' interfaces.
+	 *
+	 * For tmpfs, honour the 'huge=' mount option to determine whether
+	 * large folios are supported.
+	 *
+	 * Note: don't consider 'deny' for emergencies and 'force' for testing.
+	 */
+	if (sbinfo->huge || (sb->s_flags & SB_KERNMOUNT))
  		mapping_set_large_folios(inode->i_mapping);

Two questions from a non-fs person about the semantics here:

Quoted 2 lines

a) Can sbinfo->huge be triggered later, for example, through a remount (staring at shmem_reconfigure())

For tmpfs, yes.

Quoted 2 lines

b) Do we cover all cases with the SB_KERNMOUNT where sbinfo->huge cannot be changed later?

For mounts with the SB_KERNMOUNT flag set, which is essentially the internal shmem mount, as we discussed, we don't care about sbinfo->huge. Because for the internal shmem mount, we always consider it as potentially having large folios.

#3 lore raw
Quoted 66 lines · Baolin Wang
Quoted 63 lines · David Hildenbrand (Arm)
Quoted 51 lines · Baolin Wang

Currently, when shmem mounts are initialized, they only use 'sbinfo-

Quoted 1 line

huge' to

determine whether the shmem mount supports large folios. However, for anonymous
shmem, whether it supports large folios can be dynamically configured via sysfs
interfaces, so setting or not setting mapping_set_large_folios() during initialization
cannot accurately reflect whether anonymous shmem actually supports large folios,
which has already caused some confusion[1].

As discussed with David[2], for anonymous shmem we can treat it as always potentially
having large folios. Therefore, always support large folios for the internal shmem
mount (e.g., anonymous shmem), and which large order allocations are allowed can be
configured dynamically via the 'shmem_enabled' interfaces.

[1] https://lore.kernel.org/all/
[email protected]/
[2] https://lore.kernel.org/
all/[email protected]/

---
Changes from v2:
  - Always support large folios for internal shmem mount, per David. Changes from v1:
  - Update the comments and commit message, per Lance.
---
  mm/shmem.c | 13 +++++++++++--

  1 file changed, 11 insertions(+), 2 deletions(-)
mm/shmem.c +0 -0
index 4ecefe02881d..769ef37b1ea9 100644
@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct
 mnt_idmap *idmap,
       if (sbinfo->noswap)
           mapping_set_unevictable(inode->i_mapping);

  -    /* Don't consider 'deny' for emergencies and 'force' for testing */
-    if (sbinfo->huge)
+    /*
+     * Always support large folios for the internal shmem mount (e.g., +     * anonymous shmem), and which large order allocations are allowed +     * can be configured dynamically via the 'shmem_enabled' interfaces.
+     *

Quoted 8 lines

+     * For tmpfs, honour the 'huge=' mount option to determine whether +     * large folios are supported.
+     *
+     * Note: don't consider 'deny' for emergencies and 'force' for testing.
+     */
+    if (sbinfo->huge || (sb->s_flags & SB_KERNMOUNT)) mapping_set_large_folios(inode->i_mapping);

Two questions from a non-fs person about the semantics here:

Quoted 4 lines
Quoted 2 lines

a) Can sbinfo->huge be triggered later, for example, through a remount (staring at shmem_reconfigure())

For tmpfs, yes.

So, we could pass this check here, not setting mapping_set_large_folios(), but later someone toggles it and we missed to set mapping_set_large_folios()?

Or would we always go through another __shmem_get_inode() after a remount?

Signature · 3 lines
Cheers,

David
author reviewer
#4 lore raw
Quoted 67 lines · David Hildenbrand (Arm)
Quoted 66 lines · Baolin Wang
Quoted 63 lines · David Hildenbrand (Arm)
Quoted 51 lines · Baolin Wang

Currently, when shmem mounts are initialized, they only use 'sbinfo-

Quoted 1 line

huge' to

determine whether the shmem mount supports large folios. However, for anonymous
shmem, whether it supports large folios can be dynamically configured via sysfs
interfaces, so setting or not setting mapping_set_large_folios() during initialization
cannot accurately reflect whether anonymous shmem actually supports large folios,
which has already caused some confusion[1].

As discussed with David[2], for anonymous shmem we can treat it as always potentially
having large folios. Therefore, always support large folios for the internal shmem
mount (e.g., anonymous shmem), and which large order allocations are allowed can be
configured dynamically via the 'shmem_enabled' interfaces.

[1] https://lore.kernel.org/all/
[email protected]/
[2] https://lore.kernel.org/
all/[email protected]/

---
Changes from v2:
  - Always support large folios for internal shmem mount, per David.
Changes from v1:
  - Update the comments and commit message, per Lance.

---
   mm/shmem.c | 13 +++++++++++--
   1 file changed, 11 insertions(+), 2 deletions(-)
mm/shmem.c +0 -0
index 4ecefe02881d..769ef37b1ea9 100644
@@ -3088,8 +3088,17 @@ static struct inode *__shmem_get_inode(struct
 mnt_idmap *idmap,
       if (sbinfo->noswap)
           mapping_set_unevictable(inode->i_mapping);
   -    /* Don't consider 'deny' for emergencies and 'force' for

testing */
-    if (sbinfo->huge)
+    /*
+     * Always support large folios for the internal shmem mount (e.g., +     * anonymous shmem), and which large order allocations are allowed +     * can be configured dynamically via the 'shmem_enabled' interfaces.
+     *

Quoted 8 lines

+     * For tmpfs, honour the 'huge=' mount option to determine whether +     * large folios are supported.
+     *
+     * Note: don't consider 'deny' for emergencies and 'force' for testing.
+     */
+    if (sbinfo->huge || (sb->s_flags & SB_KERNMOUNT))
          mapping_set_large_folios(inode->i_mapping);

Two questions from a non-fs person about the semantics here:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

a) Can sbinfo->huge be triggered later, for example, through a remount (staring at shmem_reconfigure())

For tmpfs, yes.

So, we could pass this check here, not setting mapping_set_large_folios(), but later someone toggles it and we missed to set mapping_set_large_folios()?

Indeed. Good point.

Quoted 2 lines

Or would we always go through another __shmem_get_inode() after a remount?

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

[1] https://lore.kernel.org/all/[email protected]/

#5 lore raw
Quoted 24 lines · Baolin Wang
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 4 lines · Baolin Wang

For tmpfs, yes.

So, we could pass this check here, not setting mapping_set_large_folios(), but later someone toggles it and we missed to set mapping_set_large_folios()?

Indeed. Good point.

Quoted 3 lines

Or would we always go through another __shmem_get_inode() after a remount?

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

Quoted 7 lines

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

Okay, so you'll send a patch to just set mapping_set_large_folios() unconditionally?

Quoted 3 lines

[1] https://lore.kernel.org/all/20240914140613.2334139-1-
[email protected]/

Is that really required? Which call path would be the problematic bit with the above?

I'd say, we'd check in the large folio allocation code whether ->huge is set to never instead?

Signature · 3 lines
Cheers,

David
author reviewer
#6 lore raw
Quoted 28 lines · David Hildenbrand (Arm)
Quoted 27 lines · Baolin Wang
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 4 lines · Baolin Wang

For tmpfs, yes.

So, we could pass this check here, not setting mapping_set_large_folios(), but later someone toggles it and we missed to set mapping_set_large_folios()?

Indeed. Good point.

Quoted 3 lines

Or would we always go through another __shmem_get_inode() after a remount?

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Quoted 7 lines
Quoted 4 lines

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

Okay, so you'll send a patch to just set mapping_set_large_folios() unconditionally?

I'm still hesitating on this. If we set mapping_set_large_folios() unconditionally, we need to re-fix the performance regression that was addressed by commit 5a90c155defa.

But it's hard for me to convince myself to add a new flag similar to IOCB_NO_LARGE_CHUNK for this hack (like the patch in [1] does).

Quoted 8 lines
Quoted 2 lines

[1] https://lore.kernel.org/all/20240914140613.2334139-1-
[email protected]/

Is that really required? Which call path would be the problematic bit with the above?

I'd say, we'd check in the large folio allocation code whether ->huge is set to never instead?

Yes, this is exactly our current logic. When allocating large folios, we'll check the ->huge setting in shmem_huge_global_enabled(), which means large folio allocations always respect the ->huge setting.

But as I mentioned earlier, the ->huge setting cannot keep the mapping_set_large_folios() setting consistent across all mappings in the entire tmpfs mount. My concern is that under the same tmpfs mount, after remount, we might end up with some mappings supporting large folios (calling mapping_set_large_folios()) while others don't.

However, I got some insights from Documentation/admin-guide/mm/transhuge.rst. Does this mean that after remount, whether the mappings of existing files support large folios should remain unchanged?

“
``mount -o remount,huge= /mountpoint`` works fine after mount: remounting ``huge=never`` will not attempt to break up huge pages at all, just stop more from being allocated. ”

Do you think this makes sense?

#7 lore raw
Quoted 23 lines · Baolin Wang
Quoted 20 lines · David Hildenbrand (Arm)
Quoted 18 lines · Baolin Wang

Indeed. Good point.

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

Quoted 6 lines
Quoted 2 lines

Okay, so you'll send a patch to just set mapping_set_large_folios() unconditionally?

I'm still hesitating on this. If we set mapping_set_large_folios() unconditionally, we need to re-fix the performance regression that was addressed by commit 5a90c155defa.

Just so I can follow: where is the test for large folios that we would unlock large folios and cause a regression?

Quoted 10 lines

But it's hard for me to convince myself to add a new flag similar to IOCB_NO_LARGE_CHUNK for this hack (like the patch in [1] does).

Quoted 6 lines
Quoted 2 lines

[1] https://lore.kernel.org/all/20240914140613.2334139-1-
[email protected]/

Is that really required? Which call path would be the problematic bit with the above?

Quoted 6 lines
Quoted 2 lines

I'd say, we'd check in the large folio allocation code whether ->huge is set to never instead?

Yes, this is exactly our current logic. When allocating large folios, we'll check the ->huge setting in shmem_huge_global_enabled(), which means large folio allocations always respect the ->huge setting.

Makes sense.

Quoted 6 lines

But as I mentioned earlier, the ->huge setting cannot keep the mapping_set_large_folios() setting consistent across all mappings in the entire tmpfs mount. My concern is that under the same tmpfs mount, after remount, we might end up with some mappings supporting large folios (calling mapping_set_large_folios()) while others don't.

If we at least always set mapping_set_large_folios(), then there is no inconsistency in that regard :)

Quoted 4 lines

However, I got some insights from Documentation/admin-guide/mm/ transhuge.rst. Does this mean that after remount, whether the mappings of existing files support large folios should remain unchanged?

That's the current behavior, right?

Quoted 8 lines

“
``mount -o remount,huge= /mountpoint`` works fine after mount:
remounting ``huge=never`` will not attempt to break up huge pages at all, just stop more from being allocated.
”

Do you think this makes sense?

I suspect that matches existing behavior, so it should be fine.

Signature · 3 lines
Cheers,

David
author reviewer
#8 lore raw

CC Kefeng,

Quoted 27 lines · David Hildenbrand (Arm)
Quoted 26 lines · Baolin Wang
Quoted 22 lines · David Hildenbrand (Arm)
Quoted 11 lines · Baolin Wang

Indeed. Good point.

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

Quoted 7 lines

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

Okay, so you'll send a patch to just set mapping_set_large_folios() unconditionally?

Quoted 6 lines
Quoted 3 lines

I'm still hesitating on this. If we set mapping_set_large_folios() unconditionally, we need to re-fix the performance regression that was addressed by commit 5a90c155defa.

Just so I can follow: where is the test for large folios that we would unlock large folios and cause a regression?

I spent some time investigating the performance regression that was addressed by commit 5a90c155defa ("tmpfs: don't enable large folios if not supported"). From my testing, I found that the performance issue no longer exists on upstream:

mount tmpfs -t tmpfs -o size=50G /mnt/tmpfs

Base:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (3.1 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (3.0 GB/s ) dd if=/dev/zero of=/mnt/tmpfs/test bs=3000K count=1398 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (3.1 GB/s)

Base + revert 5a90c155defa:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.3 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (3.3 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (3.1 GB/s) dd if=/dev/zero of=/mnt/tmpfs/testbs=3000K count=1398 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (3.1 GB/s)

The data is basically consistent with minor fluctuation noise.

Later, I continued investigating and found that commit 665575cff098b ("filemap: move prefaulting out of hot write path") fixed the write operation performance.

Base + revert 665575cff098b + revert 5a90c155defa:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (2.9 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (2.6 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (2.6 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=3000K count=1398 (2.5 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (2.5 GB/s)

We can see that after reverting commit 665575cff098b, there is a noticeable drop in write performance for tmpfs files.

So my conclusion is that we can now safely revert commit 5a90c155defa to set mapping_set_large_folios() for all shmem mounts unconditionally.

Kefeng, please correct me if I missed anything.

#9 lore raw
Quoted 69 lines · Baolin Wang

CC Kefeng,

Quoted 27 lines · David Hildenbrand (Arm)
Quoted 26 lines · Baolin Wang
Quoted 22 lines · David Hildenbrand (Arm)
Quoted 11 lines · Baolin Wang

Indeed. Good point.

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

Quoted 7 lines

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

Okay, so you'll send a patch to just set mapping_set_large_folios() unconditionally?

Quoted 6 lines
Quoted 3 lines

I'm still hesitating on this. If we set mapping_set_large_folios() unconditionally, we need to re-fix the performance regression that was addressed by commit 5a90c155defa.

Just so I can follow: where is the test for large folios that we would unlock large folios and cause a regression?

I spent some time investigating the performance regression that was addressed by commit 5a90c155defa ("tmpfs: don't enable large folios if not supported"). From my testing, I found that the performance issue no longer exists on upstream:

mount tmpfs -t tmpfs -o size=50G /mnt/tmpfs

Base:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (3.1 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (3.0 GB/s ) dd if=/dev/zero of=/mnt/tmpfs/test bs=3000K count=1398 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (3.1 GB/s)

Base + revert 5a90c155defa:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.3 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (3.3 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (3.1 GB/s) dd if=/dev/zero of=/mnt/tmpfs/testbs=3000K count=1398 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (3.1 GB/s)

The data is basically consistent with minor fluctuation noise.

Later, I continued investigating and found that commit 665575cff098b ("filemap: move prefaulting out of hot write path") fixed the write operation performance.

Base + revert 665575cff098b + revert 5a90c155defa:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (2.9 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (2.6 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (2.6 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=3000K count=1398 (2.5 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (2.5 GB/s)

Quoted 5 lines

We can see that after reverting commit 665575cff098b, there is a noticeable drop in write performance for tmpfs files.

So my conclusion is that we can now safely revert commit 5a90c155defa to set mapping_set_large_folios() for all shmem mounts unconditionally.

Kefeng, please correct me if I missed anything.

Hi Baolin,I found my testcases "bonnie Block/Re Write"

./bonnie -d /tmp -s Size (size is from 100,256,512,1024,2048,4096).

But the dd test is similar as well, and as commit 4e527d5841e2 ("iomap: fault in smaller chunks for non-large folio mappings") said, the issue is,

"If chunk is 2MB, total 512 pages need to be handled finally. During this period, fault_in_iov_iter_readable() is called to check iov_iter readable validity. Since only 4KB will be handled each time, below address space will be checked over and over again"

But after 665575cff098b, fault_in_iov_iter_readable() is moved, so the issue should be fixed.

+CC Dave,

Since 665575cff098b is works well in generic_perform_write(), I think we
could do the same optimization in iomap_write_iter()? but it seems maintainer forget pickup them[1].

[1] https://lore.kernel.org/all/[email protected]/

author reviewer
#10 lore raw
Quoted 86 lines · Kefeng Wang
Quoted 69 lines · Baolin Wang

CC Kefeng,

Quoted 27 lines · David Hildenbrand (Arm)
Quoted 26 lines · Baolin Wang
Quoted 22 lines · David Hildenbrand (Arm)
Quoted 11 lines · Baolin Wang

Indeed. Good point.

Not really. There could be files created before remount whose mappings don't support large folios (with 'huge=never' option), while files created after remount will have mappings that support large folios (if remounted with 'huge=always' option).

Quoted 7 lines

It looks like the previous commit 5a90c155defa was also problematic. The huge mount option has introduced a lot of tricky issues:(

Now I think Zi's previous suggestion should be able to clean up this mess? That is, calling mapping_set_large_folios() unconditionally for all shmem mounts, and revisiting Kefeng's first version to fix the performance issue.

Okay, so you'll send a patch to just set mapping_set_large_folios() unconditionally?

Quoted 6 lines
Quoted 3 lines

I'm still hesitating on this. If we set mapping_set_large_folios() unconditionally, we need to re-fix the performance regression that was addressed by commit 5a90c155defa.

Just so I can follow: where is the test for large folios that we would unlock large folios and cause a regression?

I spent some time investigating the performance regression that was addressed by commit 5a90c155defa ("tmpfs: don't enable large folios if not supported"). From my testing, I found that the performance issue no longer exists on upstream:

mount tmpfs -t tmpfs -o size=50G /mnt/tmpfs

Base:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (3.1 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (3.0 GB/s ) dd if=/dev/zero of=/mnt/tmpfs/test bs=3000K count=1398 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (3.1 GB/s)

Base + revert 5a90c155defa:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.3 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (3.3 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (3.2 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (3.1 GB/s) dd if=/dev/zero of=/mnt/tmpfs/testbs=3000K count=1398 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (3.1 GB/s)

The data is basically consistent with minor fluctuation noise.

Later, I continued investigating and found that commit 665575cff098b ("filemap: move prefaulting out of hot write path") fixed the write operation performance.

Base + revert 665575cff098b + revert 5a90c155defa:
dd if=/dev/zero of=/mnt/tmpfs/test bs=400K count=10485 (3.0 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=800K count=5242 (2.9 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=1600K count=2621 (2.6 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=2200K count=1906 (2.6 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=3000K count=1398 (2.5 GB/s) dd if=/dev/zero of=/mnt/tmpfs/test bs=4500K count=932 (2.5 GB/s)

Quoted 5 lines

We can see that after reverting commit 665575cff098b, there is a noticeable drop in write performance for tmpfs files.

So my conclusion is that we can now safely revert commit 5a90c155defa to set mapping_set_large_folios() for all shmem mounts unconditionally.

Kefeng, please correct me if I missed anything.

Hi Baolin,I found my testcases "bonnie Block/Re Write"

./bonnie -d /tmp -s Size (size is from 100,256,512,1024,2048,4096).

But the dd test is similar as well, and as commit 4e527d5841e2 ("iomap: fault in smaller chunks for non-large folio mappings") said, the issue is,

Quoted 7 lines

"If chunk is 2MB, total 512 pages need to be handled finally. During this period, fault_in_iov_iter_readable() is called to check iov_iter readable validity. Since only 4KB will be handled each time, below address space will be checked over and over again"

But after 665575cff098b, fault_in_iov_iter_readable() is moved, so the issue should be fixed.

Kefeng, thanks for confirming.