aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-02-18 08:38:57 -0700
committerJens Axboe <axboe@kernel.dk>2024-02-18 08:38:57 -0700
commitdf7965cd61d0dfa67e43beac20655ceb10e2b377 (patch)
tree02bad2f0b58890cc4fb94021bd44afd926458db5
parent26824045b1c29825f9e3e397cacadb658d70322e (diff)
downloadliburing-df7965cd61d0dfa67e43beac20655ceb10e2b377.tar.gz
examples/proxy: don't hard core page size
I had it set as 4096, and while it doesn't really matter for this case as it's just for buffer alignment, it's still bad practice to make these kind of assumptions or use magic numbers. Grab the page size at init time and use that. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/proxy.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/examples/proxy.c b/examples/proxy.c
index 5986ae6d..371054dd 100644
--- a/examples/proxy.c
+++ b/examples/proxy.c
@@ -59,9 +59,9 @@ enum {
};
static int start_bgid = 1;
-
static int nr_conns;
static int open_conns;
+static long page_size;
static int mshot = 1;
static int sqpoll;
@@ -214,7 +214,7 @@ static int setup_buffer_ring(struct io_uring *ring, struct conn *c, int index)
cbr->bgid = c->start_bgid + index;
- if (posix_memalign(&cbr->buf, 4096, buf_size * nr_bufs)) {
+ if (posix_memalign(&cbr->buf, page_size, buf_size * nr_bufs)) {
perror("posix memalign");
return 1;
}
@@ -1137,6 +1137,12 @@ int main(int argc, char *argv[])
struct sigaction sa = { };
int opt, ret, fd;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ perror("sysconf(_SC_PAGESIZE)");
+ return 1;
+ }
+
while ((opt = getopt(argc, argv, "m:d:S:s:b:f:H:r:p:n:B:6Vh?")) != -1) {
switch (opt) {
case 'm':