Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

zram: rework bdev block allocation

First, writeback bdev ->bitmap bits are set only from one context, as we
can have only one single task performing writeback, so we cannot race with
anything else. Remove retry path.

Second, we always check ZRAM_WB flag to distinguish writtenback slots, so
we should not confuse 0 bdev block index and 0 handle. We can use first
bdev block (0 bit) for writeback as well.

While at it, give functions slightly more accurate names, as we don't
alloc/free anything there, we reserve a block for async writeback or
release the block.

Link: https://lkml.kernel.org/r/20251122074029.3948921-6-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Brian Geffon <bgeffon@google.com>
Cc: Minchan Kim <minchan@google.com>
Cc: Richard Chang <richardycc@google.com>
Cc: Yuwen Chen <ywen.chen@foxmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sergey Senozhatsky and committed by
Andrew Morton
e87ddea3 a4f506c5

+18 -19
+18 -19
drivers/block/zram/zram_drv.c
··· 500 500 } 501 501 502 502 #ifdef CONFIG_ZRAM_WRITEBACK 503 + #define INVALID_BDEV_BLOCK (~0UL) 504 + 503 505 struct zram_wb_ctl { 504 506 /* idle list is accessed only by the writeback task, no concurency */ 505 507 struct list_head idle_reqs; ··· 748 746 return err; 749 747 } 750 748 751 - static unsigned long alloc_block_bdev(struct zram *zram) 749 + static unsigned long zram_reserve_bdev_block(struct zram *zram) 752 750 { 753 - unsigned long blk_idx = 1; 754 - retry: 755 - /* skip 0 bit to confuse zram.handle = 0 */ 756 - blk_idx = find_next_zero_bit(zram->bitmap, zram->nr_pages, blk_idx); 751 + unsigned long blk_idx; 752 + 753 + blk_idx = find_next_zero_bit(zram->bitmap, zram->nr_pages, 0); 757 754 if (blk_idx == zram->nr_pages) 758 - return 0; 755 + return INVALID_BDEV_BLOCK; 759 756 760 - if (test_and_set_bit(blk_idx, zram->bitmap)) 761 - goto retry; 762 - 757 + set_bit(blk_idx, zram->bitmap); 763 758 atomic64_inc(&zram->stats.bd_count); 764 759 return blk_idx; 765 760 } 766 761 767 - static void free_block_bdev(struct zram *zram, unsigned long blk_idx) 762 + static void zram_release_bdev_block(struct zram *zram, unsigned long blk_idx) 768 763 { 769 764 int was_set; 770 765 ··· 886 887 * (if enabled). 887 888 */ 888 889 zram_account_writeback_rollback(zram); 889 - free_block_bdev(zram, req->blk_idx); 890 + zram_release_bdev_block(zram, req->blk_idx); 890 891 return err; 891 892 } 892 893 ··· 900 901 * finishes. 901 902 */ 902 903 if (!zram_test_flag(zram, index, ZRAM_PP_SLOT)) { 903 - free_block_bdev(zram, req->blk_idx); 904 + zram_release_bdev_block(zram, req->blk_idx); 904 905 goto out; 905 906 } 906 907 ··· 989 990 struct zram_pp_ctl *ctl, 990 991 struct zram_wb_ctl *wb_ctl) 991 992 { 993 + unsigned long blk_idx = INVALID_BDEV_BLOCK; 992 994 struct zram_wb_req *req = NULL; 993 - unsigned long blk_idx = 0; 994 995 struct zram_pp_slot *pps; 995 996 int ret = 0, err = 0; 996 997 u32 index = 0; ··· 1022 1023 ret = err; 1023 1024 } 1024 1025 1025 - if (!blk_idx) { 1026 - blk_idx = alloc_block_bdev(zram); 1027 - if (!blk_idx) { 1026 + if (blk_idx == INVALID_BDEV_BLOCK) { 1027 + blk_idx = zram_reserve_bdev_block(zram); 1028 + if (blk_idx == INVALID_BDEV_BLOCK) { 1028 1029 ret = -ENOSPC; 1029 1030 break; 1030 1031 } ··· 1058 1059 __bio_add_page(&req->bio, req->page, PAGE_SIZE, 0); 1059 1060 1060 1061 zram_submit_wb_request(zram, wb_ctl, req); 1061 - blk_idx = 0; 1062 + blk_idx = INVALID_BDEV_BLOCK; 1062 1063 req = NULL; 1063 1064 cond_resched(); 1064 1065 continue; ··· 1365 1366 return -EIO; 1366 1367 } 1367 1368 1368 - static void free_block_bdev(struct zram *zram, unsigned long blk_idx) 1369 + static void zram_release_bdev_block(struct zram *zram, unsigned long blk_idx) 1369 1370 { 1370 1371 } 1371 1372 #endif ··· 1889 1890 1890 1891 if (zram_test_flag(zram, index, ZRAM_WB)) { 1891 1892 zram_clear_flag(zram, index, ZRAM_WB); 1892 - free_block_bdev(zram, zram_get_handle(zram, index)); 1893 + zram_release_bdev_block(zram, zram_get_handle(zram, index)); 1893 1894 goto out; 1894 1895 } 1895 1896