/[base]/head/sys/geom/geom_io.c
ViewVC logotype

Log of /head/sys/geom/geom_io.c

Parent Directory Parent Directory | Revision Log Revision Log


Links to HEAD: (view) (download) (annotate)
Sticky Revision:


Revision 368124 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 28 12:12:51 2020 UTC (2 years, 11 months ago) by kib
File length: 28732 byte(s)
Diff to previous 367589
Make MAXPHYS tunable.  Bump MAXPHYS to 1M.

Replace MAXPHYS by runtime variable maxphys. It is initialized from
MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys.

Make b_pages[] array in struct buf flexible.  Size b_pages[] for buffer
cache buffers exactly to atop(maxbcachebuf) (currently it is sized to
atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1.
The +1 for pbufs allow several pbuf consumers, among them vmapbuf(),
to use unaligned buffers still sized to maxphys, esp. when such
buffers come from userspace (*).  Overall, we save significant amount
of otherwise wasted memory in b_pages[] for buffer cache buffers,
while bumping MAXPHYS to desired high value.

Eliminate all direct uses of the MAXPHYS constant in kernel and driver
sources, except a place which initialize maxphys.  Some random (and
arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted
straight.  Some drivers, which use MAXPHYS to size embeded structures,
get private MAXPHYS-like constant; their convertion is out of scope
for this work.

Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs,
dev/siis, where either submitted by, or based on changes by mav.

Suggested by: mav (*)
Reviewed by:	imp, mav, imp, mckusick, scottl (intermediate versions)
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D27225


Revision 367589 - (view) (download) (annotate) - [select for diffs]
Modified Wed Nov 11 13:48:07 2020 UTC (3 years ago) by markj
File length: 28732 byte(s)
Diff to previous 367022
ffs: Clamp BIO_SPEEDUP length

On 32-bit platforms, the computed size of the BIO_SPEEDUP requested by
softdep_request_cleanup() may be negative when assigned to bp->b_bcount,
which has type "long".

Clamp the size to LONG_MAX.  Also convert the unused g_io_speedup() to
use an off_t for the magnitude of the shortage for consistency with
softdep_send_speedup().

Reviewed by:	chs, kib
Reported by:	pho
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D27081


Revision 367022 - (view) (download) (annotate) - [select for diffs]
Modified Sat Oct 24 21:07:10 2020 UTC (3 years ago) by mav
File length: 28723 byte(s)
Diff to previous 365226
Fix asymmetry in devstat(9) calls by GEOM.

Before this GEOM passed bio pointer to transaction start, but not end.
It was irrelevant until devstat(9) got DTrace hooks, that appeared to
provide bio pointer on I/O completion, but not on submission.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.


Revision 365226 - (view) (download) (annotate) - [select for diffs]
Modified Tue Sep 1 22:14:09 2020 UTC (3 years, 2 months ago) by mjg
File length: 28727 byte(s)
Diff to previous 356818
geom: clean up empty lines in .c and .h files


Revision 356818 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jan 17 01:15:55 2020 UTC (3 years, 10 months ago) by imp
File length: 28728 byte(s)
Diff to previous 356200
Pass BIO_SPEEDUP through all the geom layers

While some geom layers pass unknown commands down, not all do. For the ones that
don't, pass BIO_SPEEDUP down to the providers that constittue the geom, as
applicable. No changes to vinum or virstor because I was unsure how to add this
support, and I'm also unsure how to test these. gvinum doesn't implement
BIO_FLUSH either, so it may just be poorly maintained. gvirstor is for testing
and not supportig BIO_SPEEDUP is fine.

Reviewed by: chs
Differential Revision: https://reviews.freebsd.org/D23183


Revision 356200 - (view) (download) (annotate) - [select for diffs]
Modified Mon Dec 30 03:13:38 2019 UTC (3 years, 10 months ago) by mav
File length: 28709 byte(s)
Diff to previous 356192
Use atomic for start_count in devstat_start_transaction().

Combined with earlier nstart/nend removal it allows to remove several locks
from request path of GEOM and few other places.  It would be cool if we had
more SMP-friendly statistics, but this helps too.

Sponsored by:	iXsystems, Inc.


Revision 356192 - (view) (download) (annotate) - [select for diffs]
Modified Mon Dec 30 00:46:10 2019 UTC (3 years, 10 months ago) by mav
File length: 28971 byte(s)
Diff to previous 356185
Retire nstart/nend counters.

Those counters were abused for decade to workaround broken orphanization
process in different classes by delaying the call while there are active
requests.  But from one side it did not close all the races, while from
another was quite expensive on SMP due to trashing twice per request cache
lines of consumer and provider and requiring locks.  It lost its sense
after I manually went through all the GEOM classes in base and made
orphanization wait for either provider close or request completion.

Consumer counters are still used under INVARIANTS to detect premature
consumer close and detach.  Provider counters are removed completely.

Sponsored by:	iXsystems, Inc.


Revision 356185 - (view) (download) (annotate) - [select for diffs]
Modified Sun Dec 29 21:16:03 2019 UTC (3 years, 10 months ago) by mav
File length: 28949 byte(s)
Diff to previous 355835
Remove GEOM_SCHED class and gsched tool.

This code was not actively maintained since it was introduced 10 years ago.
It lacks support for many later GEOM features, such as direct dispatch,
unmapped I/O, stripesize/stripeoffset, resize, etc.  Plus it is the only
remaining use of GEOM nstart/nend request counters, used there to implement
live insertion/removal, questionable by itself.  Plus, as number of people
commented, GEOM is not the best place for I/O scheduler, since it has
limited information about layers both above and below it, required for
efficient scheduling.  Plus with the modern shift to SSDs there is just no
more significant need for this kind of scheduling.

Approved by:	imp, phk, luigi
Relnotes:	yes


Revision 355835 - (view) (download) (annotate) - [select for diffs]
Modified Tue Dec 17 00:13:35 2019 UTC (3 years, 11 months ago) by imp
File length: 31081 byte(s)
Diff to previous 355404
Add BIO_SPEEDUP

Add BIO_SPEEDUP bio command and g_io_speedup wrapper. It tells the
lower layers that the upper layers are dealing with some shortage
(dirty pages and/or disk blocks). The lower layers should do what they
can to speed up anything that's been delayed.

The first use will be to tell the CAM I/O scheduler that any TRIM
shaping should be short-circuited because the system needs
blocks. We'll also call it when there's too many resources used by
UFS.

Reviewed by: kirk, kib
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D18351


Revision 355404 - (view) (download) (annotate) - [select for diffs]
Modified Wed Dec 4 21:26:03 2019 UTC (3 years, 11 months ago) by mav
File length: 29732 byte(s)
Diff to previous 350694
Mark some more hot global variables with __read_mostly.

MFC after:	1 week


Revision 350694 - (view) (download) (annotate) - [select for diffs]
Modified Wed Aug 7 19:28:35 2019 UTC (4 years, 3 months ago) by cem
File length: 29708 byte(s)
Diff to previous 345206
GEOM: Reduce unnecessary log interleaving with sbufs

Similar to what was done for device_printfs in r347229.

Convert g_print_bio() to a thin shim around g_format_bio(), which acts on an
sbuf; documented in g_bio.9.

Reviewed by:	markj
Discussed with:	rlibby
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D21165


Revision 345206 - (view) (download) (annotate) - [select for diffs]
Modified Fri Mar 15 22:39:55 2019 UTC (4 years, 8 months ago) by cem
File length: 29011 byte(s)
Diff to previous 340220
stack(9): Drop unused API mode and comment that referenced it

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D19601


Revision 340220 - (view) (download) (annotate) - [select for diffs]
Modified Wed Nov 7 16:28:09 2018 UTC (5 years ago) by sobomax
File length: 29026 byte(s)
Diff to previous 340187
Revert r340187, it breaks EOD (end-of-device) detection logic. Turns out,
i/o into last_sector+N is handled differently for N==1 and N>1 cases to
accomodate that, so some other approach would be needed to fix DIOCGDELETE
ioctl(2).


Revision 340187 - (view) (download) (annotate) - [select for diffs]
Modified Tue Nov 6 15:55:41 2018 UTC (5 years ago) by sobomax
File length: 29104 byte(s)
Diff to previous 330264
Don't allow BIO_READ, BIO_WRITE or BIO_DELETE requests that are
fully beyond the end of providers media. The only exception is made
for the zero length transfers which are allowed to be just on the
boundary. Previously, any requests starting on the boundary (i.e. next
byte after the last one) have been allowed to go through.

No response from:	freebsd-geom@, phk
MFC after:		1 month


Revision 330264 - (view) (download) (annotate) - [select for diffs]
Modified Fri Mar 2 04:34:53 2018 UTC (5 years, 8 months ago) by mckusick
File length: 29026 byte(s)
Diff to previous 329375
This change is some refactoring of Mark Johnston's changes in r329375
to fix the memory leak that I introduced in r328426. Instead of
trying to clear up the possible memory leak in all the clients, I
ensure that it gets cleaned up in the source (e.g., ffs_sbget ensures
that memory is always freed if it returns an error).

The original change in r328426 was a bit sparse in its description.
So I am expanding on its description here (thanks cem@ and rgrimes@
for your encouragement for my longer commit messages).

In preparation for adding check hashing to superblocks, r328426 is
a refactoring of the code to get the reading/writing of the superblock
into one place. Unlike the cylinder group reading/writing which
ends up in two places (ffs_getcg/ffs_geom_strategy in the kernel
and cgget/cgput in libufs), I have the core superblock functions
just in the kernel (ffs_sbfetch/ffs_sbput in ffs_subr.c which is
already imported into utilities like fsck_ffs as well as libufs to
implement sbget/sbput). The ffs_sbfetch and ffs_sbput functions
take a function pointer to do the actual I/O for which there are
four variants:

    ffs_use_bread / ffs_use_bwrite for the in-kernel filesystem

    g_use_g_read_data / g_use_g_write_data for kernel geom clients

    ufs_use_sa_read for the standalone code (stand/libsa/ufs.c
	but not stand/libsa/ufsread.c which is size constrained)

    use_pread / use_pwrite for libufs

Uses of these interfaces are in the UFS filesystem, geoms journal &
label, libsa changes, and libufs. They also permeate out into the
filesystem utilities fsck_ffs, newfs, growfs, clri, dump, quotacheck,
fsirand, fstyp, and quot. Some of these utilities should probably be
converted to directly use libufs (like dumpfs was for example), but
there does not seem to be much win in doing so.

Tested by: Peter Holm (pho@)


Revision 329375 - (view) (download) (annotate) - [select for diffs]
Modified Fri Feb 16 15:41:03 2018 UTC (5 years, 9 months ago) by markj
File length: 28981 byte(s)
Diff to previous 328426
Fix a memory leak introduced in r328426.

ffs_sbget() may return a superblock buffer even if it fails, so the
caller must be prepared to free it in this case. Moreover, when tasting
alternate superblock locations in a loop, ffs_sbget()'s readfunc
callback must free the previously allocated buffer.

Reported and tested by:	pho
Reviewed by:		kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D14390


Revision 328426 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jan 26 00:58:32 2018 UTC (5 years, 9 months ago) by mckusick
File length: 28944 byte(s)
Diff to previous 326270
Refactoring of reading and writing of the UFS/FFS superblock.
Specifically reading is done if ffs_sbget() and writing is done
in ffs_sbput(). These functions are exported to libufs via the
sbget() and sbput() functions which then used in the various
filesystem utilities. This work is in preparation for adding
subperblock check hashes.

No functional change intended.

Reviewed by: kib


Revision 326270 - (view) (download) (annotate) - [select for diffs]
Modified Mon Nov 27 15:17:37 2017 UTC (5 years, 11 months ago) by pfg
File length: 28137 byte(s)
Diff to previous 308155
sys/geom: adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


Revision 308155 - (view) (download) (annotate) - [select for diffs]
Modified Mon Oct 31 23:09:52 2016 UTC (7 years ago) by cem
File length: 28093 byte(s)
Diff to previous 306018
Add BUF_TRACKING and FULL_BUF_TRACKING buffer debugging

Upstream the BUF_TRACKING and FULL_BUF_TRACKING buffer debugging code.
This can be handy in tracking down what code touched hung bios and bufs
last. The full history is especially useful, but adds enough bloat that
it shouldn't be enabled in release builds.

Function names (or arbitrary string constants) are tracked in a
fixed-size ring in bufs. Bios gain a pointer to the upper buf for
tracking. SCSI CCBs gain a pointer to the upper bio for tracking.

Reviewed by:	markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8366


Revision 306018 - (view) (download) (annotate) - [select for diffs]
Modified Tue Sep 20 09:18:33 2016 UTC (7 years, 2 months ago) by trasz
File length: 27860 byte(s)
Diff to previous 305988
Follow up r305988 by removing g_bio_run_task and related code.
The g_io_schedule_up() gets its "if" condition swapped to make
it more similar to g_io_schedule_down().

Suggested by:	mav@
Reviewed by:	mav@
MFC after:	1 month


Revision 305988 - (view) (download) (annotate) - [select for diffs]
Modified Mon Sep 19 17:46:15 2016 UTC (7 years, 2 months ago) by trasz
File length: 28177 byte(s)
Diff to previous 300207
Remove unused bio_taskqueue().

MFC after:	1 month


Revision 300207 - (view) (download) (annotate) - [select for diffs]
Modified Thu May 19 14:08:36 2016 UTC (7 years, 6 months ago) by ken
File length: 28708 byte(s)
Diff to previous 297955
Add support for managing Shingled Magnetic Recording (SMR) drives.

This change includes support for SCSI SMR drives (which conform to the
Zoned Block Commands or ZBC spec) and ATA SMR drives (which conform to
the Zoned ATA Command Set or ZAC spec) behind SAS expanders.

This includes full management support through the GEOM BIO interface, and
through a new userland utility, zonectl(8), and through camcontrol(8).

This is now ready for filesystems to use to detect and manage zoned drives.
(There is no work in progress that I know of to use this for ZFS or UFS, if
anyone is interested, let me know and I may have some suggestions.)

Also, improve ATA command passthrough and dispatch support, both via ATA
and ATA passthrough over SCSI.

Also, add support to camcontrol(8) for the ATA Extended Power Conditions
feature set.  You can now manage ATA device power states, and set various
idle time thresholds for a drive to enter lower power states.

Note that this change cannot be MFCed in full, because it depends on
changes to the struct bio API that break compatilibity.  In order to
avoid breaking the stable API, only changes that don't touch or depend on
the struct bio changes can be merged.  For example, the camcontrol(8)
changes don't depend on the new bio API, but zonectl(8) and the probe
changes to the da(4) and ada(4) drivers do depend on it.

Also note that the SMR changes have not yet been tested with an actual
SCSI ZBC device, or a SCSI to ATA translation layer (SAT) that supports
ZBC to ZAC translation.  I have not yet gotten a suitable drive or SAT
layer, so any testing help would be appreciated.  These changes have been
tested with Seagate Host Aware SATA drives attached to both SAS and SATA
controllers.  Also, I do not have any SATA Host Managed devices, and I
suspect that it may take additional (hopefully minor) changes to support
them.

Thanks to Seagate for supplying the test hardware and answering questions.

sbin/camcontrol/Makefile:
	Add epc.c and zone.c.

sbin/camcontrol/camcontrol.8:
	Document the zone and epc subcommands.

sbin/camcontrol/camcontrol.c:
	Add the zone and epc subcommands.

	Add auxiliary register support to build_ata_cmd().  Make sure to
	set the CAM_ATAIO_NEEDRESULT, CAM_ATAIO_DMA, and CAM_ATAIO_FPDMA
	flags as appropriate for ATA commands.

	Add a new get_ata_status() function to parse ATA result from SCSI
	sense descriptors (for ATA passthrough over SCSI) and ATA I/O
	requests.

sbin/camcontrol/camcontrol.h:
	Update the build_ata_cmd() prototype

	Add get_ata_status(), zone(), and epc().

sbin/camcontrol/epc.c:
	Support for ATA Extended Power Conditions features.  This includes
	support for all features documented in the ACS-4 Revision 12
	specification from t13.org (dated February 18, 2016).

	The EPC feature set allows putting a drive into a power power mode
	immediately, or setting timeouts so that the drive will
	automatically enter progressively lower power states after various
	idle times.

sbin/camcontrol/fwdownload.c:
	Update the firmware download code for the new build_ata_cmd()
	arguments.

sbin/camcontrol/zone.c:
	Implement support for Shingled Magnetic Recording (SMR) drives
	via SCSI Zoned Block Commands (ZBC) and ATA Zoned Device ATA
	Command Set (ZAC).

	These specs were developed in concert, and are functionally
	identical.  The primary differences are due to SCSI and ATA
	differences.  (SCSI is big endian, ATA is little endian, for
	example.)

	This includes support for all commands defined in the ZBC and
	ZAC specs.

sys/cam/ata/ata_all.c:
	Decode a number of additional ATA command names in ata_op_string().

	Add a new CCB building function, ata_read_log().

	Add ata_zac_mgmt_in() and ata_zac_mgmt_out() CCB building
	functions.  These support both DMA and NCQ encapsulation.

sys/cam/ata/ata_all.h:
	Add prototypes for ata_read_log(), ata_zac_mgmt_out(), and
	ata_zac_mgmt_in().

sys/cam/ata/ata_da.c:
	Revamp the ada(4) driver to support zoned devices.

	Add four new probe states to gather information needed for zone
	support.

	Add a new adasetflags() function to avoid duplication of large
	blocks of flag setting between the async handler and register
	functions.

	Add new sysctl variables that describe zone support and paramters.

	Add support for the new BIO_ZONE bio, and all of its subcommands:
	DISK_ZONE_OPEN, DISK_ZONE_CLOSE, DISK_ZONE_FINISH, DISK_ZONE_RWP,
	DISK_ZONE_REPORT_ZONES, and DISK_ZONE_GET_PARAMS.

sys/cam/scsi/scsi_all.c:
	Add command descriptions for the ZBC IN/OUT commands.

	Add descriptions for ZBC Host Managed devices.

	Add a new function, scsi_ata_pass() to do ATA passthrough over
	SCSI.  This will eventually replace scsi_ata_pass_16() -- it
	can create the 12, 16, and 32-byte variants of the ATA
	PASS-THROUGH command, and supports setting all of the
	registers defined as of SAT-4, Revision 5 (March 11, 2016).

	Change scsi_ata_identify() to use scsi_ata_pass() instead of
	scsi_ata_pass_16().

	Add a new scsi_ata_read_log() function to facilitate reading
	ATA logs via SCSI.

sys/cam/scsi/scsi_all.h:
	Add the new ATA PASS-THROUGH(32) command CDB.  Add extended and
	variable CDB opcodes.

	Add Zoned Block Device Characteristics VPD page.

	Add ATA Return SCSI sense descriptor.

	Add prototypes for scsi_ata_read_log() and scsi_ata_pass().

sys/cam/scsi/scsi_da.c:
	Revamp the da(4) driver to support zoned devices.

	Add five new probe states, four of which are needed for ATA
	devices.

	Add five new sysctl variables that describe zone support and
	parameters.

	The da(4) driver supports SCSI ZBC devices, as well as ATA ZAC
	devices when they are attached via a SCSI to ATA Translation (SAT)
	layer.  Since ZBC -> ZAC translation is a new feature in the T10
	SAT-4 spec, most SATA drives will be supported via ATA commands
	sent via the SCSI ATA PASS-THROUGH command.  The da(4) driver will
	prefer the ZBC interface, if it is available, for performance
	reasons, but will use the ATA PASS-THROUGH interface to the ZAC
	command set if the SAT layer doesn't support translation yet.
	As I mentioned above, ZBC command support is untested.

	Add support for the new BIO_ZONE bio, and all of its subcommands:
	DISK_ZONE_OPEN, DISK_ZONE_CLOSE, DISK_ZONE_FINISH, DISK_ZONE_RWP,
	DISK_ZONE_REPORT_ZONES, and DISK_ZONE_GET_PARAMS.

	Add scsi_zbc_in() and scsi_zbc_out() CCB building functions.

	Add scsi_ata_zac_mgmt_out() and scsi_ata_zac_mgmt_in() CCB/CDB
	building functions.  Note that these have return values, unlike
	almost all other CCB building functions in CAM.  The reason is
	that they can fail, depending upon the particular combination
	of input parameters.  The primary failure case is if the user
	wants NCQ, but fails to specify additional CDB storage.  NCQ
	requires using the 32-byte version of the SCSI ATA PASS-THROUGH
	command, and the current CAM CDB size is 16 bytes.

sys/cam/scsi/scsi_da.h:
	Add ZBC IN and ZBC OUT CDBs and opcodes.

	Add SCSI Report Zones data structures.

	Add scsi_zbc_in(), scsi_zbc_out(), scsi_ata_zac_mgmt_out(), and
	scsi_ata_zac_mgmt_in() prototypes.

sys/dev/ahci/ahci.c:
	Fix SEND / RECEIVE FPDMA QUEUED in the ahci(4) driver.

	ahci_setup_fis() previously set the top bits of the sector count
	register in the FIS to 0 for FPDMA commands.  This is okay for
	read and write, because the PRIO field is in the only thing in
	those bits, and we don't implement that further up the stack.

	But, for SEND and RECEIVE FPDMA QUEUED, the subcommand is in that
	byte, so it needs to be transmitted to the drive.

	In ahci_setup_fis(), always set the the top 8 bits of the
	sector count register.  We need it in both the standard
	and NCQ / FPDMA cases.

sys/geom/eli/g_eli.c:
	Pass BIO_ZONE commands through the GELI class.

sys/geom/geom.h:
	Add g_io_zonecmd() prototype.

sys/geom/geom_dev.c:
	Add new DIOCZONECMD ioctl, which allows sending zone commands to
	disks.

sys/geom/geom_disk.c:
	Add support for BIO_ZONE commands.

sys/geom/geom_disk.h:
	Add a new flag, DISKFLAG_CANZONE, that indicates that a given
	GEOM disk client can handle BIO_ZONE commands.

sys/geom/geom_io.c:
	Add a new function, g_io_zonecmd(), that handles execution of
	BIO_ZONE commands.

	Add permissions check for BIO_ZONE commands.

	Add command decoding for BIO_ZONE commands.

sys/geom/geom_subr.c:
	Add DDB command decoding for BIO_ZONE commands.

sys/kern/subr_devstat.c:
	Record statistics for REPORT ZONES commands.  Note that the
	number of bytes transferred for REPORT ZONES won't quite match
	what is received from the harware.  This is because we're
	necessarily counting bytes coming from the da(4) / ada(4) drivers,
	which are using the disk_zone.h interface to communicate up
	the stack.  The structure sizes it uses are slightly different
	than the SCSI and ATA structure sizes.

sys/sys/ata.h:
	Add many bit and structure definitions for ZAC, NCQ, and EPC
	command support.

sys/sys/bio.h:
	Convert the bio_cmd field to a straight enumeration.  This will
	yield more space for additional commands in the future.  After
	change r297955 and other related changes, this is now possible.
	Converting to an enumeration will also prevent use as a bitmask
	in the future.

sys/sys/disk.h:
	Define the DIOCZONECMD ioctl.

sys/sys/disk_zone.h:
	Add a new API for managing zoned disks.  This is very close to
	the SCSI ZBC and ATA ZAC standards, but uses integers in native
	byte order instead of big endian (SCSI) or little endian (ATA)
	byte arrays.

	This is intended to offer to the complete feature set of the ZBC
	and ZAC disk management without requiring the application developer
	to include SCSI or ATA headers.  We also use one set of headers
	for ioctl consumers and kernel bio-level consumers.

sys/sys/param.h:
	Bump __FreeBSD_version for sys/bio.h command changes, and inclusion
	of SMR support.

usr.sbin/Makefile:
	Add the zonectl utility.

usr.sbin/diskinfo/diskinfo.c
	Add disk zoning capability to the 'diskinfo -v' output.

usr.sbin/zonectl/Makefile:
	Add zonectl makefile.

usr.sbin/zonectl/zonectl.8
	zonectl(8) man page.

usr.sbin/zonectl/zonectl.c
	The zonectl(8) utility.  This allows managing SCSI or ATA zoned
	disks via the disk_zone.h API.  You can report zones, reset write
	pointers, get parameters, etc.

Sponsored by:	Spectra Logic
Differential Revision:	https://reviews.freebsd.org/D6147
Reviewed by:	wblock (documentation)


Revision 297955 - (view) (download) (annotate) - [select for diffs]
Modified Thu Apr 14 05:10:41 2016 UTC (7 years, 7 months ago) by imp
File length: 27148 byte(s)
Diff to previous 296605
Bump bio_cmd and bio_*flags from 8 bits to 16.

Differential Revision: https://reviews.freebsd.org/D5784


Revision 296605 - (view) (download) (annotate) - [select for diffs]
Modified Thu Mar 10 06:25:31 2016 UTC (7 years, 8 months ago) by imp
File length: 27150 byte(s)
Diff to previous 295712
Don't assume that bio_cmd is bit mask.

Differential Revision: https://reviews.freebsd.org/D5593


Revision 295712 - (view) (download) (annotate) - [select for diffs]
Modified Wed Feb 17 18:28:38 2016 UTC (7 years, 9 months ago) by imp
File length: 27093 byte(s)
Diff to previous 295707
Use the right size for zeroing.

Submitted by: rpokala@


Revision 295707 - (view) (download) (annotate) - [select for diffs]
Modified Wed Feb 17 17:16:02 2016 UTC (7 years, 9 months ago) by imp
File length: 27092 byte(s)
Diff to previous 291716
Create an API to reset a struct bio (g_reset_bio). This is mandatory
for all struct bio you get back from g_{new,alloc}_bio. Temporary
bios that you create on the stack or elsewhere should use this before
first use of the bio, and between uses of the bio. At the moment, it
is nothing more than a wrapper around bzero, but that may change in
the future. The wrapper also removes one place where we encode the
size of struct bio in the KBI.


Revision 291716 - (view) (download) (annotate) - [select for diffs]
Modified Thu Dec 3 20:54:55 2015 UTC (7 years, 11 months ago) by ken
File length: 27029 byte(s)
Diff to previous 287405
Add asynchronous command support to the pass(4) driver, and the new
camdd(8) utility.

CCBs may be queued to the driver via the new CAMIOQUEUE ioctl, and
completed CCBs may be retrieved via the CAMIOGET ioctl.  User
processes can use poll(2) or kevent(2) to get notification when
I/O has completed.

While the existing CAMIOCOMMAND blocking ioctl interface only
supports user virtual data pointers in a CCB (generally only
one per CCB), the new CAMIOQUEUE ioctl supports user virtual and
physical address pointers, as well as user virtual and physical
scatter/gather lists.  This allows user applications to have more
flexibility in their data handling operations.

Kernel memory for data transferred via the queued interface is
allocated from the zone allocator in MAXPHYS sized chunks, and user
data is copied in and out.  This is likely faster than the
vmapbuf()/vunmapbuf() method used by the CAMIOCOMMAND ioctl in
configurations with many processors (there are more TLB shootdowns
caused by the mapping/unmapping operation) but may not be as fast
as running with unmapped I/O.

The new memory handling model for user requests also allows
applications to send CCBs with request sizes that are larger than
MAXPHYS.  The pass(4) driver now limits queued requests to the I/O
size listed by the SIM driver in the maxio field in the Path
Inquiry (XPT_PATH_INQ) CCB.

There are some things things would be good to add:

1. Come up with a way to do unmapped I/O on multiple buffers.
   Currently the unmapped I/O interface operates on a struct bio,
   which includes only one address and length.  It would be nice
   to be able to send an unmapped scatter/gather list down to
   busdma.  This would allow eliminating the copy we currently do
   for data.

2. Add an ioctl to list currently outstanding CCBs in the various
   queues.

3. Add an ioctl to cancel a request, or use the XPT_ABORT CCB to do
   that.

4. Test physical address support.  Virtual pointers and scatter
   gather lists have been tested, but I have not yet tested
   physical addresses or scatter/gather lists.

5. Investigate multiple queue support.  At the moment there is one
   queue of commands per pass(4) device.  If multiple processes
   open the device, they will submit I/O into the same queue and
   get events for the same completions.  This is probably the right
   model for most applications, but it is something that could be
   changed later on.

Also, add a new utility, camdd(8) that uses the asynchronous pass(4)
driver interface.

This utility is intended to be a basic data transfer/copy utility,
a simple benchmark utility, and an example of how to use the
asynchronous pass(4) interface.

It can copy data to and from pass(4) devices using any target queue
depth, starting offset and blocksize for the input and ouptut devices.
It currently only supports SCSI devices, but could be easily extended
to support ATA devices.

It can also copy data to and from regular files, block devices, tape
devices, pipes, stdin, and stdout.  It does not support queueing
multiple commands to any of those targets, since it uses the standard
read(2)/write(2)/writev(2)/readv(2) system calls.

The I/O is done by two threads, one for the reader and one for the
writer.  The reader thread sends completed read requests to the
writer thread in strictly sequential order, even if they complete
out of order.  That could be modified later on for random I/O patterns
or slightly out of order I/O.

camdd(8) uses kqueue(2)/kevent(2) to get I/O completion events from
the pass(4) driver and also to send request notifications internally.

For pass(4) devcies, camdd(8) uses a single buffer (CAM_DATA_VADDR)
per CAM CCB on the reading side, and a scatter/gather list
(CAM_DATA_SG) on the writing side.  In addition to testing both
interfaces, this makes any potential reblocking of I/O easier.  No
data is copied between the reader and the writer, but rather the
reader's buffers are split into multiple I/O requests or combined
into a single I/O request depending on the input and output blocksize.

For the file I/O path, camdd(8) also uses a single buffer (read(2),
write(2), pread(2) or pwrite(2)) on reads, and a scatter/gather list
(readv(2), writev(2), preadv(2), pwritev(2)) on writes.

Things that would be nice to do for camdd(8) eventually:

1.  Add support for I/O pattern generation.  Patterns like all
    zeros, all ones, LBA-based patterns, random patterns, etc. Right
    Now you can always use /dev/zero, /dev/random, etc.

2.  Add support for a "sink" mode, so we do only reads with no
    writes.  Right now, you can use /dev/null.

3.  Add support for automatic queue depth probing, so that we can
    figure out the right queue depth on the input and output side
    for maximum throughput.  At the moment it defaults to 6.

4.  Add support for SATA device passthrough I/O.

5.  Add support for random LBAs and/or lengths on the input and
    output sides.

6.  Track average per-I/O latency and busy time.  The busy time
    and latency could also feed in to the automatic queue depth
    determination.

sys/cam/scsi/scsi_pass.h:
	Define two new ioctls, CAMIOQUEUE and CAMIOGET, that queue
	and fetch asynchronous CAM CCBs respectively.

	Although these ioctls do not have a declared argument, they
	both take a union ccb pointer.  If we declare a size here,
	the ioctl code in sys/kern/sys_generic.c will malloc and free
	a buffer for either the CCB or the CCB pointer (depending on
	how it is declared).  Since we have to keep a copy of the
	CCB (which is fairly large) anyway, having the ioctl malloc
	and free a CCB for each call is wasteful.

sys/cam/scsi/scsi_pass.c:
	Add asynchronous CCB support.

	Add two new ioctls, CAMIOQUEUE and CAMIOGET.

	CAMIOQUEUE adds a CCB to the incoming queue.  The CCB is
	executed immediately (and moved to the active queue) if it
	is an immediate CCB, but otherwise it will be executed
	in passstart() when a CCB is available from the transport layer.

	When CCBs are completed (because they are immediate or
	passdone() if they are queued), they are put on the done
	queue.

	If we get the final close on the device before all pending
	I/O is complete, all active I/O is moved to the abandoned
	queue and we increment the peripheral reference count so
	that the peripheral driver instance doesn't go away before
	all pending I/O is done.

	The new passcreatezone() function is called on the first
	call to the CAMIOQUEUE ioctl on a given device to allocate
	the UMA zones for I/O requests and S/G list buffers.  This
	may be good to move off to a taskqueue at some point.
	The new passmemsetup() function allocates memory and
	scatter/gather lists to hold the user's data, and copies
	in any data that needs to be written.  For virtual pointers
	(CAM_DATA_VADDR), the kernel buffer is malloced from the
	new pass(4) driver malloc bucket.  For virtual
	scatter/gather lists (CAM_DATA_SG), buffers are allocated
	from a new per-pass(9) UMA zone in MAXPHYS-sized chunks.
	Physical pointers are passed in unchanged.  We have support
	for up to 16 scatter/gather segments (for the user and
	kernel S/G lists) in the default struct pass_io_req, so
	requests with longer S/G lists require an extra kernel malloc.

	The new passcopysglist() function copies a user scatter/gather
	list to a kernel scatter/gather list.  The number of elements
	in each list may be different, but (obviously) the amount of data
	stored has to be identical.

	The new passmemdone() function copies data out for the
	CAM_DATA_VADDR and CAM_DATA_SG cases.

	The new passiocleanup() function restores data pointers in
	user CCBs and frees memory.

	Add new functions to support kqueue(2)/kevent(2):

	passreadfilt() tells kevent whether or not the done
	queue is empty.

	passkqfilter() adds a knote to our list.

	passreadfiltdetach() removes a knote from our list.

	Add a new function, passpoll(), for poll(2)/select(2)
	to use.

	Add devstat(9) support for the queued CCB path.

sys/cam/ata/ata_da.c:
	Add support for the BIO_VLIST bio type.

sys/cam/cam_ccb.h:
	Add a new enumeration for the xflags field in the CCB header.
	(This doesn't change the CCB header, just adds an enumeration to
	use.)

sys/cam/cam_xpt.c:
	Add a new function, xpt_setup_ccb_flags(), that allows specifying
	CCB flags.

sys/cam/cam_xpt.h:
	Add a prototype for xpt_setup_ccb_flags().

sys/cam/scsi/scsi_da.c:
	Add support for BIO_VLIST.

sys/dev/md/md.c:
	Add BIO_VLIST support to md(4).

sys/geom/geom_disk.c:
	Add BIO_VLIST support to the GEOM disk class.  Re-factor the I/O size
	limiting code in g_disk_start() a bit.

sys/kern/subr_bus_dma.c:
	Change _bus_dmamap_load_vlist() to take a starting offset and
	length.

	Add a new function, _bus_dmamap_load_pages(), that will load a list
	of physical pages starting at an offset.

	Update _bus_dmamap_load_bio() to allow loading BIO_VLIST bios.
	Allow unmapped I/O to start at an offset.

sys/kern/subr_uio.c:
	Add two new functions, physcopyin_vlist() and physcopyout_vlist().

sys/pc98/include/bus.h:
	Guard kernel-only parts of the pc98 machine/bus.h header with
	#ifdef _KERNEL.

	This allows userland programs to include <machine/bus.h> to get the
	definition of bus_addr_t and bus_size_t.

sys/sys/bio.h:
	Add a new bio flag, BIO_VLIST.

sys/sys/uio.h:
	Add prototypes for physcopyin_vlist() and physcopyout_vlist().

share/man/man4/pass.4:
	Document the CAMIOQUEUE and CAMIOGET ioctls.

usr.sbin/Makefile:
	Add camdd.

usr.sbin/camdd/Makefile:
	Add a makefile for camdd(8).

usr.sbin/camdd/camdd.8:
	Man page for camdd(8).

usr.sbin/camdd/camdd.c:
	The new camdd(8) utility.

Sponsored by:	Spectra Logic
MFC after:	1 week


Revision 287405 - (view) (download) (annotate) - [select for diffs]
Modified Wed Sep 2 17:29:30 2015 UTC (8 years, 2 months ago) by imp
File length: 26983 byte(s)
Diff to previous 286405
After the introduction of direct dispatch, the pacing code in g_down()
broke in two ways. One, the pacing variable was accessed in multiple
threads in an unsafe way. Two, since large numbers of I/O could come
down from the buf layer at one time, large numbers of allocation
failures could happen all at once, resulting in a huge pace value that
would limit I/Os to 10 IOPS for minutes (or even hours) at a
time. While a real solution to these problems requires substantial
work (to go to a no-allocation after the first model, or to have some
way to wait for more memory with some kind of reserve for pager and
swapper requests), it is relatively easy to make this simplistic
pacing less pathological.

Move to using a volatile variable with loads and stores. While this is
a little racy, losing the race is safe: either you get memory and
proceed, or you don't and queue. Second, sleep for 1ms (or one tick, whichever
is larger) instead of 100ms. This removes the artificial 10 IOPS limit
while still easing up on new I/Os during memory shortages. Remove
tying the amount of time we do this to the number of failed requests
and do it only as long as we keep failing requests.

Finally, to avoid needless recursion when memory is tight (start ->
g_io_deliver() -> g_io_request() -> start -> ... until we use 1/2 the
stack), don't do direct dispatch while pacing. This should be a rare
event (not steady state) so the performance hit here is worth the
extra safety of not starving g_down() with directly dispatched I/O.

Differential Review: https://reviews.freebsd.org/D3546


Revision 286405 - (view) (download) (annotate) - [select for diffs]
Modified Fri Aug 7 08:24:12 2015 UTC (8 years, 3 months ago) by kib
File length: 25444 byte(s)
Diff to previous 286404
Minor style cleanup of the code surrounding r286404.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week


Revision 286404 - (view) (download) (annotate) - [select for diffs]
Modified Fri Aug 7 08:13:34 2015 UTC (8 years, 3 months ago) by kib
File length: 25426 byte(s)
Diff to previous 256880
The condition to use direct processing for the unmapped bio is
reverted.  We can do direct processing when g_io_check() does not need
to perform transient remapping of the bio, otherwise the thread has to
sleep.

Reviewed by:	mav (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week


Revision 256880 - (view) (download) (annotate) - [select for diffs]
Modified Tue Oct 22 08:22:19 2013 UTC (10 years, 1 month ago) by mav
File length: 25430 byte(s)
Diff to previous 256603
Merge GEOM direct dispatch changes from the projects/camlock branch.

When safety requirements are met, it allows to avoid passing I/O requests
to GEOM g_up/g_down thread, executing them directly in the caller context.
That allows to avoid CPU bottlenecks in g_up/g_down threads, plus avoid
several context switches per I/O.

The defined now safety requirements are:
 - caller should not hold any locks and should be reenterable;
 - callee should not depend on GEOM dual-threaded concurency semantics;
 - on the way down, if request is unmapped while callee doesn't support it,
   the context should be sleepable;
 - kernel thread stack usage should be below 50%.

To keep compatibility with GEOM classes not meeting above requirements
new provider and consumer flags added:
 - G_CF_DIRECT_SEND -- consumer code meets caller requirements (request);
 - G_CF_DIRECT_RECEIVE -- consumer code meets callee requirements (done);
 - G_PF_DIRECT_SEND -- provider code meets caller requirements (done);
 - G_PF_DIRECT_RECEIVE -- provider code meets callee requirements (request).
Capable GEOM class can set them, allowing direct dispatch in cases where
it is safe.  If any of requirements are not met, request is queued to
g_up or g_down thread same as before.

Such GEOM classes were reviewed and updated to support direct dispatch:
CONCAT, DEV, DISK, GATE, MD, MIRROR, MULTIPATH, NOP, PART, RAID, STRIPE,
VFS, ZERO, ZFS::VDEV, ZFS::ZVOL, all classes based on g_slice KPI (LABEL,
MAP, FLASHMAP, etc).

To declare direct completion capability disk(9) KPI got new flag equivalent
to G_PF_DIRECT_SEND -- DISKFLAG_DIRECT_COMPLETION.  da(4) and ada(4) disk
drivers got it set now thanks to earlier CAM locking work.

This change more then twice increases peak block storage performance on
systems with manu CPUs, together with earlier CAM locking changes reaching
more then 1 million IOPS (512 byte raw reads from 16 SATA SSDs on 4 HBAs to
256 user-level threads).

Sponsored by:	iXsystems, Inc.
MFC after:	2 months


Revision 256603 - (view) (download) (annotate) - [select for diffs]
Modified Wed Oct 16 09:12:40 2013 UTC (10 years, 1 month ago) by mav
File length: 24044 byte(s)
Diff to previous 252330
MFprojects/camlock r254905:
Introduce new function devstat_end_transaction_bio_bt(), adding new argument
to specify present time.  Use this function to move binuptime() out of lock,
substantially reducing lock congestion when slow timecounter is used.


Revision 252330 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jun 28 03:51:20 2013 UTC (10 years, 4 months ago) by jeff
File length: 23965 byte(s)
Diff to previous 248596
 - Add a general purpose resource allocator, vmem, from NetBSD.  It was
   originally inspired by the Solaris vmem detailed in the proceedings
   of usenix 2001.  The NetBSD version was heavily refactored for bugs
   and simplicity.
 - Use this resource allocator to allocate the buffer and transient maps.
   Buffer cache defrags are reduced by 25% when used by filesystems with
   mixed block sizes.  Ultimately this may permit dynamic buffer cache
   sizing on low KVA machines.

Discussed with:	alc, kib, attilio
Tested by:	pho
Sponsored by:	EMC / Isilon Storage Division


Revision 248596 - (view) (download) (annotate) - [select for diffs]
Modified Thu Mar 21 22:36:43 2013 UTC (10 years, 8 months ago) by kib
File length: 24309 byte(s)
Diff to previous 248568
Correct the page count when excess length is trimmed from the bio.

Reported and tested by:	Ivan Klymenko <fidaj@ukr.net


Revision 248568 - (view) (download) (annotate) - [select for diffs]
Modified Thu Mar 21 07:26:33 2013 UTC (10 years, 8 months ago) by kib
File length: 23972 byte(s)
Diff to previous 248508
Assert that transient mapping of the bio is only done when unmapped
buffers are allowed.

Sponsored by:	The FreeBSD Foundation


Revision 248508 - (view) (download) (annotate) - [select for diffs]
Modified Tue Mar 19 14:13:12 2013 UTC (10 years, 8 months ago) by kib
File length: 23916 byte(s)
Diff to previous 244716
Implement the concept of the unmapped VMIO buffers, i.e. buffers which
do not map the b_pages pages into buffer_map KVA.  The use of the
unmapped buffers eliminate the need to perform TLB shootdown for
mapping on the buffer creation and reuse, greatly reducing the amount
of IPIs for shootdown on big-SMP machines and eliminating up to 25-30%
of the system time on i/o intensive workloads.

The unmapped buffer should be explicitely requested by the GB_UNMAPPED
flag by the consumer.  For unmapped buffer, no KVA reservation is
performed at all. The consumer might request unmapped buffer which
does have a KVA reserve, to manually map it without recursing into
buffer cache and blocking, with the GB_KVAALLOC flag.

When the mapped buffer is requested and unmapped buffer already
exists, the cache performs an upgrade, possibly reusing the KVA
reservation.

Unmapped buffer is translated into unmapped bio in g_vfs_strategy().
Unmapped bio carry a pointer to the vm_page_t array, offset and length
instead of the data pointer.  The provider which processes the bio
should explicitely specify a readiness to accept unmapped bio,
otherwise g_down geom thread performs the transient upgrade of the bio
request by mapping the pages into the new bio_transient_map KVA
submap.

The bio_transient_map submap claims up to 10% of the buffer map, and
the total buffer_map + bio_transient_map KVA usage stays the
same. Still, it could be manually tuned by kern.bio_transient_maxcnt
tunable, in the units of the transient mappings.  Eventually, the
bio_transient_map could be removed after all geom classes and drivers
can accept unmapped i/o requests.

Unmapped support can be turned off by the vfs.unmapped_buf_allowed
tunable, disabling which makes the buffer (or cluster) creation
requests to ignore GB_UNMAPPED and GB_KVAALLOC flags.  Unmapped
buffers are only enabled by default on the architectures where
pmap_copy_page() was implemented and tested.

In the rework, filesystem metadata is not the subject to maxbufspace
limit anymore. Since the metadata buffers are always mapped, the
buffers still have to fit into the buffer map, which provides a
reasonable (but practically unreachable) upper bound on it. The
non-metadata buffer allocations, both mapped and unmapped, is
accounted against maxbufspace, as before. Effectively, this means that
the maxbufspace is forced on mapped and unmapped buffers separately.
The pre-patch bufspace limiting code did not worked, because
buffer_map fragmentation does not allow the limit to be reached.

By Jeff Roberson request, the getnewbuf() function was split into
smaller single-purpose functions.

Sponsored by:	The FreeBSD Foundation
Discussed with:	jeff (previous version)
Tested by:	pho, scottl (previous version), jhb, bf
MFC after:	2 weeks


Revision 244716 - (view) (download) (annotate) - [select for diffs]
Modified Wed Dec 26 20:07:47 2012 UTC (10 years, 10 months ago) by pjd
File length: 20315 byte(s)
Diff to previous 239132
Reset provider-specific fields when resending I/O request in low memory
conditions. This fixes assertion which checks those fields when kernel is
compiled with DIAGNOSTIC.

Reported by:	kib, pho
MFC after:	1 week


Revision 239132 - (view) (download) (annotate) - [select for diffs]
Modified Tue Aug 7 20:16:10 2012 UTC (11 years, 3 months ago) by jimharris
File length: 20244 byte(s)
Diff to previous 238886
Clone BIO_ORDERED flag, for disk drivers (namely CAM) that try to
 consume it.

Sponsored by: Intel
Discussed with: gibbs, scottl


Revision 238886 - (view) (download) (annotate) - [select for diffs]
Modified Sun Jul 29 11:51:48 2012 UTC (11 years, 3 months ago) by mav
File length: 20009 byte(s)
Diff to previous 212160
Implement media change notification for DA and CD removable media devices.
It includes three parts:
 1) Modifications to CAM to detect media media changes and report them to
disk(9) layer. For modern SATA (and potentially UAS) devices it utilizes
Asynchronous Notification mechanism to receive events from hardware.
Active polling with TEST UNIT READY commands with 3 seconds period is used
for incapable hardware. After that both CD and DA drivers work the same way,
detecting two conditions: "NOT READY: Medium not present" after medium was
detected previously, and "UNIT ATTENTION: Not ready to ready change, medium
may have changed". First one reported to disk(9) as media removal, second
as media insert/change. To reliably receive second event new
AC_UNIT_ATTENTION async added to make UAs broadcasted to all periphs by
generic error handling code in cam_periph_error().
 2) Modifications to GEOM core to handle media remove and change events.
