Skip to contentSkip to conversation

mm: shmem: fix minor off-by-one in shrinkable calculation

PATCH Applied Hugh Dickins 3 participants 3 messages Aug 25, 2024 – Aug 27, 2024

Subsystems (2)
lore
Share & tools
lore

Hugh Dickins

author maintainer
#0 lore raw

PATCH 1/1 mm: shmem: fix minor off-by-one in shrinkable calculation

There has been a long-standing and very minor off-by-one, where shmem_get_folio_gfp() decides if a large folio extends beyond i_size far enough to leave a page or more for freeing later under pressure.

This is not something needed for stable: but it will be proportionately more significant as support for smaller large folios is added, and is best fixed before duplicating the check in other places.

Fixes 779750d20b93 ("shmem: split huge pages beyond i_size under memory pressure")
---
 mm/shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index 85e3bd3e709e..37c300f69baf 100644
@@ -2326,7 +2326,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index,
 	alloced = true;
 	if (folio_test_large(folio) &&
 	    DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE) <
-					folio_next_index(folio) - 1) {
+					folio_next_index(folio)) {
 		struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
 		struct shmem_inode_info *info = SHMEM_I(inode);
 		/*
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Hugh Dickins

There has been a long-standing and very minor off-by-one, where shmem_get_folio_gfp() decides if a large folio extends beyond i_size far enough to leave a page or more for freeing later under pressure.

This is not something needed for stable: but it will be proportionately more significant as support for smaller large folios is added, and is best fixed before duplicating the check in other places.

Fixes 779750d20b93 ("shmem: split huge pages beyond i_size under memory pressure")
---
  mm/shmem.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +0 -0
index 85e3bd3e709e..37c300f69baf 100644

mm/shmem.c static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, · line 2332

Quoted 8 lines
mm/shmem.c +1 -1
@@ -2326,7 +2326,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index,
  	alloced = true;
  	if (folio_test_large(folio) &&
  	    DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE) <
-					folio_next_index(folio) - 1) {
+					folio_next_index(folio)) {
  		struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
  		struct shmem_inode_info *info = SHMEM_I(inode);
  		/*
Signature · 3 lines
Cheers,

David / dhildenb
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Hugh Dickins
Quoted 10 lines · Hugh Dickins

There has been a long-standing and very minor off-by-one, where shmem_get_folio_gfp() decides if a large folio extends beyond i_size far enough to leave a page or more for freeing later under pressure.

This is not something needed for stable: but it will be proportionately more significant as support for smaller large folios is added, and is best fixed before duplicating the check in other places.

Fixes 779750d20b93 ("shmem: split huge pages beyond i_size under memory pressure")

LGTM. Feel free to add:

Quoted 17 lines
---
  mm/shmem.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index 85e3bd3e709e..37c300f69baf 100644
@@ -2326,7 +2326,7 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index,
  	alloced = true;
  	if (folio_test_large(folio) &&
  	    DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE) <
-					folio_next_index(folio) - 1) {
+					folio_next_index(folio)) {
  		struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
  		struct shmem_inode_info *info = SHMEM_I(inode);
  		/*