[v2,5/7] mm: task_mmu: use a folio in smaps_account()

Message ID 20231110033324.2455523-6-wangkefeng.wang@huawei.com
State New
Headers
Series [v2,1/7] fs/proc/page: remove unneeded PageTail && PageSlab check |

Commit Message

Kefeng Wang Nov. 10, 2023, 3:33 a.m. UTC
  Replace seven implicit calls to compound_head() with one page_folio().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 fs/proc/task_mmu.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Matthew Wilcox Nov. 10, 2023, 6:29 p.m. UTC | #1
On Fri, Nov 10, 2023 at 11:33:22AM +0800, Kefeng Wang wrote:
> Replace seven implicit calls to compound_head() with one page_folio().

You're so focused on trying to accomplish your goal (killing off the
page_idle and page_young functions) that you're doing a poor job thinkig
about the conversions you're doing along the way.

> +++ b/fs/proc/task_mmu.c
> @@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
>  {
>  	int i, nr = compound ? compound_nr(page) : 1;
>  	unsigned long size = nr * PAGE_SIZE;
> +	struct folio *folio = page_folio(page);

Stop right here.  The use of compound_nr() should give you pause.

After looking at how smaps_account() is used, it seems to me that the
two callers should each pass in PAGE_SIZE or PMD_SIZE instead of doing
this calculation.

More generally, step back from this series.  Do a good job of
transforming fs/proc/task_mmu.c to use folios.  Once you've done
that, you can approach the young/idle work again.
  
Kefeng Wang Nov. 11, 2023, 10:57 a.m. UTC | #2
On 2023/11/11 2:29, Matthew Wilcox wrote:
> On Fri, Nov 10, 2023 at 11:33:22AM +0800, Kefeng Wang wrote:
>> Replace seven implicit calls to compound_head() with one page_folio().
> 
> You're so focused on trying to accomplish your goal (killing off the
> page_idle and page_young functions) that you're doing a poor job thinkig
> about the conversions you're doing along the way.
> 
>> +++ b/fs/proc/task_mmu.c
>> @@ -445,23 +445,25 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
>>   {
>>   	int i, nr = compound ? compound_nr(page) : 1;
>>   	unsigned long size = nr * PAGE_SIZE;
>> +	struct folio *folio = page_folio(page);
> 
> Stop right here.  The use of compound_nr() should give you pause.
> 
> After looking at how smaps_account() is used, it seems to me that the
> two callers should each pass in PAGE_SIZE or PMD_SIZE instead of doing
> this calculation.

Yes,this will save extra calculation

> 
> More generally, step back from this series.  Do a good job of
> transforming fs/proc/task_mmu.c to use folios.  Once you've done
> that, you can approach the young/idle work again.
> 
Thanks for you advise,will try this firstly.
>
  

Patch

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 51e0ec658457..fe15f99a4908 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -445,23 +445,25 @@  static void smaps_account(struct mem_size_stats *mss, struct page *page,
 {
 	int i, nr = compound ? compound_nr(page) : 1;
 	unsigned long size = nr * PAGE_SIZE;
+	struct folio *folio = page_folio(page);
 
 	/*
 	 * First accumulate quantities that depend only on |size| and the type
 	 * of the compound page.
 	 */
-	if (PageAnon(page)) {
+	if (folio_test_anon(folio)) {
 		mss->anonymous += size;
-		if (!PageSwapBacked(page) && !dirty && !PageDirty(page))
+		if (!folio_test_swapbacked(folio) && !dirty &&
+		    !folio_test_dirty(folio))
 			mss->lazyfree += size;
 	}
 
-	if (PageKsm(page))
+	if (folio_test_ksm(folio))
 		mss->ksm += size;
 
 	mss->resident += size;
 	/* Accumulate the size in pages that have been accessed. */
-	if (young || page_is_young(page) || PageReferenced(page))
+	if (young || folio_test_young(folio) || folio_test_referenced(folio))
 		mss->referenced += size;
 
 	/*
@@ -479,7 +481,7 @@  static void smaps_account(struct mem_size_stats *mss, struct page *page,
 	 * especially for migration entries.  Treat regular migration entries
 	 * as mapcount == 1.
 	 */
-	if ((page_count(page) == 1) || migration) {
+	if ((folio_ref_count(folio) == 1) || migration) {
 		smaps_page_accumulate(mss, page, size, size << PSS_SHIFT, dirty,
 			locked, true);
 		return;