• Vincent Donnefort's avatar
    tracing: Allow user-space mapping of the ring-buffer · cf9f0f7c
    Vincent Donnefort authored
    Currently, user-space extracts data from the ring-buffer via splice,
    which is handy for storage or network sharing. However, due to splice
    limitations, it is imposible to do real-time analysis without a copy.
    
    A solution for that problem is to let the user-space map the ring-buffer
    directly.
    
    The mapping is exposed via the per-CPU file trace_pipe_raw. The first
    element of the mapping is the meta-page. It is followed by each
    subbuffer constituting the ring-buffer, ordered by their unique page ID:
    
      * Meta-page -- include/uapi/linux/trace_mmap.h for a description
      * Subbuf ID 0
      * Subbuf ID 1
         ...
    
    It is therefore easy to translate a subbuf ID into an offset in the
    mapping:
    
      reader_id = meta->reader->id;
      reader_offset = meta->meta_page_size + reader_id * meta->subbuf_size;
    
    When new data is available, the mapper must call a newly introduced ioctl:
    TRACE_MMAP_IOCTL_GET_READER. This will update the Meta-page reader ID to
    point to the next reader containing unread data.
    
    Mapping will prevent snapshot and buffer size modifications.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240510140435.3550353-4-vdonnefort@google.com
    
    CC: <linux-mm@kvack.org>
    Signed-off-by: default avatarVincent Donnefort <vdonnefort@google.com>
    Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
    cf9f0f7c
trace.c 258 KB