O_DIRECT on stdin?
jepler at unpythonic.net
jepler at unpythonic.net
Mon Nov 7 16:35:03 EST 2005
Here's some text from my open(2) manpage:
Transfer sizes, and the alignment of user buffer and file offset must all
be multiples of the logical block size of the file system.
It's unlikely that in practice you can get Python's sys.stdin.read() or
os.read() to reliably use a buffer that fits the alignment restriction.
However, a small "C" extension could provide something like os.read() which
*does* meet the restriction. The meat of it would look something like
#define PAGESIZE 4096 // a guess which may be right for x86 linux
#define REQUESTSIZE 1048576
ssize_t result;
char *buf, *base;
PyObject *pyresult;
buf = malloc(bufsize, REQUESTSIZE + PAGESIZE - 1);
base = round_up(buf, PAGESIZE);
result = read(0, base, REQUESTSIZE);
if(result == -1) {
set python error from errno
pyresult = NULL;
goto DONE;
}
pyresult = PyString_FromStringAndSize(base, result);
DONE:
free(buf);
return pyresult;
Here's a clever but untested "C" macro that claims to implement round_up:
#define round_up(amount, align) ((((amount) - 1) | ((align) - 1)) + 1)
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051107/fd3e562d/attachment.sig>
More information about the Python-list
mailing list