Media removal handled by spoiling all consumers attached to the provider.
Media change event also schedules provider retaste after spoiling to probe
new media. New flag G_CF_ORPHAN was added to consumers to reflect that
consumer is in process of destruction. It allows retaste to create new
geom instance of the same class, while previous one is still dying.
 3) Modifications to some GEOM classes: DEV -- to report media change
events to devd; VFS -- to handle spoiling same as orphan to prevent
accessing replaced media. PART class already handles spoiling alike to
orphan.

Reviewed by:	silence on geom@ and scsi@
Tested by:	avg
Sponsored by:	iXsystems, Inc. / PC-BSD
MFC after:	2 months


Revision 212160 - (view) (download) (annotate) - [select for diffs]
Modified Thu Sep 2 19:40:28 2010 UTC (13 years, 2 months ago) by gibbs
File length: 19961 byte(s)
Diff to previous 208992
Correct bioq_disksort so that bioq_insert_tail() offers barrier semantic.
Add the BIO_ORDERED flag for struct bio and update bio clients to use it.

The barrier semantics of bioq_insert_tail() were broken in two ways:

 o In bioq_disksort(), an added bio could be inserted at the head of
   the queue, even when a barrier was present, if the sort key for
   the new entry was less than that of the last queued barrier bio.

 o The last_offset used to generate the sort key for newly queued bios
   did not stay at the position of the barrier until either the
   barrier was de-queued, or a new barrier (which updates last_offset)
   was queued.  When a barrier is in effect, we know that the disk
   will pass through the barrier position just before the
   "blocked bios" are released, so using the barrier's offset for
   last_offset is the optimal choice.

