Skip to content

Commit

Permalink
Ensure mincore_call_threshold is decremented atomically
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereira committed Aug 25, 2024
1 parent 557a6e7 commit b8a873c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/lwan-mod-serve-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct mmap_cache_data {
#if defined(LWAN_HAVE_ZSTD)
struct lwan_value zstd;
#endif
int mincore_call_threshold;
unsigned int mincore_call_threshold;
};

struct sendfile_cache_data {
Expand Down Expand Up @@ -1260,9 +1260,11 @@ static enum lwan_http_status mmap_serve(struct lwan_request *request,
compression_hdr);

#ifdef LWAN_HAVE_MINCORE
if (md->mincore_call_threshold-- == 0) {
if (ATOMIC_DEC(md->mincore_call_threshold) == 0) {
unsigned char mincore_vec[MINCORE_VEC_LEN(MMAP_SIZE_THRESHOLD)];

md->mincore_call_threshold = MINCORE_CALL_THRESHOLD;

if (!mincore(to_serve->value, to_serve->len, mincore_vec)) {
const size_t pgs = MINCORE_VEC_LEN(to_serve->len);

Expand All @@ -1276,8 +1278,6 @@ static enum lwan_http_status mmap_serve(struct lwan_request *request,
break;
}
}

md->mincore_call_threshold = MINCORE_CALL_THRESHOLD;
}
#endif

Expand Down

0 comments on commit b8a873c

Please sign in to comment.