diff mbox series

[3/4] mm/ksm: rename mm_slot_cache to ksm_slot_cache

Message ID 20240428100619.3332036-3-alexs@kernel.org (mailing list archive)
State New
Headers show
Series [1/4] mm/ksm: rename mm_slot members to ksm_slot for better readability. | expand

Commit Message

alexs@kernel.org April 28, 2024, 10:06 a.m. UTC
From: "Alex Shi (tencent)" <alexs@kernel.org>

To distinguish ksm_mm_slot and mm_slot for better code readability,
rename mm_slot_cache as ksm_slot_cache. No function change.

Signed-off-by: Alex Shi (tencent) <alexs@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
---
 mm/ksm.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

David Hildenbrand April 30, 2024, 12:57 p.m. UTC | #1
On 28.04.24 12:06, alexs@kernel.org wrote:
> From: "Alex Shi (tencent)" <alexs@kernel.org>
> 
> To distinguish ksm_mm_slot and mm_slot for better code readability,
> rename mm_slot_cache as ksm_slot_cache. No function change.
> 
> Signed-off-by: Alex Shi (tencent) <alexs@kernel.org>
> Cc: David Hildenbrand <david@redhat.com>
> ---
>   mm/ksm.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 6efa33c48381..22d2132f83a4 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -247,7 +247,7 @@ static struct ksm_scan ksm_scan = {
>   
>   static struct kmem_cache *rmap_item_cache;
>   static struct kmem_cache *stable_node_cache;
> -static struct kmem_cache *mm_slot_cache;
> +static struct kmem_cache *ksm_slot_cache;
>   
>   /* Default number of pages to scan per batch */
>   #define DEFAULT_PAGES_TO_SCAN 100
> @@ -502,8 +502,8 @@ static int __init ksm_slab_init(void)
>   	if (!stable_node_cache)
>   		goto out_free1;
>   
> -	mm_slot_cache = KSM_KMEM_CACHE(ksm_mm_slot, 0);
> -	if (!mm_slot_cache)
> +	ksm_slot_cache = KSM_KMEM_CACHE(ksm_mm_slot, 0);
> +	if (!ksm_slot_cache)
>   		goto out_free2;
>   
>   	return 0;
> @@ -518,10 +518,10 @@ static int __init ksm_slab_init(void)
>   
>   static void __init ksm_slab_free(void)
>   {
> -	kmem_cache_destroy(mm_slot_cache);
> +	kmem_cache_destroy(ksm_slot_cache);
>   	kmem_cache_destroy(stable_node_cache);
>   	kmem_cache_destroy(rmap_item_cache);
> -	mm_slot_cache = NULL;
> +	ksm_slot_cache = NULL;
>   }
>   
>   static __always_inline bool is_stable_node_chain(struct ksm_stable_node *chain)
> @@ -1244,7 +1244,7 @@ static int unmerge_and_remove_all_rmap_items(void)
>   			list_del(&ksm_slot->slot.mm_node);
>   			spin_unlock(&ksm_mmlist_lock);
>   
> -			mm_slot_free(mm_slot_cache, ksm_slot);
> +			mm_slot_free(ksm_slot_cache, ksm_slot);
>   			clear_bit(MMF_VM_MERGEABLE, &mm->flags);
>   			clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
>   			mmdrop(mm);
> @@ -2713,7 +2713,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
>   		list_del(&ksm_slot->slot.mm_node);
>   		spin_unlock(&ksm_mmlist_lock);
>   
> -		mm_slot_free(mm_slot_cache, ksm_slot);
> +		mm_slot_free(ksm_slot_cache, ksm_slot);
>   		clear_bit(MMF_VM_MERGEABLE, &mm->flags);
>   		clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
>   		mmap_read_unlock(mm);
> @@ -2972,7 +2972,7 @@ int __ksm_enter(struct mm_struct *mm)
>   	struct mm_slot *slot;
>   	int needs_wakeup;
>   
> -	ksm_slot = mm_slot_alloc(mm_slot_cache);
> +	ksm_slot = mm_slot_alloc(ksm_slot_cache);

Similarly, this makes the code more confusion. The pattern in khugepaged 
is similarly:

mm_slot = mm_slot_alloc(mm_slot_cache);

I don't think we want these renamings.

E.g., "ksm_mm_slot_cache" might be a bit better than "mm_slot_cache". 
But then, we are in KSM code ... so I don't really see an improvement.
Alex Shi May 16, 2024, 12:15 p.m. UTC | #2
On 4/30/24 8:57 PM, David Hildenbrand wrote:
>>
>> @@ -2972,7 +2972,7 @@ int __ksm_enter(struct mm_struct *mm)
>>       struct mm_slot *slot;
>>       int needs_wakeup;
>>   -    ksm_slot = mm_slot_alloc(mm_slot_cache);
>> +    ksm_slot = mm_slot_alloc(ksm_slot_cache);
> 
> Similarly, this makes the code more confusion. The pattern in khugepaged is similarly:
> 
> mm_slot = mm_slot_alloc(mm_slot_cache);

Could we rename it to khg_mm_slot_cache in khugepaged?
 
> 
> I don't think we want these renamings.
> 
> E.g., "ksm_mm_slot_cache" might be a bit better than "mm_slot_cache". But then, we are in KSM code ... so I don't really see an improvement.

Thanks for comments and sorry for response late.

yes, ksm_mm_slot_cache is better even in KSM code. As a cscope/tag dependency patient, this change could reduce much of confusing in name searching. And that's why a one-side change satisfies me.
Yes, maybe better naming could make it more readable, any more further help? :)