sys/geom/sched/subr_disk.c:
sys/kern/subr_disk.c:
	o Update last_offset in bioq_insert_tail().

	o Only update last_offset in bioq_remove() if the removed bio is
	  at the head of the queue (typically due to a call via
	  bioq_takefirst()) and no barrier is active.

	o In bioq_disksort(), if we have a barrier (insert_point is non-NULL),
	  set prev to the barrier and cur to it's next element.  Now that
	  last_offset is kept at the barrier position, this change isn't
	  strictly necessary, but since we have to take a decision branch
	  anyway, it does avoid one, no-op, loop iteration in the while
	  loop that immediately follows.

	o In bioq_disksort(), bypass the normal sort for bios with the
	  BIO_ORDERED attribute and instead insert them into the queue
	  with bioq_insert_tail().  bioq_insert_tail() not only gives
	  the desired command order during insertion, but also provides
	  barrier semantics so that commands disksorted in the future
	  cannot pass the just enqueued transaction.

sys/sys/bio.h:
	Add BIO_ORDERED as bit 4 of the bio_flags field in struct bio.

sys/cam/ata/ata_da.c:
sys/cam/scsi/scsi_da.c
	Use an ordered command for SCSI/ATA-NCQ commands issued in
	response to bios with the BIO_ORDERED flag set.

