How to call syscall readahead in Python?

How can I call readahead syscall in Python 3?

readahead () starts readahead in a file so that subsequent reads from this file will be executed from the cache, and not block the I / O drive

+4
source share
1 answer

Use ctypesand get the system call from 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 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))
+3
source

Source: https://habr.com/ru/post/1648237/


All Articles