Skip to contentSkip to conversation

mm/shmem: shmem_replace_page() remember NR_SHMEM

PATCH Applied Hugh Dickins 2 participants 2 messages Aug 11, 2022

Subsystems (2)
lore
Share & tools
lore

Hugh Dickins

author maintainer
#0 lore raw

PATCH 1/1 mm/shmem: shmem_replace_page() remember NR_SHMEM

Elsewhere, NR_SHMEM is updated at the same time as shmem NR_FILE_PAGES; but shmem_replace_page() was forgetting to do that - so NR_SHMEM stats could grow too big or too small, in those unusual cases when it's used.

---
This is not terribly important, and will clash with one of Matthew's 59 for 5.21; I don't mind if this gets delayed, and we just do it again on top of his series later, or he fold the equivalent into his series; but thought I'd better send it in as another fix to shmem_replace_page() while that function is on our minds.

 mm/shmem.c | 2 ++
 1 file changed, 2 insertions(+)
mm/shmem.c +2 -0
@@ -1659,7 +1659,9 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
 		new = page_folio(newpage);
 		mem_cgroup_migrate(old, new);
 		__inc_lruvec_page_state(newpage, NR_FILE_PAGES);
+		__inc_lruvec_page_state(newpage, NR_SHMEM);
 		__dec_lruvec_page_state(oldpage, NR_FILE_PAGES);
+		__dec_lruvec_page_state(oldpage, NR_SHMEM);
 	}
 	xa_unlock_irq(&swap_mapping->i_pages);
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Hugh Dickins

Elsewhere, NR_SHMEM is updated at the same time as shmem NR_FILE_PAGES; but shmem_replace_page() was forgetting to do that - so NR_SHMEM stats could grow too big or too small, in those unusual cases when it's used.

Quoted 6 lines

---
This is not terribly important, and will clash with one of Matthew's 59 for 5.21; I don't mind if this gets delayed, and we just do it again on top of his series later, or he fold the equivalent into his series; but thought I'd better send it in as another fix to shmem_replace_page() while that function is on our minds.

Let's get this into 6.0 since it's a bugfix, and I'll rebase my patches for 6.1 on top of it.