diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2020-04-16 00:04:10 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2020-04-16 00:04:10 +0000 |
commit | df15d52732010342bb4c049a1a4aed40e5f869e0 (patch) | |
tree | 0e94cee07cab6b60dbbe9dea3d86af3a6a89c39b /tests/umovestr_cached_adjacent.c | |
parent | 4ffb2aa19c3f5a9c118229de887bea93378b4500 (diff) | |
download | strace-df15d52732010342bb4c049a1a4aed40e5f869e0.tar.gz |
Extend memory caching of umove* functions
* ucopy.c (cached_raddr): Double the size.
(get_next_unused_idx, lookup_cached_raddr_idx, set_cached_raddr_idx):
New functions.
(vm_read_mem): Use them. When the data to be fetched resides in
up to 4 adjacent memory pages, fetch these pages and cache them.
* tests/umovestr_cached_adjacent.c: New file.
* tests/pure_executables.list: Add umovestr_cached_adjacent.
* tests/.gitignore: Likewise.
* tests/umovestr_cached.test: Handle the first argument.
* tests/gen_tests.in (umovestr_cached_adjacent): New test.
Diffstat (limited to 'tests/umovestr_cached_adjacent.c')
-rw-r--r-- | tests/umovestr_cached_adjacent.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/umovestr_cached_adjacent.c b/tests/umovestr_cached_adjacent.c new file mode 100644 index 000000000..53a573b3d --- /dev/null +++ b/tests/umovestr_cached_adjacent.c @@ -0,0 +1,48 @@ +/* + * Check effectiveness of umovestr memory caching. + * + * Copyright (c) 2019-2020 Dmitry V. Levin <ldv@altlinux.org> + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/uio.h> + +int +main(void) +{ + const size_t size = get_page_size() + (DEFAULT_STRLEN - 1); + char *const buf = tail_alloc(size); + fill_memory_ex(buf, DEFAULT_STRLEN * 2, 'a', 'z' - 'a' + 1); + + struct iovec *const io = tail_alloc(sizeof(*io) * DEFAULT_STRLEN); + for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) { + io[i].iov_base = buf + i; + io[i].iov_len = DEFAULT_STRLEN; + } + + tprintf("%s", ""); + + int rc = writev(-1, io, DEFAULT_STRLEN); + const char *errstr = sprintrc(rc); + + tprintf("writev(-1, ["); + for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) { + if (i) + tprintf(", "); + tprintf("{iov_base=\"%.*s\", iov_len=%u}", + (int) io[i].iov_len, + (char *) io[i].iov_base, + (unsigned int) io[i].iov_len); + } + tprintf("], %u) = %s\n", DEFAULT_STRLEN, errstr); + + tprintf("+++ exited with 0 +++\n"); + return 0; +} |