From: Roman Gushchin <roman.gushchin@linux.dev>
To: Chen Ridong <chenridong@huaweicloud.com>
Cc: akpm@linux-foundation.org, mhocko@kernel.org, hannes@cmpxchg.org,
yosryahmed@google.com, shakeel.butt@linux.dev,
muchun.song@linux.dev, davidf@vimeo.com, vbabka@suse.cz,
mkoutny@suse.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
chenridong@huawei.com, wangweiyang2@huawei.com
Subject: Re: [PATCH -v2 next 4/4] memcg: factor out stat(event)/stat_local(event_local) reading functions
Date: Tue, 14 Jan 2025 18:45:20 +0000 [thread overview]
Message-ID: <Z4awwH3cbhjl0H4W@google.com> (raw)
In-Reply-To: <20250114122519.1404275-5-chenridong@huaweicloud.com>
On Tue, Jan 14, 2025 at 12:25:19PM +0000, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> The only difference between 'lruvec_page_state' and
> 'lruvec_page_state_local' is that they read 'state' and 'state_local',
> respectively. Factor out an inner functions to make the code more concise.
> Do the same for reading 'memcg_page_stat' and 'memcg_events'.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> mm/memcontrol.c | 72 +++++++++++++++++++++----------------------------
> 1 file changed, 30 insertions(+), 42 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index b10e0a8f3375..14541610cad0 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -375,7 +375,8 @@ struct lruvec_stats {
> long state_pending[NR_MEMCG_NODE_STAT_ITEMS];
> };
>
> -unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx)
> +static unsigned long __lruvec_page_state(struct lruvec *lruvec,
> + enum node_stat_item idx, bool local)
> {
> struct mem_cgroup_per_node *pn;
> long x;
> @@ -389,7 +390,8 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx)
> return 0;
>
> pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
> - x = READ_ONCE(pn->lruvec_stats->state[i]);
> + x = local ? READ_ONCE(pn->lruvec_stats->state_local[i]) :
> + READ_ONCE(pn->lruvec_stats->state[i]);
> #ifdef CONFIG_SMP
> if (x < 0)
> x = 0;
> @@ -397,27 +399,16 @@ unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx)
> return x;
> }
>
> +
> +unsigned long lruvec_page_state(struct lruvec *lruvec, enum node_stat_item idx)
> +{
> + return __lruvec_page_state(lruvec, idx, false);
> +}
I'd move these wrapper function definitions to memcontrol.h and make them
static inline.
Other than that, lgtm.
Thank you!
next prev parent reply other threads:[~2025-01-14 18:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-14 12:25 [PATCH -v2 next 0/4] Some cleanup for memcg Chen Ridong
2025-01-14 12:25 ` [PATCH -v2 next 1/4] memcg: use OFP_PEAK_UNSET instead of -1 Chen Ridong
2025-01-14 18:36 ` Roman Gushchin
2025-01-14 12:25 ` [PATCH -v2 next 2/4] memcg: call the free function when allocation of pn fails Chen Ridong
2025-01-14 18:36 ` Roman Gushchin
2025-01-14 12:25 ` [PATCH -v2 next 3/4] memcg: factor out the replace_stock_objcg function Chen Ridong
2025-01-14 18:39 ` Roman Gushchin
2025-01-16 0:56 ` Shakeel Butt
2025-01-14 12:25 ` [PATCH -v2 next 4/4] memcg: factor out stat(event)/stat_local(event_local) reading functions Chen Ridong
2025-01-14 18:45 ` Roman Gushchin [this message]
2025-01-16 0:57 ` Shakeel Butt
2025-01-16 1:21 ` Chen Ridong
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=Z4awwH3cbhjl0H4W@google.com \
--to=roman.gushchin@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huawei.com \
--cc=chenridong@huaweicloud.com \
--cc=davidf@vimeo.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@suse.cz \
--cc=wangweiyang2@huawei.com \
--cc=yosryahmed@google.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