From: Yosry Ahmed <yosryahmed@google.com>
To: Hugh Dickins <hughd@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeelb@google.com>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Naoya Horiguchi <naoya.horiguchi@nec.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org, cgroups@vger.kernel.org
Subject: Re: [PATCH] memcg: page_cgroup_ino() get memcg from compound_head(page)
Date: Tue, 14 Mar 2023 19:37:13 -0700 [thread overview]
Message-ID: <CAJD7tkayQPpqxuh4Jqn0m=w2WhFsk2_NAcevdmcE9vvLnLm3Bw@mail.gmail.com> (raw)
In-Reply-To: <20230313083452.1319968-1-yosryahmed@google.com>
Somehow I was stupid enough to forget CC'ing Matthew :)
+Matthew Wilcox
On Mon, Mar 13, 2023 at 1:34 AM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> From: Hugh Dickins <hughd@google.com>
>
> In a kernel with added WARN_ON_ONCE(PageTail) in page_memcg_check(), we
> observed a warning from page_cgroup_ino() when reading
> /proc/kpagecgroup. This warning was added to catch fragile reads of
> a page memcg. Make page_cgroup_ino() get memcg from compound_head(page):
> that gives it the correct memcg for each subpage of a compound page,
> so is the right fix.
>
> I dithered between the right fix and the safer "fix": it's unlikely but
> conceivable that some userspace has learnt that /proc/kpagecgroup gives
> no memcg on tail pages, and compensates for that in some (racy) way: so
> continuing to give no memcg on tails, without warning, might be safer.
>
> But hwpoison_filter_task(), the only other user of page_cgroup_ino(),
> persuaded me. It looks as if it currently leaves out tail pages of the
> selected memcg, by mistake: whereas hwpoison_inject() uses compound_head()
> and expects the tails to be included. So hwpoison testing coverage has
> probably been restricted by the wrong output from page_cgroup_ino() (if
> that memcg filter is used at all): in the short term, it might be safer
> not to enable wider coverage there, but long term we would regret that.
>
> Signed-off-by: Hugh Dickins <hughd@google.com>
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
> ---
>
> (Yosry: Alternatively, we could modify page_memcg_check() to do
> page_folio() like its sibling page_memcg(), as page_cgroup_ino() is the
> only remaining caller other than print_page_owner_memcg(); and it already
> excludes pages that have page->memcg_data = 0)
>
> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 5abffe6f8389..e3a55295725e 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -395,7 +395,7 @@ ino_t page_cgroup_ino(struct page *page)
> unsigned long ino = 0;
>
> rcu_read_lock();
> - memcg = page_memcg_check(page);
> + memcg = page_memcg_check(compound_head(page));
>
> while (memcg && !(memcg->css.flags & CSS_ONLINE))
> memcg = parent_mem_cgroup(memcg);
> --
> 2.40.0.rc1.284.g88254d51c5-goog
>
prev parent reply other threads:[~2023-03-15 2:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 8:34 Yosry Ahmed
2023-03-13 19:44 ` Andrew Morton
2023-03-13 21:08 ` Yosry Ahmed
2023-03-14 10:02 ` Michal Hocko
2023-03-14 19:45 ` Yosry Ahmed
2023-03-14 19:46 ` Yosry Ahmed
2023-03-15 2:34 ` Roman Gushchin
2023-03-15 2:39 ` Yosry Ahmed
2023-03-15 3:06 ` Waiman Long
2023-03-15 3:10 ` Yosry Ahmed
2023-03-15 3:33 ` Waiman Long
2023-03-15 3:40 ` Yosry Ahmed
2023-03-15 4:54 ` Matthew Wilcox
2023-03-15 7:04 ` Yosry Ahmed
2023-03-15 12:19 ` Matthew Wilcox
2023-03-15 21:43 ` Yosry Ahmed
2023-03-16 0:09 ` Waiman Long
2023-03-16 0:25 ` Yosry Ahmed
2023-03-16 3:07 ` Matthew Wilcox
2023-03-16 3:16 ` Yosry Ahmed
2023-03-22 6:52 ` Yosry Ahmed
2023-03-14 10:00 ` Michal Hocko
2023-03-15 2:37 ` Yosry Ahmed [this message]
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='CAJD7tkayQPpqxuh4Jqn0m=w2WhFsk2_NAcevdmcE9vvLnLm3Bw@mail.gmail.com' \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=linmiaohe@huawei.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=naoya.horiguchi@nec.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
--cc=vdavydov.dev@gmail.com \
--cc=willy@infradead.org \
/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