* Heuristic to detect sequential operation. */
| 504 | * Heuristic to detect sequential operation. |
| 505 | */ |
| 506 | static int |
| 507 | sequential_heuristic(struct uio *uio, struct file *fp) |
| 508 | { |
| 509 | enum uio_rw rw; |
| 510 | |
| 511 | ASSERT_VOP_LOCKED(fp->f_vnode, __func__); |
| 512 | |
| 513 | rw = uio->uio_rw; |
| 514 | if (fp->f_flag & FRDAHEAD) |
| 515 | return (fp->f_seqcount[rw] << IO_SEQSHIFT); |
| 516 | |
| 517 | /* |
| 518 | * Offset 0 is handled specially. open() sets f_seqcount to 1 so |
| 519 | * that the first I/O is normally considered to be slightly |
| 520 | * sequential. Seeking to offset 0 doesn't change sequentiality |
| 521 | * unless previous seeks have reduced f_seqcount to 0, in which |
| 522 | * case offset 0 is not special. |
| 523 | */ |
| 524 | if ((uio->uio_offset == 0 && fp->f_seqcount[rw] > 0) || |
| 525 | uio->uio_offset == fp->f_nextoff[rw]) { |
| 526 | /* |
| 527 | * f_seqcount is in units of fixed-size blocks so that it |
| 528 | * depends mainly on the amount of sequential I/O and not |
| 529 | * much on the number of sequential I/O's. The fixed size |
| 530 | * of 16384 is hard-coded here since it is (not quite) just |
| 531 | * a magic size that works well here. This size is more |
| 532 | * closely related to the best I/O size for real disks than |
| 533 | * to any block size used by software. |
| 534 | */ |
| 535 | if (uio->uio_resid >= IO_SEQMAX * 16384) |
| 536 | fp->f_seqcount[rw] = IO_SEQMAX; |
| 537 | else { |
| 538 | fp->f_seqcount[rw] += howmany(uio->uio_resid, 16384); |
| 539 | if (fp->f_seqcount[rw] > IO_SEQMAX) |
| 540 | fp->f_seqcount[rw] = IO_SEQMAX; |
| 541 | } |
| 542 | return (fp->f_seqcount[rw] << IO_SEQSHIFT); |
| 543 | } |
| 544 | |
| 545 | /* Not sequential. Quickly draw-down sequentiality. */ |
| 546 | if (fp->f_seqcount[rw] > 1) |
| 547 | fp->f_seqcount[rw] = 1; |
| 548 | else |
| 549 | fp->f_seqcount[rw] = 0; |
| 550 | return (0); |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | * Package up an I/O request on a vnode into a uio and do it. |