diff --git a/src/unix/syscall.c b/src/unix/syscall.c index 0fc7804c0..2c4221cca 100755 --- a/src/unix/syscall.c +++ b/src/unix/syscall.c @@ -498,6 +498,7 @@ closure_function(9, 2, void, sendfile_bh, thread_log(t, " rewound %ld bytes to %ld", rewind, f_in->offset); } rv = bound(written) == 0 ? -EAGAIN : bound(written); + sg_buf_release(bound(cur_buf)); thread_log(t, " write would block, returning %ld", rv); } else { thread_log(t, " zero or error, rv %ld", rv); @@ -523,7 +524,6 @@ closure_function(9, 2, void, sendfile_bh, } else { bound(written) += rv; bound(cur_buf)->misc += rv; - assert(bound(cur_buf)->length >= rv); if (bound(cur_buf)->misc == bound(cur_buf)->length) { sg_buf_release(bound(cur_buf)); if (bound(written) == bound(readlen)) { @@ -534,6 +534,7 @@ closure_function(9, 2, void, sendfile_bh, assert(bound(cur_buf) != INVALID_ADDRESS); bound(cur_buf)->misc = 0; /* offset for our use */ } + assert(bound(cur_buf)->misc < bound(cur_buf)->length); } /* issue next write */ diff --git a/src/x86_64/pagecache.c b/src/x86_64/pagecache.c index 69859ed17..ab92d125d 100644 --- a/src/x86_64/pagecache.c +++ b/src/x86_64/pagecache.c @@ -491,7 +491,7 @@ static inline void page_list_init(struct pagelist *pl) u64 pagecache_drain(pagecache pc, u64 drain_bytes) { - u64 pages = drain_bytes >> pc->page_order; + u64 pages = pad(drain_bytes, pagecache_pagesize(pc)) >> pc->page_order; spin_lock(&pc->lock); u64 evicted = evict_pages_cache_locked(pc, pages); spin_unlock(&pc->lock); diff --git a/src/x86_64/service.c b/src/x86_64/service.c index 743215208..90b4e9c98 100644 --- a/src/x86_64/service.c +++ b/src/x86_64/service.c @@ -127,7 +127,7 @@ void mm_service(void) u64 free = heap_total(p) - heap_allocated(p); mm_debug("%s: total %ld, alloc %ld, free %ld\n", __func__, heap_total(p), heap_allocated(p), free); if (free < CACHE_DRAIN_CUTOFF) { - u64 drain_bytes = CACHE_DRAIN_CUTOFF - free + PAGESIZE - 1; + u64 drain_bytes = CACHE_DRAIN_CUTOFF - free; u64 drained = pagecache_drain(global_pagecache, drain_bytes); if (drained > 0) mm_debug(" drained %ld / %ld requested...\n", drained, drain_bytes);