public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing] test/fixed-hugepage: Add small-huge page mixture testcase
       [not found] <CGME20240805084453epcas5p363b93b10eaf53df5725417d3d7fbcca0@epcas5p3.samsung.com>
@ 2024-08-05  8:44 ` Chenliang Li
  2024-08-08  2:30   ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Chenliang Li @ 2024-08-05  8:44 UTC (permalink / raw)
  To: axboe, asml.silence; +Cc: io-uring, gost.dev, Chenliang Li

Add a test case where a fixed buffer is composed of a small page and
a huge page, and begins with the small page. Originally we have huge-small
test case where the buffer begins with the huge page, add this one to
cover more should-not-coalesce scenarios.

Suggested-by: Pavel Begunkov <[email protected]>
Signed-off-by: Chenliang Li <[email protected]>
---
 test/fixed-hugepage.c | 42 ++++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/test/fixed-hugepage.c b/test/fixed-hugepage.c
index 67a3fa0..b455d9f 100644
--- a/test/fixed-hugepage.c
+++ b/test/fixed-hugepage.c
@@ -76,10 +76,11 @@ static int mmap_hugebufs(struct iovec *iov, int nr_bufs, size_t buf_size, size_t
 }
 
 /* map a hugepage and smaller page to a contiguous memory */
-static int mmap_mixture(struct iovec *iov, int nr_bufs, size_t buf_size)
+static int mmap_mixture(struct iovec *iov, int nr_bufs, size_t buf_size, bool huge_on_left)
 {
 	int i;
-	void *small_base = NULL, *huge_base = NULL, *start = NULL;
+	void *small_base = NULL, *huge_base = NULL, *start = NULL,
+	     *huge_start = NULL, *small_start = NULL;
 	size_t small_size = buf_size - HUGEPAGE_SIZE;
 	size_t seg_size = ((buf_size / HUGEPAGE_SIZE) + 1) * HUGEPAGE_SIZE;
 
@@ -92,7 +93,15 @@ static int mmap_mixture(struct iovec *iov, int nr_bufs, size_t buf_size)
 	}
 
 	for (i = 0; i < nr_bufs; i++) {
-		huge_base = mmap(start, HUGEPAGE_SIZE, PROT_READ | PROT_WRITE,
+		if (huge_on_left) {
+			huge_start = start;
+			small_start = start + HUGEPAGE_SIZE;
+		} else {
+			huge_start = start + HUGEPAGE_SIZE;
+			small_start = start + HUGEPAGE_SIZE - small_size;
+		}
+
+		huge_base = mmap(huge_start, HUGEPAGE_SIZE, PROT_READ | PROT_WRITE,
 				MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_FIXED, -1, 0);
 		if (huge_base == MAP_FAILED) {
 			printf("Unable to map hugetlb page in the page mixture. "
@@ -101,7 +110,7 @@ static int mmap_mixture(struct iovec *iov, int nr_bufs, size_t buf_size)
 			return -1;
 		}
 
-		small_base = mmap(start + HUGEPAGE_SIZE, small_size, PROT_READ | PROT_WRITE,
+		small_base = mmap(small_start, small_size, PROT_READ | PROT_WRITE,
 				MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
 		if (small_base == MAP_FAILED) {
 			printf("Unable to map small page in the page mixture. "
@@ -110,8 +119,14 @@ static int mmap_mixture(struct iovec *iov, int nr_bufs, size_t buf_size)
 			return -1;
 		}
 
-		memset(huge_base, 0, buf_size);
-		iov[i].iov_base = huge_base;
+		if (huge_on_left) {
+			iov[i].iov_base = huge_base;
+			memset(huge_base, 0, buf_size);
+		}
+		else {
+			iov[i].iov_base = small_base;
+			memset(small_base, 0, buf_size);
+		}
 		iov[i].iov_len = buf_size;
 		start += seg_size;
 	}
@@ -315,13 +330,13 @@ static int test_multi_unaligned_mthps(struct io_uring *ring, int fd_in, int fd_o
 }
 
 /* Should not coalesce */
-static int test_page_mixture(struct io_uring *ring, int fd_in, int fd_out)
+static int test_page_mixture(struct io_uring *ring, int fd_in, int fd_out, int huge_on_left)
 {
 	struct iovec iov[NR_BUFS];
 	size_t buf_size = HUGEPAGE_SIZE + MTHP_16KB;
 	int ret;
 
-	if (mmap_mixture(iov, NR_BUFS, buf_size))
+	if (mmap_mixture(iov, NR_BUFS, buf_size, huge_on_left))
 		return T_EXIT_SKIP;
 
 	ret = register_submit(ring, iov, NR_BUFS, fd_in, fd_out);
@@ -377,10 +392,17 @@ int main(int argc, char *argv[])
 		return ret;
 	}
 
-	ret = test_page_mixture(&ring, fd_in, fd_out);
+	ret = test_page_mixture(&ring, fd_in, fd_out, true);
+	if (ret != T_EXIT_PASS) {
+		if (ret != T_EXIT_SKIP)
+			fprintf(stderr, "Test huge small page mixture (start with huge) failed.\n");
+		return ret;
+	}
+
+	ret = test_page_mixture(&ring, fd_in, fd_out, false);
 	if (ret != T_EXIT_PASS) {
 		if (ret != T_EXIT_SKIP)
-			fprintf(stderr, "Test huge small page mixture failed.\n");
+			fprintf(stderr, "Test huge small page mixture (start with small) failed.\n");
 		return ret;
 	}
 

base-commit: 118622a3188e637d66ddec386b22e86fa8c01700
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH liburing] test/fixed-hugepage: Add small-huge page mixture testcase
  2024-08-05  8:44 ` [PATCH liburing] test/fixed-hugepage: Add small-huge page mixture testcase Chenliang Li
@ 2024-08-08  2:30   ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2024-08-08  2:30 UTC (permalink / raw)
  To: asml.silence, Chenliang Li; +Cc: io-uring, gost.dev


On Mon, 05 Aug 2024 16:44:42 +0800, Chenliang Li wrote:
> Add a test case where a fixed buffer is composed of a small page and
> a huge page, and begins with the small page. Originally we have huge-small
> test case where the buffer begins with the huge page, add this one to
> cover more should-not-coalesce scenarios.
> 
> 

Applied, thanks!

[1/1] test/fixed-hugepage: Add small-huge page mixture testcase
      commit: 4f134cc45955cf9957e3de9e5f0dbf2162aa49a1

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-08  2:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20240805084453epcas5p363b93b10eaf53df5725417d3d7fbcca0@epcas5p3.samsung.com>
2024-08-05  8:44 ` [PATCH liburing] test/fixed-hugepage: Add small-huge page mixture testcase Chenliang Li
2024-08-08  2:30   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox