diff mbox series

[RFC,v2,1/3] mm: Factor out the pagetable pages account into new helper function

Message ID e094c4a2e07ff66708f7a3a9f6b86eb694f33cf0.1655887440.git.baolin.wang@linux.alibaba.com (mailing list archive)
State New
Headers show
Series Add PUD and kernel PTE level pagetable account | expand

Commit Message

Baolin Wang June 22, 2022, 8:58 a.m. UTC
Factor out the pagetable pages account into new helper functions to avoid
duplicated code. Meanwhile these helper functions also will be used to
account pagetable pages which do not need split pagetale lock.

Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
 include/linux/mm.h | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

Comments

Matthew Wilcox June 23, 2022, 4:07 p.m. UTC | #1
On Wed, Jun 22, 2022 at 04:58:52PM +0800, Baolin Wang wrote:
> +static inline void pgtable_set_and_inc(struct page *page)
> +{
> +	__SetPageTable(page);
> +	inc_lruvec_page_state(page, NR_PAGETABLE);
> +}

I don't like the names.  The accounting is also wrong for non-order-0
allocations.  It should be

	mod_lruvec_page_state(page, NR_PAGETABLE, compound_nr(page))

but it's probably better to change the API to pass in the number of
pages instead of recalculating it.

I can't think of a good name.  What's wrong with just adding

static inline bool pgtable_pud_page_ctor(struct page *page)

to go along with the pte and pmd variants?
Baolin Wang June 24, 2022, 8:41 a.m. UTC | #2
On 6/24/2022 12:07 AM, Matthew Wilcox wrote:
> On Wed, Jun 22, 2022 at 04:58:52PM +0800, Baolin Wang wrote:
>> +static inline void pgtable_set_and_inc(struct page *page)
>> +{
>> +	__SetPageTable(page);
>> +	inc_lruvec_page_state(page, NR_PAGETABLE);
>> +}
> 
> I don't like the names.  The accounting is also wrong for non-order-0
> allocations.  It should be
> 
> 	mod_lruvec_page_state(page, NR_PAGETABLE, compound_nr(page))

Yes, seems need another patch to convert using compound_nr().

> 
> but it's probably better to change the API to pass in the number of
> pages instead of recalculating it.

Lots of callers will not calculate the number of pages, so I think we 
can just add the compound_nr() in the API firstly, which also can avoid 
changing lots of callers.

> I can't think of a good name.  What's wrong with just adding
> 
> static inline bool pgtable_pud_page_ctor(struct page *page)
> 
> to go along with the pte and pmd variants?

IMHO that means we will need another function like 
pgtable_kernel_pte_page_ctor/dtor() to account kernel pagetable, however 
they do the same thing. So a common function which only do 
'__SetPageTable' and account pagetable will be more helpful.

So how about pgtable_page_inc()/pgtable_page_dec()?
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6d4e9ce1..6da6634 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2377,20 +2377,30 @@  static inline void pgtable_init(void)
 	pgtable_cache_init();
 }
 
+static inline void pgtable_set_and_inc(struct page *page)
+{
+	__SetPageTable(page);
+	inc_lruvec_page_state(page, NR_PAGETABLE);
+}
+
+static inline void pgtable_clear_and_dec(struct page *page)
+{
+	__ClearPageTable(page);
+	dec_lruvec_page_state(page, NR_PAGETABLE);
+}
+
 static inline bool pgtable_pte_page_ctor(struct page *page)
 {
 	if (!ptlock_init(page))
 		return false;
-	__SetPageTable(page);
-	inc_lruvec_page_state(page, NR_PAGETABLE);
+	pgtable_set_and_inc(page);
 	return true;
 }
 
 static inline void pgtable_pte_page_dtor(struct page *page)
 {
 	ptlock_free(page);
-	__ClearPageTable(page);
-	dec_lruvec_page_state(page, NR_PAGETABLE);
+	pgtable_clear_and_dec(page);
 }
 
 #define pte_offset_map_lock(mm, pmd, address, ptlp)	\
@@ -2476,16 +2486,14 @@  static inline bool pgtable_pmd_page_ctor(struct page *page)
 {
 	if (!pmd_ptlock_init(page))
 		return false;
-	__SetPageTable(page);
-	inc_lruvec_page_state(page, NR_PAGETABLE);
+	pgtable_set_and_inc(page);
 	return true;
 }
 
 static inline void pgtable_pmd_page_dtor(struct page *page)
 {
 	pmd_ptlock_free(page);
-	__ClearPageTable(page);
-	dec_lruvec_page_state(page, NR_PAGETABLE);
+	pgtable_clear_and_dec(page);
 }
 
 /*