Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-06-13 Thread Yang Shi




On 6/13/19 1:19 AM, Kirill Tkhai wrote:

On 10.06.2019 20:25, Yang Shi wrote:


On 6/10/19 1:23 AM, Kirill Tkhai wrote:

On 29.05.2019 14:25, Yang Shi wrote:

On 5/29/19 4:14 PM, Kirill Tkhai wrote:

On 29.05.2019 05:43, Yang Shi wrote:

On 5/28/19 10:42 PM, Kirill Tkhai wrote:

Hi, Yang,

On 28.05.2019 15:44, Yang Shi wrote:

Currently THP deferred split shrinker is not memcg aware, this may cause
premature OOM with some configuration. For example the below test would
run into premature OOM easily:

$ cgcreate -g memory:thp
$ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
$ cgexec -g memory:thp transhuge-stress 4000

transhuge-stress comes from kernel selftest.

It is easy to hit OOM, but there are still a lot THP on the deferred
split queue, memcg direct reclaim can't touch them since the deferred
split shrinker is not memcg aware.

Convert deferred split shrinker memcg aware by introducing per memcg
deferred split queue.  The THP should be on either per node or per memcg
deferred split queue if it belongs to a memcg.  When the page is
immigrated to the other memcg, it will be immigrated to the target
memcg's deferred split queue too.

And, move deleting THP from deferred split queue in page free before
memcg uncharge so that the page's memcg information is available.

Reuse the second tail page's deferred_list for per memcg list since the
same THP can't be on multiple deferred split queues.

Cc: Kirill Tkhai 
Cc: Johannes Weiner 
Cc: Michal Hocko 
Cc: "Kirill A . Shutemov" 
Cc: Hugh Dickins 
Cc: Shakeel Butt 
Signed-off-by: Yang Shi 
---
     include/linux/huge_mm.h    |  24 ++
     include/linux/memcontrol.h |   6 ++
     include/linux/mm_types.h   |   7 +-
     mm/huge_memory.c   | 182 
+
     mm/memcontrol.c    |  20 +
     mm/swap.c  |   4 +
     6 files changed, 194 insertions(+), 49 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 7cd5c15..f6d1cde 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
     return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
     }
     +static inline struct list_head *page_deferred_list(struct page *page)
+{
+    /*
+ * Global deferred list in the second tail pages is occupied by
+ * compound_head.
+ */
+    return [2].deferred_list;
+}
+
+static inline struct list_head *page_memcg_deferred_list(struct page *page)
+{
+    /*
+ * Memcg deferred list in the second tail pages is occupied by
+ * compound_head.
+ */
+    return [2].memcg_deferred_list;
+}
+
+extern void del_thp_from_deferred_split_queue(struct page *);
+
     #else /* CONFIG_TRANSPARENT_HUGEPAGE */
     #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
     #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
     {
     return false;
     }
