• Minchan Kim's avatar
    zram: handle multiple pages attached bio's bvec · e86942c7
    Minchan Kim authored
    Patch series "zram clean up", v2.
    
    This patchset aims to clean up zram .
    
    [1] clean up multiple pages's bvec handling.
    [2] clean up partial IO handling
    [3-6] clean up zram via using accessor and removing pointless structure.
    
    With [2-6] applied, we can get a few hundred bytes as well as huge
    readibility enhance.
    
    x86: 708 byte save
    
        add/remove: 1/1 grow/shrink: 0/11 up/down: 478/-1186 (-708)
        function                                     old     new   delta
        zram_special_page_read                         -     478    +478
        zram_reset_device                            317     314      -3
        mem_used_max_store                           131     128      -3
        compact_store                                 96      93      -3
        mm_stat_show                                 203     197      -6
        zram_add                                     719     712      -7
        zram_slot_free_notify                        229     214     -15
        zram_make_request                            819     803     -16
        zram_meta_free                               128     111     -17
        zram_free_page                               180     151     -29
        disksize_store                               432     361     -71
        zram_decompress_page.isra                    504       -    -504
        zram_bvec_rw                                2592    2080    -512
        Total: Before=25350773, After=25350065, chg -0.00%
    
    ppc64: 231 byte save
    
        add/remove: 2/0 grow/shrink: 1/9 up/down: 681/-912 (-231)
        function                                     old     new   delta
        zram_special_page_read                         -     480    +480
        zram_slot_lock                                 -     200    +200
        vermagic                                      39      40      +1
        mm_stat_show                                 256     248      -8
        zram_meta_free                               200     184     -16
        zram_add                                     944     912     -32
        zram_free_page                               348     308     -40
        disksize_store                               572     492     -80
        zram_decompress_page                         664     564    -100
        zram_slot_free_notify                        292     160    -132
        zram_make_request                           1132    1000    -132
        zram_bvec_rw                                2768    2396    -372
        Total: Before=17565825, After=17565594, chg -0.00%
    
    This patch (of 6):
    
    Johannes Thumshirn reported system goes the panic when using NVMe over
    Fabrics loopback target with zram.
    
    The reason is zram expects each bvec in bio contains a single page
    but nvme can attach a huge bulk of pages attached to the bio's bvec
    so that zram's index arithmetic could be wrong so that out-of-bound
    access makes system panic.
    
    [1] in mainline solved solved the problem by limiting max_sectors with
    SECTORS_PER_PAGE but it makes zram slow because bio should split with
    each pages so this patch makes zram aware of multiple pages in a bvec
    so it could solve without any regression(ie, bio split).
    
    [1] 0bc31538, zram: set physical queue limits to avoid array out of
        bounds accesses
    
    Link: http://lkml.kernel.org/r/20170413134057.GA27499@bboxSigned-off-by: default avatarMinchan Kim <minchan@kernel.org>
    Reported-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
    Tested-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
    Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
    Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
    Cc: Hannes Reinecke <hare@suse.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    e86942c7
zram_drv.c 33.2 KB