linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Zi Yan <ziy@nvidia.com>,
	linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	Hugh Dickins <hughd@google.com>,
	David Hildenbrand <david@redhat.com>,
	Yang Shi <yang@os.amperecomputing.com>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	Yu Zhao <yuzhao@google.com>, John Hubbard <jhubbard@nvidia.com>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 01/10] selftests/mm: make file-backed THP split work by setting force option
Date: Wed, 22 Jan 2025 14:32:07 +0800	[thread overview]
Message-ID: <d1a5f942-0c43-475d-854a-9e4a34d04556@linux.alibaba.com> (raw)
In-Reply-To: <20250116211042.741543-2-ziy@nvidia.com>



On 2025/1/17 05:10, Zi Yan wrote:
> Commit acd7ccb284b8 ("mm: shmem: add large folio support for tmpfs")
> changes huge=always to allocate THP/mTHP based on write size and
> split_huge_page_test does not write PMD size data, so file-back THP is not
> created during the test.
> 
> Set /sys/kernel/mm/transparent_hugepage/shmem_enabled to "force" to force
> THP allocation.
> 
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
>   .../selftests/mm/split_huge_page_test.c       | 47 +++++++++++++++++--
>   1 file changed, 43 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index 3f353f3d070f..eccaa347140b 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -264,15 +264,46 @@ void split_pte_mapped_thp(void)
>   void split_file_backed_thp(void)
>   {
>   	int status;
> -	int fd;
> -	ssize_t num_written;
> +	int fd, shmem_sysctl_fd;
> +	ssize_t num_written, num_read;
>   	char tmpfs_template[] = "/tmp/thp_split_XXXXXX";
>   	const char *tmpfs_loc = mkdtemp(tmpfs_template);
> -	char testfile[INPUT_MAX];
> +	char testfile[INPUT_MAX], sysctl_buf[INPUT_MAX] = {0};
>   	uint64_t pgoff_start = 0, pgoff_end = 1024;
> +	const char *shmem_sysctl = "/sys/kernel/mm/transparent_hugepage/shmem_enabled";
> +	char *opt1, *opt2;
>   
>   	ksft_print_msg("Please enable pr_debug in split_huge_pages_in_file() for more info.\n");
>   
> +	shmem_sysctl_fd = open(shmem_sysctl, O_RDWR);
> +	if (shmem_sysctl_fd == -1) {
> +		ksft_perror("cannot open shmem sysctl");
> +		goto out;
> +	}
> +
> +	num_read = read(shmem_sysctl_fd, sysctl_buf, INPUT_MAX);
> +	if (num_read < 1) {
> +		ksft_perror("Failed to read shmem sysctl");

You should close() shmem_sysctl_fd before returning.

> +		goto out;
> +	}
> +
> +	opt1 = strchr(sysctl_buf, '[');
> +	opt2 = strchr(sysctl_buf, ']');
> +	if (!opt1 || !opt2) {

Ditto.

> +		ksft_perror("cannot read shmem sysctl config");
> +		goto out;
> +	}
> +
> +	/* get existing shmem sysctl config into sysctl_buf */
> +	strncpy(sysctl_buf, opt1 + 1, opt2 - opt1 - 1);
> +	memset(sysctl_buf + (opt2 - opt1 - 1), 0, INPUT_MAX);
> +
> +	num_written = write(shmem_sysctl_fd, "force", sizeof("force"));
> +	if (num_written < 1) {
> +		ksft_perror("Fail to write force to shmem sysctl");
> +		goto out;
> +	}
> +
>   	status = mount("tmpfs", tmpfs_loc, "tmpfs", 0, "huge=always,size=4m");
>   
>   	if (status)
> @@ -317,13 +348,21 @@ void split_file_backed_thp(void)
>   	if (status)
>   		ksft_exit_fail_msg("cannot remove tmp dir: %s\n", strerror(errno));
>   
> +	num_written = write(shmem_sysctl_fd, sysctl_buf, strlen(sysctl_buf) + 1);
> +	if (num_written < 1)
> +		ksft_perror("Fail to restore shmem sysctl");
> +
>   	ksft_print_msg("Please check dmesg for more information\n");
> -	ksft_test_result_pass("File-backed THP split test done\n");
> +	ksft_test_result_pass("File-backed THP split to order %d test done\n", order);

Seems the patch set split has issues. No 'order' variable in this patch.

Anyway, I've fixed these issues in my local tree, and it works well. If 
you fix them in the next version, please feel free to add:
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Tested-by: Baolin Wang <baolin.wang@linux.alibaba.com>


>   	return;
>   
>   cleanup:
> +	num_written = write(shmem_sysctl_fd, sysctl_buf, strlen(sysctl_buf) + 1);
> +	if (num_written < 1)
> +		ksft_perror("Fail to restore shmem sysctl");
>   	umount(tmpfs_loc);
>   	rmdir(tmpfs_loc);
> +out:
>   	ksft_exit_fail_msg("Error occurred\n");
>   }
>   


  reply	other threads:[~2025-01-22  6:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16 21:10 [PATCH v5 00/10] Buddy allocator like folio split Zi Yan
2025-01-16 21:10 ` [PATCH v5 01/10] selftests/mm: make file-backed THP split work by setting force option Zi Yan
2025-01-22  6:32   ` Baolin Wang [this message]
2025-01-22 12:21     ` Zi Yan
2025-01-16 21:10 ` [PATCH v5 02/10] mm/huge_memory: allow split shmem large folio to any lower order Zi Yan
2025-01-22  6:44   ` Baolin Wang
2025-01-16 21:10 ` [PATCH v5 03/10] selftests/mm: test splitting file-backed THP " Zi Yan
2025-01-22  6:47   ` Baolin Wang
2025-01-16 21:10 ` [PATCH v5 04/10] mm/huge_memory: add two new (not yet used) functions for folio_split() Zi Yan
2025-01-16 21:10 ` [PATCH v5 05/10] mm/huge_memory: move folio split common code to __folio_split() Zi Yan
2025-01-16 21:10 ` [PATCH v5 06/10] mm/huge_memory: add buddy allocator like folio_split() Zi Yan
2025-01-16 21:10 ` [PATCH v5 07/10] mm/huge_memory: remove the old, unused __split_huge_page() Zi Yan
2025-01-16 21:10 ` [PATCH v5 08/10] mm/huge_memory: add folio_split() to debugfs testing interface Zi Yan
2025-01-16 21:10 ` [PATCH v5 09/10] mm/truncate: use folio_split() for truncate operation Zi Yan
2025-01-16 21:10 ` [PATCH v5 10/10] selftests/mm: add tests for folio_split(), buddy allocator like split Zi Yan

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=d1a5f942-0c43-475d-854a-9e4a34d04556@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=jhubbard@nvidia.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    --cc=yang@os.amperecomputing.com \
    --cc=yuzhao@google.com \
    --cc=ziy@nvidia.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