}
+static PyObject *fadvise_done(PyObject *self, PyObject *args)
+{
+ int fd = -1;
+ long long ofs = 0;
+ if (!PyArg_ParseTuple(args, "iL", &fd, &ofs))
+ return NULL;
+#ifdef POSIX_FADV_DONTNEED
+ posix_fadvise(fd, 0, ofs, POSIX_FADV_DONTNEED);
+#endif
+ return Py_BuildValue("");
+}
+
+
static PyMethodDef hashsplit_methods[] = {
{ "blobbits", blobbits, METH_VARARGS,
"Return the number of bits in the rolling checksum." },
"Write random bytes to the given file descriptor" },
{ "open_noatime", open_noatime, METH_VARARGS,
"open() the given filename for read with O_NOATIME if possible" },
+ { "fadvise_done", fadvise_done, METH_VARARGS,
+ "Inform the kernel that we're finished with earlier parts of a file" },
{ NULL, NULL, 0, NULL }, // sentinel
};
def blobiter(files):
for f in files:
+ ofs = 0
while 1:
+ fadvise_done(f, max(0, ofs - 1024*1024))
b = f.read(BLOB_HWM)
+ ofs += len(b)
if not b:
+ fadvise_done(f, ofs)
break
yield b
except:
pass
raise
+
+
+def fadvise_done(f, ofs):
+ assert(ofs >= 0)
+ if ofs > 0:
+ _hashsplit.fadvise_done(f.fileno(), ofs)