Skip to content

Commit

Permalink
sendfile: missing sg_buf release on partial write, pagecache_drain: p…
Browse files Browse the repository at this point in the history
…ad to pagesize
  • Loading branch information
wjhun committed Apr 23, 2020
1 parent 752ab6b commit 12e8862
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/unix/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/x86_64/pagecache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/x86_64/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 12e8862

Please sign in to comment.