[PATCH v20 0/9] Free some vmemmap pages of HugeTLB page

2021-04-15 Thread Muchun Song
e code. Thanks Mike and Oscar. - Remap the tail vmemmap page with PAGE_KERNEL_RO instead of PAGE_KERNEL. Thanks Matthew. - Add some overhead analysis in the cover letter. - Use vmemap pmd table lock instead of a hugetlb specific global lock. Changelog in v1 -> v2: - Fix do not call d

Re: [External] Re: [PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm

2021-04-14 Thread Muchun Song
On Wed, Apr 14, 2021 at 6:15 PM Michal Hocko wrote: > > On Wed 14-04-21 18:04:35, Muchun Song wrote: > > On Wed, Apr 14, 2021 at 5:24 PM Michal Hocko wrote: > > > > > > On Tue 13-04-21 14:51:48, Muchun Song wrote: > > > > When mm is NULL, we do not nee

Re: [External] Re: [PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm

2021-04-14 Thread Muchun Song
On Wed, Apr 14, 2021 at 5:24 PM Michal Hocko wrote: > > On Tue 13-04-21 14:51:48, Muchun Song wrote: > > When mm is NULL, we do not need to hold rcu lock and call css_tryget for > > the root memcg. And we also do not need to check !mm in every loop of > > while. So

Re: [External] Re: [PATCH 4/7] mm: memcontrol: simplify lruvec_holds_page_lru_lock

2021-04-14 Thread Muchun Song
On Wed, Apr 14, 2021 at 5:44 PM Michal Hocko wrote: > > On Tue 13-04-21 14:51:50, Muchun Song wrote: > > We already have a helper lruvec_memcg() to get the memcg from lruvec, we > > do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So use > > lruvec

[PATCH 6/7] mm: memcontrol: move obj_cgroup_uncharge_pages() out of css_set_lock

2021-04-13 Thread Muchun Song
The css_set_lock is used to guard the list of inherited objcgs. So there is no need to uncharge kernel memory under css_set_lock. Just move it out of the lock. Signed-off-by: Muchun Song --- mm/memcontrol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b

[PATCH 7/7] mm: vmscan: remove noinline_for_stack

2021-04-13 Thread Muchun Song
f reclaim stack") replace pagevecs by lists of pages_to_free. So we do not need noinline_for_stack, just remove it (let the compiler decide whether to inline). Signed-off-by: Muchun Song Acked-by: Johannes Weiner Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt --- mm/vmscan.c | 6 +++--

[PATCH 5/7] mm: memcontrol: simplify the logic of objcg pinning memcg

2021-04-13 Thread Muchun Song
RITE_ONCE(). Signed-off-by: Muchun Song Acked-by: Johannes Weiner --- mm/memcontrol.c | 20 ++-- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1f807448233e..42d8c0f4ab1d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c

[PATCH 3/7] mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec

2021-04-13 Thread Muchun Song
parameter. Just remove it to simplify the code. Signed-off-by: Muchun Song Acked-by: Johannes Weiner --- include/linux/memcontrol.h | 10 +- mm/compaction.c| 2 +- mm/memcontrol.c| 9 +++-- mm/swap.c | 2 +- mm/workingset.c| 2 +- 5

[PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm

2021-04-13 Thread Muchun Song
When mm is NULL, we do not need to hold rcu lock and call css_tryget for the root memcg. And we also do not need to check !mm in every loop of while. So bail out early when !mm. Signed-off-by: Muchun Song Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 21

[PATCH 1/7] mm: memcontrol: fix page charging in page replacement

2021-04-13 Thread Muchun Song
ll trigger? So it is better to fix it. Signed-off-by: Muchun Song Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 64ada9e650a5..f229de925aa5 10064

[PATCH 4/7] mm: memcontrol: simplify lruvec_holds_page_lru_lock

2021-04-13 Thread Muchun Song
"memcg = page_memcg(page) ? : root_mem_cgroup". And use lruvec_pgdat to simplify the code. We can have a single definition for this function that works for !CONFIG_MEMCG, CONFIG_MEMCG + mem_cgroup_disabled() and CONFIG_MEMCG. Signed-off-by: Muchun Song Acked-by: Johannes Weiner --- inc

[PATCH 0/7] memcontrol code cleanup and simplification

2021-04-13 Thread Muchun Song
This patch series is part of [1] patch series. Because those patches are code cleanup or simplification. I gather those patches into a separate series to make it easier to review. [1] https://lore.kernel.org/linux-mm/20210409122959.82264-1-songmuc...@bytedance.com/ Muchun Song (7): mm

Re: [External] Re: [PATCH] mm: memcontrol: fix forget to obtain the ref to objcg in split_page_memcg

2021-04-12 Thread Muchun Song
On Mon, Apr 12, 2021 at 6:42 PM Christian Borntraeger wrote: > > FWIW, I was away the last week, and I checked yesterdays next (e99d8a849517) > regression runs. > I still do see errors in our CI system: > > [ 2263.021681] [ cut here ] > [ 2263.021697] percpu ref (obj_cgrou

Re: [External] Re: [RFC PATCH v2 06/18] mm: memcontrol: move the objcg infrastructure out of CONFIG_MEMCG_KMEM

2021-04-10 Thread Muchun Song
On Sat, Apr 10, 2021 at 12:56 AM Johannes Weiner wrote: > > On Fri, Apr 09, 2021 at 08:29:47PM +0800, Muchun Song wrote: > > Because memory allocations pinning memcgs for a long time - it exists > > at a larger scale and is causing recurring problems in the real world: > >

Re: [External] Re: [RFC PATCH v2 04/18] mm: memcontrol: simplify lruvec_holds_page_lru_lock

2021-04-10 Thread Muchun Song
On Sat, Apr 10, 2021 at 12:00 AM Johannes Weiner wrote: > > On Fri, Apr 09, 2021 at 08:29:45PM +0800, Muchun Song wrote: > > We already have a helper lruvec_memcg() to get the memcg from lruvec, we > > do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So us

Re: [External] Re: [RFC PATCH v2 09/18] mm: vmscan: remove noinline_for_stack

2021-04-09 Thread Muchun Song
On Sat, Apr 10, 2021 at 2:31 AM Johannes Weiner wrote: > > On Fri, Apr 09, 2021 at 08:29:50PM +0800, Muchun Song wrote: > > The noinline_for_stack is introduced by commit 666356297ec4 ("vmscan: > > set up pagevec as late as possible in shrink_inactive_list()"), its

[RFC PATCH v2 18/18] mm: lru: use lruvec lock to serialize memcg changes

2021-04-09 Thread Muchun Song
, removing an atomic operation would be an optimization. Also this change would not dirty cacheline for a page which isn't on the LRU. Signed-off-by: Muchun Song --- mm/compaction.c | 1 + mm/memcontrol.c | 31 +++ mm/swap.c | 41 +++--

[RFC PATCH v2 16/18] mm: memcontrol: rename {un}lock_page_memcg() to {un}lock_page_objcg()

2021-04-09 Thread Muchun Song
Now the lock_page_memcg() does not lock a page and memcg binding, it actually lock a page and objcg binding. So rename lock_page_memcg() to lock_page_objcg(). This is just code cleanup without any functionality changes. Signed-off-by: Muchun Song --- Documentation/admin-guide/cgroup-v1

[RFC PATCH v2 13/18] mm: memcontrol: make all the callers of page_memcg() safe

2021-04-09 Thread Muchun Song
preparation for reparenting the LRU pages. Signed-off-by: Muchun Song --- fs/buffer.c| 3 ++- fs/fs-writeback.c | 23 +++-- include/linux/memcontrol.h | 34 --- mm/memcontrol.c| 51

[RFC PATCH v2 17/18] mm: lru: add VM_BUG_ON_PAGE to lru maintenance function

2021-04-09 Thread Muchun Song
We need to make sure that the page is deleted from or added to the correct lruvec list. So add a VM_BUG_ON_PAGE() to catch invalid users. Signed-off-by: Muchun Song --- include/linux/mm_inline.h | 6 ++ mm/vmscan.c | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff

[RFC PATCH v2 14/18] mm: memcontrol: introduce memcg_reparent_ops

2021-04-09 Thread Muchun Song
ks safe when the LRU pages reparented. Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 11 +++ mm/memcontrol.c| 49 -- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/

[RFC PATCH v2 15/18] mm: memcontrol: use obj_cgroup APIs to charge the LRU pages

2021-04-09 Thread Muchun Song
stability: - css_set_lock - cgroup_mutex - the lruvec lock - the split queue lock (only THP page) If the caller only want to ensure that the page counters of memcg are updated correctly, ensure that the binding stability of page and objcg is sufficient. Signed-off-by: Muchun Song --- incl

[RFC PATCH v2 12/18] mm: thp: make deferred split queue lock safe when the LRU pages reparented

2021-04-09 Thread Muchun Song
Similar to lruvec lock, we use the same approach to make the lock safe when the LRU pages reparented. Signed-off-by: Muchun Song --- mm/huge_memory.c | 23 +++ 1 file changed, 23 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 275dbfc8b2ae..aa5d7b72d5fc

[RFC PATCH v2 11/18] mm: thp: introduce lock/unlock_split_queue{_irqsave}()

2021-04-09 Thread Muchun Song
like lruvec lock did) to make thp deferred split queue lock safe when the LRU pages reparented. Signed-off-by: Muchun Song --- mm/huge_memory.c | 96 +++- 1 file changed, 74 insertions(+), 22 deletions(-) diff --git a/mm/huge_memory.c b/mm

[RFC PATCH v2 10/18] mm: vmscan: rework move_pages_to_lru()

2021-04-09 Thread Muchun Song
the correct lruvec lock. Signed-off-by: Muchun Song --- mm/vmscan.c | 46 +++--- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e40b21298d77..4431007825ad 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2013,23

[RFC PATCH v2 09/18] mm: vmscan: remove noinline_for_stack

2021-04-09 Thread Muchun Song
f reclaim stack") replace pagevecs by lists of pages_to_free. So we do not need noinline_for_stack, just remove it (let the compiler decide whether to inline). Signed-off-by: Muchun Song --- mm/vmscan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c

[RFC PATCH v2 08/18] mm: memcontrol: make lruvec lock safe when the LRU pages reparented

2021-04-09 Thread Muchun Song
cannot be changed when we hold the lruvec lock. Since lruvec_memcg(lruvec) is always equal to page_memcg(page) after we hold the lruvec lock, lruvec_memcg_debug() check is pointless. So remove it. This is a preparation for reparenting the LRU pages. Signed-off-by: Muchun Song -

[RFC PATCH v2 07/18] mm: memcontrol: introduce compact_lock_page_lruvec_irqsave

2021-04-09 Thread Muchun Song
whether we need to reacquire the new lruvec lock. So compact_lock_irqsave() is not suitable for us. Similar to lock_page_lruvec_irqsave(), introduce compact_lock_page_lruvec_irqsave() to acquire the lruvec lock in the compaction routine. Signed-off-by: Muchun Song --- mm/compac

[RFC PATCH v2 06/18] mm: memcontrol: move the objcg infrastructure out of CONFIG_MEMCG_KMEM

2021-04-09 Thread Muchun Song
llocate an object cgroup for the root_mem_cgroup and introduce root_obj_cgroup to cache its value just like root_mem_cgroup. Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 4 ++- mm/memcontrol.c| 71 +- 2 files changed, 60

[RFC PATCH v2 05/18] mm: memcontrol: simplify the logic of objcg pinning memcg

2021-04-09 Thread Muchun Song
RITE_ONCE(). Signed-off-by: Muchun Song --- mm/memcontrol.c | 20 +++- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1f807448233e..90c1ac58c64c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -261,7 +261,6 @@ st

[RFC PATCH v2 04/18] mm: memcontrol: simplify lruvec_holds_page_lru_lock

2021-04-09 Thread Muchun Song
"memcg = page_memcg(page) ? : root_mem_cgroup". And use lruvec_pgdat to simplify the code. We can have a single definition for this function that works for !CONFIG_MEMCG, CONFIG_MEMCG + mem_cgroup_disabled() and CONFIG_MEMCG. Signed-off-by: Muchun Song --- include/linux/memcont

[RFC PATCH v2 03/18] mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec

2021-04-09 Thread Muchun Song
parameter. Just remove it to simplify the code. Signed-off-by: Muchun Song Acked-by: Johannes Weiner --- include/linux/memcontrol.h | 10 +- mm/compaction.c| 2 +- mm/memcontrol.c| 9 +++-- mm/swap.c | 2 +- mm/workingset.c| 2 +- 5

[RFC PATCH v2 02/18] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm

2021-04-09 Thread Muchun Song
When mm is NULL, we do not need to hold rcu lock and call css_tryget for the root memcg. And we also do not need to check !mm in every loop of while. So bail out early when !mm. Signed-off-by: Muchun Song Acked-by: Johannes Weiner --- mm/memcontrol.c | 21 ++--- 1 file changed

[RFC PATCH v2 01/18] mm: memcontrol: fix page charging in page replacement

2021-04-09 Thread Muchun Song
ll trigger? So it is better to fix it. Signed-off-by: Muchun Song Acked-by: Johannes Weiner --- mm/memcontrol.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 64ada9e650a5..f229de925aa5 100644 --- a/mm/memcontrol.c +++ b/mm/me

[RFC PATCH v2 00/18] Use obj_cgroup APIs to charge the LRU pages

2021-04-09 Thread Muchun Song
he objcg direction. Any comments are welcome. Thanks. Changlogs in RFC v2: 1. Collect Acked-by tags by Johannes. Thanks. 2. Rework lruvec_holds_page_lru_lock() suggested by Johannes. Thanks. 3. Fix move_pages_to_lru(). Muchun Song (18): mm: memcontrol: fix page charging in page replacemen

Re: [External] Re: [RFC PATCH 04/15] mm: memcontrol: use lruvec_memcg in lruvec_holds_page_lru_lock

2021-04-03 Thread Muchun Song
On Sat, Apr 3, 2021 at 12:21 AM Johannes Weiner wrote: > > On Tue, Mar 30, 2021 at 06:15:20PM +0800, Muchun Song wrote: > > We already have a helper lruvec_memcg() to get the memcg from lruvec, we > > do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So us

Re: [External] [PATCH v3 7/8] hugetlb: make free_huge_page irq safe

2021-04-02 Thread Muchun Song
On Sat, Apr 3, 2021 at 4:56 AM Mike Kravetz wrote: > > On 4/2/21 5:47 AM, Muchun Song wrote: > > On Wed, Mar 31, 2021 at 11:42 AM Mike Kravetz > > wrote: > >> > >> Commit c77c0a8ac4c5 ("mm/hugetlb: defer freeing of huge pages if in > >> no

Re: [External] [PATCH 2/3] mm: Charge active memcg when no mm is set

2021-04-02 Thread Muchun Song
ff-by: Dan Schatzberg > Acked-by: Johannes Weiner > Acked-by: Tejun Heo > Acked-by: Chris Down > Reviewed-by: Shakeel Butt Reviewed-by: Muchun Song Thanks.

Re: [External] [PATCH v3 7/8] hugetlb: make free_huge_page irq safe

2021-04-02 Thread Muchun Song
s://lore.kernel.org/linux-mm/00000000f1c03b05bc43a...@google.com/ > > Signed-off-by: Mike Kravetz > Acked-by: Michal Hocko > Reviewed-by: Muchun Song Hi Mike, Today I pulled the newest code (next-20210401). I found that alloc_and_dissolve_huge_page is not updated. In th

[PATCH v3] writeback: fix obtain a reference to a freeing memcg css

2021-04-02 Thread Muchun Song
the result of a code review. Fixes: 682aa8e1a6a1 ("writeback: implement unlocked_inode_to_wb transaction and use it for stat updates") Signed-off-by: Muchun Song Acked-by: Michal Hocko --- Changelog in v3: 1. Do not change GFP_ATOMIC. 2. Update commit log. Thanks for Michal&#x

Re: [External] Re: [RFC PATCH 00/15] Use obj_cgroup APIs to charge the LRU pages

2021-04-01 Thread Muchun Song
> On Tue, Mar 30, 2021 at 11:58:31AM -0700, Roman Gushchin wrote: > > > > > On Tue, Mar 30, 2021 at 11:34:11AM -0700, Shakeel Butt wrote: > > > > > > On Tue, Mar 30, 2021 at 3:20 AM Muchun Song > > > > > > wrote: > > > > >

Re: [External] Re: [RFC PATCH 00/15] Use obj_cgroup APIs to charge the LRU pages

2021-04-01 Thread Muchun Song
On Fri, Apr 2, 2021 at 1:15 AM Shakeel Butt wrote: > > On Thu, Apr 1, 2021 at 9:08 AM Muchun Song wrote: > > > [...] > > > The zombie issue is a pretty urgent concern that has caused several > > > production emergencies now. It needs a fix sooner rather than l

Re: [External] Re: [RFC PATCH 00/15] Use obj_cgroup APIs to charge the LRU pages

2021-04-01 Thread Muchun Song
; > On Tue, Mar 30, 2021 at 11:34:11AM -0700, Shakeel Butt wrote: > > > > > On Tue, Mar 30, 2021 at 3:20 AM Muchun Song > > > > > wrote: > > > > > > > > > > > > Since the following patchsets

Re: [External] Re: [PATCH v2] writeback: fix obtain a reference to a freeing memcg css

2021-04-01 Thread Muchun Song
On Thu, Apr 1, 2021 at 10:37 PM Michal Hocko wrote: > > On Thu 01-04-21 21:59:13, Muchun Song wrote: > > On Thu, Apr 1, 2021 at 6:26 PM Michal Hocko wrote: > [...] > > > Even if the css ref count is not really necessary it shouldn't cause any > > > harm and

Re: [External] Re: [PATCH v2] writeback: fix obtain a reference to a freeing memcg css

2021-04-01 Thread Muchun Song
On Thu, Apr 1, 2021 at 6:26 PM Michal Hocko wrote: > > On Thu 01-04-21 17:33:43, Muchun Song wrote: > > The caller of wb_get_create() should pin the memcg, because > > wb_get_create() relies on this guarantee. The rcu read lock > > only can guarantee that the memcg css

[PATCH v2] writeback: fix obtain a reference to a freeing memcg css

2021-04-01 Thread Muchun Song
t;) Signed-off-by: Muchun Song --- Changelog in v2: 1. Replace GFP_ATOMIC with GFP_NOIO suggested by Matthew. fs/fs-writeback.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index e91980f49388..df7f89f8f771 100644 --- a/fs/fs-w

Re: [PATCH v2] kernel/resource: Fix locking in request_free_mem_region

2021-03-31 Thread Muchun Song
On Fri, Mar 26, 2021 at 9:22 AM Alistair Popple wrote: > > request_free_mem_region() is used to find an empty range of physical > addresses for hotplugging ZONE_DEVICE memory. It does this by iterating > over the range of possible addresses using region_intersects() to see if > the range is free.

[PATCH] mm: memcontrol: fix forget to obtain the ref to objcg in split_page_memcg

2021-03-31 Thread Muchun Song
Christian Borntraeger reported a warning about "percpu ref (obj_cgroup_release) <= 0 (-1) after switching to atomic". Because we forgot to obtain the reference to the objcg and wrongly obtain the reference of memcg. Reported-by: Christian Borntraeger Signed-off-by: Muchun Song

Re: [External] RE: kernel warning percpu ref in obj_cgroup_release

2021-03-31 Thread Muchun Song
On Wed, Mar 31, 2021 at 2:22 PM Christian Borntraeger wrote: > > > > On 30.03.21 18:25, Muchun Song wrote: > > On Tue, Mar 30, 2021 at 11:10 PM Christian Borntraeger > > wrote: > >> > >> > >> On 30.03.21 15:49, Muchun Song wrote: > >

Re: [External] Re: [PATCH] writeback: fix obtain a reference to a freeing memcg css

2021-03-31 Thread Muchun Song
On Tue, Mar 30, 2021 at 7:34 PM Matthew Wilcox wrote: > > On Tue, Mar 30, 2021 at 05:29:33PM +0800, Muchun Song wrote: > > +++ b/fs/fs-writeback.c > > @@ -506,8 +506,10 @@ static void inode_switch_wbs(struct inode *inode, int > > new_wb_id) > >

Re: [External] RE: kernel warning percpu ref in obj_cgroup_release

2021-03-31 Thread Muchun Song
On Wed, Mar 31, 2021 at 2:22 PM Christian Borntraeger wrote: > > > > On 30.03.21 18:25, Muchun Song wrote: > > On Tue, Mar 30, 2021 at 11:10 PM Christian Borntraeger > > wrote: > >> > >> > >> On 30.03.21 15:49, Muchun Song wrote: > >

Re: [External] RE: kernel warning percpu ref in obj_cgroup_release

2021-03-30 Thread Muchun Song
On Tue, Mar 30, 2021 at 11:10 PM Christian Borntraeger wrote: > > > On 30.03.21 15:49, Muchun Song wrote: > > On Tue, Mar 30, 2021 at 9:27 PM Christian Borntraeger > > wrote: > >> > >> So bisect shows this for belows warning: > > > > Thanks

Re: [External] Re: kernel warning percpu ref in obj_cgroup_release

2021-03-30 Thread Muchun Song
8f019a > Author: Muchun Song > Date: Mon Mar 29 11:12:06 2021 +1100 > > mm: memcontrol: use obj_cgroup APIs to charge kmem pages > > Since Roman's series "The new cgroup slab memory controller" applied. > All > slab objects are charged via the

[RFC PATCH 15/15] mm: lru: add VM_BUG_ON_PAGE to lru maintenance function

2021-03-30 Thread Muchun Song
We need to make sure that the page is deleted from or added to the correct lruvec list. So add a VM_BUG_ON_PAGE() to catch invalid users. Signed-off-by: Muchun Song --- include/linux/mm_inline.h | 6 ++ mm/vmscan.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff

[RFC PATCH 14/15] mm: memcontrol: rename {un}lock_page_memcg() to {un}lock_page_objcg()

2021-03-30 Thread Muchun Song
Now the lock_page_memcg() does not lock a page and memcg binding, it actually lock a page and objcg binding. So rename lock_page_memcg() to lock_page_objcg(). This is just code cleanup without any functionality changes. Signed-off-by: Muchun Song --- Documentation/admin-guide/cgroup-v1

[RFC PATCH 13/15] mm: memcontrol: use obj_cgroup APIs to charge the LRU pages

2021-03-30 Thread Muchun Song
stability: - css_set_lock - cgroup_mutex - the lruvec lock - the split queue lock (only THP page) If the caller only want to ensure that the page counters of memcg are updated correctly, ensure that the binding stability of page and objcg is sufficient. Signed-off-by: Muchun Song --- incl

[RFC PATCH 12/15] mm: memcontrol: introduce memcg_reparent_ops

2021-03-30 Thread Muchun Song
ks safe when the LRU pages reparented. Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 11 +++ mm/memcontrol.c| 49 -- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/

[RFC PATCH 11/15] mm: memcontrol: make all the callers of page_memcg() safe

2021-03-30 Thread Muchun Song
preparation for reparenting the LRU pages. Signed-off-by: Muchun Song --- fs/buffer.c| 3 ++- fs/fs-writeback.c | 23 +++-- include/linux/memcontrol.h | 34 --- mm/memcontrol.c| 50

[RFC PATCH 10/15] mm: thp: make deferred split queue lock safe when the LRU pages reparented

2021-03-30 Thread Muchun Song
Similar to lruvec lock, we use the same approach to make the lock safe when the LRU pages reparented. Signed-off-by: Muchun Song --- mm/huge_memory.c | 26 ++ 1 file changed, 26 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 186dc11e8992

[RFC PATCH 09/15] mm: thp: introduce lock/unlock_split_queue{_irqsave}()

2021-03-30 Thread Muchun Song
like lruvec lock did) to make thp deferred split queue lock safe when the LRU pages reparented. Signed-off-by: Muchun Song --- mm/huge_memory.c | 97 +++- 1 file changed, 75 insertions(+), 22 deletions(-) diff --git a/mm/huge_memory.c b/mm

[RFC PATCH 08/15] mm: memcontrol: make lruvec lock safe when the LRU pages reparented

2021-03-30 Thread Muchun Song
cannot be changed when we hold the lruvec lock. Since lruvec_memcg(lruvec) is always equal to page_memcg(page) after we hold the lruvec lock, lruvec_memcg_debug() check is pointless. So remove it. This is a preparation for reparenting the LRU pages. Signed-off-by: Muchun Song -

[RFC PATCH 07/15] mm: memcontrol: introduce compact_lock_page_lruvec_irqsave

2021-03-30 Thread Muchun Song
whether we need to reacquire the new lruvec lock. So compact_lock_irqsave() is not suitable for us. Similar to lock_page_lruvec_irqsave(), introduce compact_lock_page_lruvec_irqsave() to acquire the lruvec lock in the compaction routine. Signed-off-by: Muchun Song --- mm/compac

[RFC PATCH 06/15] mm: memcontrol: move the objcg infrastructure out of CONFIG_MEMCG_KMEM

2021-03-30 Thread Muchun Song
llocate an object cgroup for the root_mem_cgroup and introduce root_obj_cgroup to cache its value just like root_mem_cgroup. Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 4 ++- mm/memcontrol.c| 71 +- 2 files changed, 60

[RFC PATCH 04/15] mm: memcontrol: use lruvec_memcg in lruvec_holds_page_lru_lock

2021-03-30 Thread Muchun Song
We already have a helper lruvec_memcg() to get the memcg from lruvec, we do not need to do it ourselves in the lruvec_holds_page_lru_lock(). So use lruvec_memcg() instead. Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff

[RFC PATCH 05/15] mm: memcontrol: simplify the logic of objcg pinning memcg

2021-03-30 Thread Muchun Song
RITE_ONCE(). Signed-off-by: Muchun Song --- mm/memcontrol.c | 20 +++- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 405c9642aac0..fdabe12e9df0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -261,7 +261,6 @@ st

[RFC PATCH 03/15] mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec

2021-03-30 Thread Muchun Song
parameter. Just remove it to simplify the code. Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 10 +- mm/compaction.c| 2 +- mm/memcontrol.c| 9 +++-- mm/page-writeback.c| 2 +- mm/swap.c | 2 +- mm/workingset.c

[RFC PATCH 01/15] mm: memcontrol: fix page charging in page replacement

2021-03-30 Thread Muchun Song
ll trigger? So it is better to fix it. Signed-off-by: Muchun Song --- mm/memcontrol.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 249bf6b4d94c..d0c4f6e91e17 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6936,9 +6936,

[RFC PATCH 02/15] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm

2021-03-30 Thread Muchun Song
When mm is NULL, we do not need to hold rcu lock and call css_tryget for the root memcg. And we also do not need to check !mm in every loop of while. So bail out early when !mm. Signed-off-by: Muchun Song --- mm/memcontrol.c | 21 ++--- 1 file changed, 10 insertions(+), 11

[RFC PATCH 00/15] Use obj_cgroup APIs to charge the LRU pages

2021-03-30 Thread Muchun Song
he objcg direction. Muchun Song (15): mm: memcontrol: fix page charging in page replacement mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm mm: memcontrol: remove the pgdata parameter of mem_cgroup_page_lruvec mm: memcontrol: use lruvec_memcg in lruvec_holds_page_lru_loc

[PATCH] writeback: fix obtain a reference to a freeing memcg css

2021-03-30 Thread Muchun Song
calling wb_get_create(). This is not a problem I encountered in the real world. Just the result of a code review. Fixes: 682aa8e1a6a1 ("writeback: implement unlocked_inode_to_wb transaction and use it for stat updates") Signed-off-by: Muchun Song --- fs/fs-writeback.c | 4 +++- 1 file

Re: [External] Re: [PATCH v2 1/8] mm/cma: change cma mutex to irq safe spinlock

2021-03-30 Thread Muchun Song
On Tue, Mar 30, 2021 at 4:18 PM Michal Hocko wrote: > > On Tue 30-03-21 16:08:36, Muchun Song wrote: > > On Tue, Mar 30, 2021 at 4:01 PM Michal Hocko wrote: > > > > > > On Mon 29-03-21 16:23:55, Mike Kravetz wrote: > > > > Ideally, cma_release could be

Re: [External] Re: [PATCH v2 1/8] mm/cma: change cma mutex to irq safe spinlock

2021-03-30 Thread Muchun Song
On Tue, Mar 30, 2021 at 4:01 PM Michal Hocko wrote: > > On Mon 29-03-21 16:23:55, Mike Kravetz wrote: > > Ideally, cma_release could be called from any context. However, that is > > not possible because a mutex is used to protect the per-area bitmap. > > Change the bitmap to an irq safe spinlock.

Re: [External] [PATCH v2 6/8] hugetlb: change free_pool_huge_page to remove_pool_huge_page

2021-03-29 Thread Muchun Song
ght forward accounting effectively > reverting the commit. > > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Some nits below. > --- > mm/hugetlb.c | 95 +--- > 1 file changed, 53 insertions(+), 42 deletions(-) > &g

Re: [External] [PATCH v2 3/8] hugetlb: add per-hstate mutex to synchronize user adjustments

2021-03-29 Thread Muchun Song
; allow one hugetlb page adjustment at a time. This will synchronize > modifications to the next_nid_to_alloc variable. > > Signed-off-by: Mike Kravetz Thanks Mike. Reviewed-by: Muchun Song > Acked-by: Michal Hocko > Reviewed-by: Oscar Salvador > Reviewed-by: Miaohe Lin > ---

Re: [External] [PATCH v2 5/8] hugetlb: call update_and_free_page without hugetlb_lock

2021-03-29 Thread Muchun Song
Mike Kravetz > Acked-by: Michal Hocko > Reviewed-by: Muchun Song > --- > mm/hugetlb.c | 32 +++- > 1 file changed, 27 insertions(+), 5 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 16beae49..dec7bd0dc63d 100644 > --- a/mm/hu

Re: [External] [PATCH] linux/memcontrol.h: Remove duplicate struct declaration

2021-03-29 Thread Muchun Song
On Tue, Mar 30, 2021 at 10:03 AM Wan Jiabing wrote: > > struct mem_cgroup is declared twice. One has been declared > at forward struct declaration. Remove the duplicate. > > Signed-off-by: Wan Jiabing Reviewed-by: Muchun Song Thanks. > --- > include/linux/memcontr

Re: [External] [PATCH 2/3] mm: Charge active memcg when no mm is set

2021-03-29 Thread Muchun Song
On Mon, Mar 29, 2021 at 10:49 PM Dan Schatzberg wrote: > > set_active_memcg() worked for kernel allocations but was silently > ignored for user pages. > > This patch establishes a precedence order for who gets charged: > > 1. If there is a memcg associated with the page already, that memcg is >

Re: [External] [PATCH 8/8] hugetlb: add lockdep_assert_held() calls for hugetlb_lock

2021-03-27 Thread Muchun Song
On Thu, Mar 25, 2021 at 8:29 AM Mike Kravetz wrote: > > After making hugetlb lock irq safe and separating some functionality > done under the lock, add some lockdep_assert_held to help verify > locking. > > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Thanks. >

Re: [External] [PATCH 7/8] hugetlb: make free_huge_page irq safe

2021-03-27 Thread Muchun Song
ck calls to spin_*lock_irq* calls. > - Make subpool lock irq safe in a similar manner. > - Revert the !in_task check and workqueue handoff. > > [1] https://lore.kernel.org/linux-mm/f1c03b05bc43a...@google.com/ > > Signed-off-by: Mike Kravetz The changes are straightfor

Re: [External] [PATCH 5/8] hugetlb: call update_and_free_page without hugetlb_lock

2021-03-26 Thread Muchun Song
allow loops which decrease > the huge page pool to drop the hugetlb_lock with each page to reduce > long hold times. > > The ugly unlock/lock cycle in free_pool_huge_page will be removed in > a subsequent patch which restructures free_pool_huge_page. > > Signed-off-by: Mike Kr

Re: [External] [PATCH 4/8] hugetlb: create remove_hugetlb_page() to separate functionality

2021-03-26 Thread Muchun Song
ne and separating functionality is in preparation for > restructuring code to reduce lock hold times. > > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Thanks for your effort on this. > --- > mm/hugetlb.c | 70 +--- >

Re: [External] Re: [PATCH] mm: memcontrol: fix memsw uncharge for root_mem_cgroup

2021-03-24 Thread Muchun Song
On Wed, Mar 24, 2021 at 4:33 PM Michal Hocko wrote: > > On Wed 24-03-21 12:11:35, Muchun Song wrote: > > On Tue, Mar 23, 2021 at 11:04 PM Muchun Song > > wrote: > > > > > > The pages aren't accounted at the root level, so we cannot uncharge the > >

Re: [PATCH] mm: memcontrol: fix memsw uncharge for root_mem_cgroup

2021-03-23 Thread Muchun Song
On Tue, Mar 23, 2021 at 11:04 PM Muchun Song wrote: > > The pages aren't accounted at the root level, so we cannot uncharge the > page to the memsw counter for the root memcg. Fix this. > > Fixes: 1f47b61fb407 ("mm: memcontrol: fix swap counter leak on swapout from &g

[PATCH] mm: memcontrol: fix memsw uncharge for root_mem_cgroup

2021-03-23 Thread Muchun Song
The pages aren't accounted at the root level, so we cannot uncharge the page to the memsw counter for the root memcg. Fix this. Fixes: 1f47b61fb407 ("mm: memcontrol: fix swap counter leak on swapout from offline cgroup") Signed-off-by: Muchun Song --- mm/memcontrol.c | 3 ++- 1

Re: [External] Re: [PATCH v5 1/7] mm: memcontrol: slab: fix obtain a reference to a freeing memcg

2021-03-23 Thread Muchun Song
On Mon, Mar 22, 2021 at 10:46 PM Johannes Weiner wrote: > > On Sat, Mar 20, 2021 at 12:38:14AM +0800, Muchun Song wrote: > > The rcu_read_lock/unlock only can guarantee that the memcg will not be > > freed, but it cannot guarantee the success of css_get (which is in the >

[PATCH v5 7/7] mm: memcontrol: move PageMemcgKmem to the scope of CONFIG_MEMCG_KMEM

2021-03-19 Thread Muchun Song
The page only can be marked as kmem when CONFIG_MEMCG_KMEM is enabled. So move PageMemcgKmem() to the scope of the CONFIG_MEMCG_KMEM. As a bonus, on !CONFIG_MEMCG_KMEM build some code can be compiled out. Signed-off-by: Muchun Song Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by

[PATCH v5 5/7] mm: memcontrol: use obj_cgroup APIs to charge kmem pages

2021-03-19 Thread Muchun Song
up. We can use the __page_objcg() to get the object cgroup associated with a kmem page. Or we can use page_memcg() to get the memory cgroup associated with a kmem page, but caller must ensure that the returned memcg won't be released (e.g. acquire the rcu_read_lock or css_set_lock). Signed-off-b

[PATCH v5 4/7] mm: memcontrol: change ug->dummy_page only if memcg changed

2021-03-19 Thread Muchun Song
Just like assignment to ug->memcg, we only need to update ug->dummy_page if memcg changed. So move it to there. This is a very small optimization. Signed-off-by: Muchun Song Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion

[PATCH v5 6/7] mm: memcontrol: inline __memcg_kmem_{un}charge() into obj_cgroup_{un}charge_pages()

2021-03-19 Thread Muchun Song
without any functionality changes. Signed-off-by: Muchun Song --- mm/memcontrol.c | 63 +++-- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 962499542531..249bf6b4d94c 100644 --- a/mm

[PATCH v5 3/7] mm: memcontrol: directly access page->memcg_data in mm/page_alloc.c

2021-03-19 Thread Muchun Song
whether the value of page->memcg_data is 0. So just directly access page->memcg_data here. Signed-off-by: Muchun Song Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt --- mm/page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_a

[PATCH v5 2/7] mm: memcontrol: introduce obj_cgroup_{un}charge_pages

2021-03-19 Thread Muchun Song
objcg stock. And obj_cgroup_{un}charge_pages() are introduced to charge in units of page level. In the later patch, we also can reuse those two helpers to charge or uncharge a number of kernel pages to a object cgroup. This is just a code movement without any functional changes. Signed-off-by: Muchun

[PATCH v5 1/7] mm: memcontrol: slab: fix obtain a reference to a freeing memcg

2021-03-19 Thread Muchun Song
ix this by holding a reference to the memcg which is passed to the __memcg_kmem_uncharge() before calling __memcg_kmem_uncharge(). Fixes: 3de7d4f25a74 ("mm: memcg/slab: optimize objcg stock draining") Signed-off-by: Muchun Song --- mm/memcontrol.c | 10 +- 1 file changed, 9 inse

[PATCH v5 0/7] Use obj_cgroup APIs to charge kmem pages

2021-03-19 Thread Muchun Song
ohannes and Shakeel). 3. Reduce the CC list to mm/memcg folks (Thanks to Johannes). 4. Introduce remote objcg charging APIs instead of convert "remote memcg charging APIs" to "remote objcg charging APIs". Muchun Song (7): mm: memcontrol: slab: fix obtain a reference to

Re: [External] Re: [PATCH v4 4/5] mm: memcontrol: use obj_cgroup APIs to charge kmem pages

2021-03-19 Thread Muchun Song
On Fri, Mar 19, 2021 at 9:59 PM Shakeel Butt wrote: > > On Thu, Mar 18, 2021 at 9:05 PM Muchun Song wrote: > > > > On Fri, Mar 19, 2021 at 11:40 AM Shakeel Butt wrote: > > > > > > On Thu, Mar 18, 2021 at 4:08 AM Muchun Song > > > wrote: >

Re: [External] Re: [PATCH v19 7/8] mm: hugetlb: add a kernel parameter hugetlb_free_vmemmap

2021-03-19 Thread Muchun Song
On Fri, Mar 19, 2021 at 4:59 PM Oscar Salvador wrote: > > On Mon, Mar 15, 2021 at 05:20:14PM +0800, Muchun Song wrote: > > --- a/arch/x86/mm/init_64.c > > +++ b/arch/x86/mm/init_64.c > > @@ -34,6 +34,7 @@ > > #include > > #include > > #include >

Re: [External] Re: [PATCH v4 4/5] mm: memcontrol: use obj_cgroup APIs to charge kmem pages

2021-03-18 Thread Muchun Song
On Fri, Mar 19, 2021 at 11:40 AM Shakeel Butt wrote: > > On Thu, Mar 18, 2021 at 4:08 AM Muchun Song wrote: > > > [...] > > > > +static inline struct mem_cgroup *get_obj_cgroup_memcg(struct obj_cgroup > > *objcg) > > I would prefer get_mem_cgroup_from

[PATCH v4 4/5] mm: memcontrol: use obj_cgroup APIs to charge kmem pages

2021-03-18 Thread Muchun Song
up. We can use the __page_objcg() to get the object cgroup associated with a kmem page. Or we can use page_memcg() to get the memory cgroup associated with a kmem page, but caller must ensure that the returned memcg won't be released (e.g. acquire the rcu_read_lock or css_set_lock). Signe

[PATCH v4 3/5] mm: memcontrol: change ug->dummy_page only if memcg changed

2021-03-18 Thread Muchun Song
Just like assignment to ug->memcg, we only need to update ug->dummy_page if memcg changed. So move it to there. This is a very small optimization. Signed-off-by: Muchun Song --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcon

[PATCH v4 5/5] mm: memcontrol: move PageMemcgKmem to the scope of CONFIG_MEMCG_KMEM

2021-03-18 Thread Muchun Song
The page only can be marked as kmem when CONFIG_MEMCG_KMEM is enabled. So move PageMemcgKmem() to the scope of the CONFIG_MEMCG_KMEM. As a bonus, on !CONFIG_MEMCG_KMEM build some code can be compiled out. Signed-off-by: Muchun Song Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by

[PATCH v4 2/5] mm: memcontrol: directly access page->memcg_data in mm/page_alloc.c

2021-03-18 Thread Muchun Song
whether the value of page->memcg_data is 0. So just directly access page->memcg_data here. Signed-off-by: Muchun Song --- mm/page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f10966e3b4a5..e5454b85a106 100644 --

<    1   2   3   4   5   6   7   8   9   10   >