sys/cam/scsi/scsi_da.c
	Use an ordered tag when issuing a synchronize cache command.

	Wrap some lines to 80 columns.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c
sys/geom/geom_io.c
	Mark bios with the BIO_FLUSH command as BIO_ORDERED.

Sponsored by:	Spectra Logic Corporation
MFC after:	1 month


Revision 208992 - (view) (download) (annotate) - [select for diffs]
Modified Thu Jun 10 17:49:36 2010 UTC (13 years, 5 months ago) by trasz
File length: 19930 byte(s)
Diff to previous 206650
Untangle g_print_bio(), silencing Coverity.

Found with:	Coverity Prevent
CID:		3566, 3567


Revision 206650 - (view) (download) (annotate) - [select for diffs]
Modified Thu Apr 15 08:39:56 2010 UTC (13 years, 7 months ago) by avg
File length: 19973 byte(s)
Diff to previous 205619
g_io_check: respond to zero pp->mediasize with ENXIO

Previsouly this condition was reported with EIO by bio_offset > mediasize
check.
Perhaps that check should be extended to bio_offset+bio_length > mediasize.

MFC after:	1 week


Revision 205619 - (view) (download) (annotate) - [select for diffs]
Modified Wed Mar 24 18:04:25 2010 UTC (13 years, 8 months ago) by mav
File length: 19937 byte(s)
Diff to previous 201264
Do not fetch precise time of request start when stats collection disabled.

