From: David Hildenbrand <david@redhat.com>
To: Yang Yang <yang.yang29@zte.com.cn>, akpm@linux-foundation.org
Cc: imbrenda@linux.ibm.com, jiang.xuexin@zte.com.cn,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
ran.xiaokai@zte.com.cn, xu.xin.sc@gmail.com, xu.xin16@zte.com.cn
Subject: Re: [PATCH v8 6/6] selftest: add a testcase of ksm zero pages
Date: Tue, 23 May 2023 12:15:02 +0200 [thread overview]
Message-ID: <c496e8b8-e0d4-a2d6-5cce-e336904e15ae@redhat.com> (raw)
In-Reply-To: <20230522105433.4277-1-yang.yang29@zte.com.cn>
On 22.05.23 12:54, Yang Yang wrote:
> From: xu xin <xu.xin16@zte.com.cn>
>
> Add a function test_unmerge_zero_page() to test the functionality on
> unsharing and counting ksm-placed zero pages and counting of this patch
> series.
>
> test_unmerge_zero_page() actually contains three subjct test objects:
> (1) whether the count of ksm zero pages can update correctly after merging;
> (2) whether the count of ksm zero pages can update correctly after
> unmerging;
> (3) whether ksm zero pages are really unmerged.
>
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Xuexin Jiang <jiang.xuexin@zte.com.cn>
> Reviewed-by: Xiaokai Ran <ran.xiaokai@zte.com.cn>
> Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
> ---
> tools/testing/selftests/mm/ksm_functional_tests.c | 75 +++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index 26853badae70..9b7fb94ed64f 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -29,6 +29,8 @@
>
> static int ksm_fd;
> static int ksm_full_scans_fd;
> +static int ksm_zero_pages_fd;
> +static int ksm_use_zero_pages_fd;
> static int pagemap_fd;
> static size_t pagesize;
>
> @@ -59,6 +61,21 @@ static bool range_maps_duplicates(char *addr, unsigned long size)
> return false;
> }
>
> +static long get_ksm_zero_pages(void)
> +{
> + char buf[20];
> + ssize_t read_size;
> + unsigned long ksm_zero_pages;
> +
I would add:
if (!ksm_zero_pages_fd)
return 0;
> + read_size = pread(ksm_zero_pages_fd, buf, sizeof(buf) - 1, 0);
> + if (read_size < 0)
> + return -errno;
> + buf[read_size] = 0;
> + ksm_zero_pages = strtol(buf, NULL, 10);
> +
> + return ksm_zero_pages;
> +}
> +
> static long ksm_get_full_scans(void)
> {
> char buf[10];
> @@ -159,6 +176,61 @@ static void test_unmerge(void)
> munmap(map, size);
> }
>
> +static inline unsigned long expected_ksm_pages(unsigned long mergeable_size)
> +{
> + return mergeable_size / pagesize;
> +}
I suggest to just inline that.
> +
> +static void test_unmerge_zero_pages(void)
> +{
> + const unsigned int size = 2 * MiB;
> + char *map;
> + unsigned long pages_expected;
> +
> + ksft_print_msg("[RUN] %s\n", __func__);
> +
> + /* Confirm the interfaces*/
Missing space at the end of the comment. But I suggest to just drop this comment.
> + if (ksm_zero_pages_fd < 0) {
> + ksft_test_result_skip("open(\"/sys/kernel/mm/ksm/ksm_zero_pages\") failed\n");
> + return;
> + }
> + if (ksm_use_zero_pages_fd < 0) {
> + ksft_test_result_skip("open \"/sys/kernel/mm/ksm/use_zero_pages\" failed\n");
> + return;
> + }
> + if (write(ksm_use_zero_pages_fd, "1", 1) != 1) {
> + ksft_test_result_skip("write \"/sys/kernel/mm/ksm/use_zero_pages\" failed\n");
> + return;
> + }
> +
> + /* Mmap zero pages*/
Missing space at the end of the comment
> + map = mmap_and_merge_range(0x00, size, false);
> + if (map == MAP_FAILED)
> + return;
> +
> + /* Check if ksm_zero_pages can be update correctly after merging */
> + pages_expected = expected_ksm_pages(size);
> + ksft_test_result(pages_expected == get_ksm_zero_pages(),
> + "The count zero_page_sharing was updated after merging\n");
> +
Make sure that the number of tests (ksft_test_result*() invocations) is on any return
path as expected (e.g., 1).
if (pages_expected != get_ksm_zero_pages) {
ksft_test_result_pass("'zero_page_sharing' updated after merging\n");
goto unmap;
}
> + /* try to unmerge half of the region */
> + if (madvise(map, size / 2, MADV_UNMERGEABLE)) {
> + ksft_test_result_fail("MADV_UNMERGEABLE failed\n");
> + goto unmap;
> + }
> +
> + /* Check if ksm_zero_pages can be update correctly after unmerging */
> + pages_expected = expected_ksm_pages(size / 2);
Just do
pages_expected /= 2;
> + ksft_test_result(pages_expected == get_ksm_zero_pages(),
> + "The count zero_page_sharing was updated after unmerging\n");
> +
if (pages_expected == get_ksm_zero_pages()) {
ksft_test_result_pass("'zero_page_sharing' updated after unmerging\n");
goto unmap;
}
> + /* Check if ksm zero pages are really unmerged */
> + ksft_test_result(!range_maps_duplicates(map, size / 2),
> + "KSM zero pages were unmerged\n");
> +unmap:
> + munmap(map, size);
> +}
> +
> static void test_unmerge_discarded(void)
> {
> const unsigned int size = 2 * MiB;
> @@ -379,8 +451,11 @@ int main(int argc, char **argv)
> pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
> if (pagemap_fd < 0)
> ksft_exit_skip("open(\"/proc/self/pagemap\") failed\n");
> + ksm_zero_pages_fd = open("/sys/kernel/mm/ksm/ksm_zero_pages", O_RDONLY);
> + ksm_use_zero_pages_fd = open("/sys/kernel/mm/ksm/use_zero_pages", O_RDWR);
>
> test_unmerge();
> + test_unmerge_zero_pages();
> test_unmerge_discarded();
> #ifdef __NR_userfaultfd
> test_unmerge_uffd_wp();
You should need something like this:
diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
index 26853badae70..00df05bfc3a3 100644
--- a/tools/testing/selftests/mm/ksm_functional_tests.c
+++ b/tools/testing/selftests/mm/ksm_functional_tests.c
@@ -358,7 +358,7 @@ static void test_prctl_unmerge(void)
int main(int argc, char **argv)
{
- unsigned int tests = 5;
+ unsigned int tests = 6;
int err;
#ifdef __NR_userfaultfd
--
Thanks,
David / dhildenb
prev parent reply other threads:[~2023-05-23 10:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-22 10:42 [PATCH v8 0/6] ksm: support tracking KSM-placed zero-pages yang.yang29
[not found] ` <20230522104908.3999-1-yang.yang29@zte.com.cn>
2023-05-23 9:41 ` [PATCH v8 1/6] ksm: support unsharing KSM-placed zero pages David Hildenbrand
2023-05-23 13:55 ` xu xin
2023-05-23 13:57 ` xu xin
2023-05-23 14:00 ` David Hildenbrand
2023-05-23 14:11 ` xu xin
[not found] ` <20230522105229.4066-1-yang.yang29@zte.com.cn>
2023-05-23 9:47 ` [PATCH v8 2/6] ksm: count all zero pages placed by KSM David Hildenbrand
2023-05-23 9:51 ` David Hildenbrand
[not found] ` <20230522105305.4126-1-yang.yang29@zte.com.cn>
2023-05-23 9:55 ` [PATCH v8 3/6] ksm: add ksm zero pages for each process David Hildenbrand
[not found] ` <20230522105335.4176-1-yang.yang29@zte.com.cn>
2023-05-23 9:58 ` [PATCH v8 4/6] ksm: add documentation for ksm zero pages David Hildenbrand
[not found] ` <20230522105402.4225-1-yang.yang29@zte.com.cn>
2023-05-23 10:01 ` [PATCH v8 5/6] ksm: update the calculation of KSM profit David Hildenbrand
[not found] ` <20230522105433.4277-1-yang.yang29@zte.com.cn>
2023-05-23 10:15 ` David Hildenbrand [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=c496e8b8-e0d4-a2d6-5cce-e336904e15ae@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=imbrenda@linux.ibm.com \
--cc=jiang.xuexin@zte.com.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ran.xiaokai@zte.com.cn \
--cc=xu.xin.sc@gmail.com \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
/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