Skip to content

Commit b738bc5

Browse files
grwilsonbehlendorf
authored andcommitted
Illumos 5694 - traverse_prefetcher does not prefetch enough
5694 traverse_prefetcher does not prefetch enough Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Alex Reece <alex@delphix.com> Reviewed by: Christopher Siden <christopher.siden@delphix.com> Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com> Reviewed by: Bayard Bell <buffer.g.overflow@gmail.com> Approved by: Garrett D'Amore <garrett@damore.org> References: https://www.illumos.org/issues/5694 illumos/illumos-gate@34d7ce05 Ported-by: Chris Dunlop <chris@onthe.net.au> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #3230
1 parent ee2f17a commit b738bc5

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

man/man5/zfs-module-parameters.5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,10 @@ Use \fB1\fR for yes (default) and \fB0\fR to disable.
10581058
.sp
10591059
.ne 2
10601060
.na
1061-
\fBzfs_pd_blks_max\fR (int)
1061+
\fBzfs_pd_bytes_max\fR (int)
10621062
.ad
10631063
.RS 12n
1064-
Max number of blocks to prefetch
1064+
The number of bytes which should be prefetched.
10651065
.sp
10661066
Default value: \fB100\fR.
10671067
.RE

module/zfs/dmu_traverse.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@
3838
#include <sys/callb.h>
3939
#include <sys/zfeature.h>
4040

41-
int zfs_pd_blks_max = 100;
41+
int32_t zfs_pd_bytes_max = 50 * 1024 * 1024; /* 50MB */
4242

4343
typedef struct prefetch_data {
4444
kmutex_t pd_mtx;
4545
kcondvar_t pd_cv;
46-
int pd_blks_max;
47-
int pd_blks_fetched;
46+
int32_t pd_bytes_fetched;
4847
int pd_flags;
4948
boolean_t pd_cancel;
5049
boolean_t pd_exited;
@@ -251,11 +250,12 @@ traverse_visitbp(traverse_data_t *td, const dnode_phys_t *dnp,
251250
}
252251

253252
if (pd != NULL && !pd->pd_exited && prefetch_needed(pd, bp)) {
253+
uint64_t size = BP_GET_LSIZE(bp);
254254
mutex_enter(&pd->pd_mtx);
255-
ASSERT(pd->pd_blks_fetched >= 0);
256-
while (pd->pd_blks_fetched == 0 && !pd->pd_exited)
255+
ASSERT(pd->pd_bytes_fetched >= 0);
256+
while (pd->pd_bytes_fetched < size && !pd->pd_exited)
257257
cv_wait(&pd->pd_cv, &pd->pd_mtx);
258-
pd->pd_blks_fetched--;
258+
pd->pd_bytes_fetched -= size;
259259
cv_broadcast(&pd->pd_cv);
260260
mutex_exit(&pd->pd_mtx);
261261
}
@@ -452,17 +452,17 @@ traverse_prefetcher(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
452452
prefetch_data_t *pfd = arg;
453453
uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
454454

455-
ASSERT(pfd->pd_blks_fetched >= 0);
455+
ASSERT(pfd->pd_bytes_fetched >= 0);
456456
if (pfd->pd_cancel)
457457
return (SET_ERROR(EINTR));
458458

459459
if (!prefetch_needed(pfd, bp))
460460
return (0);
461461

462462
mutex_enter(&pfd->pd_mtx);
463-
while (!pfd->pd_cancel && pfd->pd_blks_fetched >= pfd->pd_blks_max)
463+
while (!pfd->pd_cancel && pfd->pd_bytes_fetched >= zfs_pd_bytes_max)
464464
cv_wait(&pfd->pd_cv, &pfd->pd_mtx);
465-
pfd->pd_blks_fetched++;
465+
pfd->pd_bytes_fetched += BP_GET_LSIZE(bp);
466466
cv_broadcast(&pfd->pd_cv);
467467
mutex_exit(&pfd->pd_mtx);
468468

@@ -531,7 +531,6 @@ traverse_impl(spa_t *spa, dsl_dataset_t *ds, uint64_t objset, blkptr_t *rootbp,
531531
td->td_flags = flags;
532532
td->td_paused = B_FALSE;
533533

534-
pd->pd_blks_max = zfs_pd_blks_max;
535534
pd->pd_flags = flags;
536535
mutex_init(&pd->pd_mtx, NULL, MUTEX_DEFAULT, NULL);
537536
cv_init(&pd->pd_cv, NULL, CV_DEFAULT, NULL);
@@ -661,6 +660,6 @@ traverse_pool(spa_t *spa, uint64_t txg_start, int flags,
661660
EXPORT_SYMBOL(traverse_dataset);
662661
EXPORT_SYMBOL(traverse_pool);
663662

664-
module_param(zfs_pd_blks_max, int, 0644);
665-
MODULE_PARM_DESC(zfs_pd_blks_max, "Max number of blocks to prefetch");
663+
module_param(zfs_pd_bytes_max, int, 0644);
664+
MODULE_PARM_DESC(zfs_pd_bytes_max, "Max number of bytes to prefetch");
666665
#endif

0 commit comments

Comments
 (0)