From: "Michal Koutný" <mkoutny@suse.com>
To: David Finkel <davidf@vimeo.com>
Cc: Muchun Song <muchun.song@linux.dev>, Tejun Heo <tj@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
core-services@vimeo.com, Jonathan Corbet <corbet@lwn.net>,
Michal Hocko <mhocko@kernel.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Shuah Khan <shuah@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Zefan Li <lizefan.x@bytedance.com>,
cgroups@vger.kernel.org, linux-doc@vger.kernel.org,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
Waiman Long <longman@redhat.com>
Subject: Re: [PATCH v5 1/2] mm, memcg: cg2 memory{.swap,}.peak write handlers
Date: Fri, 26 Jul 2024 16:16:33 +0200 [thread overview]
Message-ID: <5xlwzzz3gs4rk5df32kfh7fx5ftj3a4iwryqxdb4c3oniuehwk@d5kum5xr4uw6> (raw)
In-Reply-To: <20240724161942.3448841-2-davidf@vimeo.com>
[-- Attachment #1: Type: text/plain, Size: 2000 bytes --]
Hello David.
On Wed, Jul 24, 2024 at 12:19:41PM GMT, David Finkel <davidf@vimeo.com> wrote:
> Writing a specific string to the memory.peak and memory.swap.peak
> pseudo-files reset the high watermark to the current usage for
> subsequent reads through that same fd.
This is elegant and nice work! (Caught my attention, so a few nits below.)
> --- a/include/linux/cgroup-defs.h
> +++ b/include/linux/cgroup-defs.h
> @@ -775,6 +775,11 @@ struct cgroup_subsys {
>
> extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem;
>
> +struct cgroup_of_peak {
> + long value;
Wouldn't this better be unsigned like watermarks themselves?
> + struct list_head list;
> +};
> --- a/include/linux/page_counter.h
> +++ b/include/linux/page_counter.h
> @@ -26,6 +26,7 @@ struct page_counter {
> atomic_long_t children_low_usage;
>
> unsigned long watermark;
> + unsigned long local_watermark;
At first, I struggled understading what the locality is (when the local
value is actually in of_peak), IIUC, it's more about temporal position.
I'd suggest a comment (if not a name) like:
/* latest reset watermark */
> + unsigned long local_watermark;
> +
> + /* User wants global or local peak? */
> + if (fd_peak == -1UL)
Here you use typed -1UL but not in other places. (Maybe define an
explicit macro value ((unsigned long)-1)?)
> +static ssize_t peak_write(struct kernfs_open_file *of, char *buf, size_t nbytes,
> + loff_t off, struct page_counter *pc,
> + struct list_head *watchers)
> +{
...
> + list_for_each_entry(peer_ctx, watchers, list)
> + if (usage > peer_ctx->value)
> + peer_ctx->value = usage;
The READ_ONCE() in peak_show() suggests it could be WRITE_ONCE() here.
> +
> + /* initial write, register watcher */
> + if (ofp->value == -1)
> + list_add(&ofp->list, watchers);
> +
> + ofp->value = usage;
Move the registration before iteration and drop the extra assignment?
Thanks,
Michal
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2024-07-26 14:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 16:19 David Finkel
2024-07-24 16:19 ` David Finkel
2024-07-26 14:16 ` Michal Koutný [this message]
2024-07-29 13:34 ` David Finkel
2024-07-24 16:19 ` [PATCH v5 2/2] mm, memcg: cg2 memory{.swap,}.peak write tests David Finkel
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=5xlwzzz3gs4rk5df32kfh7fx5ftj3a4iwryqxdb4c3oniuehwk@d5kum5xr4uw6 \
--to=mkoutny@suse.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=core-services@vimeo.com \
--cc=davidf@vimeo.com \
--cc=hannes@cmpxchg.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=tj@kernel.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