+
+static inline void del_thp_from_deferred_split_queue(struct page *page)
+{
+}
     #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
       #endif /* _LINUX_HUGE_MM_H */
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bc74d6a..9ff5fab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -316,6 +316,12 @@ struct mem_cgroup {
     struct list_head event_list;
     spinlock_t event_list_lock;
     +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+    struct list_head split_queue;
+    unsigned long split_queue_len;
+    spinlock_t split_queue_lock;
+#endif
+
     struct mem_cgroup_per_node *nodeinfo[0];
     /* WARNING: nodeinfo must be the last member here */
     };
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8ec38b1..405f5e6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -139,7 +139,12 @@ struct page {
     struct {    /* Second tail page of compound page */
     unsigned long _compound_pad_1;    /* compound_head */
     unsigned long _compound_pad_2;
-    struct list_head deferred_list;
+    union {
+    /* Global THP deferred split list */
+    struct list_head deferred_list;
+    /* Memcg THP deferred split list */
+    struct list_head memcg_deferred_list;

Why we need two namesakes for this list entry?

For me it looks redundantly: it does not give additional information,
but it leads to duplication (and we have two helpers page_deferred_list()
and page_memcg_deferred_list() instead of one).

Yes, kind of. Actually I was also wondering if this is worth or not. My point 
is this may improve the code readability. We can figure out what split queue 
(per node or per memcg) is being manipulated just by the name of the list.

If the most people thought this is unnecessary, I'm definitely ok to just keep 
one name.


+    };
     };
     struct {    

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-06-13 Thread Kirill Tkhai
On 10.06.2019 20:25, Yang Shi wrote:
> 
> 
> On 6/10/19 1:23 AM, Kirill Tkhai wrote:
>> On 29.05.2019 14:25, Yang Shi wrote:
>>>
>>> On 5/29/19 4:14 PM, Kirill Tkhai wrote:
 On 29.05.2019 05:43, Yang Shi wrote:
> On 5/28/19 10:42 PM, Kirill Tkhai wrote:
>> Hi, Yang,
>>
>> On 28.05.2019 15:44, Yang Shi wrote:
>>> Currently THP deferred split shrinker is not memcg aware, this may cause
>>> premature OOM with some configuration. For example the below test would
>>> run into premature OOM easily:
>>>
>>> $ cgcreate -g memory:thp
>>> $ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
>>> $ cgexec -g memory:thp transhuge-stress 4000
>>>
>>> transhuge-stress comes from kernel selftest.
>>>
>>> It is easy to hit OOM, but there are still a lot THP on the deferred
>>> split queue, memcg direct reclaim can't touch them since the deferred
>>> split shrinker is not memcg aware.
>>>
>>> Convert deferred split shrinker memcg aware by introducing per memcg
>>> deferred split queue.  The THP should be on either per node or per memcg
>>> deferred split queue if it belongs to a memcg.  When the page is
>>> immigrated to the other memcg, it will be immigrated to the target
>>> memcg's deferred split queue too.
>>>
>>> And, move deleting THP from deferred split queue in page free before
>>> memcg uncharge so that the page's memcg information is available.
>>>
>>> Reuse the second tail page's deferred_list for per memcg list since the
>>> same THP can't be on multiple deferred split queues.
>>>
>>> Cc: Kirill Tkhai 
>>> Cc: Johannes Weiner 
>>> Cc: Michal Hocko 
>>> Cc: "Kirill A . Shutemov" 
>>> Cc: Hugh Dickins 
>>> Cc: Shakeel Butt 
>>> Signed-off-by: Yang Shi 
>>> ---
>>>     include/linux/huge_mm.h    |  24 ++
>>>     include/linux/memcontrol.h |   6 ++
>>>     include/linux/mm_types.h   |   7 +-
>>>     mm/huge_memory.c   | 182 
>>> +
>>>     mm/memcontrol.c    |  20 +
>>>     mm/swap.c  |   4 +
>>>     6 files changed, 194 insertions(+), 49 deletions(-)
>>>
>>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
>>> index 7cd5c15..f6d1cde 100644
>>> --- a/include/linux/huge_mm.h
>>> +++ b/include/linux/huge_mm.h
>>> @@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
>>>     return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
>>>     }
>>>     +static inline struct list_head *page_deferred_list(struct page 
>>> *page)
>>> +{
>>> +    /*
>>> + * Global deferred list in the second tail pages is occupied by
>>> + * compound_head.
>>> + */
>>> +    return [2].deferred_list;
>>> +}
>>> +
>>> +static inline struct list_head *page_memcg_deferred_list(struct page 
>>> *page)
>>> +{
>>> +    /*
>>> + * Memcg deferred list in the second tail pages is occupied by
>>> + * compound_head.
>>> + */
>>> +    return [2].memcg_deferred_list;
>>> +}
>>> +
>>> +extern void del_thp_from_deferred_split_queue(struct page *);
>>> +
>>>     #else /* CONFIG_TRANSPARENT_HUGEPAGE */
>>>     #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
>>>     #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
>>> @@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
>>>     {
>>>     return false;
>>>     }
>>> +
>>> +static inline void del_thp_from_deferred_split_queue(struct page *page)
>>> +{
>>> +}
>>>     #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>>>       #endif /* _LINUX_HUGE_MM_H */
>>> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
>>> index bc74d6a..9ff5fab 100644
>>> --- a/include/linux/memcontrol.h
>>> +++ b/include/linux/memcontrol.h
>>> @@ -316,6 +316,12 @@ struct mem_cgroup {
>>>     struct list_head event_list;
>>>     spinlock_t event_list_lock;
>>>     +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>> +    struct list_head split_queue;
>>> +    unsigned long split_queue_len;
>>> +    spinlock_t split_queue_lock;
>>> +#endif
>>> +
>>>     struct mem_cgroup_per_node *nodeinfo[0];
>>>     /* WARNING: nodeinfo must be the last member here */
>>>     };
>>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
>>> index 8ec38b1..405f5e6 100644
>>> --- a/include/linux/mm_types.h
>>> +++ b/include/linux/mm_types.h
>>> @@ -139,7 +139,12 @@ struct page {
>>>     struct {    /* Second tail page of compound page */
>>>     unsigned long _compound_pad_1;    /* compound_head */
>>>     unsigned long _compound_pad_2;
>>> -    struct list_head deferred_list;
>>> +

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-06-10 Thread Yang Shi




On 6/10/19 1:23 AM, Kirill Tkhai wrote:

On 29.05.2019 14:25, Yang Shi wrote:


On 5/29/19 4:14 PM, Kirill Tkhai wrote:

On 29.05.2019 05:43, Yang Shi wrote:

On 5/28/19 10:42 PM, Kirill Tkhai wrote:

Hi, Yang,

On 28.05.2019 15:44, Yang Shi wrote:

Currently THP deferred split shrinker is not memcg aware, this may cause
premature OOM with some configuration. For example the below test would
run into premature OOM easily:

$ cgcreate -g memory:thp
$ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
$ cgexec -g memory:thp transhuge-stress 4000

transhuge-stress comes from kernel selftest.

It is easy to hit OOM, but there are still a lot THP on the deferred
split queue, memcg direct reclaim can't touch them since the deferred
split shrinker is not memcg aware.

Convert deferred split shrinker memcg aware by introducing per memcg
deferred split queue.  The THP should be on either per node or per memcg
deferred split queue if it belongs to a memcg.  When the page is
immigrated to the other memcg, it will be immigrated to the target
memcg's deferred split queue too.

And, move deleting THP from deferred split queue in page free before
memcg uncharge so that the page's memcg information is available.

Reuse the second tail page's deferred_list for per memcg list since the
same THP can't be on multiple deferred split queues.

Cc: Kirill Tkhai 
Cc: Johannes Weiner 
Cc: Michal Hocko 
Cc: "Kirill A . Shutemov" 
Cc: Hugh Dickins 
Cc: Shakeel Butt 
Signed-off-by: Yang Shi 
---
    include/linux/huge_mm.h    |  24 ++
    include/linux/memcontrol.h |   6 ++
    include/linux/mm_types.h   |   7 +-
    mm/huge_memory.c   | 182 
+
    mm/memcontrol.c    |  20 +
    mm/swap.c  |   4 +
    6 files changed, 194 insertions(+), 49 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 7cd5c15..f6d1cde 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
    return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
    }
    +static inline struct list_head *page_deferred_list(struct page *page)
+{
+    /*
+ * Global deferred list in the second tail pages is occupied by
+ * compound_head.
+ */
+    return [2].deferred_list;
+}
+
+static inline struct list_head *page_memcg_deferred_list(struct page *page)
+{
+    /*
+ * Memcg deferred list in the second tail pages is occupied by
+ * compound_head.
+ */
+    return [2].memcg_deferred_list;
+}
+
+extern void del_thp_from_deferred_split_queue(struct page *);
+
    #else /* CONFIG_TRANSPARENT_HUGEPAGE */
    #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
    #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
    {
    return false;
    }
+
+static inline void del_thp_from_deferred_split_queue(struct page *page)
+{
+}
    #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
      #endif /* _LINUX_HUGE_MM_H */
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bc74d6a..9ff5fab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -316,6 +316,12 @@ struct mem_cgroup {
    struct list_head event_list;
    spinlock_t event_list_lock;
    +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+    struct list_head split_queue;
+    unsigned long split_queue_len;
+    spinlock_t split_queue_lock;
+#endif
+
    struct mem_cgroup_per_node *nodeinfo[0];
    /* WARNING: nodeinfo must be the last member here */
    };
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8ec38b1..405f5e6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -139,7 +139,12 @@ struct page {
    struct {    /* Second tail page of compound page */
    unsigned long _compound_pad_1;    /* compound_head */
    unsigned long _compound_pad_2;
-    struct list_head deferred_list;
+    union {
+    /* Global THP deferred split list */
+    struct list_head deferred_list;
+    /* Memcg THP deferred split list */
+    struct list_head memcg_deferred_list;

Why we need two namesakes for this list entry?

For me it looks redundantly: it does not give additional information,
but it leads to duplication (and we have two helpers page_deferred_list()
and page_memcg_deferred_list() instead of one).

Yes, kind of. Actually I was also wondering if this is worth or not. My point 
is this may improve the code readability. We can figure out what split queue 
(per node or per memcg) is being manipulated just by the name of the list.

If the most people thought this is unnecessary, I'm definitely ok to just keep 
one name.


+    };
    };
    struct {    /* Page table pages */
    unsigned long _pt_pad_1;    /* compound_head */
diff --git 

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-06-10 Thread Kirill Tkhai
On 29.05.2019 14:25, Yang Shi wrote:
> 
> 
> On 5/29/19 4:14 PM, Kirill Tkhai wrote:
>> On 29.05.2019 05:43, Yang Shi wrote:
>>>
>>> On 5/28/19 10:42 PM, Kirill Tkhai wrote:
 Hi, Yang,

 On 28.05.2019 15:44, Yang Shi wrote:
> Currently THP deferred split shrinker is not memcg aware, this may cause
> premature OOM with some configuration. For example the below test would
> run into premature OOM easily:
>
> $ cgcreate -g memory:thp
> $ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
> $ cgexec -g memory:thp transhuge-stress 4000
>
> transhuge-stress comes from kernel selftest.
>
> It is easy to hit OOM, but there are still a lot THP on the deferred
> split queue, memcg direct reclaim can't touch them since the deferred
> split shrinker is not memcg aware.
>
> Convert deferred split shrinker memcg aware by introducing per memcg
> deferred split queue.  The THP should be on either per node or per memcg
> deferred split queue if it belongs to a memcg.  When the page is
> immigrated to the other memcg, it will be immigrated to the target
> memcg's deferred split queue too.
>
> And, move deleting THP from deferred split queue in page free before
> memcg uncharge so that the page's memcg information is available.
>
> Reuse the second tail page's deferred_list for per memcg list since the
> same THP can't be on multiple deferred split queues.
>
> Cc: Kirill Tkhai 
> Cc: Johannes Weiner 
> Cc: Michal Hocko 
> Cc: "Kirill A . Shutemov" 
> Cc: Hugh Dickins 
> Cc: Shakeel Butt 
> Signed-off-by: Yang Shi 
> ---
>    include/linux/huge_mm.h    |  24 ++
>    include/linux/memcontrol.h |   6 ++
>    include/linux/mm_types.h   |   7 +-
>    mm/huge_memory.c   | 182 
> +
>    mm/memcontrol.c    |  20 +
>    mm/swap.c  |   4 +
>    6 files changed, 194 insertions(+), 49 deletions(-)
>
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index 7cd5c15..f6d1cde 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
>    return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
>    }
>    +static inline struct list_head *page_deferred_list(struct page *page)
> +{
> +    /*
> + * Global deferred list in the second tail pages is occupied by
> + * compound_head.
> + */
> +    return [2].deferred_list;
> +}
> +
> +static inline struct list_head *page_memcg_deferred_list(struct page 
> *page)
> +{
> +    /*
> + * Memcg deferred list in the second tail pages is occupied by
> + * compound_head.
> + */
> +    return [2].memcg_deferred_list;
> +}
> +
> +extern void del_thp_from_deferred_split_queue(struct page *);
> +
>    #else /* CONFIG_TRANSPARENT_HUGEPAGE */
>    #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
>    #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
> @@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
>    {
>    return false;
>    }
> +
> +static inline void del_thp_from_deferred_split_queue(struct page *page)
> +{
> +}
>    #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>      #endif /* _LINUX_HUGE_MM_H */
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index bc74d6a..9ff5fab 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -316,6 +316,12 @@ struct mem_cgroup {
>    struct list_head event_list;
>    spinlock_t event_list_lock;
>    +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> +    struct list_head split_queue;
> +    unsigned long split_queue_len;
> +    spinlock_t split_queue_lock;
> +#endif
> +
>    struct mem_cgroup_per_node *nodeinfo[0];
>    /* WARNING: nodeinfo must be the last member here */
>    };
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 8ec38b1..405f5e6 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -139,7 +139,12 @@ struct page {
>    struct {    /* Second tail page of compound page */
>    unsigned long _compound_pad_1;    /* compound_head */
>    unsigned long _compound_pad_2;
> -    struct list_head deferred_list;
> +    union {
> +    /* Global THP deferred split list */
> +    struct list_head deferred_list;
> +    /* Memcg THP deferred split list */
> +    struct list_head memcg_deferred_list;
 Why we need two namesakes for this list entry?

 For me it looks redundantly: it does 

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-30 Thread Yang Shi




On 5/30/19 8:07 PM, Kirill A. Shutemov wrote:

On Tue, May 28, 2019 at 08:44:22PM +0800, Yang Shi wrote:

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bc74d6a..9ff5fab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -316,6 +316,12 @@ struct mem_cgroup {
struct list_head event_list;
spinlock_t event_list_lock;
  
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE

+   struct list_head split_queue;
+   unsigned long split_queue_len;
+   spinlock_t split_queue_lock;

Maybe we should wrap there into a struct and have helper that would return
pointer to the struct which is right for the page: from pgdat or from
memcg, depending on the situation?

This way we will be able to kill most of code duplication, right?


Yes, it sounds simpler than using list_lru.







Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-30 Thread Kirill A. Shutemov
On Tue, May 28, 2019 at 08:44:22PM +0800, Yang Shi wrote:
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index bc74d6a..9ff5fab 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -316,6 +316,12 @@ struct mem_cgroup {
>   struct list_head event_list;
>   spinlock_t event_list_lock;
>  
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> + struct list_head split_queue;
> + unsigned long split_queue_len;
> + spinlock_t split_queue_lock;

Maybe we should wrap there into a struct and have helper that would return
pointer to the struct which is right for the page: from pgdat or from
memcg, depending on the situation?

This way we will be able to kill most of code duplication, right?

-- 
 Kirill A. Shutemov


Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-29 Thread Yang Shi




On 5/29/19 4:14 PM, Kirill Tkhai wrote:

On 29.05.2019 05:43, Yang Shi wrote:


On 5/28/19 10:42 PM, Kirill Tkhai wrote:

Hi, Yang,

On 28.05.2019 15:44, Yang Shi wrote:

Currently THP deferred split shrinker is not memcg aware, this may cause
premature OOM with some configuration. For example the below test would
run into premature OOM easily:

$ cgcreate -g memory:thp
$ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
$ cgexec -g memory:thp transhuge-stress 4000

transhuge-stress comes from kernel selftest.

It is easy to hit OOM, but there are still a lot THP on the deferred
split queue, memcg direct reclaim can't touch them since the deferred
split shrinker is not memcg aware.

Convert deferred split shrinker memcg aware by introducing per memcg
deferred split queue.  The THP should be on either per node or per memcg
deferred split queue if it belongs to a memcg.  When the page is
immigrated to the other memcg, it will be immigrated to the target
memcg's deferred split queue too.

And, move deleting THP from deferred split queue in page free before
memcg uncharge so that the page's memcg information is available.

Reuse the second tail page's deferred_list for per memcg list since the
same THP can't be on multiple deferred split queues.

Cc: Kirill Tkhai 
Cc: Johannes Weiner 
Cc: Michal Hocko 
Cc: "Kirill A . Shutemov" 
Cc: Hugh Dickins 
Cc: Shakeel Butt 
Signed-off-by: Yang Shi 
---
   include/linux/huge_mm.h    |  24 ++
   include/linux/memcontrol.h |   6 ++
   include/linux/mm_types.h   |   7 +-
   mm/huge_memory.c   | 182 
+
   mm/memcontrol.c    |  20 +
   mm/swap.c  |   4 +
   6 files changed, 194 insertions(+), 49 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 7cd5c15..f6d1cde 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
   return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
   }
   +static inline struct list_head *page_deferred_list(struct page *page)
+{
+    /*
+ * Global deferred list in the second tail pages is occupied by
+ * compound_head.
+ */
+    return [2].deferred_list;
+}
+
+static inline struct list_head *page_memcg_deferred_list(struct page *page)
+{
+    /*
+ * Memcg deferred list in the second tail pages is occupied by
+ * compound_head.
+ */
+    return [2].memcg_deferred_list;
+}
+
+extern void del_thp_from_deferred_split_queue(struct page *);
+
   #else /* CONFIG_TRANSPARENT_HUGEPAGE */
   #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
   #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
   {
   return false;
   }
+
+static inline void del_thp_from_deferred_split_queue(struct page *page)
+{
+}
   #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
     #endif /* _LINUX_HUGE_MM_H */
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bc74d6a..9ff5fab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -316,6 +316,12 @@ struct mem_cgroup {
   struct list_head event_list;
   spinlock_t event_list_lock;
   +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+    struct list_head split_queue;
+    unsigned long split_queue_len;
+    spinlock_t split_queue_lock;
+#endif
+
   struct mem_cgroup_per_node *nodeinfo[0];
   /* WARNING: nodeinfo must be the last member here */
   };
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8ec38b1..405f5e6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -139,7 +139,12 @@ struct page {
   struct {    /* Second tail page of compound page */
   unsigned long _compound_pad_1;    /* compound_head */
   unsigned long _compound_pad_2;
-    struct list_head deferred_list;
+    union {
+    /* Global THP deferred split list */
+    struct list_head deferred_list;
+    /* Memcg THP deferred split list */
+    struct list_head memcg_deferred_list;

Why we need two namesakes for this list entry?

For me it looks redundantly: it does not give additional information,
but it leads to duplication (and we have two helpers page_deferred_list()
and page_memcg_deferred_list() instead of one).

Yes, kind of. Actually I was also wondering if this is worth or not. My point 
is this may improve the code readability. We can figure out what split queue 
(per node or per memcg) is being manipulated just by the name of the list.

If the most people thought this is unnecessary, I'm definitely ok to just keep 
one name.


+    };
   };
   struct {    /* Page table pages */
   unsigned long _pt_pad_1;    /* compound_head */
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 9f8bce9..0b9cfe1 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ 

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-29 Thread Kirill Tkhai
On 29.05.2019 05:43, Yang Shi wrote:
> 
> 
> On 5/28/19 10:42 PM, Kirill Tkhai wrote:
>> Hi, Yang,
>>
>> On 28.05.2019 15:44, Yang Shi wrote:
>>> Currently THP deferred split shrinker is not memcg aware, this may cause
>>> premature OOM with some configuration. For example the below test would
>>> run into premature OOM easily:
>>>
>>> $ cgcreate -g memory:thp
>>> $ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
>>> $ cgexec -g memory:thp transhuge-stress 4000
>>>
>>> transhuge-stress comes from kernel selftest.
>>>
>>> It is easy to hit OOM, but there are still a lot THP on the deferred
>>> split queue, memcg direct reclaim can't touch them since the deferred
>>> split shrinker is not memcg aware.
>>>
>>> Convert deferred split shrinker memcg aware by introducing per memcg
>>> deferred split queue.  The THP should be on either per node or per memcg
>>> deferred split queue if it belongs to a memcg.  When the page is
>>> immigrated to the other memcg, it will be immigrated to the target
>>> memcg's deferred split queue too.
>>>
>>> And, move deleting THP from deferred split queue in page free before
>>> memcg uncharge so that the page's memcg information is available.
>>>
>>> Reuse the second tail page's deferred_list for per memcg list since the
>>> same THP can't be on multiple deferred split queues.
>>>
>>> Cc: Kirill Tkhai 
>>> Cc: Johannes Weiner 
>>> Cc: Michal Hocko 
>>> Cc: "Kirill A . Shutemov" 
>>> Cc: Hugh Dickins 
>>> Cc: Shakeel Butt 
>>> Signed-off-by: Yang Shi 
>>> ---
>>>   include/linux/huge_mm.h    |  24 ++
>>>   include/linux/memcontrol.h |   6 ++
>>>   include/linux/mm_types.h   |   7 +-
>>>   mm/huge_memory.c   | 182 
>>> +
>>>   mm/memcontrol.c    |  20 +
>>>   mm/swap.c  |   4 +
>>>   6 files changed, 194 insertions(+), 49 deletions(-)
>>>
>>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
>>> index 7cd5c15..f6d1cde 100644
>>> --- a/include/linux/huge_mm.h
>>> +++ b/include/linux/huge_mm.h
>>> @@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
>>>   return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
>>>   }
>>>   +static inline struct list_head *page_deferred_list(struct page *page)
>>> +{
>>> +    /*
>>> + * Global deferred list in the second tail pages is occupied by
>>> + * compound_head.
>>> + */
>>> +    return [2].deferred_list;
>>> +}
>>> +
>>> +static inline struct list_head *page_memcg_deferred_list(struct page *page)
>>> +{
>>> +    /*
>>> + * Memcg deferred list in the second tail pages is occupied by
>>> + * compound_head.
>>> + */
>>> +    return [2].memcg_deferred_list;
>>> +}
>>> +
>>> +extern void del_thp_from_deferred_split_queue(struct page *);
>>> +
>>>   #else /* CONFIG_TRANSPARENT_HUGEPAGE */
>>>   #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
>>>   #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
>>> @@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
>>>   {
>>>   return false;
>>>   }
>>> +
>>> +static inline void del_thp_from_deferred_split_queue(struct page *page)
>>> +{
>>> +}
>>>   #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>>>     #endif /* _LINUX_HUGE_MM_H */
>>> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
>>> index bc74d6a..9ff5fab 100644
>>> --- a/include/linux/memcontrol.h
>>> +++ b/include/linux/memcontrol.h
>>> @@ -316,6 +316,12 @@ struct mem_cgroup {
>>>   struct list_head event_list;
>>>   spinlock_t event_list_lock;
>>>   +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>> +    struct list_head split_queue;
>>> +    unsigned long split_queue_len;
>>> +    spinlock_t split_queue_lock;
>>> +#endif
>>> +
>>>   struct mem_cgroup_per_node *nodeinfo[0];
>>>   /* WARNING: nodeinfo must be the last member here */
>>>   };
>>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
>>> index 8ec38b1..405f5e6 100644
>>> --- a/include/linux/mm_types.h
>>> +++ b/include/linux/mm_types.h
>>> @@ -139,7 +139,12 @@ struct page {
>>>   struct {    /* Second tail page of compound page */
>>>   unsigned long _compound_pad_1;    /* compound_head */
>>>   unsigned long _compound_pad_2;
>>> -    struct list_head deferred_list;
>>> +    union {
>>> +    /* Global THP deferred split list */
>>> +    struct list_head deferred_list;
>>> +    /* Memcg THP deferred split list */
>>> +    struct list_head memcg_deferred_list;
>> Why we need two namesakes for this list entry?
>>
>> For me it looks redundantly: it does not give additional information,
>> but it leads to duplication (and we have two helpers page_deferred_list()
>> and page_memcg_deferred_list() instead of one).
> 
> Yes, kind of. Actually I was also wondering if this is worth or not. My point 
> is this may improve the code readability. We can figure out what split queue 
> (per node or per memcg) is being 

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-28 Thread Yang Shi




On 5/28/19 10:42 PM, Kirill Tkhai wrote:

Hi, Yang,

On 28.05.2019 15:44, Yang Shi wrote:

Currently THP deferred split shrinker is not memcg aware, this may cause
premature OOM with some configuration. For example the below test would
run into premature OOM easily:

$ cgcreate -g memory:thp
$ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
$ cgexec -g memory:thp transhuge-stress 4000

transhuge-stress comes from kernel selftest.

It is easy to hit OOM, but there are still a lot THP on the deferred
split queue, memcg direct reclaim can't touch them since the deferred
split shrinker is not memcg aware.

Convert deferred split shrinker memcg aware by introducing per memcg
deferred split queue.  The THP should be on either per node or per memcg
deferred split queue if it belongs to a memcg.  When the page is
immigrated to the other memcg, it will be immigrated to the target
memcg's deferred split queue too.

And, move deleting THP from deferred split queue in page free before
memcg uncharge so that the page's memcg information is available.

Reuse the second tail page's deferred_list for per memcg list since the
same THP can't be on multiple deferred split queues.

Cc: Kirill Tkhai 
Cc: Johannes Weiner 
Cc: Michal Hocko 
Cc: "Kirill A . Shutemov" 
Cc: Hugh Dickins 
Cc: Shakeel Butt 
Signed-off-by: Yang Shi 
---
  include/linux/huge_mm.h|  24 ++
  include/linux/memcontrol.h |   6 ++
  include/linux/mm_types.h   |   7 +-
  mm/huge_memory.c   | 182 +
  mm/memcontrol.c|  20 +
  mm/swap.c  |   4 +
  6 files changed, 194 insertions(+), 49 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 7cd5c15..f6d1cde 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
  }
  
+static inline struct list_head *page_deferred_list(struct page *page)

+{
+   /*
+* Global deferred list in the second tail pages is occupied by
+* compound_head.
+*/
+   return [2].deferred_list;
+}
+
+static inline struct list_head *page_memcg_deferred_list(struct page *page)
+{
+   /*
+* Memcg deferred list in the second tail pages is occupied by
+* compound_head.
+*/
+   return [2].memcg_deferred_list;
+}
+
+extern void del_thp_from_deferred_split_queue(struct page *);
+
  #else /* CONFIG_TRANSPARENT_HUGEPAGE */
  #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
  #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
  {
return false;
  }
+
+static inline void del_thp_from_deferred_split_queue(struct page *page)
+{
+}
  #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  
  #endif /* _LINUX_HUGE_MM_H */

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bc74d6a..9ff5fab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -316,6 +316,12 @@ struct mem_cgroup {
struct list_head event_list;
spinlock_t event_list_lock;
  
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE

+   struct list_head split_queue;
+   unsigned long split_queue_len;
+   spinlock_t split_queue_lock;
+#endif
+
struct mem_cgroup_per_node *nodeinfo[0];
/* WARNING: nodeinfo must be the last member here */
  };
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8ec38b1..405f5e6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -139,7 +139,12 @@ struct page {
struct {/* Second tail page of compound page */
unsigned long _compound_pad_1;  /* compound_head */
unsigned long _compound_pad_2;
-   struct list_head deferred_list;
+   union {
+   /* Global THP deferred split list */
+   struct list_head deferred_list;
+   /* Memcg THP deferred split list */
+   struct list_head memcg_deferred_list;

Why we need two namesakes for this list entry?

For me it looks redundantly: it does not give additional information,
but it leads to duplication (and we have two helpers page_deferred_list()
and page_memcg_deferred_list() instead of one).


Yes, kind of. Actually I was also wondering if this is worth or not. My 
point is this may improve the code readability. We can figure out what 
split queue (per node or per memcg) is being manipulated just by the 
name of the list.


If the most people thought this is unnecessary, I'm definitely ok to 
just keep one name.





+   };
};
struct {/* Page table pages */
unsigned long _pt_pad_1;/* compound_head */
diff --git 

Re: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-28 Thread Kirill Tkhai
Hi, Yang,

On 28.05.2019 15:44, Yang Shi wrote:
> Currently THP deferred split shrinker is not memcg aware, this may cause
> premature OOM with some configuration. For example the below test would
> run into premature OOM easily:
> 
> $ cgcreate -g memory:thp
> $ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
> $ cgexec -g memory:thp transhuge-stress 4000
> 
> transhuge-stress comes from kernel selftest.
> 
> It is easy to hit OOM, but there are still a lot THP on the deferred
> split queue, memcg direct reclaim can't touch them since the deferred
> split shrinker is not memcg aware.
> 
> Convert deferred split shrinker memcg aware by introducing per memcg
> deferred split queue.  The THP should be on either per node or per memcg
> deferred split queue if it belongs to a memcg.  When the page is
> immigrated to the other memcg, it will be immigrated to the target
> memcg's deferred split queue too.
> 
> And, move deleting THP from deferred split queue in page free before
> memcg uncharge so that the page's memcg information is available.
> 
> Reuse the second tail page's deferred_list for per memcg list since the
> same THP can't be on multiple deferred split queues.
> 
> Cc: Kirill Tkhai 
> Cc: Johannes Weiner 
> Cc: Michal Hocko 
> Cc: "Kirill A . Shutemov" 
> Cc: Hugh Dickins 
> Cc: Shakeel Butt 
> Signed-off-by: Yang Shi 
> ---
>  include/linux/huge_mm.h|  24 ++
>  include/linux/memcontrol.h |   6 ++
>  include/linux/mm_types.h   |   7 +-
>  mm/huge_memory.c   | 182 
> +
>  mm/memcontrol.c|  20 +
>  mm/swap.c  |   4 +
>  6 files changed, 194 insertions(+), 49 deletions(-)
> 
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index 7cd5c15..f6d1cde 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
>   return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
>  }
>  
> +static inline struct list_head *page_deferred_list(struct page *page)
> +{
> + /*
> +  * Global deferred list in the second tail pages is occupied by
> +  * compound_head.
> +  */
> + return [2].deferred_list;
> +}
> +
> +static inline struct list_head *page_memcg_deferred_list(struct page *page)
> +{
> + /*
> +  * Memcg deferred list in the second tail pages is occupied by
> +  * compound_head.
> +  */
> + return [2].memcg_deferred_list;
> +}
> +
> +extern void del_thp_from_deferred_split_queue(struct page *);
> +
>  #else /* CONFIG_TRANSPARENT_HUGEPAGE */
>  #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
>  #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
> @@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
>  {
>   return false;
>  }
> +
> +static inline void del_thp_from_deferred_split_queue(struct page *page)
> +{
> +}
>  #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>  
>  #endif /* _LINUX_HUGE_MM_H */
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index bc74d6a..9ff5fab 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -316,6 +316,12 @@ struct mem_cgroup {
>   struct list_head event_list;
>   spinlock_t event_list_lock;
>  
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> + struct list_head split_queue;
> + unsigned long split_queue_len;
> + spinlock_t split_queue_lock;
> +#endif
> +
>   struct mem_cgroup_per_node *nodeinfo[0];
>   /* WARNING: nodeinfo must be the last member here */
>  };
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 8ec38b1..405f5e6 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -139,7 +139,12 @@ struct page {
>   struct {/* Second tail page of compound page */
>   unsigned long _compound_pad_1;  /* compound_head */
>   unsigned long _compound_pad_2;
> - struct list_head deferred_list;
> + union {
> + /* Global THP deferred split list */
> + struct list_head deferred_list;
> + /* Memcg THP deferred split list */
> + struct list_head memcg_deferred_list;

Why we need two namesakes for this list entry?

For me it looks redundantly: it does not give additional information,
but it leads to duplication (and we have two helpers page_deferred_list()
and page_memcg_deferred_list() instead of one).

> + };
>   };
>   struct {/* Page table pages */
>   unsigned long _pt_pad_1;/* compound_head */
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 9f8bce9..0b9cfe1 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -492,12 +492,6 @@ pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct 
> *vma)
>   return pmd;
>  }
>  

[PATCH 1/3] mm: thp: make deferred split shrinker memcg aware

2019-05-28 Thread Yang Shi
Currently THP deferred split shrinker is not memcg aware, this may cause
premature OOM with some configuration. For example the below test would
run into premature OOM easily:

$ cgcreate -g memory:thp
$ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes
$ cgexec -g memory:thp transhuge-stress 4000

transhuge-stress comes from kernel selftest.

It is easy to hit OOM, but there are still a lot THP on the deferred
split queue, memcg direct reclaim can't touch them since the deferred
split shrinker is not memcg aware.

Convert deferred split shrinker memcg aware by introducing per memcg
deferred split queue.  The THP should be on either per node or per memcg
deferred split queue if it belongs to a memcg.  When the page is
immigrated to the other memcg, it will be immigrated to the target
memcg's deferred split queue too.

And, move deleting THP from deferred split queue in page free before
memcg uncharge so that the page's memcg information is available.

Reuse the second tail page's deferred_list for per memcg list since the
same THP can't be on multiple deferred split queues.

Cc: Kirill Tkhai 
Cc: Johannes Weiner 
Cc: Michal Hocko 
Cc: "Kirill A . Shutemov" 
Cc: Hugh Dickins 
Cc: Shakeel Butt 
Signed-off-by: Yang Shi 
---
 include/linux/huge_mm.h|  24 ++
 include/linux/memcontrol.h |   6 ++
 include/linux/mm_types.h   |   7 +-
 mm/huge_memory.c   | 182 +
 mm/memcontrol.c|  20 +
 mm/swap.c  |   4 +
 6 files changed, 194 insertions(+), 49 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 7cd5c15..f6d1cde 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void)
return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
 }
 
+static inline struct list_head *page_deferred_list(struct page *page)
+{
+   /*
+* Global deferred list in the second tail pages is occupied by
+* compound_head.
+*/
+   return [2].deferred_list;
+}
+
+static inline struct list_head *page_memcg_deferred_list(struct page *page)
+{
+   /*
+* Memcg deferred list in the second tail pages is occupied by
+* compound_head.
+*/
+   return [2].memcg_deferred_list;
+}
+
+extern void del_thp_from_deferred_split_queue(struct page *);
+
 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
 #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
 #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
@@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void)
 {
return false;
 }
+
+static inline void del_thp_from_deferred_split_queue(struct page *page)
+{
+}
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
 #endif /* _LINUX_HUGE_MM_H */
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index bc74d6a..9ff5fab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -316,6 +316,12 @@ struct mem_cgroup {
struct list_head event_list;
spinlock_t event_list_lock;
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+   struct list_head split_queue;
+   unsigned long split_queue_len;
+   spinlock_t split_queue_lock;
+#endif
+
struct mem_cgroup_per_node *nodeinfo[0];
/* WARNING: nodeinfo must be the last member here */
 };
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8ec38b1..405f5e6 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -139,7 +139,12 @@ struct page {
struct {/* Second tail page of compound page */
unsigned long _compound_pad_1;  /* compound_head */
unsigned long _compound_pad_2;
-   struct list_head deferred_list;
+   union {
+   /* Global THP deferred split list */
+   struct list_head deferred_list;
+   /* Memcg THP deferred split list */
+   struct list_head memcg_deferred_list;
+   };
};
struct {/* Page table pages */
unsigned long _pt_pad_1;/* compound_head */
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 9f8bce9..0b9cfe1 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -492,12 +492,6 @@ pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct 
*vma)
return pmd;
 }
 
-static inline struct list_head *page_deferred_list(struct page *page)
-{
-   /* ->lru in the tail pages is occupied by compound_head. */
-   return [2].deferred_list;
-}
-
 void prep_transhuge_page(struct page *page)
 {
/*
@@ -505,7 +499,10 @@ void prep_transhuge_page(struct page *page)
 * as list_head: assuming THP order >= 2
 */
 
-   INIT_LIST_HEAD(page_deferred_list(page));
+   if (mem_cgroup_disabled())
+