From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Pu Lehui <pulehui@huaweicloud.com>
Cc: mhiramat@kernel.org, oleg@redhat.com, peterz@infradead.org,
akpm@linux-foundation.org, Liam.Howlett@oracle.com,
vbabka@suse.cz, jannh@google.com, pfalcato@suse.de,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, pulehui@huawei.com
Subject: Re: [PATCH v1 3/4] selftests/mm: Extract read_sysfs and write_sysfs into vm_util
Date: Fri, 30 May 2025 12:48:44 +0100 [thread overview]
Message-ID: <f1dfdffa-23b3-4d4a-8912-3a35e65963e4@lucifer.local> (raw)
In-Reply-To: <20250529155650.4017699-4-pulehui@huaweicloud.com>
On Thu, May 29, 2025 at 03:56:49PM +0000, Pu Lehui wrote:
> From: Pu Lehui <pulehui@huawei.com>
>
> Extract read_sysfs and write_sysfs into vm_util. Meanwhile, rename
> the function in thuge-gen that has the same name as read_sysfs.
Nice!
>
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
> tools/testing/selftests/mm/ksm_tests.c | 32 ++--------------------
> tools/testing/selftests/mm/thuge-gen.c | 6 ++--
> tools/testing/selftests/mm/vm_util.c | 38 ++++++++++++++++++++++++++
> tools/testing/selftests/mm/vm_util.h | 2 ++
> 4 files changed, 45 insertions(+), 33 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
> index dcdd5bb20f3d..e80deac1436b 100644
> --- a/tools/testing/selftests/mm/ksm_tests.c
> +++ b/tools/testing/selftests/mm/ksm_tests.c
> @@ -58,40 +58,12 @@ int debug;
>
> static int ksm_write_sysfs(const char *file_path, unsigned long val)
> {
> - FILE *f = fopen(file_path, "w");
> -
> - if (!f) {
> - fprintf(stderr, "f %s\n", file_path);
> - perror("fopen");
> - return 1;
> - }
> - if (fprintf(f, "%lu", val) < 0) {
> - perror("fprintf");
> - fclose(f);
> - return 1;
> - }
> - fclose(f);
> -
> - return 0;
> + return write_sysfs(file_path, val);
> }
>
> static int ksm_read_sysfs(const char *file_path, unsigned long *val)
> {
> - FILE *f = fopen(file_path, "r");
> -
> - if (!f) {
> - fprintf(stderr, "f %s\n", file_path);
> - perror("fopen");
> - return 1;
> - }
> - if (fscanf(f, "%lu", val) != 1) {
> - perror("fscanf");
> - fclose(f);
> - return 1;
> - }
> - fclose(f);
> -
> - return 0;
> + return read_sysfs(file_path, val);
> }
>
> static void ksm_print_sysfs(void)
> diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c
> index a41bc1234b37..95b6f043a3cb 100644
> --- a/tools/testing/selftests/mm/thuge-gen.c
> +++ b/tools/testing/selftests/mm/thuge-gen.c
> @@ -77,7 +77,7 @@ void show(unsigned long ps)
> system(buf);
> }
>
> -unsigned long read_sysfs(int warn, char *fmt, ...)
> +unsigned long thuge_read_sysfs(int warn, char *fmt, ...)
> {
I wonder if we could update these to use the newly shared functions?
Not a big deal though, perhaps a bit out of scope here, more of a nice-to-have.
> char *line = NULL;
> size_t linelen = 0;
> @@ -106,7 +106,7 @@ unsigned long read_sysfs(int warn, char *fmt, ...)
>
> unsigned long read_free(unsigned long ps)
> {
> - return read_sysfs(ps != getpagesize(),
> + return thuge_read_sysfs(ps != getpagesize(),
> "/sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages",
> ps >> 10);
> }
> @@ -195,7 +195,7 @@ void find_pagesizes(void)
> }
> globfree(&g);
>
> - if (read_sysfs(0, "/proc/sys/kernel/shmmax") < NUM_PAGES * largest)
> + if (thuge_read_sysfs(0, "/proc/sys/kernel/shmmax") < NUM_PAGES * largest)
> ksft_exit_fail_msg("Please do echo %lu > /proc/sys/kernel/shmmax",
> largest * NUM_PAGES);
>
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index 1357e2d6a7b6..d899c272e0ee 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -486,3 +486,41 @@ int close_procmap(struct procmap_fd *procmap)
> {
> return close(procmap->fd);
> }
> +
> +int write_sysfs(const char *file_path, unsigned long val)
> +{
> + FILE *f = fopen(file_path, "w");
> +
> + if (!f) {
> + fprintf(stderr, "f %s\n", file_path);
> + perror("fopen");
> + return 1;
> + }
> + if (fprintf(f, "%lu", val) < 0) {
> + perror("fprintf");
> + fclose(f);
> + return 1;
> + }
> + fclose(f);
> +
> + return 0;
> +}
> +
> +int read_sysfs(const char *file_path, unsigned long *val)
> +{
> + FILE *f = fopen(file_path, "r");
> +
> + if (!f) {
> + fprintf(stderr, "f %s\n", file_path);
> + perror("fopen");
> + return 1;
> + }
> + if (fscanf(f, "%lu", val) != 1) {
> + perror("fscanf");
> + fclose(f);
> + return 1;
> + }
> + fclose(f);
> +
> + return 0;
> +}
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 9211ba640d9c..f84c7c4680ea 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -87,6 +87,8 @@ int open_procmap(pid_t pid, struct procmap_fd *procmap_out);
> int query_procmap(struct procmap_fd *procmap);
> bool find_vma_procmap(struct procmap_fd *procmap, void *address);
> int close_procmap(struct procmap_fd *procmap);
> +int write_sysfs(const char *file_path, unsigned long val);
> +int read_sysfs(const char *file_path, unsigned long *val);
>
> static inline int open_self_procmap(struct procmap_fd *procmap_out)
> {
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-05-30 11:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-29 15:56 [PATCH v1 0/4] Fix uprobe pte be overwritten when expanding vma Pu Lehui
2025-05-29 15:56 ` [PATCH v1 1/4] mm: " Pu Lehui
2025-05-30 9:28 ` Lorenzo Stoakes
2025-05-30 18:51 ` David Hildenbrand
2025-06-02 11:55 ` Lorenzo Stoakes
2025-06-02 12:26 ` David Hildenbrand
2025-06-02 13:26 ` Lorenzo Stoakes
2025-06-02 16:28 ` David Hildenbrand
2025-06-02 17:01 ` Lorenzo Stoakes
2025-06-03 12:16 ` David Hildenbrand
2025-06-04 1:51 ` Andrew Morton
2025-05-29 15:56 ` [PATCH v1 2/4] mm: Expose abnormal new_pte during move_ptes Pu Lehui
2025-05-29 19:19 ` Andrew Morton
2025-05-30 1:24 ` Pu Lehui
2025-05-30 3:47 ` Andrew Morton
2025-05-30 10:21 ` Lorenzo Stoakes
2025-05-30 16:44 ` Oleg Nesterov
2025-05-29 15:56 ` [PATCH v1 3/4] selftests/mm: Extract read_sysfs and write_sysfs into vm_util Pu Lehui
2025-05-30 11:48 ` Lorenzo Stoakes [this message]
2025-06-03 7:17 ` Pu Lehui
2025-06-04 2:36 ` Andrew Morton
2025-06-04 8:21 ` Pu Lehui
2025-05-29 15:56 ` [PATCH v1 4/4] selftests/mm: Add test about uprobe pte be orphan during vma merge Pu Lehui
2025-05-30 11:32 ` Lorenzo Stoakes
2025-06-03 7:08 ` Pu Lehui
2025-06-03 9:56 ` Lorenzo Stoakes
2025-06-10 10:37 ` Aishwarya
2025-06-10 11:27 ` Pedro Falcato
2025-06-10 11:34 ` Mark Brown
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=f1dfdffa-23b3-4d4a-8912-3a35e65963e4@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhiramat@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=pulehui@huawei.com \
--cc=pulehui@huaweicloud.com \
--cc=stable@vger.kernel.org \
--cc=vbabka@suse.cz \
/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).