如何在Python中调用syscall readahead?

Are*_*ski 6 file-io file system-calls python-3.x

如何在Python 3中调用readahead系统调用?

readahead()在文件上启动readahead,以便从缓存中满足从该文件的后续读取,而不是在磁盘I/O上阻塞

dhk*_*hke 5

从以下位置使用ctypes并拉入系统调用libc

    import ctypes, os

    # load ourselves, we already have libc
    libc = ctypes.CDLL(None, use_errno=True)

    # XXX - YMMV, ctypes doesn't have c_off_t much less c_off64_t.
    # Assume it's c_longlong, but don't count on that.
    off64_t = ctypes.c_longlong

    def readahead(fobj, offset, count):
        fno = fobj if isinstance(fobj, int) else fobj.fileno()

        code = libc.readahead(
            ctypes.c_int(fno),
            off64_t(offset),
            ctypes.c_size_t(count)
        )
        if code != 0:
            errno = ctypes.get_errno()
            raise OSError(errno, os.strerror(errno))
Run Code Online (Sandbox Code Playgroud)