summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2024-04-29 19:36:22 +0900
committerRyo Nakamura <upa@haeena.net>2024-04-29 19:36:22 +0900
commit235ba41c5b5adde50ec44deebcd4a5d97e2eb995 (patch)
tree42257e7686216492c1bc329a829ba4adae8312e1 /src
parent675126a8368503edee00854a5d82f9cc32524bc2 (diff)
default chunk size is filesize/(nr_conn*4) (Issue #20)
and clean-up chunk_sz related parts.
Diffstat (limited to 'src')
-rw-r--r--src/main.c2
-rw-r--r--src/mscp.c14
-rw-r--r--src/path.c7
3 files changed, 6 insertions, 17 deletions
diff --git a/src/main.c b/src/main.c
index 2e66202..d3c15fb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,7 +47,7 @@ void usage(bool print_help)
" -R CHECKPOINT resume transferring from the checkpoint\n"
"\n"
" -s MIN_CHUNK_SIZE min chunk size (default: 16M bytes)\n"
- " -S MAX_CHUNK_SIZE max chunk size (default: filesize/nr_conn)\n"
+ " -S MAX_CHUNK_SIZE max chunk size (default: filesize/nr_conn/4)\n"
" -a NR_AHEAD number of inflight SFTP commands (default: 32)\n"
" -b BUF_SZ buffer size for i/o and transfer\n"
" -L LIMIT_BITRATE Limit the bitrate, n[KMG] (default: 0, no limit)\n"
diff --git a/src/mscp.c b/src/mscp.c
index 1cb60ef..996f797 100644
--- a/src/mscp.c
+++ b/src/mscp.c
@@ -330,18 +330,10 @@ int mscp_set_dst_path(struct mscp *m, const char *dst_path)
return 0;
}
-static int get_page_mask(void)
+static size_t get_page_mask(void)
{
- long page_sz = sysconf(_SC_PAGESIZE);
- size_t page_mask = 0;
- int n;
-
- for (n = 0; page_sz > 0; page_sz >>= 1, n++) {
- page_mask <<= 1;
- page_mask |= 1;
- }
-
- return page_mask >> 1;
+ size_t page_sz = sysconf(_SC_PAGESIZE);
+ return ~(page_sz - 1);
}
static void mscp_stop_copy_thread(struct mscp *m)
diff --git a/src/path.c b/src/path.c
index f85e20f..140ad36 100644
--- a/src/path.c
+++ b/src/path.c
@@ -102,13 +102,10 @@ static int resolve_chunk(struct path *p, size_t size, struct path_resolve_args *
size_t chunk_sz, off, len;
size_t remaind;
- if (size <= a->min_chunk_sz)
- chunk_sz = size;
- else if (a->max_chunk_sz)
+ if (a->max_chunk_sz)
chunk_sz = a->max_chunk_sz;
else {
- chunk_sz = (size - (size % a->nr_conn)) / a->nr_conn;
- chunk_sz &= ~a->chunk_align; /* align with page_sz */
+ chunk_sz = (size / (a->nr_conn * 4)) & a->chunk_align;
if (chunk_sz <= a->min_chunk_sz)
chunk_sz = a->min_chunk_sz;
}