Reviewed by:	pjd, phk


Revision 201264 - (view) (download) (annotate) - [select for diffs]
Modified Wed Dec 30 17:23:27 2009 UTC (13 years, 10 months ago) by mav
File length: 19880 byte(s)
Diff to previous 196904
Call wakeup() only for the first request on the queue.


Revision 196904 - (view) (download) (annotate) - [select for diffs]
Modified Sun Sep 6 19:33:13 2009 UTC (14 years, 2 months ago) by mav
File length: 19732 byte(s)
Diff to previous 195195
MFp4:
Remove msleep() timeout from g_io_schedule_up/down(). It works fine
without it, saving few percents of CPU on high request rates without
need to rearm callout twice per request.


Revision 195195 - (view) (download) (annotate) - [select for diffs]
Modified Tue Jun 30 14:34:06 2009 UTC (14 years, 4 months ago) by trasz
File length: 19740 byte(s)
Diff to previous 193981
Make gjournal work with kernel compiled with "options DIAGNOSTIC".
Previously, it would panic immediately.

Reviewed by:	pjd
Approved by:	re (kib)


Revision 193981 - (view) (download) (annotate) - [select for diffs]
Modified Thu Jun 11 09:55:26 2009 UTC (14 years, 5 months ago) by luigi
File length: 19472 byte(s)
Diff to previous 183146
As discussed in the devsummit, introduce two fields in the
struct bio to store classification information, and a hook
for classifier functions that can be called by g_io_request().

