From: Shakeel Butt <shakeelb@google.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Yang Shi <shy828301@gmail.com>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
Naresh Kamboju <naresh.kamboju@linaro.org>,
linux-mm <linux-mm@kvack.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mgorman@techsingularity.net>,
Michal Hocko <mhocko@kernel.org>,
Dan Schatzberg <schatzberg.dan@gmail.com>
Subject: Re: fs/buffer.c: WARNING: alloc_page_buffers while mke2fs
Date: Tue, 3 Mar 2020 15:22:00 -0800 [thread overview]
Message-ID: <CALvZod4=7EoJ=JiCnOfnM1tG7zV72Usksujnv9Z7OAdhrYtJRA@mail.gmail.com> (raw)
In-Reply-To: <20200303210632.GC68565@cmpxchg.org>
On Tue, Mar 3, 2020 at 1:06 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> On Tue, Mar 03, 2020 at 12:40:33PM -0800, Shakeel Butt wrote:
> > On Tue, Mar 3, 2020 at 12:26 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
> > > From e0e5ace069af5a36e41eafe3bf21a67966127c04 Mon Sep 17 00:00:00 2001
> > > From: Johannes Weiner <hannes@cmpxchg.org>
> > > Date: Tue, 3 Mar 2020 15:15:39 -0500
> > > Subject: [PATCH] mm: support nesting memalloc_use_memcg()
> > >
> > > The memalloc_use_memcg() function to override the default memcg
> > > accounting context currently doesn't nest. But the patches to make the
> > > loop driver cgroup-aware will end up nesting:
> > >
> > > [ 98.137605] alloc_page_buffers+0x210/0x288
> > > [ 98.141799] __getblk_gfp+0x1d4/0x400
> > > [ 98.145475] ext4_read_block_bitmap_nowait+0x148/0xbc8
> > > [ 98.150628] ext4_mb_init_cache+0x25c/0x9b0
> > > [ 98.154821] ext4_mb_init_group+0x270/0x390
> > > [ 98.159014] ext4_mb_good_group+0x264/0x270
> > > [ 98.163208] ext4_mb_regular_allocator+0x480/0x798
> > > [ 98.168011] ext4_mb_new_blocks+0x958/0x10f8
> > > [ 98.172294] ext4_ext_map_blocks+0xec8/0x1618
> > > [ 98.176660] ext4_map_blocks+0x1b8/0x8a0
> > > [ 98.180592] ext4_writepages+0x830/0xf10
> > > [ 98.184523] do_writepages+0xb4/0x198
> > > [ 98.188195] __filemap_fdatawrite_range+0x170/0x1c8
> > > [ 98.193086] filemap_write_and_wait_range+0x40/0xb0
> > > [ 98.197974] ext4_punch_hole+0x4a4/0x660
> > > [ 98.201907] ext4_fallocate+0x294/0x1190
> > > [ 98.205839] loop_process_work+0x690/0x1100
> > > [ 98.210032] loop_workfn+0x2c/0x110
> > > [ 98.213529] process_one_work+0x3e0/0x648
> > > [ 98.217546] worker_thread+0x70/0x670
> > > [ 98.221217] kthread+0x1b8/0x1c0
> > > [ 98.224452] ret_from_fork+0x10/0x18
> > >
> > > where loop_process_work() sets the memcg override to the memcg that
> > > submitted the IO request, and alloc_page_buffers() sets the override
> > > to the memcg that instantiated the cache page, which may differ.
> > >
> > > Make memalloc_use_memcg() return the old memcg and convert existing
> > > users to a stacking model. Delete the unused memalloc_unuse_memcg().
> > >
> > > Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> >
> > Reviewed-by: Shakeel Butt <shakeelb@google.com>
>
> Thanks Shakeel
>
> > > @@ -316,31 +316,26 @@ static inline void memalloc_nocma_restore(unsigned int flags)
> > > * __GFP_ACCOUNT allocations till the end of the scope will be charged to the
> > > * given memcg.
> > > *
> > > - * NOTE: This function is not nesting safe.
> > > - */
> > > -static inline void memalloc_use_memcg(struct mem_cgroup *memcg)
> > > -{
> > > - WARN_ON_ONCE(current->active_memcg);
> > > - current->active_memcg = memcg;
> > > -}
> > > -
> > > -/**
> > > - * memalloc_unuse_memcg - Ends the remote memcg charging scope.
> > > + * NOTE: This function can nest. Users must save the return value and
> > > + * reset the previous value after their own charging scope is over:
> >
> > Should we mention that this is still not irq safe? At the moment other
> > than skmem we don't do memcg charging in the interrupt and skmem has a
> > memcg already associated with it. Maybe in future there might be a
> > case where we want a specific memcg be charged for kmem in the
> > interrupt context. Until then we can mark that this function should
> > not be used in interrupt.
>
> Is it actually unsafe? It's not an RMW operation, being interrupted
> doesn't corrupt its state.
>
> I.e. this is safe:
>
> process: interrupt:
> old = current->active_memcg
> old = current->active_memcg
> current->active_memcg = new
> allocate
> current->active_memcg = old
> current->active_memcg = new
> return old
>
> This is safe as well:
>
> process: interrupt:
> old = current->active_memcg
> current->active_memcg = new
> old = current->active_memcg
> current->active_memcg = new
> allocate
> current->active_memcg = old
> return old
Yes, you are right. Thanks for the explanation.
next prev parent reply other threads:[~2020-03-03 23:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CA+G9fYs==eMEmY_OpdhyCHO_1Z5f_M8CAQQTh-AOf5xAvBHKAQ@mail.gmail.com>
2020-03-03 10:52 ` fs/buffer.c: WARNING: alloc_page_buffers while mke2fs Tetsuo Handa
2020-03-03 17:47 ` Yang Shi
2020-03-03 18:14 ` Shakeel Butt
2020-03-03 18:34 ` Yang Shi
2020-03-03 19:42 ` Yang Shi
2020-03-03 20:26 ` Shakeel Butt
2020-03-03 20:33 ` Johannes Weiner
2020-03-03 20:59 ` Yang Shi
2020-03-03 20:26 ` Johannes Weiner
2020-03-03 20:40 ` Shakeel Butt
2020-03-03 21:06 ` Johannes Weiner
2020-03-03 23:22 ` Shakeel Butt [this message]
2020-03-04 0:29 ` Andrew Morton
2020-04-20 16:41 ` Shakeel Butt
2020-04-20 22:45 ` Dan Schatzberg
2020-04-21 5:02 ` Naresh Kamboju
2020-03-03 20:57 ` Yang Shi
2020-03-03 18:40 ` Naresh Kamboju
2020-03-03 19:04 ` Yang Shi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALvZod4=7EoJ=JiCnOfnM1tG7zV72Usksujnv9Z7OAdhrYtJRA@mail.gmail.com' \
--to=shakeelb@google.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=naresh.kamboju@linaro.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=schatzberg.dan@gmail.com \
--cc=shy828301@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).