Skip to contentSkip to conversation

SEEK_HOLE and SEEK_DATA

DISCUSSION [email protected] 4 participants 7 messages Feb 2, 2006 – Feb 3, 2006 VFS

lore
Share & tools
lore
#0 lore raw

Solaris 10 has added a moderately useful new feature... lseek now supports whence = 3 (SEEK_DATA) and 4 (SEEK_HOLE). What these do is advance the file pointer to the start of the next run of the appropriate kind past the given (absolute) offset.

This is, of course, to make backing up and copying sparse files more efficient.

I'm still figuring out the fine details of semantics. EOF is considered the start of a hole. If the seek position is past EOF, they return ENXIO.

I'm still trying to figure out if they search > the given offset or >=. Reading the code, it actually looks like lseek(fd, 13, SEEK_DATA) will return 0 on a non-sparse file, because they round down to blocks and then search by blocks.

Not that this affects the usual case where you start at offset 0 and alternate SEEK_DATA/SEEK_HOLE to find ranges to copy.

I was just wondering if it's an extension worth adopting.

#1 lore raw
Quoted 4 lines · On Thu, Feb 02, 2006 at 04:03:49AM -0500, [email protected] wrote:

Solaris 10 has added a moderately useful new feature... lseek now supports whence = 3 (SEEK_DATA) and 4 (SEEK_HOLE). What these do is advance the file pointer to the start of the next run of the appropriate kind past the given (absolute) offset.

Some filesystems in linux (XFS for one, probably others?) already have a mechanism (albeit more complex the way it's exposed) to find holes & data.

#2 lore raw
Quoted 10 lines · Chris Wedgwood
Quoted 4 lines · On Thu, Feb 02, 2006 at 04:03:49AM -0500, [email protected] wrote:

Solaris 10 has added a moderately useful new feature... lseek now supports whence = 3 (SEEK_DATA) and 4 (SEEK_HOLE). What these do is advance the file pointer to the start of the next run of the appropriate kind past the given (absolute) offset.

Some filesystems in linux (XFS for one, probably others?) already have a mechanism (albeit more complex the way it's exposed) to find holes & data.

NTFS, though not the Linux driver. Both XFS_IOC_GETBMAPX and FSCTL_QUERY_ALLOCATED_RANGE are much more efficient than SEEK_HOLE/SEEK_DATA (and let's forget about FIBMAP).

Szaka

#3 lore raw
Quoted 3 lines · Szakacsits Szabolcs

NTFS, though not the Linux driver. Both XFS_IOC_GETBMAPX and FSCTL_QUERY_ALLOCATED_RANGE are much more efficient than SEEK_HOLE/SEEK_DATA (and let's forget about FIBMAP).

If there was something consistent across all filesystems albeit it different to SEEK_HOLE & SEEK_DATA those could be implemented in glibc.

Given we've gotten along fine without them for some time I don't see that a little bit of thought and taking some time to chew over this will do any harm.

#4 lore raw
In reply to Szakacsits Szabolcs

The popular XDSM interface (commonly incorrectly called DMAPI) provides dm_probe_hole() for this (in fact, XFS on Linux implements XDSM).

But dm_probe_hole() is considerably harder to use (as a programmer) than SEEK_HOLE/SEEK_DATA. The worst thing about services like dm_probe_hole is the fact that you get back variable size data; SEEK_HOLE/SEEK_DATA doesn't have that problem. It isn't obvious to me that a series of seek/tell are noticeably slower when copying a file than a single system call that returns a list.

I usually prefer a special version of read() that shows you holes explicitly to either of the other approaches, but SEEK_HOLE/SEEK_DATA has the definite advantage of being a smaller perturbance of the API and easier to understand.

For those not familiar with XDSM and DMAPI, they're intended to facilitate file migration and backup and date back to 1993. DMAPI (Data Management API) is the general term for an API that meets certain requirements of data management, while XDSM is an X/Open standard that was the first and essentially the only DMAPI. Lots of commerical grade filesystem drivers implement at least an approximation of XDSM.

--
Bryan Henderson IBM Almaden Research Center
San Jose CA Filesystems

#5 lore raw
Quoted 2 lines · Bryan Henderson

It isn't obvious to me that a series of seek/tell are noticeably slower when copying a file than a single system call that returns a list.

It depends on how fast one is able to copy.

A special but not so unusual case of this if one doesn't want to copy at all and just interested in querying this information for analyses, future decisions, etc. Then the numbers would be something like this for e.g. a 200 GB sparse file:

JFS + FIBMAP 137.80 sec 97% CPU

  XFS  + FIBMAP            117.81 sec  97% CPU
  ext3 + FIBMAP             88.40 sec  96% CPU
  XFS  + XFS_IOC_GETBMAPX    0.05 sec  95% CPU

SEEK_HOLE/SEEK_DATA is somewhere between XFS_IOC_GETBMAPX and FIBMAP, in the worst case half-way.

Quoted 4 lines

I usually prefer a special version of read() that shows you holes explicitly to either of the other approaches, but SEEK_HOLE/SEEK_DATA has the definite advantage of being a smaller perturbance of the API and easier to understand.

Absolutely. For the price being less useful and efficient.

Szaka

#6 lore raw
In reply to Bryan Henderson
Quoted 2 lines · Bryan Henderson

But dm_probe_hole() is considerably harder to use (as a programmer) than SEEK_HOLE/SEEK_DATA.

It's also not in mainline nor likely to ever get merged.