I had almost forgotten about this; but a few months back when I came into contact with the wd TRIM support in current I wanted to change the interface around before it appears in a release.
The current interface is two ioctls: - first you call DIOCGDISCARDINFO; this tells you the maximum number of blocks that can be discarded at once on the current device. - Then you call DIOCDISCARD with a block number and (I think) block count to actually do it. I have the following objections to this interface: 1. The interface doesn't need to and shouldn't expose the hardware limit of how many blocks can be discarded at once; instead, for large discards (which are not the common case) the loop over block ranges should be done in the driver. 2. The interface uses DEV_BSIZE units. Rather than promote the further proliferation of DEV_BSIZE, it should use either byte offsets or the device's own addressable block size. (I think byte offsets are best; making everything byte offsets minimizes the chance of sending in the wrong units.) 3. The interface is ioctl-based. I would like to see VOP_DISCARD for vnodes (which on regular files creates holes) and a corresponding block device op on struct bdevsw. And a syscall for user access to the operation. This would provide access to functionality that's currently lacking; also it will allow discard to work on vnd devices. Thoughts? (we can argue about what to call the syscall; I think there's prior art but can't remember what at the moment) -- David A. Holland dholl...@netbsd.org