Thanks a lot!
Alex
David Hildenbrand May 22, 2024, 11:49 a.m. UTC | #3
On 16.05.24 14:15, Alex Shi wrote:
> 
> 
> On 4/30/24 8:57 PM, David Hildenbrand wrote:
>>>
>>> @@ -2972,7 +2972,7 @@ int __ksm_enter(struct mm_struct *mm)
>>>        struct mm_slot *slot;
>>>        int needs_wakeup;
>>>    -    ksm_slot = mm_slot_alloc(mm_slot_cache);
>>> +    ksm_slot = mm_slot_alloc(ksm_slot_cache);
>>
>> Similarly, this makes the code more confusion. The pattern in khugepaged is similarly:
>>
>> mm_slot = mm_slot_alloc(mm_slot_cache);
> 
> Could we rename it to khg_mm_slot_cache in khugepaged?

I don't see any sense in such renaming, sorry. This code resides in 
ksm.c/khugepaged.c respectively and at least for me is, therefore, quite 
clear.
diff mbox series

Patch

diff --git a/mm/ksm.c b/mm/ksm.c
index 6efa33c48381..22d2132f83a4 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -247,7 +247,7 @@  static struct ksm_scan ksm_scan = {
 
 static struct kmem_cache *rmap_item_cache;
 static struct kmem_cache *stable_node_cache;
-static struct kmem_cache *mm_slot_cache;
+static struct kmem_cache *ksm_slot_cache;
 
 /* Default number of pages to scan per batch */
 #define DEFAULT_PAGES_TO_SCAN 100
@@ -502,8 +502,8 @@  static int __init ksm_slab_init(void)
 	if (!stable_node_cache)
 		goto out_free1;
 
-	mm_slot_cache = KSM_KMEM_CACHE(ksm_mm_slot, 0);
-	if (!mm_slot_cache)
+	ksm_slot_cache = KSM_KMEM_CACHE(ksm_mm_slot, 0);
+	if (!ksm_slot_cache)
 		goto out_free2;
 
 	return 0;
@@ -518,10 +518,10 @@  static int __init ksm_slab_init(void)
 
 static void __init ksm_slab_free(void)
 {
-	kmem_cache_destroy(mm_slot_cache);
+	kmem_cache_destroy(ksm_slot_cache);
 	kmem_cache_destroy(stable_node_cache);
 	kmem_cache_destroy(rmap_item_cache);
-	mm_slot_cache = NULL;
+	ksm_slot_cache = NULL;
 }
 
 static __always_inline bool is_stable_node_chain(struct ksm_stable_node *chain)
@@ -1244,7 +1244,7 @@  static int unmerge_and_remove_all_rmap_items(void)
 			list_del(&ksm_slot->slot.mm_node);
 			spin_unlock(&ksm_mmlist_lock);
 
-			mm_slot_free(mm_slot_cache, ksm_slot);
+			mm_slot_free(ksm_slot_cache, ksm_slot);
 			clear_bit(MMF_VM_MERGEABLE, &mm->flags);
 			clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
 			mmdrop(mm);
@@ -2713,7 +2713,7 @@  static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
 		list_del(&ksm_slot->slot.mm_node);
 		spin_unlock(&ksm_mmlist_lock);
 
-		mm_slot_free(mm_slot_cache, ksm_slot);
+		mm_slot_free(ksm_slot_cache, ksm_slot);
 		clear_bit(MMF_VM_MERGEABLE, &mm->flags);
 		clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
 		mmap_read_unlock(mm);
@@ -2972,7 +2972,7 @@  int __ksm_enter(struct mm_struct *mm)
 	struct mm_slot *slot;
 	int needs_wakeup;
 
-	ksm_slot = mm_slot_alloc(mm_slot_cache);
+	ksm_slot = mm_slot_alloc(ksm_slot_cache);
 	if (!ksm_slot)
 		return -ENOMEM;
 
@@ -3040,7 +3040,7 @@  void __ksm_exit(struct mm_struct *mm)
 	spin_unlock(&ksm_mmlist_lock);
 
 	if (easy_to_free) {
-		mm_slot_free(mm_slot_cache, ksm_slot);
+		mm_slot_free(ksm_slot_cache, ksm_slot);
 		clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
 		clear_bit(MMF_VM_MERGEABLE, &mm->flags);
 		mmdrop(mm);