Skip to content

Commit 1831634

Browse files
committed
fix for musl libc: avoid huge stack allocation
too used to thread stacks being several megabytes, maybe :) The crawlerstats gets a bit big so do a normal memory allocation for it. seems to work, but I can't run tests on musl without making the debug binary build.
1 parent 3286294 commit 1831634

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎items.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,11 +1497,15 @@ static void *lru_maintainer_thread(void *arg) {
14971497
rel_time_t last_automove_check = 0;
14981498
useconds_t next_juggles[MAX_NUMBER_OF_SLAB_CLASSES];
14991499
useconds_t backoff_juggles[MAX_NUMBER_OF_SLAB_CLASSES];
1500-
struct crawler_expired_data cdata;
1501-
memset(&cdata, 0, sizeof(struct crawler_expired_data));
1500+
struct crawler_expired_data *cdata =
1501+
calloc(1, sizeof(struct crawler_expired_data));
1502+
if (cdata == NULL) {
1503+
fprintf(stderr, "Failed to allocate crawler data for LRU maintainer thread\n");
1504+
abort();
1505+
}
15021506
memset(next_juggles, 0, sizeof(next_juggles));
1503-
pthread_mutex_init(&cdata.lock, NULL);
1504-
cdata.crawl_complete = true; // kick off the crawler.
1507+
pthread_mutex_init(&cdata->lock, NULL);
1508+
cdata->crawl_complete = true; // kick off the crawler.
15051509
logger *l = logger_create();
15061510
if (l == NULL) {
15071511
fprintf(stderr, "Failed to allocate logger for LRU maintainer thread\n");
@@ -1566,7 +1570,7 @@ static void *lru_maintainer_thread(void *arg) {
15661570

15671571
/* Once per second at most */
15681572
if (settings.lru_crawler && last_crawler_check != current_time) {
1569-
lru_maintainer_crawler_check(&cdata, l);
1573+
lru_maintainer_crawler_check(cdata, l);
15701574
last_crawler_check = current_time;
15711575
}
15721576

@@ -1595,6 +1599,8 @@ static void *lru_maintainer_thread(void *arg) {
15951599
}
15961600
pthread_mutex_unlock(&lru_maintainer_lock);
15971601
slab_automove_free(am);
1602+
// LRU crawler *must* be stopped.
1603+
free(cdata);
15981604
if (settings.verbose > 2)
15991605
fprintf(stderr, "LRU maintainer thread stopping\n");
16001606

0 commit comments

Comments
 (0)