From: Shakeel Butt <shakeel.butt@linux.dev>
To: Chen Ridong <chenridong@huaweicloud.com>
Cc: akpm@linux-foundation.org, mhocko@kernel.org, hannes@cmpxchg.org,
yosryahmed@google.com, roman.gushchin@linux.dev,
muchun.song@linux.dev, davidf@vimeo.com, vbabka@suse.cz,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, chenridong@huawei.com,
wangweiyang2@huawei.com
Subject: Re: [next -v1 4/5] memcg: factor out the __refill_obj_stock function
Date: Tue, 17 Dec 2024 10:19:38 -0800 [thread overview]
Message-ID: <q7k5vqzeit4ib6joowtib6mlpwu2zdnrzse5kx44wx7jhmb6ta@w6deef6omz3d> (raw)
In-Reply-To: <20241206013512.2883617-5-chenridong@huaweicloud.com>
On Fri, Dec 06, 2024 at 01:35:11AM +0000, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> Factor out the '__refill_obj_stock' function to make the code more
> cohesive.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> mm/memcontrol.c | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index f977e0be1c04..0c9331d7b606 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2697,6 +2697,21 @@ void __memcg_kmem_uncharge_page(struct page *page, int order)
> obj_cgroup_put(objcg);
> }
>
> +/* If the cached_objcg was refilled, return true; otherwise, return false */
> +static bool __refill_obj_stock(struct memcg_stock_pcp *stock,
> + struct obj_cgroup *objcg, struct obj_cgroup **old_objcg)
> +{
> + if (READ_ONCE(stock->cached_objcg) != objcg) {
Keep the above check in the calling functions and make this a void
function. Also I think we need a better name.
> + *old_objcg = drain_obj_stock(stock);
> + obj_cgroup_get(objcg);
> + stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes)
> + ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0;
> + WRITE_ONCE(stock->cached_objcg, objcg);
> + return true;
> + }
> + return false;
> +}
> +
> static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat,
> enum node_stat_item idx, int nr)
> {
> @@ -2713,12 +2728,7 @@ static void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat,
> * accumulating over a page of vmstat data or when pgdat or idx
> * changes.
> */
> - if (READ_ONCE(stock->cached_objcg) != objcg) {
> - old = drain_obj_stock(stock);
> - obj_cgroup_get(objcg);
> - stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes)
> - ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0;
> - WRITE_ONCE(stock->cached_objcg, objcg);
> + if (__refill_obj_stock(stock, objcg, &old)) {
> stock->cached_pgdat = pgdat;
> } else if (stock->cached_pgdat != pgdat) {
> /* Flush the existing cached vmstat data */
> @@ -2871,14 +2881,9 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes,
> local_lock_irqsave(&memcg_stock.stock_lock, flags);
>
> stock = this_cpu_ptr(&memcg_stock);
> - if (READ_ONCE(stock->cached_objcg) != objcg) { /* reset if necessary */
> - old = drain_obj_stock(stock);
> - obj_cgroup_get(objcg);
> - WRITE_ONCE(stock->cached_objcg, objcg);
> - stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes)
> - ? atomic_xchg(&objcg->nr_charged_bytes, 0) : 0;
> + if (__refill_obj_stock(stock, objcg, &old))
> allow_uncharge = true; /* Allow uncharge when objcg changes */
> - }
> +
> stock->nr_bytes += nr_bytes;
>
> if (allow_uncharge && (stock->nr_bytes > PAGE_SIZE)) {
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-12-17 18:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 1:35 [next -v1 0/5] Some cleanup for memcg Chen Ridong
2024-12-06 1:35 ` [next -v1 1/5] memcg: use OFP_PEAK_UNSET instead of -1 Chen Ridong
2024-12-17 12:27 ` Michal Koutný
2024-12-17 16:55 ` David Finkel
2024-12-17 17:47 ` Shakeel Butt
2024-12-06 1:35 ` [next -v1 2/5] memcg: call the free function when allocation of pn fails Chen Ridong
2024-12-17 12:27 ` Michal Koutný
2024-12-17 17:47 ` Shakeel Butt
2024-12-06 1:35 ` [next -v1 3/5] memcg: simplify the mem_cgroup_update_lru_size function Chen Ridong
2024-12-06 5:33 ` Yu Zhao
2024-12-06 6:40 ` Chen Ridong
2024-12-06 8:24 ` Hugh Dickins
2024-12-06 10:02 ` Chen Ridong
2024-12-06 21:20 ` Shakeel Butt
2024-12-10 11:35 ` Chen Ridong
2024-12-06 1:35 ` [next -v1 4/5] memcg: factor out the __refill_obj_stock function Chen Ridong
2024-12-17 18:19 ` Shakeel Butt [this message]
2024-12-19 1:54 ` Chen Ridong
2024-12-06 1:35 ` [next -v1 5/5] memcg: factor out stat(event)/stat_local(event_local) reading functions Chen Ridong
2024-12-20 9:51 ` Chen Ridong
2024-12-14 1:47 ` [next -v1 0/5] Some cleanup for memcg 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=q7k5vqzeit4ib6joowtib6mlpwu2zdnrzse5kx44wx7jhmb6ta@w6deef6omz3d \
--to=shakeel.butt@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=muchun.song@linux.dev \
--cc=roman.gushchin@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