This code is from Fabio Checconi as part of his GSOC work.


Revision 183146 - (view) (download) (annotate) - [select for diffs]
Modified Thu Sep 18 15:02:19 2008 UTC (15 years, 2 months ago) by sbruno
File length: 17367 byte(s)
Diff to previous 174669
Just a fixup for a KTRACE message I stumbled upon many moons ago.

Reviewed by:	Scott Long
MFC after:	2 days


Revision 174669 - (view) (download) (annotate) - [select for diffs]
Modified Sun Dec 16 18:03:31 2007 UTC (15 years, 11 months ago) by phk
File length: 17367 byte(s)
Diff to previous 173001
Don't limit BIO_DELETE requests to MAXPHYS, they perform no data
transfers, so they are not subject to the VM system limitation.


Revision 173001 - (view) (download) (annotate) - [select for diffs]
Modified Fri Oct 26 06:55:00 2007 UTC (16 years, 1 month ago) by pjd
File length: 17393 byte(s)
Diff to previous 169283
Save stack only when KTR_GEOM is both compiled into the kernel and enabled
in debug.ktr.mask. Because saving stack is very expensive, it's better only
to do it when one really wants to.

Reported by:	Dan Nelson


Revision 169283 - (view) (download) (annotate) - [select for diffs]
Modified Sat May 5 16:35:22 2007 UTC (16 years, 6 months ago) by pjd
File length: 17258 byte(s)
Diff to previous 167086
Implement g_delete_data() similar to g_read_data() and g_write_data().

OK'ed by:	phk


Revision 167086 - (view) (download) (annotate) - [select for diffs]
Modified Tue Feb 27 17:23:29 2007 UTC (16 years, 8 months ago) by jhb
File length: 16766 byte(s)
Diff to previous 166934
Use pause() rather than tsleep() on stack variables and function pointers.


Revision 166934 - (view) (download) (annotate) - [select for diffs]
Modified Fri Feb 23 23:06:10 2007 UTC (16 years, 9 months ago) by jhb
File length: 16783 byte(s)
Diff to previous 166325
Use tsleep() rather than msleep() with a NULL mtx parameter.


