Skip to contentSkip to conversation

examples/zcrx: Use PAGE_SIZE for ring refill alignment

PATCH Applied Haiyue Wang 2 participants 5 messages Apr 19, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 examples/zcrx: Use PAGE_SIZE for ring refill alignment

According to the 'Create refill ring' section in [1], use the macro PAGE_SIZE instead of 4096 hard code number.

[1]: https://www.kernel.org/doc/html/latest/networking/iou-zcrx.html

---
 examples/zcrx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/zcrx.c +1 -1
index 8393cfe..c96bbfe 100644
@@ -66,7 +66,7 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries)
 	ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe);
 	/* add space for the header (head/tail/etc.) */
 	ring_size += PAGE_SIZE;
-	return T_ALIGN_UP(ring_size, 4096);
+	return T_ALIGN_UP(ring_size, PAGE_SIZE);
 }
 
 static void setup_zcrx(struct io_uring *ring)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/2 .gitignore: Add `examples/zcrx`

Add the built binary 'zcrx' for clean git track.

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +1 -0
index 4148091..c693631 100644
@@ -28,6 +28,7 @@
 /examples/rsrc-update-bench
 /examples/kdigest
 /examples/reg-wait
+/examples/zcrx
 
 /test/*.t
 /test/*.dmesg
Signature · 1 line
2.49.0
maintainer
#2 lore raw
In reply to Haiyue Wang
Quoted 15 lines · Haiyue Wang

According to the 'Create refill ring' section in [1], use the macro PAGE_SIZE instead of 4096 hard code number.

[1]: https://www.kernel.org/doc/html/latest/networking/iou-zcrx.html

---
 examples/zcrx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/zcrx.c +0 -0
index 8393cfe..c96bbfe 100644

examples/zcrx.c static inline size_t get_refill_ring_size(unsigned int rq_entries) · line 72

Quoted 8 lines
examples/zcrx.c +1 -1
@@ -66,7 +66,7 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries)
 	ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe);
 	/* add space for the header (head/tail/etc.) */
 	ring_size += PAGE_SIZE;
-	return T_ALIGN_UP(ring_size, 4096);
+	return T_ALIGN_UP(ring_size, PAGE_SIZE);
 }
 
 static void setup_zcrx(struct io_uring *ring)

Well, in that same file:

#define PAGE_SIZE (4096)

so this won't really fix anything. Examples or test code should use:

sysconf(_SC_PAGESIZE)

to get the page size at runtime.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 23 lines · Jens Axboe
Quoted 22 lines · Haiyue Wang

According to the 'Create refill ring' section in [1], use the macro PAGE_SIZE instead of 4096 hard code number.

[1]: https://www.kernel.org/doc/html/latest/networking/iou-zcrx.html

---
  examples/zcrx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
examples/zcrx.c +1 -1
index 8393cfe..c96bbfe 100644
@@ -66,7 +66,7 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries)
  	ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe);
  	/* add space for the header (head/tail/etc.) */
  	ring_size += PAGE_SIZE;
-	return T_ALIGN_UP(ring_size, 4096);
+	return T_ALIGN_UP(ring_size, PAGE_SIZE);
  }
 
Quoted 8 lines

examples/zcrx.c static inline size_t get_refill_ring_size(unsigned int rq_entries) · line 72

Quoted 1 line
examples/zcrx.c +0 -0
  static void setup_zcrx(struct io_uring *ring)

Well, in that same file:

#define PAGE_SIZE (4096)

so this won't really fix anything. Examples or test code should use:

The original plan is to make the code consistent for page size as:

	ring_size += PAGE_SIZE
Quoted 3 lines

sysconf(_SC_PAGESIZE)

So fix it as 'examples/proxy'?

	static long page_size;

	page_size = sysconf(_SC_PAGESIZE);
	if (page_size < 0) {
		perror("sysconf(_SC_PAGESIZE)");
		return 1;
	}
Quoted 2 lines

to get the page size at runtime.

maintainer Applied
#4 lore raw

Re: (subset) [PATCH liburing v1 1/2] examples/zcrx: Use PAGE_SIZE for ring refill alignment

In reply to Haiyue Wang
Quoted 6 lines · Haiyue Wang

According to the 'Create refill ring' section in [1], use the macro PAGE_SIZE instead of 4096 hard code number.

[1]: https://www.kernel.org/doc/html/latest/networking/iou-zcrx.html

Applied, thanks!

[2/2] .gitignore: Add examples/zcrx

      commit: 7245359287ef984056d2ed1a62b110196492b93e

Best regards,

Signature · 1 line
Jens Axboe