lfsck->li_bookmark_obj = obj;
rc = lfsck_bookmark_load(env, lfsck);
- if (rc == -ENODATA)
+ if (rc == 0) {
+ struct lfsck_bookmark *mb = &lfsck->li_bookmark_ram;
+
+ /* It is upgraded from old release, set it as
+ * LFSCK_ASYNC_WIN_DEFAULT to avoid memory pressure. */
+ if (unlikely(mb->lb_async_windows == 0)) {
+ mb->lb_async_windows = LFSCK_ASYNC_WIN_DEFAULT;
+ mutex_lock(&lfsck->li_mutex);
+ rc = lfsck_bookmark_store(env, lfsck);
+ mutex_unlock(&lfsck->li_mutex);
+ }
+ } else if (rc == -ENODATA) {
rc = lfsck_bookmark_init(env, lfsck);
+ }
RETURN(rc);
}
}
if (start->ls_valid & LSV_ASYNC_WINDOWS) {
+ if (start->ls_async_windows < 1 ||
+ start->ls_async_windows > LFSCK_ASYNC_WIN_MAX)
+ return -EINVAL;
+
if (bk->lb_async_windows != start->ls_async_windows) {
bk->lb_async_windows = start->ls_async_windows;
dirty = true;
/* Wake up the main engine thread only when the list
* is empty or half of the prefetched items have been
* handled to avoid too frequent thread schedule. */
- if (lad->lad_prefetched == 0 ||
- (bk->lb_async_windows != 0 &&
- bk->lb_async_windows / 2 ==
- lad->lad_prefetched))
+ if (lad->lad_prefetched <= (bk->lb_async_windows / 2))
wakeup = true;
spin_unlock(&lad->lad_lock);
if (wakeup)
continue;
l_wait_event(mthread->t_ctl_waitq,
- bk->lb_async_windows == 0 ||
lad->lad_prefetched < bk->lb_async_windows ||
!thread_is_running(mthread) ||
thread_is_stopped(athread),
lfsck = lfsck_instance_find(key, true, false);
if (likely(lfsck != NULL)) {
- if (val > LFSCK_ASYNC_WIN_MAX) {
- CWARN("%s: Too large async window size, which "
- "may cause memory issues. The valid range "
- "is [0 - %u]. If you do not want to restrict "
- "the window size for async requests pipeline, "
- "just set it as 0.\n",
+ if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
+ CWARN("%s: invalid async windows size that may "
+ "cause memory issues. The valid range is "
+ "[1 - %u].\n",
lfsck_lfsck2name(lfsck), LFSCK_ASYNC_WIN_MAX);
rc = -EINVAL;
} else if (lfsck->li_bookmark_ram.lb_async_windows != val) {
bool wakeup = false;
l_wait_event(mthread->t_ctl_waitq,
- bk->lb_async_windows == 0 ||
lad->lad_prefetched < bk->lb_async_windows ||
!thread_is_running(mthread) ||
thread_is_stopped(athread),
}
case 'w':
val = atoi(optarg);
- if (val < 0 || val > LFSCK_ASYNC_WIN_MAX) {
+ if (val < 1 || val > LFSCK_ASYNC_WIN_MAX) {
fprintf(stderr,
- "Too large async window size, "
- "which may cause memory issues. "
- "The valid range is [0 - %u]. "
- "If you do not want to restrict "
- "the window size for async reqeusts "
- "pipeline, just set it as 0.\n",
+ "Invalid async window size that "
+ "may cause memory issues. The valid "
+ "range is [1 - %u].\n",
LFSCK_ASYNC_WIN_MAX);
return -EINVAL;
}