Revision 166325 - (view) (download) (annotate) - [select for diffs]
Modified Sun Jan 28 23:36:07 2007 UTC (16 years, 9 months ago) by pjd
File length: 16789 byte(s)
Diff to previous 163832
We expect 'bio_data != NULL' for BIO_{READ,WRITE,GETATTR}, but for
BIO_{DELETE,FLUSH} we expect 'bio_data == NULL'.

Reviewed by:	phk


Revision 163832 - (view) (download) (annotate) - [select for diffs]
Modified Tue Oct 31 21:11:21 2006 UTC (17 years ago) by pjd
File length: 16622 byte(s)
Diff to previous 159304
Add a new I/O request - BIO_FLUSH, which basically tells providers below to
flush their caches. For now will mostly be used by disks to flush their
write cache.

Sponsored by:	home.pl


Revision 159304 - (view) (download) (annotate) - [select for diffs]
Modified Mon Jun 5 21:13:22 2006 UTC (17 years, 5 months ago) by pjd
File length: 16050 byte(s)
Diff to previous 156686
Add g_duplicate_bio() function which does the same thing what g_clone_bio()
is doing, but g_duplicate_bio() allocates new bio with M_WAITOK flag.


Revision 156686 - (view) (download) (annotate) - [select for diffs]
Modified Mon Mar 13 14:59:57 2006 UTC (17 years, 8 months ago) by ru
File length: 15527 byte(s)
Diff to previous 156170
Fix a typo.


Revision 156170 - (view) (download) (annotate) - [select for diffs]
Modified Wed Mar 1 19:01:58 2006 UTC (17 years, 8 months ago) by pjd
File length: 15527 byte(s)
Diff to previous 150177
Assert proper use of bio_caller1, bio_caller2, bio_cflags, bio_driver1,
bio_driver2 and bio_pflags fields.

Reviewed by:	phk


Revision 150177 - (view) (download) (annotate) - [select for diffs]
Modified Thu Sep 15 19:05:37 2005 UTC (18 years, 2 months ago) by jhb
File length: 14646 byte(s)
Diff to previous 149576
- Add a new simple facility for marking the current thread as being in a
  state where sleeping on a sleep queue is not allowed.  The facility
  doesn't support recursion but uses a simple private per-thread flag
  (TDP_NOSLEEPING).  The sleepq_add() function will panic if the flag is
  set and INVARIANTS is enabled.
- Use this new facility to replace the g_xup and g_xdown mutexes that were
  (ab)used to achieve similar behavior.
- Disallow sleeping in interrupt threads when invoking interrupt handlers.

MFC after:	1 week
Reviewed by:	phk


Revision 149576 - (view) (download) (annotate) - [select for diffs]
Modified Mon Aug 29 11:39:24 2005 UTC (18 years, 2 months ago) by pjd
File length: 15000 byte(s)
Diff to previous 148410
Use KTR to log allocations and destructions of bios.
This should hopefully allow to track down "duplicate free of g_bio" panics.


Revision 148410 - (view) (download) (annotate) - [select for diffs]
Modified Mon Jul 25 21:12:54 2005 UTC (18 years, 4 months ago) by phk
File length: 14303 byte(s)
Diff to previous 136755
By design I left a tiny race in updating the I/O statistics based on
the assumption that performance was more important that beancounter
quality statistics.

As it transpires the microoptimization is not measurable in the
real world and the inconsistent statistics confuse users, so revert
the decision.

MT6 candidate:	possibly
MT5 candidate:	possibly


Revision 136755 - (view) (download) (annotate) - [select for diffs]
Modified Thu Oct 21 18:35:24 2004 UTC (19 years, 1 month ago) by rwatson
File length: 14105 byte(s)
Diff to previous 136399
Add KTR_GEOM, which allows tracing of basic GEOM I/O events occuring
in the g_up and g_down threads.  Each time a bio is propelled up and
down the stack, an event is generating showing the provider, offset,
and length, as well as thread wakeup and work status information.


Revision 136399 - (view) (download) (annotate) - [select for diffs]
Modified Mon Oct 11 21:22:59 2004 UTC (19 years, 1 month ago) by ups
File length: 13040 byte(s)
Diff to previous 136201
Trace information about a buffer while we still control it.

Reviewed by:    phk
Approved by:    sam (mentor)


Revision 136201 - (view) (download) (annotate) - [select for diffs]
Modified Wed Oct 6 20:59:59 2004 UTC (19 years, 1 month ago) by phk
File length: 13039 byte(s)
Diff to previous 135876
Don't set the BIO_ONQUEUE debugging flag until we actually put the bio
onto a queue.  This made the ENOMEM handling an instant panic.


Revision 135876 - (view) (download) (annotate) - [select for diffs]
Modified Tue Sep 28 11:56:37 2004 UTC (19 years, 1 month ago) by phk
File length: 13038 byte(s)
Diff to previous 135873
Protect the start/end counts on consumers and providers with the up/down
mutexes.

Make it possible to also protect the disk statistics (at a minor cost in
performance) by setting bit 2 of kern.geom.collectstats.


Revision 135873 - (view) (download) (annotate) - [select for diffs]
Modified Tue Sep 28 08:34:27 2004 UTC (19 years, 1 month ago) by pjd
File length: 12645 byte(s)
Diff to previous 134519
- Set maximum request size to MAXPHYS (128kB), instead of DFLPHYS (64kB).
- Set minimum request size to sectorsize, instead of 512 bytes.

Approved by:	phk (some time ago)


Revision 134519 - (view) (download) (annotate) - [select for diffs]
Modified Mon Aug 30 09:33:06 2004 UTC (19 years, 2 months ago) by phk
File length: 12561 byte(s)
Diff to previous 134379
Add more KASSERTS and checks.


Revision 134379 - (view) (download) (annotate) - [select for diffs]
Modified Fri Aug 27 14:43:11 2004 UTC (19 years, 3 months ago) by phk
File length: 11768 byte(s)
Diff to previous 133487
Introduce g_alloc_bio() as a waiting variant of g_new_bio().

Use in places where we can sleep and where we previously failed to check
for a NULL pointer.

MT5 candidate.


Revision 133487 - (view) (download) (annotate) - [select for diffs]
Modified Wed Aug 11 12:04:35 2004 UTC (19 years, 3 months ago) by pjd
File length: 11648 byte(s)
Diff to previous 131160
When sending request once again because of ENOMEM, reset bio_children
and bio_inbed fields to 0. Without this change we can end up with
I/O leakage in some rare situations.
I tested this change by putting failure probability mechanism simlar
to this used in NOP class into g_clone_bio(9) function, so it was
able to return NULL with the given probability.

Discussed with:	phk


Revision 131160 - (view) (download) (annotate) - [select for diffs]
Modified Sat Jun 26 23:27:42 2004 UTC (19 years, 5 months ago) by rwatson
File length: 11603 byte(s)
Diff to previous 130280
The g_up and g_down threads use a local 'mymutex' mutex to allow WITNESS
to warn about attempts to sleep in the I/O path.  This change pushes the
definition and use of 'mymutex' behind #ifdef WITNESS to avoid the cost
in non-debugging cases.  This results in a clear .22% performance win for
512 byte and 1k I/O tests on my SMP test box.  Not much, but every bit
counts.


Revision 130280 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jun 9 19:44:44 2004 UTC (19 years, 5 months ago) by phk
File length: 11427 byte(s)
Diff to previous 127863
Make the sysctl kern.geom.collectstats more granular.

Bit 0 controls statistics collection on GEOM providers.
Bit 1 controls statistics collection on GEOM consumers.

Default value is 1.

Prodded by:	scottl


Revision 127863 - (view) (download) (annotate) - [select for diffs]
Modified Sun Apr 4 20:37:28 2004 UTC (19 years, 7 months ago) by pjd
File length: 11380 byte(s)
Diff to previous 125713
Calculate bio_completed properly or die!

Approved by:	phk


Revision 125713 - (view) (download) (annotate) - [select for diffs]
Modified Wed Feb 11 18:21:32 2004 UTC (19 years, 9 months ago) by pjd
File length: 11202 byte(s)
Diff to previous 125137
Added g_print_bio() function to print informations about given bio.

Approved by:	phk, scottl (mentor)


Revision 125137 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jan 28 08:39:18 2004 UTC (19 years, 10 months ago) by phk
File length: 10555 byte(s)
Diff to previous 123271
Bring back the geom_bioqueues, they _are_ a good idea.

ATA will uses these RSN.


Revision 123271 - (view) (download) (annotate) - [select for diffs]
Modified Sun Dec 7 23:20:53 2003 UTC (19 years, 11 months ago) by truckman
File length: 9892 byte(s)
Diff to previous 121323
Correct usage of mtx_init() API.  This is not a functional change since
the code happened to work because MTX_DEF and NULL are both defined as 0.

Reviewed by:	phk


Revision 121323 - (view) (download) (annotate) - [select for diffs]
Modified Wed Oct 22 06:32:20 2003 UTC (20 years, 1 month ago) by phk
File length: 9886 byte(s)
Diff to previous 121253
Forgotten commit:  If a provider has zero sectorsize, it is an
indication of lack of media.

