diff mbox series

[13/16] mm/huge_memory: add helper __get_deferred_split_queue

Message ID 20220622170627.19786-14-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup patches for huge_memory | expand

Commit Message

Miaohe Lin June 22, 2022, 5:06 p.m. UTC
Add helper __get_deferred_split_queue to remove the duplicated codes of
getting ds_queue. No functional change intended.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/huge_memory.c | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)

Comments

Muchun Song June 23, 2022, 7:03 a.m. UTC | #1
On Thu, Jun 23, 2022 at 01:06:24AM +0800, Miaohe Lin wrote:
> Add helper __get_deferred_split_queue to remove the duplicated codes of
> getting ds_queue. No functional change intended.
>

Sorry, I suggest dropping this change since I have reworked the code here [1].

[1] https://lore.kernel.org/all/20220621125658.64935-7-songmuchun@bytedance.com/

> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/huge_memory.c | 35 ++++++++++++-----------------------
>  1 file changed, 12 insertions(+), 23 deletions(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 0030b4f67cd9..de8155ff584c 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -555,25 +555,23 @@ pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
>  	return pmd;
>  }
>  
> -#ifdef CONFIG_MEMCG
> -static inline struct deferred_split *get_deferred_split_queue(struct page *page)
> +static inline struct deferred_split *__get_deferred_split_queue(struct pglist_data *pgdat,
> +								struct mem_cgroup *memcg)
>  {
> -	struct mem_cgroup *memcg = page_memcg(compound_head(page));
> -	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
> -
> +#ifdef CONFIG_MEMCG
>  	if (memcg)
>  		return &memcg->deferred_split_queue;
> -	else
> -		return &pgdat->deferred_split_queue;
> +#endif
> +	return &pgdat->deferred_split_queue;
>  }
> -#else
> +
>  static inline struct deferred_split *get_deferred_split_queue(struct page *page)
>  {
> +	struct mem_cgroup *memcg = page_memcg(compound_head(page));
>  	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
>  
> -	return &pgdat->deferred_split_queue;
> +	return __get_deferred_split_queue(pgdat, memcg);
>  }
> -#endif
>  
>  void prep_transhuge_page(struct page *page)
>  {
> @@ -2774,31 +2772,22 @@ void deferred_split_huge_page(struct page *page)
>  static unsigned long deferred_split_count(struct shrinker *shrink,
>  		struct shrink_control *sc)
>  {
> -	struct pglist_data *pgdata = NODE_DATA(sc->nid);
> -	struct deferred_split *ds_queue = &pgdata->deferred_split_queue;
> +	struct deferred_split *ds_queue;
>  
> -#ifdef CONFIG_MEMCG
> -	if (sc->memcg)
> -		ds_queue = &sc->memcg->deferred_split_queue;
> -#endif
> +	ds_queue = __get_deferred_split_queue(NODE_DATA(sc->nid), sc->memcg);
>  	return READ_ONCE(ds_queue->split_queue_len);
>  }
>  
>  static unsigned long deferred_split_scan(struct shrinker *shrink,
>  		struct shrink_control *sc)
>  {
> -	struct pglist_data *pgdata = NODE_DATA(sc->nid);
> -	struct deferred_split *ds_queue = &pgdata->deferred_split_queue;
> +	struct deferred_split *ds_queue;
>  	unsigned long flags;
>  	LIST_HEAD(list), *pos, *next;
>  	struct page *page;
>  	int split = 0;
>  
> -#ifdef CONFIG_MEMCG
> -	if (sc->memcg)
> -		ds_queue = &sc->memcg->deferred_split_queue;
> -#endif
> -
> +	ds_queue = __get_deferred_split_queue(NODE_DATA(sc->nid), sc->memcg);
>  	spin_lock_irqsave(&ds_queue->split_queue_lock, flags);
>  	/* Take pin on all head pages to avoid freeing them under us */
>  	list_for_each_safe(pos, next, &ds_queue->split_queue) {
> -- 
> 2.23.0
> 
>
Miaohe Lin June 23, 2022, 12:11 p.m. UTC | #2
On 2022/6/23 15:03, Muchun Song wrote:
> On Thu, Jun 23, 2022 at 01:06:24AM +0800, Miaohe Lin wrote:
>> Add helper __get_deferred_split_queue to remove the duplicated codes of
>> getting ds_queue. No functional change intended.
>>
> 
> Sorry, I suggest dropping this change since I have reworked the code here [1].

That's all right. Thanks for your work. :)

> 
> [1] https://lore.kernel.org/all/20220621125658.64935-7-songmuchun@bytedance.com/
> 
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>  mm/huge_memory.c | 35 ++++++++++++-----------------------
>>  1 file changed, 12 insertions(+), 23 deletions(-)
>>
>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>> index 0030b4f67cd9..de8155ff584c 100644
>> --- a/mm/huge_memory.c
>> +++ b/mm/huge_memory.c
>> @@ -555,25 +555,23 @@ pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
>>  	return pmd;
>>  }
>>  
>> -#ifdef CONFIG_MEMCG
>> -static inline struct deferred_split *get_deferred_split_queue(struct page *page)
>> +static inline struct deferred_split *__get_deferred_split_queue(struct pglist_data *pgdat,
>> +								struct mem_cgroup *memcg)
>>  {
>> -	struct mem_cgroup *memcg = page_memcg(compound_head(page));
>> -	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
>> -
>> +#ifdef CONFIG_MEMCG
>>  	if (memcg)
>>  		return &memcg->deferred_split_queue;
>> -	else
>> -		return &pgdat->deferred_split_queue;
>> +#endif
>> +	return &pgdat->deferred_split_queue;
>>  }
>> -#else
>> +
>>  static inline struct deferred_split *get_deferred_split_queue(struct page *page)
>>  {
>> +	struct mem_cgroup *memcg = page_memcg(compound_head(page));
>>  	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
>>  
>> -	return &pgdat->deferred_split_queue;
>> +	return __get_deferred_split_queue(pgdat, memcg);
>>  }
>> -#endif
>>  
>>  void prep_transhuge_page(struct page *page)
>>  {
>> @@ -2774,31 +2772,22 @@ void deferred_split_huge_page(struct page *page)
>>  static unsigned long deferred_split_count(struct shrinker *shrink,
>>  		struct shrink_control *sc)
>>  {
>> -	struct pglist_data *pgdata = NODE_DATA(sc->nid);
>> -	struct deferred_split *ds_queue = &pgdata->deferred_split_queue;
>> +	struct deferred_split *ds_queue;
>>  
>> -#ifdef CONFIG_MEMCG
>> -	if (sc->memcg)
>> -		ds_queue = &sc->memcg->deferred_split_queue;
>> -#endif
>> +	ds_queue = __get_deferred_split_queue(NODE_DATA(sc->nid), sc->memcg);
>>  	return READ_ONCE(ds_queue->split_queue_len);
>>  }
>>  
>>  static unsigned long deferred_split_scan(struct shrinker *shrink,
>>  		struct shrink_control *sc)
>>  {
>> -	struct pglist_data *pgdata = NODE_DATA(sc->nid);
>> -	struct deferred_split *ds_queue = &pgdata->deferred_split_queue;
>> +	struct deferred_split *ds_queue;
>>  	unsigned long flags;
>>  	LIST_HEAD(list), *pos, *next;
>>  	struct page *page;
>>  	int split = 0;
>>  
>> -#ifdef CONFIG_MEMCG
>> -	if (sc->memcg)
>> -		ds_queue = &sc->memcg->deferred_split_queue;
>> -#endif
>> -
>> +	ds_queue = __get_deferred_split_queue(NODE_DATA(sc->nid), sc->memcg);
>>  	spin_lock_irqsave(&ds_queue->split_queue_lock, flags);
>>  	/* Take pin on all head pages to avoid freeing them under us */
>>  	list_for_each_safe(pos, next, &ds_queue->split_queue) {
>> -- 
>> 2.23.0
>>
>>
> .
>
diff mbox series

Patch

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0030b4f67cd9..de8155ff584c 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -555,25 +555,23 @@  pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
 	return pmd;
 }
 
-#ifdef CONFIG_MEMCG
-static inline struct deferred_split *get_deferred_split_queue(struct page *page)
+static inline struct deferred_split *__get_deferred_split_queue(struct pglist_data *pgdat,
+								struct mem_cgroup *memcg)
 {
-	struct mem_cgroup *memcg = page_memcg(compound_head(page));
-	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
-
+#ifdef CONFIG_MEMCG
 	if (memcg)
 		return &memcg->deferred_split_queue;
-	else
-		return &pgdat->deferred_split_queue;
+#endif
+	return &pgdat->deferred_split_queue;
 }
-#else
+
 static inline struct deferred_split *get_deferred_split_queue(struct page *page)
 {
+	struct mem_cgroup *memcg = page_memcg(compound_head(page));
 	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
 
-	return &pgdat->deferred_split_queue;
+	return __get_deferred_split_queue(pgdat, memcg);
 }
-#endif
 
 void prep_transhuge_page(struct page *page)
 {
@@ -2774,31 +2772,22 @@  void deferred_split_huge_page(struct page *page)
 static unsigned long deferred_split_count(struct shrinker *shrink,
 		struct shrink_control *sc)
 {
-	struct pglist_data *pgdata = NODE_DATA(sc->nid);
-	struct deferred_split *ds_queue = &pgdata->deferred_split_queue;
+	struct deferred_split *ds_queue;
 
-#ifdef CONFIG_MEMCG
-	if (sc->memcg)
-		ds_queue = &sc->memcg->deferred_split_queue;
-#endif
+	ds_queue = __get_deferred_split_queue(NODE_DATA(sc->nid), sc->memcg);
 	return READ_ONCE(ds_queue->split_queue_len);
 }
 
 static unsigned long deferred_split_scan(struct shrinker *shrink,
 		struct shrink_control *sc)
 {
-	struct pglist_data *pgdata = NODE_DATA(sc->nid);
-	struct deferred_split *ds_queue = &pgdata->deferred_split_queue;
+	struct deferred_split *ds_queue;
 	unsigned long flags;
 	LIST_HEAD(list), *pos, *next;
 	struct page *page;
 	int split = 0;
 
-#ifdef CONFIG_MEMCG
-	if (sc->memcg)
-		ds_queue = &sc->memcg->deferred_split_queue;
-#endif
-
+	ds_queue = __get_deferred_split_queue(NODE_DATA(sc->nid), sc->memcg);
 	spin_lock_irqsave(&ds_queue->split_queue_lock, flags);
 	/* Take pin on all head pages to avoid freeing them under us */
 	list_for_each_safe(pos, next, &ds_queue->split_queue) {