• L
    tty: teach n_tty line discipline about the new "cookie continuations" · 3bf1cb8c
    Linus Torvalds 提交于
    stable inclusion
    from stable-5.10.21
    commit 0c78bf9c55f1b7e5301cc79a6cc0514bc0d60c99
    bugzilla: 50609
    
    --------------------------------
    
    commit 15ea8ae8 upstream.
    
    With the conversion to do the tty ldisc read operations in small chunks,
    the n_tty line discipline became noticeably slower for throughput
    oriented loads, because rather than read things in up to 2kB chunks, it
    would return at most 64 bytes per read() system call.
    
    The cost is mainly all in the "do system calls over and over", not
    really in the new "copy to an extra kernel buffer".
    
    This can be fixed by teaching the n_tty line discipline about the
    "cookie continuation" model, which the chunking code supports because
    things like hdlc need to be able to handle packets up to 64kB in size.
    
    Doing that doesn't just get us back to the old performace, but to much
    better performance: my stupid "copy 10MB of data over a pty" test
    program is now almost twice as fast as it used to be (going down from
    0.1s to 0.054s).
    
    This is entirely because it now creates maximal chunks (which happens to
    be "one byte less than one page" due to how we do the circular tty
    buffers).
    
    NOTE! This case only handles the simpler non-icanon case, which is the
    one where people may care about throughput.  I'm going to do the icanon
    case later too, because while performance isn't a major issue for that,
    there may be programs that think they'll always get a full line and
    don't like the 64-byte chunking for that reason.
    
    Such programs are arguably buggy (signals etc can cause random partial
    results from tty reads anyway), and good programs will handle such
    partial reads, but expecting everybody to write "good programs" has
    never been a winning policy for the kernel..
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NChen Jun <chenjun102@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    3bf1cb8c
n_tty.c 61.9 KB