Tripped up:	peter


Revision 121253 - (view) (download) (annotate) - [select for diffs]
Modified Sun Oct 19 19:06:54 2003 UTC (20 years, 1 month ago) by phk
File length: 9953 byte(s)
Diff to previous 120852
Remove KASSERT check for negative bio_offsets, add "normal" EIO
error return for same.


Revision 120852 - (view) (download) (annotate) - [select for diffs]
Modified Mon Oct 6 09:07:35 2003 UTC (20 years, 1 month ago) by phk
File length: 9900 byte(s)
Diff to previous 120493
Allow our bio tools to be used for local bio-chopping by not mandating
a bio_from value.  bio_to is still mandated (mostly for debuggign) and
shall be copied from the parent bio.


Revision 120493 - (view) (download) (annotate) - [select for diffs]
Modified Fri Sep 26 20:52:46 2003 UTC (20 years, 2 months ago) by phk
File length: 9823 byte(s)
Diff to previous 119973
Add more KASSERTS().


Revision 119973 - (view) (download) (annotate) - [select for diffs]
Modified Thu Sep 11 00:49:02 2003 UTC (20 years, 2 months ago) by phk
File length: 9608 byte(s)
Diff to previous 118855
Reorder a couple of KASSERTS to give more sensible messages.

Found by:	GEOM 101 class of '03


Revision 118855 - (view) (download) (annotate) - [select for diffs]
Modified Wed Aug 13 06:42:56 2003 UTC (20 years, 3 months ago) by phk
File length: 9608 byte(s)
Diff to previous 116522
In case we encounter a zero sectorsize provider in g_io_check(), fail
the request with a printf rather than a divide by zero error.


Revision 116522 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jun 18 10:33:09 2003 UTC (20 years, 5 months ago) by phk
File length: 9443 byte(s)
Diff to previous 116196
Sleep on "-" in our normal state to simplify debugging.


Revision 116196 - (view) (download) (annotate) - [select for diffs]
Modified Wed Jun 11 06:49:16 2003 UTC (20 years, 5 months ago) by obrien
File length: 9451 byte(s)
Diff to previous 114795
Use __FBSDID().

Approved by:	phk


Revision 114795 - (view) (download) (annotate) - [select for diffs]
Modified Wed May 7 05:37:31 2003 UTC (20 years, 6 months ago) by phk
File length: 9421 byte(s)
Diff to previous 114526
Hide the "ENOMEM" notice messages behind bootverbose.  They are still
a valuable debugging tool for certain kinds of problems.

Approved by:	re/scottl


Revision 114526 - (view) (download) (annotate) - [select for diffs]
Modified Fri May 2 12:36:12 2003 UTC (20 years, 6 months ago) by phk
File length: 9401 byte(s)
Diff to previous 114511
Use an uma-zone for allocation bio requests.


Revision 114511 - (view) (download) (annotate) - [select for diffs]
Modified Fri May 2 06:42:59 2003 UTC (20 years, 6 months ago) by phk
File length: 9590 byte(s)
Diff to previous 114508
Back out all the stuff that didn't belong in the last commit.


Revision 114508 - (view) (download) (annotate) - [select for diffs]
Modified Fri May 2 06:36:14 2003 UTC (20 years, 6 months ago) by phk
File length: 9691 byte(s)
Diff to previous 113432
Use g_slice_spoiled() rather than g_std_spoiled().

Remember to free the buffer we got from g_read_data().


Revision 113432 - (view) (download) (annotate) - [select for diffs]
Modified Sun Apr 13 09:02:06 2003 UTC (20 years, 7 months ago) by phk
File length: 9590 byte(s)
Diff to previous 113392
Time has run from the "run GEOM in userland" harness, and the new regression
test is built to test GEOM as running in the kernel.

This commit is basically "unifdef -D_KERNEL" to remove the mainly #include
related code to support the userland-harness.


Revision 113392 - (view) (download) (annotate) - [select for diffs]
Modified Sat Apr 12 09:13:01 2003 UTC (20 years, 7 months ago) by phk
File length: 9734 byte(s)
Diff to previous 113032
Retire the experimental bio_taskqueue(), it was not quite as usable as
hoped.  It can be revived from here, should other drivers be able to
use it.


Revision 113032 - (view) (download) (annotate) - [select for diffs]
Modified Thu Apr 3 19:19:36 2003 UTC (20 years, 7 months ago) by phk
File length: 10401 byte(s)
Diff to previous 112830
Remove all references to BIO_SETATTR.  We will not be using it.


Revision 112830 - (view) (download) (annotate) - [select for diffs]
Modified Sat Mar 29 22:34:37 2003 UTC (20 years, 8 months ago) by phk
File length: 10812 byte(s)
Diff to previous 112370
Fix a bug in the ENOMEM pacing code which probably made it panic systems
after a lot of ENOMEM errors.


Revision 112370 - (view) (download) (annotate) - [select for diffs]
Modified Tue Mar 18 09:42:33 2003 UTC (20 years, 8 months ago) by phk
File length: 10768 byte(s)
Diff to previous 112367
Retire the GEOM private statistics code and use devstat instead.


Revision 112367 - (view) (download) (annotate) - [select for diffs]
Modified Tue Mar 18 08:45:25 2003 UTC (20 years, 8 months ago) by phk
File length: 12356 byte(s)
Diff to previous 112027
Including <sys/stdint.h> is (almost?) universally only to be able to use
%j in printfs, so put a newsted include in <sys/systm.h> where the printf
prototype lives and save everybody else the trouble.


Revision 112027 - (view) (download) (annotate) - [select for diffs]
Modified Sun Mar 9 09:59:48 2003 UTC (20 years, 8 months ago) by phk
File length: 12380 byte(s)
Diff to previous 111119
Don't abuse the statistics counters for detecting if we have outstanding
I/O requests, instead use the new dedicated fields in the consumer and
provider to track this.


Revision 111119 - (view) (download) (annotate) - [select for diffs]
Modified Wed Feb 19 05:47:46 2003 UTC (20 years, 9 months ago) by imp
File length: 12338 byte(s)
Diff to previous 110736
Back out M_* changes, per decision of the TRB.

Approved by: trb


Revision 110736 - (view) (download) (annotate) - [select for diffs]
Modified Tue Feb 11 22:30:26 2003 UTC (20 years, 9 months ago) by phk
File length: 12331 byte(s)
Diff to previous 110703
Implement a bio-taskqueue to reduce number of context switches in
disk I/O processing.

        The intent is that the disk driver in its hardware interrupt
        routine will simply schedule the bio on the task queue with
        a routine to finish off whatever needs done.

        The g_up thread will then schedule this routine, the likely
        outcome of which is a biodone() which queues the bio on
        g_up's regular queue where it will be picked up and processed.

        Compared to the using the regular taskqueue, this saves one
        contextswitch.

Change our scheduling of the g_up and g_down queues to be water-tight,
at the cost of breaking the userland regression test-shims.

Input and ideas from:   scottl


Revision 110703 - (view) (download) (annotate) - [select for diffs]
Modified Tue Feb 11 13:13:10 2003 UTC (20 years, 9 months ago) by phk
File length: 11065 byte(s)
Diff to previous 110685
Don't short-circuit zero-length requests of they are BIO_[SG]ETATTR.


Revision 110685 - (view) (download) (annotate) - [select for diffs]
Modified Tue Feb 11 11:01:26 2003 UTC (20 years, 9 months ago) by phk
File length: 10940 byte(s)
Diff to previous 110592
Turn the "updating" flag (back) into two sequence number fields at
either ends of the structure so we have a way to determine if a
snapshot is consistent.


Revision 110592 - (view) (download) (annotate) - [select for diffs]
Modified Sun Feb 9 17:04:57 2003 UTC (20 years, 9 months ago) by phk
File length: 10960 byte(s)
Diff to previous 110541
Update the statistics collection code to track busy time instead of
idle time.

Statistics now default to "on" and can be turned off with
        sysctl kern.geom.collectstats=0

Performance impact of statistics collection is on the order of
800 nsec per consumer/provider set on a 700MHz Athlon.


Revision 110541 - (view) (download) (annotate) - [select for diffs]
Added Sat Feb 8 13:03:57 2003 UTC (20 years, 9 months ago) by phk
File length: 10662 byte(s)
Diff to previous 110523
Move the g_stat struct to its own .h file, we will export it to other code.

Insted of embedding a struct g_stat in consumers and providers, merely
include a pointer.

Remove a couple of <sys/time.h> includes now unneeded.

Add a special allocator for struct g_stat.  This allocator will allocate
entire pages and hand out g_stat functions from there.  The "id" field
indicates free/used status.

Add "/dev/geom.stats" device driver whic exports the pages from the
allocator to userland with mmap(2) in read-only mode.

This mmap(2) interface should be considered a non-public interface and
the functions in libgeom (not yet committed) should be used to access
the statistics data.



This form allows you to request diffs between any two revisions of this file. For each of the two "sides" of the diff, enter a numeric revision.

  Diffs between and
  Type of Diff should be a

  ViewVC Help
Powered by ViewVC 1.1.27