From patchwork Mon Sep 18 11:04:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAD73CD13D9 for ; Mon, 18 Sep 2023 11:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239151AbjIRLFw (ORCPT ); Mon, 18 Sep 2023 07:05:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233284AbjIRLFY (ORCPT ); Mon, 18 Sep 2023 07:05:24 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B06C3; Mon, 18 Sep 2023 04:05:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6F10321AAD; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KWAyNqeHPBaQf4arjiE4/hRGo9wqjgCUyjPtyne5gYU=; b=WK6HshtwytK408unLa4mLWjYwBxhCZof6DdLQTgZ4AI/XaZWm46GdBKQZEQhUun+bTWOMq zDyElD/cOxaztc7PuC7to8biBd9xz+hji12mH1PWnb7m+WgdYaMbrzqabhSLucUleZGedS xqBahdCO6Lp/uSpQXdxtjMq61SksZDg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KWAyNqeHPBaQf4arjiE4/hRGo9wqjgCUyjPtyne5gYU=; b=MiKmQv4b8JyQ48UMYHZHdCOWKmcq6/cHLqwZN1mnyA7ApnQDVGpjIC5NlM/v7CzkwPNajE X1Yag6fVltG9tsDQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id DC7102C143; Mon, 18 Sep 2023 11:05:16 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id E5DCB51CD13F; Mon, 18 Sep 2023 13:05:16 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 01/18] mm/readahead: rework loop in page_cache_ra_unbounded() Date: Mon, 18 Sep 2023 13:04:53 +0200 Message-Id: <20230918110510.66470-2-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Rework the loop in page_cache_ra_unbounded() to advance with the number of pages in a folio instead of just one page at a time. Signed-off-by: Hannes Reinecke --- mm/readahead.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index e815c114de21..40a5f1f65281 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -208,7 +208,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i = 0; /* * Partway through the readahead operation, we will have added @@ -226,7 +226,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, /* * Preallocate as many pages as we will need. */ - for (i = 0; i < nr_to_read; i++) { + do { struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { @@ -239,8 +239,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -251,15 +251,16 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, gfp_mask) < 0) { folio_put(folio); read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } if (i == nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; - } + ractl->_nr_pages += folio_nr_pages(folio); + i += folio_nr_pages(folio); + } while (i < nr_to_read); /* * Now start the IO. We ignore I/O errors - if the folio is not From patchwork Mon Sep 18 11:04:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4202FCD3431 for ; Mon, 18 Sep 2023 11:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241264AbjIRLGE (ORCPT ); Mon, 18 Sep 2023 07:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235735AbjIRLFZ (ORCPT ); Mon, 18 Sep 2023 07:05:25 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9DF0E1; Mon, 18 Sep 2023 04:05:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6D7701FDFC; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DL+P5tZIMHEHlrB0+vP60AiHQ5Zy42uXD3xbHSI4Wtg=; b=EY2EOwV3LgZerJhl4xarcrMhImgZYyt2AxmSSgUTaXfCdOrGJhBviEdEWfFLAEcn5FQvOu SLFyBDsKTsvd+CGVc66gznATphjoWoDujt1ili9yyXJ7MIeY37POYckNBNpcDNnfxsxR+i qmj29o+kZJCUT/+rDsA2c9hlvtQYQuM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DL+P5tZIMHEHlrB0+vP60AiHQ5Zy42uXD3xbHSI4Wtg=; b=Uak9qn6At/6tfbvuW2szDZPnD13gjEczTHSmgBl16nK7K9qdY4DBsIc7zEPw1SXjzU7kQJ 9ahXSndQeLIRvJBw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id E66332C145; Mon, 18 Sep 2023 11:05:16 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id EE08D51CD141; Mon, 18 Sep 2023 13:05:16 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 02/18] fs/mpage: use blocks_per_folio instead of blocks_per_page Date: Mon, 18 Sep 2023 13:04:54 +0200 Message-Id: <20230918110510.66470-3-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert mpage to folios and associate the number of blocks with a folio and not a page. Signed-off-by: Hannes Reinecke --- fs/mpage.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/fs/mpage.c b/fs/mpage.c index 242e213ee064..c9d9fdadb500 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -114,12 +114,12 @@ static void map_buffer_to_folio(struct folio *folio, struct buffer_head *bh, * don't make any buffers if there is only one buffer on * the folio and the folio just needs to be set up to date */ - if (inode->i_blkbits == PAGE_SHIFT && + if (inode->i_blkbits == folio_shift(folio) && buffer_uptodate(bh)) { folio_mark_uptodate(folio); return; } - create_empty_buffers(&folio->page, i_blocksize(inode), 0); + folio_create_empty_buffers(folio, i_blocksize(inode), 0); head = folio_buffers(folio); } @@ -161,7 +161,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) struct folio *folio = args->folio; struct inode *inode = folio->mapping->host; const unsigned blkbits = inode->i_blkbits; - const unsigned blocks_per_page = PAGE_SIZE >> blkbits; + const unsigned blocks_per_folio = folio_size(folio) >> blkbits; const unsigned blocksize = 1 << blkbits; struct buffer_head *map_bh = &args->map_bh; sector_t block_in_file; @@ -169,7 +169,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) sector_t last_block_in_file; sector_t blocks[MAX_BUF_PER_PAGE]; unsigned page_block; - unsigned first_hole = blocks_per_page; + unsigned first_hole = blocks_per_folio; struct block_device *bdev = NULL; int length; int fully_mapped = 1; @@ -190,7 +190,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) goto confused; block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); - last_block = block_in_file + args->nr_pages * blocks_per_page; + last_block = block_in_file + args->nr_pages * blocks_per_folio; last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits; if (last_block > last_block_in_file) last_block = last_block_in_file; @@ -211,7 +211,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) clear_buffer_mapped(map_bh); break; } - if (page_block == blocks_per_page) + if (page_block == blocks_per_folio) break; blocks[page_block] = map_bh->b_blocknr + map_offset + relative_block; @@ -225,7 +225,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) * Then do more get_blocks calls until we are done with this folio. */ map_bh->b_folio = folio; - while (page_block < blocks_per_page) { + while (page_block < blocks_per_folio) { map_bh->b_state = 0; map_bh->b_size = 0; @@ -238,7 +238,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) if (!buffer_mapped(map_bh)) { fully_mapped = 0; - if (first_hole == blocks_per_page) + if (first_hole == blocks_per_folio) first_hole = page_block; page_block++; block_in_file++; @@ -256,7 +256,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) goto confused; } - if (first_hole != blocks_per_page) + if (first_hole != blocks_per_folio) goto confused; /* hole -> non-hole */ /* Contiguous blocks? */ @@ -267,7 +267,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) if (relative_block == nblocks) { clear_buffer_mapped(map_bh); break; - } else if (page_block == blocks_per_page) + } else if (page_block == blocks_per_folio) break; blocks[page_block] = map_bh->b_blocknr+relative_block; page_block++; @@ -276,7 +276,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) bdev = map_bh->b_bdev; } - if (first_hole != blocks_per_page) { + if (first_hole != blocks_per_folio) { folio_zero_segment(folio, first_hole << blkbits, PAGE_SIZE); if (first_hole == 0) { folio_mark_uptodate(folio); @@ -311,10 +311,10 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) relative_block = block_in_file - args->first_logical_block; nblocks = map_bh->b_size >> blkbits; if ((buffer_boundary(map_bh) && relative_block == nblocks) || - (first_hole != blocks_per_page)) + (first_hole != blocks_per_folio)) args->bio = mpage_bio_submit_read(args->bio); else - args->last_block_in_bio = blocks[blocks_per_page - 1]; + args->last_block_in_bio = blocks[blocks_per_folio - 1]; out: return args->bio; @@ -393,7 +393,7 @@ int mpage_read_folio(struct folio *folio, get_block_t get_block) { struct mpage_readpage_args args = { .folio = folio, - .nr_pages = 1, + .nr_pages = folio_nr_pages(folio), .get_block = get_block, }; @@ -474,12 +474,12 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; const unsigned blkbits = inode->i_blkbits; - const unsigned blocks_per_page = PAGE_SIZE >> blkbits; + const unsigned blocks_per_folio = folio_size(folio) >> blkbits; sector_t last_block; sector_t block_in_file; sector_t blocks[MAX_BUF_PER_PAGE]; unsigned page_block; - unsigned first_unmapped = blocks_per_page; + unsigned first_unmapped = blocks_per_folio; struct block_device *bdev = NULL; int boundary = 0; sector_t boundary_block = 0; @@ -504,12 +504,12 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, */ if (buffer_dirty(bh)) goto confused; - if (first_unmapped == blocks_per_page) + if (first_unmapped == blocks_per_folio) first_unmapped = page_block; continue; } - if (first_unmapped != blocks_per_page) + if (first_unmapped != blocks_per_folio) goto confused; /* hole -> non-hole */ if (!buffer_dirty(bh) || !buffer_uptodate(bh)) @@ -552,7 +552,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, goto page_is_mapped; last_block = (i_size - 1) >> blkbits; map_bh.b_folio = folio; - for (page_block = 0; page_block < blocks_per_page; ) { + for (page_block = 0; page_block < blocks_per_folio; ) { map_bh.b_state = 0; map_bh.b_size = 1 << blkbits; @@ -631,14 +631,14 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, BUG_ON(folio_test_writeback(folio)); folio_start_writeback(folio); folio_unlock(folio); - if (boundary || (first_unmapped != blocks_per_page)) { + if (boundary || (first_unmapped != blocks_per_folio)) { bio = mpage_bio_submit_write(bio); if (boundary_block) { write_boundary_block(boundary_bdev, boundary_block, 1 << blkbits); } } else { - mpd->last_block_in_bio = blocks[blocks_per_page - 1]; + mpd->last_block_in_bio = blocks[blocks_per_folio - 1]; } goto out; From patchwork Mon Sep 18 11:04:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9C02CD342E for ; Mon, 18 Sep 2023 11:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241243AbjIRLGA (ORCPT ); Mon, 18 Sep 2023 07:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236209AbjIRLF0 (ORCPT ); Mon, 18 Sep 2023 07:05:26 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D814102; Mon, 18 Sep 2023 04:05:19 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6F12721AAE; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sO3vom66G3v5wN0Rdlws4SQilffG/SX/AZnhq8li8s0=; b=cj8Xl1vQV0GmNA9HBXj8qCFC/7Y3exTb67ZcPO94wqHHvTrAZ/dB1kK1qT6l5mP1JwBQ4J usw1tv6VgKf8IcXVvgCQOZsIKdukqXuDAPHAEfoaoAkgmjaGvwy/mEf5Mlr/yUjfLPh0Kj tyD0jeT+/Fvc/hDcQtHzmoAqYmUXuc4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sO3vom66G3v5wN0Rdlws4SQilffG/SX/AZnhq8li8s0=; b=piMdi4Fsth+ZBmMAKv2Q8dM0wTMAQce5SwRLodipTLgzMORWiDmU7WzMTnR9V1Eq1Y4u5E gc7ZlULoKZUZdDBw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id F104D2C146; Mon, 18 Sep 2023 11:05:16 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 01FB851CD143; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 03/18] block/buffer_head: introduce block_{index_to_sector,sector_to_index} Date: Mon, 18 Sep 2023 13:04:55 +0200 Message-Id: <20230918110510.66470-4-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Introduce accessor functions block_index_to_sector() and block_sector_to_index() to convert the page index into the corresponding sector and vice versa. Signed-off-by: Hannes Reinecke --- include/linux/buffer_head.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 4ede47649a81..55a3032f8375 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -277,6 +277,7 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size); void block_commit_write(struct page *page, unsigned int from, unsigned int to); int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, get_block_t get_block); + sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *); int block_truncate_page(struct address_space *, loff_t, get_block_t *); @@ -449,6 +450,22 @@ __bread(struct block_device *bdev, sector_t block, unsigned size) bool block_dirty_folio(struct address_space *mapping, struct folio *folio); +static inline sector_t block_index_to_sector(pgoff_t index, unsigned int blkbits) +{ + if (PAGE_SHIFT < blkbits) + return (sector_t)index >> (blkbits - PAGE_SHIFT); + else + return (sector_t)index << (PAGE_SHIFT - blkbits); +} + +static inline pgoff_t block_sector_to_index(sector_t block, unsigned int blkbits) +{ + if (PAGE_SHIFT < blkbits) + return (pgoff_t)block << (blkbits - PAGE_SHIFT); + else + return (pgoff_t)block >> (PAGE_SHIFT - blkbits); +} + #ifdef CONFIG_BUFFER_HEAD void buffer_init(void); From patchwork Mon Sep 18 11:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09B5BCD3429 for ; Mon, 18 Sep 2023 11:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241228AbjIRLF5 (ORCPT ); Mon, 18 Sep 2023 07:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233408AbjIRLFY (ORCPT ); Mon, 18 Sep 2023 07:05:24 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEDBE8F; Mon, 18 Sep 2023 04:05:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6DC561FDFD; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hjD8cnhpkb2Y5lGXJnngRv/a5ht52uC6A09ZJu2R4Sk=; b=q+DxNIy/ZdGzclXyaNKtO0EP6Qa3MpMBMit+ZPD8D4xYLfbyW1iiGWcnLCUtu5shbb0foY KCfjVqmChiQbJO+ucF0/u2OP0+gPG0fgLyK6X7qBP7/P5yqbltpEXKR0D/7IM7NkkWdNY7 7kHxkG+/jUsm1xBJhitj2z9c1iZ0Qvg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hjD8cnhpkb2Y5lGXJnngRv/a5ht52uC6A09ZJu2R4Sk=; b=xuR9poqmq8V9n9KU6b9VFXUJK6lbKZ5g1NhIREtuK4VxBXSb/fMzVXpbc7SzdKtg1vmkv7 3Rrxili5oEqVPqDw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 066092C149; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 0AA3651CD145; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 04/18] fs/buffer.c: use accessor function to translate page index to sectors Date: Mon, 18 Sep 2023 13:04:56 +0200 Message-Id: <20230918110510.66470-5-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use accessor functions block_index_to_sector() and block_sector_to_index() to translate the page index into the block sector and vice versa. Signed-off-by: Hannes Reinecke --- fs/buffer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 2379564e5aea..66895432d91f 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -199,7 +199,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t block) int all_mapped = 1; static DEFINE_RATELIMIT_STATE(last_warned, HZ, 1); - index = block >> (PAGE_SHIFT - bd_inode->i_blkbits); + index = block_sector_to_index(block, bd_inode->i_blkbits); folio = __filemap_get_folio(bd_mapping, index, FGP_ACCESSED, 0); if (IS_ERR(folio)) goto out; @@ -1702,13 +1702,13 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) struct inode *bd_inode = bdev->bd_inode; struct address_space *bd_mapping = bd_inode->i_mapping; struct folio_batch fbatch; - pgoff_t index = block >> (PAGE_SHIFT - bd_inode->i_blkbits); + pgoff_t index = block_sector_to_index(block, bd_inode->i_blkbits); pgoff_t end; int i, count; struct buffer_head *bh; struct buffer_head *head; - end = (block + len - 1) >> (PAGE_SHIFT - bd_inode->i_blkbits); + end = block_sector_to_index(block + len - 1, bd_inode->i_blkbits); folio_batch_init(&fbatch); while (filemap_get_folios(bd_mapping, &index, end, &fbatch)) { count = folio_batch_count(&fbatch); @@ -1835,7 +1835,7 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio, blocksize = bh->b_size; bbits = block_size_bits(blocksize); - block = (sector_t)folio->index << (PAGE_SHIFT - bbits); + block = block_index_to_sector(folio->index, bbits); last_block = (i_size_read(inode) - 1) >> bbits; /* @@ -2087,7 +2087,7 @@ int __block_write_begin_int(struct folio *folio, loff_t pos, unsigned len, blocksize = head->b_size; bbits = block_size_bits(blocksize); - block = (sector_t)folio->index << (PAGE_SHIFT - bbits); + block = block_index_to_sector(folio->index, bbits); for(bh = head, block_start = 0; bh != head || !block_start; block++, block_start=block_end, bh = bh->b_this_page) { @@ -2369,7 +2369,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) blocksize = head->b_size; bbits = block_size_bits(blocksize); - iblock = (sector_t)folio->index << (PAGE_SHIFT - bbits); + iblock = block_index_to_sector(folio->index, bbits); lblock = (limit+blocksize-1) >> bbits; bh = head; nr = 0; @@ -2657,7 +2657,7 @@ int block_truncate_page(struct address_space *mapping, return 0; length = blocksize - length; - iblock = (sector_t)index << (PAGE_SHIFT - inode->i_blkbits); + iblock = block_index_to_sector(index, inode->i_blkbits); folio = filemap_grab_folio(mapping, index); if (IS_ERR(folio)) From patchwork Mon Sep 18 11:04:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28576CD37B0 for ; Mon, 18 Sep 2023 11:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241202AbjIRLF5 (ORCPT ); Mon, 18 Sep 2023 07:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234735AbjIRLFZ (ORCPT ); Mon, 18 Sep 2023 07:05:25 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF819FD; Mon, 18 Sep 2023 04:05:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7BF781FDFF; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JUAe4yzlD4Eoh42gjXbVpU2X4y7THkjmua5ySlekNfg=; b=1/tZ3PU6BLkKC52ewzLRI/ybegGD7vJNp3HGk9M2dQsQ9S2ozKGfrdXsPJd7nnlwFW53xN 4yYyTdqIdZmrg3+cnx0wPx2jVwwJwLAx6O74iyTrQ6jpBTIe7ARfZvk2DgadSNuTQUX2w5 r6q3hl9c4OzSl30+8JBtjjwZQR27tPg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JUAe4yzlD4Eoh42gjXbVpU2X4y7THkjmua5ySlekNfg=; b=Fi+IlHP27ptD5VAo6UDbEfvUpyN+KyyvjdD/tT1lKA25UBKjcr/89Ug8hBItC+lVe53Rrj BMfE2u5JpUfNmlDw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 6347B2C153; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 1265251CD147; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 05/18] fs/mpage: use accessor function to translate page index to sectors Date: Mon, 18 Sep 2023 13:04:57 +0200 Message-Id: <20230918110510.66470-6-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use accessor functions to translate between page index and block sectors and ensure the resulting buffer size is calculated correctly. Signed-off-by: Hannes Reinecke --- fs/mpage.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/mpage.c b/fs/mpage.c index c9d9fdadb500..26460afd829a 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -168,7 +168,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) sector_t last_block; sector_t last_block_in_file; sector_t blocks[MAX_BUF_PER_PAGE]; - unsigned page_block; + unsigned num_blocks, page_block; unsigned first_hole = blocks_per_folio; struct block_device *bdev = NULL; int length; @@ -189,8 +189,12 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) if (folio_buffers(folio)) goto confused; - block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); - last_block = block_in_file + args->nr_pages * blocks_per_folio; + block_in_file = block_index_to_sector(folio->index, blkbits); + if (blkbits > PAGE_SHIFT) + num_blocks = args->nr_pages >> (blkbits - PAGE_SHIFT); + else + num_blocks = args->nr_pages * blocks_per_folio; + last_block = block_in_file + num_blocks; last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits; if (last_block > last_block_in_file) last_block = last_block_in_file; @@ -277,7 +281,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) } if (first_hole != blocks_per_folio) { - folio_zero_segment(folio, first_hole << blkbits, PAGE_SIZE); + folio_zero_segment(folio, first_hole << blkbits, folio_size(folio)); if (first_hole == 0) { folio_mark_uptodate(folio); folio_unlock(folio); @@ -543,7 +547,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, * The page has no buffers: map it to disk */ BUG_ON(!folio_test_uptodate(folio)); - block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits); + block_in_file = block_index_to_sector(folio->index, blkbits); /* * Whole page beyond EOF? Skip allocating blocks to avoid leaking * space. From patchwork Mon Sep 18 11:04:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A45FCD3430 for ; Mon, 18 Sep 2023 11:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241250AbjIRLGD (ORCPT ); Mon, 18 Sep 2023 07:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235528AbjIRLFZ (ORCPT ); Mon, 18 Sep 2023 07:05:25 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFC52FF; Mon, 18 Sep 2023 04:05:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7888321AB1; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zQdnjHkpphpTUZvovpEEYbCyA4aD++DzvNzuV2MwetQ=; b=x6juv+yivgnzd1s2Cvo7yOHmPrQzRukbHDxCP1y1H/pXLOOkZnZSNPwQEi97Y5v7s/2ln8 XZyyhroVs6lVY5TuobUIO0zBWsWuQCgGsq/DQXqJitW7DUN4avEjD1N/vqTFXUTBqmhHv5 nP3RbTFVLiKCp8E/uw/Dl9VAsKfTKkE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zQdnjHkpphpTUZvovpEEYbCyA4aD++DzvNzuV2MwetQ=; b=RNvEEQaqux8fUEAdfZUqsWWhx/kfpzRGbBVsEB8v0U6oh8r/nvHAHQ/dSF5jtFSCz8w7bE ofp/aLks2o/8V3Dg== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 618C52C14F; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 1AE0351CD149; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 06/18] fs: Allow fine-grained control of folio sizes Date: Mon, 18 Sep 2023 13:04:58 +0200 Message-Id: <20230918110510.66470-7-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: "Matthew Wilcox (Oracle)" Some filesystems want to be able to limit the maximum size of folios, and some want to be able to ensure that folios are at least a certain size. Add mapping_set_folio_orders() to allow this level of control (although it is not yet honoured). [Pankaj]: added mapping_min_folio_order() Signed-off-by: Pankaj Raghav Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Hannes Reinecke --- include/linux/pagemap.h | 48 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 351c3b7f93a1..129d62a891be 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -202,10 +202,16 @@ enum mapping_flags { AS_EXITING = 4, /* final truncate in progress */ /* writeback related tags are not used */ AS_NO_WRITEBACK_TAGS = 5, - AS_LARGE_FOLIO_SUPPORT = 6, - AS_RELEASE_ALWAYS, /* Call ->release_folio(), even if no private data */ + AS_RELEASE_ALWAYS = 6, /* Call ->release_folio(), even if no private data */ + AS_FOLIO_ORDER_MIN = 8, + AS_FOLIO_ORDER_MAX = 13, + /* 8-17 are used for FOLIO_ORDER */ }; +#define AS_FOLIO_ORDER_MIN_MASK 0x00001f00 +#define AS_FOLIO_ORDER_MAX_MASK 0x0002e000 +#define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK) + /** * mapping_set_error - record a writeback error in the address_space * @mapping: the mapping in which an error should be set @@ -310,6 +316,29 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) m->gfp_mask = mask; } +/** + * mapping_set_folio_orders() - Set the range of folio sizes supported. + * @mapping: The file. + * @min: Minimum folio order (between 0-31 inclusive). + * @max: Maximum folio order (between 0-31 inclusive). + * + * The filesystem should call this function in its inode constructor to + * indicate which sizes of folio the VFS can use to cache the contents + * of the file. This should only be used if the filesystem needs special + * handling of folio sizes (ie there is something the core cannot know). + * Do not tune it based on, eg, i_size. + * + * Context: This should not be called while the inode is active as it + * is non-atomic. + */ +static inline void mapping_set_folio_orders(struct address_space *mapping, + unsigned int min, unsigned int max) +{ + mapping->flags = (mapping->flags & ~AS_FOLIO_ORDER_MASK) | + (min << AS_FOLIO_ORDER_MIN) | + (max << AS_FOLIO_ORDER_MAX); +} + /** * mapping_set_large_folios() - Indicate the file supports large folios. * @mapping: The file. @@ -323,7 +352,17 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) */ static inline void mapping_set_large_folios(struct address_space *mapping) { - __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); + mapping_set_folio_orders(mapping, 0, 31); +} + +static inline unsigned mapping_max_folio_order(struct address_space *mapping) +{ + return (mapping->flags & AS_FOLIO_ORDER_MAX_MASK) >> AS_FOLIO_ORDER_MAX; +} + +static inline unsigned mapping_min_folio_order(struct address_space *mapping) +{ + return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN; } /* @@ -332,8 +371,7 @@ static inline void mapping_set_large_folios(struct address_space *mapping) */ static inline bool mapping_large_folio_support(struct address_space *mapping) { - return IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); + return mapping_max_folio_order(mapping) > 0; } static inline int filemap_nr_thps(struct address_space *mapping) From patchwork Mon Sep 18 11:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABC96CD3424 for ; Mon, 18 Sep 2023 11:06:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237827AbjIRLFz (ORCPT ); Mon, 18 Sep 2023 07:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234440AbjIRLFZ (ORCPT ); Mon, 18 Sep 2023 07:05:25 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CF39100; Mon, 18 Sep 2023 04:05:19 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7876321AB0; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xN6TM7GHFN0mqNZxYxxtWtFr22aM89KuuSlQeaM7rVQ=; b=oivGAnFiHoQC3mzve3gBbJhTW0HH2z9Ykvz/cBJoO8cE3qBvC15vlkaVeR62458BHPICXA 0vyEYWgJ8zbFp4wEddXmdAsRZ+UvnqwlGC0WO1+QbwU585t/AlhxOEJKvm32uBRV/2dBfJ XhpsCs3qaXgk0Q/u6wNL0c3Tr2OB9Wo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xN6TM7GHFN0mqNZxYxxtWtFr22aM89KuuSlQeaM7rVQ=; b=3pQ/CfDScouXELAST2XLDIoiqVihUdtxb1CypSlVKmNS3qXPs2j3hZjPhAVdUe2IzSiW9G 11xZze9zvMzyXGBw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 613C22C14B; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 233A151CD14B; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 07/18] mm/filemap: allocate folios with mapping order preference Date: Mon, 18 Sep 2023 13:04:59 +0200 Message-Id: <20230918110510.66470-8-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use mapping_min_folio_order() when calling filemap_alloc_folio() to allocate folios with the order specified by the mapping. Signed-off-by: Hannes Reinecke --- mm/filemap.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 582f5317ff71..98c3737644d5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -507,9 +507,14 @@ static void __filemap_fdatawait_range(struct address_space *mapping, pgoff_t end = end_byte >> PAGE_SHIFT; struct folio_batch fbatch; unsigned nr_folios; + unsigned int order = mapping_min_folio_order(mapping); folio_batch_init(&fbatch); + if (order) { + index = ALIGN_DOWN(index, 1 << order); + end = ALIGN_DOWN(end, 1 << order); + } while (index <= end) { unsigned i; @@ -2482,7 +2487,8 @@ static int filemap_create_folio(struct file *file, struct folio *folio; int error; - folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), + mapping_min_folio_order(mapping)); if (!folio) return -ENOMEM; @@ -2542,9 +2548,16 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, pgoff_t last_index; struct folio *folio; int err = 0; + unsigned int order = mapping_min_folio_order(mapping); /* "last_index" is the index of the page beyond the end of the read */ last_index = DIV_ROUND_UP(iocb->ki_pos + count, PAGE_SIZE); + if (order) { + /* Align with folio order */ + WARN_ON(index % 1 << order); + index = ALIGN_DOWN(index, 1 << order); + last_index = ALIGN(last_index, 1 << order); + } retry: if (fatal_signal_pending(current)) return -EINTR; @@ -2561,7 +2574,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; err = filemap_create_folio(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, fbatch); + index, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -3676,7 +3689,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, repeat: folio = filemap_get_folio(mapping, index); if (IS_ERR(folio)) { - folio = filemap_alloc_folio(gfp, 0); + folio = filemap_alloc_folio(gfp, + mapping_min_folio_order(mapping)); if (!folio) return ERR_PTR(-ENOMEM); err = filemap_add_folio(mapping, folio, index, gfp); From patchwork Mon Sep 18 11:05:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DC4BCD13DD for ; Mon, 18 Sep 2023 11:06:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239774AbjIRLFy (ORCPT ); Mon, 18 Sep 2023 07:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233421AbjIRLFZ (ORCPT ); Mon, 18 Sep 2023 07:05:25 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA826E6; Mon, 18 Sep 2023 04:05:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7ABFD1FDFE; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VXuGAE77Y1ZoaYEDFz/VrOFxHm5srcxFRGpv+gi7iDM=; b=2DC+zaAqoOp1lPfpc9dJf9O6mU4r1FYfud+aEkHHIRWd0XZ7a/XVTgw51KCWiTL/f3PeqZ 7Vze48ZDjg2q2nBZWh3WIgKAtKj0e/xAVlQYyzosoDkFRceNdQwhJtpWWe1PMXOZIR2mdB +HBL4GuIjFXm9uzE/NNb1/JT+rce6wQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VXuGAE77Y1ZoaYEDFz/VrOFxHm5srcxFRGpv+gi7iDM=; b=5h2DwkMQgRMJCe5jaWSSz1DP0EspCtrdR+wii+DtlQz7WVCgWToeypod/1SmlGj1yon+6B pdfjpJmW70IwdgBg== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 633C12C152; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 2B63C51CD14D; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 08/18] mm/readahead: allocate folios with mapping order preference Date: Mon, 18 Sep 2023 13:05:00 +0200 Message-Id: <20230918110510.66470-9-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use mapping_get_folio_order() when calling filemap_alloc_folio() to allocate folios with the order specified by the mapping. Signed-off-by: Hannes Reinecke --- mm/readahead.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 40a5f1f65281..0466a2bdb80a 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -244,7 +244,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, continue; } - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, + mapping_min_folio_order(mapping)); if (!folio) break; if (filemap_add_folio(mapping, folio, index + i, @@ -311,6 +312,8 @@ void force_page_cache_ra(struct readahead_control *ractl, struct file_ra_state *ra = ractl->ra; struct backing_dev_info *bdi = inode_to_bdi(mapping->host); unsigned long max_pages, index; + unsigned int order = mapping_min_folio_order(mapping); + unsigned int min_pages = 1 << order; if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; @@ -320,6 +323,10 @@ void force_page_cache_ra(struct readahead_control *ractl, * be up to the optimal hardware IO size */ index = readahead_index(ractl); + if (order) { + WARN_ON(index & (min_pages - 1)); + index = ALIGN_DOWN(index, min_pages); + } max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); nr_to_read = min_t(unsigned long, nr_to_read, max_pages); while (nr_to_read) { @@ -327,6 +334,8 @@ void force_page_cache_ra(struct readahead_control *ractl, if (this_chunk > nr_to_read) this_chunk = nr_to_read; + if (this_chunk < min_pages) + this_chunk = min_pages; ractl->_index = index; do_page_cache_ra(ractl, this_chunk, 0); @@ -597,8 +606,8 @@ static void ondemand_readahead(struct readahead_control *ractl, pgoff_t start; rcu_read_lock(); - start = page_cache_next_miss(ractl->mapping, index + 1, - max_pages); + start = page_cache_next_miss(ractl->mapping, + index + folio_nr_pages(folio), max_pages); rcu_read_unlock(); if (!start || start - index > max_pages) @@ -782,18 +791,20 @@ void readahead_expand(struct readahead_control *ractl, struct file_ra_state *ra = ractl->ra; pgoff_t new_index, new_nr_pages; gfp_t gfp_mask = readahead_gfp_mask(mapping); + unsigned int order = mapping_min_folio_order(mapping); + unsigned int min_nr_pages = 1 << order; - new_index = new_start / PAGE_SIZE; + new_index = new_start / (min_nr_pages * PAGE_SIZE); /* Expand the leading edge downwards */ while (ractl->_index > new_index) { - unsigned long index = ractl->_index - 1; + unsigned long index = ractl->_index - min_nr_pages; struct folio *folio = xa_load(&mapping->i_pages, index); if (folio && !xa_is_value(folio)) return; /* Folio apparently present */ - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, order); if (!folio) return; if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) { @@ -805,12 +816,12 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true; psi_memstall_enter(&ractl->_pflags); } - ractl->_nr_pages++; + ractl->_nr_pages += folio_nr_pages(folio); ractl->_index = folio->index; } new_len += new_start - readahead_pos(ractl); - new_nr_pages = DIV_ROUND_UP(new_len, PAGE_SIZE); + new_nr_pages = DIV_ROUND_UP(new_len, min_nr_pages * PAGE_SIZE); /* Expand the trailing edge upwards */ while (ractl->_nr_pages < new_nr_pages) { @@ -820,7 +831,7 @@ void readahead_expand(struct readahead_control *ractl, if (folio && !xa_is_value(folio)) return; /* Folio apparently present */ - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, order); if (!folio) return; if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) { @@ -832,10 +843,10 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true; psi_memstall_enter(&ractl->_pflags); } - ractl->_nr_pages++; + ractl->_nr_pages += folio_nr_pages(folio); if (ra) { - ra->size++; - ra->async_size++; + ra->size += folio_nr_pages(folio); + ra->async_size += folio_nr_pages(folio); } } } From patchwork Mon Sep 18 11:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C56CFC46CA1 for ; Mon, 18 Sep 2023 11:06:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237319AbjIRLGW (ORCPT ); Mon, 18 Sep 2023 07:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236351AbjIRLF1 (ORCPT ); Mon, 18 Sep 2023 07:05:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482D294; Mon, 18 Sep 2023 04:05:21 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7902F21AB2; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l3AoJv2BI4/Yeg1oZ6DdfLHBbwEuOnZEioucjclZ6/Y=; b=Uf4h7o73hvBBWy0H8CPu+88GxRJcN/oV1LGJmdqMDllRbB+gR5VUw8aStuiiYFhRgEYdju OVX3CmkNXvYt/Jaqe5Y1JuehWrfGwklG5xC6EY/ShKW+2Ysu+SMLJkiI4G5TbgE8ApnQBs yJTfbYbN6pAMTfxvetGC+EJeow5BiD4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l3AoJv2BI4/Yeg1oZ6DdfLHBbwEuOnZEioucjclZ6/Y=; b=WYgm3DL0ajNKFozSyfShaisgQ/WKknxBghYuLNvjMebG7PtG/xAofBcO/vfQPwqWgmbBIA ejzDgezFBVF+TDDw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 614122C14E; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 338E851CD14F; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 09/18] fs/buffer: use mapping order in grow_dev_page() Date: Mon, 18 Sep 2023 13:05:01 +0200 Message-Id: <20230918110510.66470-10-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the correct mapping order in grow_dev_page() to ensure folios are created with the correct order. Signed-off-by: Hannes Reinecke --- fs/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 66895432d91f..a219b79c57ad 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1044,6 +1044,7 @@ grow_dev_page(struct block_device *bdev, sector_t block, sector_t end_block; int ret = 0; gfp_t gfp_mask; + fgf_t fgf = FGP_LOCK | FGP_ACCESSED | FGP_CREAT; gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp; @@ -1054,9 +1055,8 @@ grow_dev_page(struct block_device *bdev, sector_t block, * code knows what it's doing. */ gfp_mask |= __GFP_NOFAIL; - - folio = __filemap_get_folio(inode->i_mapping, index, - FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp_mask); + fgf |= fgf_set_order(mapping_min_folio_order(inode->i_mapping)); + folio = __filemap_get_folio(inode->i_mapping, index, fgf, gfp_mask); bh = folio_buffers(folio); if (bh) { From patchwork Mon Sep 18 11:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E0CBCD3439 for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241336AbjIRLGK (ORCPT ); Mon, 18 Sep 2023 07:06:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237473AbjIRLF2 (ORCPT ); Mon, 18 Sep 2023 07:05:28 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4C1FF; Mon, 18 Sep 2023 04:05:22 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8116221AB6; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=37q0Dr7l40hFyEhU5apCFAKXSTQyY2pMTjvow9Tbtr8=; b=ZvfNLIm7YDN8G0NP6GB5QZ1M6i9iIm8r5z6ta9AhScs/76bcT79GcdBLkr4CEGASubLJJm RL/2wqCVl3l4nj9Bx9oE3qYdI4ECMCbPF8XwqFuQdrPknnQb69Eyl3OyGE2kPvrAqwTD0e suo4tmEr1iua1UjfBqpXAQUOrF9rgyQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=37q0Dr7l40hFyEhU5apCFAKXSTQyY2pMTjvow9Tbtr8=; b=QjNRvSy7gNPviwziegXxM6sJmyBaRkWeUo2VDstmPTB9sqoDg9zP6Zbk/XBk2l5TxE1qCg bubVmSlUbBuDFQCQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 6980B2C15F; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 3B43D51CD151; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 10/18] block/bdev: lift restrictions on supported blocksize Date: Mon, 18 Sep 2023 13:05:02 +0200 Message-Id: <20230918110510.66470-11-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org We now can support blocksizes larger than PAGE_SIZE, so lift the restriction. Signed-off-by: Hannes Reinecke --- block/bdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index f3b13aa1b7d4..adbcf7af0b56 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -137,8 +137,8 @@ static void set_init_blocksize(struct block_device *bdev) int set_blocksize(struct block_device *bdev, int size) { - /* Size must be a power of two, and between 512 and PAGE_SIZE */ - if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) + /* Size must be a power of two, and larger than 512 */ + if (size < 512 || !is_power_of_2(size)) return -EINVAL; /* Size cannot be smaller than the size supported by the device */ From patchwork Mon Sep 18 11:05:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED993CD3438 for ; Mon, 18 Sep 2023 11:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241285AbjIRLGH (ORCPT ); Mon, 18 Sep 2023 07:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237562AbjIRLF2 (ORCPT ); Mon, 18 Sep 2023 07:05:28 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6298101; Mon, 18 Sep 2023 04:05:22 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8502121AB8; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=12LMwdHZ1bZ03RR+L49Ac8+YMFXdYZwVGlXkz8YquqM=; b=dFpKEK4HeBOY3FewXaP7aJtlTdk6AnpOKd5O9i+LAbNCc2lHEJdxzKrF+7DEUo848CZIfI 3r83uBVKDg8zPugjmS+JWHroeQdVpXUn/+sgaEeVsy0kI6w9fZfcdCwQoA0uaGrsmsuGxL jbSuxDdd69gcz1d+cohNFjmlclWvXtg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=12LMwdHZ1bZ03RR+L49Ac8+YMFXdYZwVGlXkz8YquqM=; b=zqNAQDBNpyFItxIXFqKGYZdQYwaKTOpB0xmuEb47kyGqB7bslHfHMYBqwQ7egP4XZPoEK+ 4BmnSQlqI86VdDAQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 6ED792C162; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 4386C51CD153; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 11/18] block/bdev: enable large folio support for large logical block sizes Date: Mon, 18 Sep 2023 13:05:03 +0200 Message-Id: <20230918110510.66470-12-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Enable large folio support when the logical block size is larger than PAGE_SIZE. Signed-off-by: Hannes Reinecke --- block/bdev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index adbcf7af0b56..d5198743401a 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -133,6 +133,9 @@ static void set_init_blocksize(struct block_device *bdev) bsize <<= 1; } bdev->bd_inode->i_blkbits = blksize_bits(bsize); + if (bsize > PAGE_SIZE) + mapping_set_folio_orders(bdev->bd_inode->i_mapping, + get_order(bsize), MAX_ORDER); } int set_blocksize(struct block_device *bdev, int size) @@ -149,6 +152,9 @@ int set_blocksize(struct block_device *bdev, int size) if (bdev->bd_inode->i_blkbits != blksize_bits(size)) { sync_blockdev(bdev); bdev->bd_inode->i_blkbits = blksize_bits(size); + if (size > PAGE_SIZE) + mapping_set_folio_orders(bdev->bd_inode->i_mapping, + get_order(size), MAX_ORDER); kill_bdev(bdev); } return 0; @@ -425,6 +431,11 @@ void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors) void bdev_add(struct block_device *bdev, dev_t dev) { + unsigned int bsize = bdev_logical_block_size(bdev); + + if (bsize > PAGE_SIZE) + mapping_set_folio_orders(bdev->bd_inode->i_mapping, + get_order(bsize), MAX_ORDER); bdev->bd_dev = dev; bdev->bd_inode->i_rdev = dev; bdev->bd_inode->i_ino = dev; From patchwork Mon Sep 18 11:05:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98E6FCD343D for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241367AbjIRLGS (ORCPT ); Mon, 18 Sep 2023 07:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236942AbjIRLF1 (ORCPT ); Mon, 18 Sep 2023 07:05:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4490E8F; Mon, 18 Sep 2023 04:05:21 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7C55521AB3; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mfy2vCFgtAVM1TI9ZnFzaxxlIo0HxTD01Jxhm4xNrxg=; b=Ca1hy6TigpEZnzpiywPNfr1br8jbqU03nMElLxp6CpVGUpfRNyxQxuMROZykAR1h0c7ob1 qFFC6tOWF1+Q/YJ2pskJ3tbOSJxnZ8UPZ3y9PiOQ9Kwo2TLAi1RwDRcm/wP+uwUmvHs+Lb anmvOqcEA9HzoAMpLGr/YYSbVsyX5is= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mfy2vCFgtAVM1TI9ZnFzaxxlIo0HxTD01Jxhm4xNrxg=; b=btuNDoqqtEgZAlJCAKE86b75PiL6yTMsfdAQdDT9lcaxldv1yTZidGPTN2GAAkJRBWzU5j ctslc2fqD3YNBkCQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 65B192C15A; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 4BEEC51CD155; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 12/18] brd: convert to folios Date: Mon, 18 Sep 2023 13:05:04 +0200 Message-Id: <20230918110510.66470-13-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert the driver to work on folios instead of pages. Signed-off-by: Hannes Reinecke --- drivers/block/brd.c | 150 ++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 76 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 970bd6ff38c4..9aa7511abc33 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -28,11 +28,10 @@ #include /* - * Each block ramdisk device has a xarray brd_pages of pages that stores - * the pages containing the block device's contents. A brd page's ->index is - * its offset in PAGE_SIZE units. This is similar to, but in no way connected - * with, the kernel's pagecache or buffer cache (which sit above our block - * device). + * Each block ramdisk device has a xarray of folios that stores the folios + * containing the block device's contents. A brd folio's ->index is its offset + * in PAGE_SIZE units. This is similar to, but in no way connected with, + * the kernel's pagecache or buffer cache (which sit above our block device). */ struct brd_device { int brd_number; @@ -40,81 +39,81 @@ struct brd_device { struct list_head brd_list; /* - * Backing store of pages. This is the contents of the block device. + * Backing store of folios. This is the contents of the block device. */ - struct xarray brd_pages; - u64 brd_nr_pages; + struct xarray brd_folios; + u64 brd_nr_folios; }; /* - * Look up and return a brd's page for a given sector. + * Look up and return a brd's folio for a given sector. */ -static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector) +static struct folio *brd_lookup_folio(struct brd_device *brd, sector_t sector) { pgoff_t idx; - struct page *page; + struct folio *folio; - idx = sector >> PAGE_SECTORS_SHIFT; /* sector to page index */ - page = xa_load(&brd->brd_pages, idx); + idx = sector >> PAGE_SECTORS_SHIFT; /* sector to folio index */ + folio = xa_load(&brd->brd_folios, idx); - BUG_ON(page && page->index != idx); + BUG_ON(folio && folio->index != idx); - return page; + return folio; } /* - * Insert a new page for a given sector, if one does not already exist. + * Insert a new folio for a given sector, if one does not already exist. */ -static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp) +static int brd_insert_folio(struct brd_device *brd, sector_t sector, gfp_t gfp) { pgoff_t idx; - struct page *page, *cur; + struct folio *folio, *cur; int ret = 0; - page = brd_lookup_page(brd, sector); - if (page) + folio = brd_lookup_folio(brd, sector); + if (folio) return 0; - page = alloc_page(gfp | __GFP_ZERO | __GFP_HIGHMEM); - if (!page) + folio = folio_alloc(gfp | __GFP_ZERO | __GFP_HIGHMEM, 0); + if (!folio) return -ENOMEM; - xa_lock(&brd->brd_pages); + xa_lock(&brd->brd_folios); idx = sector >> PAGE_SECTORS_SHIFT; - page->index = idx; + folio->index = idx; - cur = __xa_cmpxchg(&brd->brd_pages, idx, NULL, page, gfp); + cur = __xa_cmpxchg(&brd->brd_folios, idx, NULL, folio, gfp); if (unlikely(cur)) { - __free_page(page); + folio_put(folio); ret = xa_err(cur); if (!ret && (cur->index != idx)) ret = -EIO; } else { - brd->brd_nr_pages++; + brd->brd_nr_folios++; } - xa_unlock(&brd->brd_pages); + xa_unlock(&brd->brd_folios); return ret; } /* - * Free all backing store pages and xarray. This must only be called when + * Free all backing store folios and xarray. This must only be called when * there are no other users of the device. */ -static void brd_free_pages(struct brd_device *brd) +static void brd_free_folios(struct brd_device *brd) { - struct page *page; + struct folio *folio; pgoff_t idx; - xa_for_each(&brd->brd_pages, idx, page) { - __free_page(page); + xa_for_each(&brd->brd_folios, idx, folio) { + folio_put(folio); cond_resched(); } - xa_destroy(&brd->brd_pages); + xa_destroy(&brd->brd_folios); } /* @@ -128,12 +127,12 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n, int ret; copy = min_t(size_t, n, PAGE_SIZE - offset); - ret = brd_insert_page(brd, sector, gfp); + ret = brd_insert_folio(brd, sector, gfp); if (ret) return ret; if (copy < n) { sector += copy >> SECTOR_SHIFT; - ret = brd_insert_page(brd, sector, gfp); + ret = brd_insert_folio(brd, sector, gfp); } return ret; } @@ -144,29 +143,29 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n, static void copy_to_brd(struct brd_device *brd, const void *src, sector_t sector, size_t n) { - struct page *page; + struct folio *folio; void *dst; unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; size_t copy; copy = min_t(size_t, n, PAGE_SIZE - offset); - page = brd_lookup_page(brd, sector); - BUG_ON(!page); + folio = brd_lookup_folio(brd, sector); + BUG_ON(!folio); - dst = kmap_atomic(page); - memcpy(dst + offset, src, copy); - kunmap_atomic(dst); + dst = kmap_local_folio(folio, offset); + memcpy(dst, src, copy); + kunmap_local(dst); if (copy < n) { src += copy; sector += copy >> SECTOR_SHIFT; copy = n - copy; - page = brd_lookup_page(brd, sector); - BUG_ON(!page); + folio = brd_lookup_folio(brd, sector); + BUG_ON(!folio); - dst = kmap_atomic(page); + dst = kmap_local_folio(folio, 0); memcpy(dst, src, copy); - kunmap_atomic(dst); + kunmap_local(dst); } } @@ -176,17 +175,17 @@ static void copy_to_brd(struct brd_device *brd, const void *src, static void copy_from_brd(void *dst, struct brd_device *brd, sector_t sector, size_t n) { - struct page *page; + struct folio *folio; void *src; unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; size_t copy; copy = min_t(size_t, n, PAGE_SIZE - offset); - page = brd_lookup_page(brd, sector); - if (page) { - src = kmap_atomic(page); - memcpy(dst, src + offset, copy); - kunmap_atomic(src); + folio = brd_lookup_folio(brd, sector); + if (folio) { + src = kmap_local_folio(folio, offset); + memcpy(dst, src, copy); + kunmap_local(src); } else memset(dst, 0, copy); @@ -194,20 +193,20 @@ static void copy_from_brd(void *dst, struct brd_device *brd, dst += copy; sector += copy >> SECTOR_SHIFT; copy = n - copy; - page = brd_lookup_page(brd, sector); - if (page) { - src = kmap_atomic(page); + folio = brd_lookup_folio(brd, sector); + if (folio) { + src = kmap_local_folio(folio, 0); memcpy(dst, src, copy); - kunmap_atomic(src); + kunmap_local(src); } else memset(dst, 0, copy); } } /* - * Process a single bvec of a bio. + * Process a single folio of a bio. */ -static int brd_do_bvec(struct brd_device *brd, struct page *page, +static int brd_do_folio(struct brd_device *brd, struct folio *folio, unsigned int len, unsigned int off, blk_opf_t opf, sector_t sector) { @@ -217,7 +216,7 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page, if (op_is_write(opf)) { /* * Must use NOIO because we don't want to recurse back into the - * block or filesystem layers from page reclaim. + * block or filesystem layers from folio reclaim. */ gfp_t gfp = opf & REQ_NOWAIT ? GFP_NOWAIT : GFP_NOIO; @@ -226,15 +225,15 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page, goto out; } - mem = kmap_atomic(page); + mem = kmap_local_folio(folio, off); if (!op_is_write(opf)) { - copy_from_brd(mem + off, brd, sector, len); - flush_dcache_page(page); + copy_from_brd(mem, brd, sector, len); + flush_dcache_folio(folio); } else { - flush_dcache_page(page); - copy_to_brd(brd, mem + off, sector, len); + flush_dcache_folio(folio); + copy_to_brd(brd, mem, sector, len); } - kunmap_atomic(mem); + kunmap_local(mem); out: return err; @@ -244,19 +243,18 @@ static void brd_submit_bio(struct bio *bio) { struct brd_device *brd = bio->bi_bdev->bd_disk->private_data; sector_t sector = bio->bi_iter.bi_sector; - struct bio_vec bvec; - struct bvec_iter iter; + struct folio_iter iter; - bio_for_each_segment(bvec, bio, iter) { - unsigned int len = bvec.bv_len; + bio_for_each_folio_all(iter, bio) { + unsigned int len = iter.length; int err; /* Don't support un-aligned buffer */ - WARN_ON_ONCE((bvec.bv_offset & (SECTOR_SIZE - 1)) || + WARN_ON_ONCE((iter.offset & (SECTOR_SIZE - 1)) || (len & (SECTOR_SIZE - 1))); - err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset, - bio->bi_opf, sector); + err = brd_do_folio(brd, iter.folio, len, iter.offset, + bio->bi_opf, sector); if (err) { if (err == -ENOMEM && bio->bi_opf & REQ_NOWAIT) { bio_wouldblock_error(bio); @@ -328,12 +326,12 @@ static int brd_alloc(int i) brd->brd_number = i; list_add_tail(&brd->brd_list, &brd_devices); - xa_init(&brd->brd_pages); + xa_init(&brd->brd_folios); snprintf(buf, DISK_NAME_LEN, "ram%d", i); if (!IS_ERR_OR_NULL(brd_debugfs_dir)) debugfs_create_u64(buf, 0444, brd_debugfs_dir, - &brd->brd_nr_pages); + &brd->brd_nr_folios); disk = brd->brd_disk = blk_alloc_disk(NUMA_NO_NODE); if (!disk) @@ -388,7 +386,7 @@ static void brd_cleanup(void) list_for_each_entry_safe(brd, next, &brd_devices, brd_list) { del_gendisk(brd->brd_disk); put_disk(brd->brd_disk); - brd_free_pages(brd); + brd_free_folios(brd); list_del(&brd->brd_list); kfree(brd); } @@ -419,7 +417,7 @@ static int __init brd_init(void) brd_check_and_reset_par(); - brd_debugfs_dir = debugfs_create_dir("ramdisk_pages", NULL); + brd_debugfs_dir = debugfs_create_dir("ramdisk_folios", NULL); for (i = 0; i < rd_nr; i++) { err = brd_alloc(i); From patchwork Mon Sep 18 11:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82AAECD343B for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241355AbjIRLGQ (ORCPT ); Mon, 18 Sep 2023 07:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237319AbjIRLF1 (ORCPT ); Mon, 18 Sep 2023 07:05:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D4AEFD; Mon, 18 Sep 2023 04:05:22 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7EEF321AB4; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jfTnCrMUyIgQQOyzhN/BiKgDJel5tnRX3E4HLhLkzxM=; b=XOyY0LhapqBgN6pSKH7Mbc/6mT6ZAnmquMKLsh56kby7XJS0lw3lGfM6p8BddNwOSZZufF 9M8gbXHtHKAz1CXngAFPd5U2l1wGTkrcYGN+BiIPhY8DcqCphP1fHKHlnwRL84fjVPkLqn 21UbGnJjpVrWevNnDoJ9HWKQiNh7sOM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jfTnCrMUyIgQQOyzhN/BiKgDJel5tnRX3E4HLhLkzxM=; b=leI3RX8xZZGHsGV42OBUe/ir6ItWAM5XB2Sngtv/AlY6qQVFDI/twvdZfepPD3oBhxgC2+ 9xzu4bb4ZHkeKLCQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 66DF32C15B; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 5401D51CD157; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 13/18] brd: abstract page_size conventions Date: Mon, 18 Sep 2023 13:05:05 +0200 Message-Id: <20230918110510.66470-14-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In preparation for changing the block sizes abstract away references to PAGE_SIZE and friends. Signed-off-by: Hannes Reinecke --- drivers/block/brd.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 9aa7511abc33..d6595b1a22e8 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -45,6 +45,23 @@ struct brd_device { u64 brd_nr_folios; }; +#define BRD_SECTOR_SHIFT(b) (PAGE_SHIFT - SECTOR_SHIFT) + +static pgoff_t brd_sector_index(struct brd_device *brd, sector_t sector) +{ + pgoff_t idx; + + idx = sector >> BRD_SECTOR_SHIFT(brd); + return idx; +} + +static int brd_sector_offset(struct brd_device *brd, sector_t sector) +{ + unsigned int rd_sector_mask = (1 << BRD_SECTOR_SHIFT(brd)) - 1; + + return ((unsigned int)sector & rd_sector_mask) << SECTOR_SHIFT; +} + /* * Look up and return a brd's folio for a given sector. */ @@ -53,7 +70,7 @@ static struct folio *brd_lookup_folio(struct brd_device *brd, sector_t sector) pgoff_t idx; struct folio *folio; - idx = sector >> PAGE_SECTORS_SHIFT; /* sector to folio index */ + idx = brd_sector_index(brd, sector); /* sector to folio index */ folio = xa_load(&brd->brd_folios, idx); BUG_ON(folio && folio->index != idx); @@ -68,19 +85,20 @@ static int brd_insert_folio(struct brd_device *brd, sector_t sector, gfp_t gfp) { pgoff_t idx; struct folio *folio, *cur; + unsigned int rd_sector_order = get_order(PAGE_SIZE); int ret = 0; folio = brd_lookup_folio(brd, sector); if (folio) return 0; - folio = folio_alloc(gfp | __GFP_ZERO | __GFP_HIGHMEM, 0); + folio = folio_alloc(gfp | __GFP_ZERO | __GFP_HIGHMEM, rd_sector_order); if (!folio) return -ENOMEM; xa_lock(&brd->brd_folios); - idx = sector >> PAGE_SECTORS_SHIFT; + idx = brd_sector_index(brd, sector); folio->index = idx; cur = __xa_cmpxchg(&brd->brd_folios, idx, NULL, folio, gfp); @@ -122,11 +140,12 @@ static void brd_free_folios(struct brd_device *brd) static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n, gfp_t gfp) { - unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; + unsigned int rd_sector_size = PAGE_SIZE; + unsigned int offset = brd_sector_offset(brd, sector); size_t copy; int ret; - copy = min_t(size_t, n, PAGE_SIZE - offset); + copy = min_t(size_t, n, rd_sector_size - offset); ret = brd_insert_folio(brd, sector, gfp); if (ret) return ret; @@ -145,10 +164,11 @@ static void copy_to_brd(struct brd_device *brd, const void *src, { struct folio *folio; void *dst; - unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; + unsigned int rd_sector_size = PAGE_SIZE; + unsigned int offset = brd_sector_offset(brd, sector); size_t copy; - copy = min_t(size_t, n, PAGE_SIZE - offset); + copy = min_t(size_t, n, rd_sector_size - offset); folio = brd_lookup_folio(brd, sector); BUG_ON(!folio); @@ -177,10 +197,11 @@ static void copy_from_brd(void *dst, struct brd_device *brd, { struct folio *folio; void *src; - unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT; + unsigned int rd_sector_size = PAGE_SIZE; + unsigned int offset = brd_sector_offset(brd, sector); size_t copy; - copy = min_t(size_t, n, PAGE_SIZE - offset); + copy = min_t(size_t, n, rd_sector_size - offset); folio = brd_lookup_folio(brd, sector); if (folio) { src = kmap_local_folio(folio, offset); From patchwork Mon Sep 18 11:05:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EB39CD342A for ; Mon, 18 Sep 2023 11:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241235AbjIRLF6 (ORCPT ); Mon, 18 Sep 2023 07:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235741AbjIRLF0 (ORCPT ); Mon, 18 Sep 2023 07:05:26 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E122101; Mon, 18 Sep 2023 04:05:19 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 814BD1FE00; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zOEpzxJooswozjT85Ui4aOBC3IjFJwXMatMEtlRVlTE=; b=rYAqHJnVkJwB51wZE49UY0JLIbmEbebfQPosKcEIQPnT9C7oTK+ewb1dKjwyIpbvHBDAn1 YdrFtwlyK+k3TI9hE5R8DAq30TRJEDIwHr8/JQzIiFeVxqxAIUHUPu1EuPxTsMI++q/PmN gfgVes7FcHkjUaERvIJsXT3SJtJ9qkI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zOEpzxJooswozjT85Ui4aOBC3IjFJwXMatMEtlRVlTE=; b=QCrgXxXzcqU5sBvHxJolByfPw9kozqKuDFDd0aVs49tOeIhHZVn/cxrmUlfCTBny1Y/uy9 TJhtZSrw0dt1dMDw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 670712C15C; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 5C0F851CD159; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 14/18] brd: use memcpy_{to,from}_folio() Date: Mon, 18 Sep 2023 13:05:06 +0200 Message-Id: <20230918110510.66470-15-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Simplify copy routines by using memcpy_to_folio()/memcpy_from_folio(). Signed-off-by: Hannes Reinecke --- drivers/block/brd.c | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index d6595b1a22e8..90e1b6c4fbc8 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -163,7 +163,6 @@ static void copy_to_brd(struct brd_device *brd, const void *src, sector_t sector, size_t n) { struct folio *folio; - void *dst; unsigned int rd_sector_size = PAGE_SIZE; unsigned int offset = brd_sector_offset(brd, sector); size_t copy; @@ -172,21 +171,7 @@ static void copy_to_brd(struct brd_device *brd, const void *src, folio = brd_lookup_folio(brd, sector); BUG_ON(!folio); - dst = kmap_local_folio(folio, offset); - memcpy(dst, src, copy); - kunmap_local(dst); - - if (copy < n) { - src += copy; - sector += copy >> SECTOR_SHIFT; - copy = n - copy; - folio = brd_lookup_folio(brd, sector); - BUG_ON(!folio); - - dst = kmap_local_folio(folio, 0); - memcpy(dst, src, copy); - kunmap_local(dst); - } + memcpy_to_folio(folio, offset, src, copy); } /* @@ -196,32 +181,16 @@ static void copy_from_brd(void *dst, struct brd_device *brd, sector_t sector, size_t n) { struct folio *folio; - void *src; unsigned int rd_sector_size = PAGE_SIZE; unsigned int offset = brd_sector_offset(brd, sector); size_t copy; copy = min_t(size_t, n, rd_sector_size - offset); folio = brd_lookup_folio(brd, sector); - if (folio) { - src = kmap_local_folio(folio, offset); - memcpy(dst, src, copy); - kunmap_local(src); - } else + if (folio) + memcpy_from_folio(dst, folio, offset, copy); + else memset(dst, 0, copy); - - if (copy < n) { - dst += copy; - sector += copy >> SECTOR_SHIFT; - copy = n - copy; - folio = brd_lookup_folio(brd, sector); - if (folio) { - src = kmap_local_folio(folio, 0); - memcpy(dst, src, copy); - kunmap_local(src); - } else - memset(dst, 0, copy); - } } /* From patchwork Mon Sep 18 11:05:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B66B2CD343E for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241391AbjIRLGT (ORCPT ); Mon, 18 Sep 2023 07:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237146AbjIRLF1 (ORCPT ); Mon, 18 Sep 2023 07:05:27 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D358C3; Mon, 18 Sep 2023 04:05:21 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8D3271FE01; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BVPahaNIXwTpL/pMoLNSBcQ3X6Y5CcM2ahaMzcXgzso=; b=OVz6NWhpbR0q0OZZ1jpe84PjWI4R5DxCDX97ryr4BxU55E++YPrOTU0eeWImxbZ2GIMGey FA4LXWd2Eowowu626PVwcvwRek+GTTlQCNA4E89LYV06t0sIHN1MqSTtlkJkeUY0oain5N d4r/B1A+KSW4+LOBUd2eeSDahbz1Hm0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BVPahaNIXwTpL/pMoLNSBcQ3X6Y5CcM2ahaMzcXgzso=; b=f8Uy+m+oyJYVe5iQbmdeBTEF4CixVkmkwM4vuEMvktls1jPhVvGn/eWStGZfy097JYLXyv wdRTDi6zLS5OUeAw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 7739F2C165; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 6411251CD15B; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 15/18] brd: make sector size configurable Date: Mon, 18 Sep 2023 13:05:07 +0200 Message-Id: <20230918110510.66470-16-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a module option 'rd_blksize' to allow the user to change the sector size of the RAM disks. Signed-off-by: Hannes Reinecke --- drivers/block/brd.c | 50 +++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 90e1b6c4fbc8..0c5f3dbbb77c 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -30,7 +30,7 @@ /* * Each block ramdisk device has a xarray of folios that stores the folios * containing the block device's contents. A brd folio's ->index is its offset - * in PAGE_SIZE units. This is similar to, but in no way connected with, + * in brd_sector_size units. This is similar to, but in no way connected with, * the kernel's pagecache or buffer cache (which sit above our block device). */ struct brd_device { @@ -43,9 +43,11 @@ struct brd_device { */ struct xarray brd_folios; u64 brd_nr_folios; + unsigned int brd_sector_shift; + unsigned int brd_sector_size; }; -#define BRD_SECTOR_SHIFT(b) (PAGE_SHIFT - SECTOR_SHIFT) +#define BRD_SECTOR_SHIFT(b) ((b)->brd_sector_shift - SECTOR_SHIFT) static pgoff_t brd_sector_index(struct brd_device *brd, sector_t sector) { @@ -85,7 +87,7 @@ static int brd_insert_folio(struct brd_device *brd, sector_t sector, gfp_t gfp) { pgoff_t idx; struct folio *folio, *cur; - unsigned int rd_sector_order = get_order(PAGE_SIZE); + unsigned int rd_sector_order = get_order(brd->brd_sector_size); int ret = 0; folio = brd_lookup_folio(brd, sector); @@ -140,7 +142,7 @@ static void brd_free_folios(struct brd_device *brd) static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n, gfp_t gfp) { - unsigned int rd_sector_size = PAGE_SIZE; + unsigned int rd_sector_size = brd->brd_sector_size; unsigned int offset = brd_sector_offset(brd, sector); size_t copy; int ret; @@ -163,7 +165,7 @@ static void copy_to_brd(struct brd_device *brd, const void *src, sector_t sector, size_t n) { struct folio *folio; - unsigned int rd_sector_size = PAGE_SIZE; + unsigned int rd_sector_size = brd->brd_sector_size; unsigned int offset = brd_sector_offset(brd, sector); size_t copy; @@ -181,7 +183,7 @@ static void copy_from_brd(void *dst, struct brd_device *brd, sector_t sector, size_t n) { struct folio *folio; - unsigned int rd_sector_size = PAGE_SIZE; + unsigned int rd_sector_size = brd->brd_sector_size; unsigned int offset = brd_sector_offset(brd, sector); size_t copy; @@ -279,6 +281,10 @@ static int max_part = 1; module_param(max_part, int, 0444); MODULE_PARM_DESC(max_part, "Num Minors to reserve between devices"); +static unsigned int rd_blksize = PAGE_SIZE; +module_param(rd_blksize, uint, 0444); +MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes."); + MODULE_LICENSE("GPL"); MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR); MODULE_ALIAS("rd"); @@ -305,6 +311,7 @@ static int brd_alloc(int i) struct brd_device *brd; struct gendisk *disk; char buf[DISK_NAME_LEN]; + unsigned int rd_max_sectors; int err = -ENOMEM; list_for_each_entry(brd, &brd_devices, brd_list) @@ -315,6 +322,25 @@ static int brd_alloc(int i) return -ENOMEM; brd->brd_number = i; list_add_tail(&brd->brd_list, &brd_devices); + if (!is_power_of_2(rd_blksize)) { + pr_err("rd_blksize %d is not supported\n", rd_blksize); + err = -EINVAL; + goto out_free_dev; + } + if (rd_blksize < SECTOR_SIZE) { + pr_err("rd_blksize must be at least 512 bytes\n"); + err = -EINVAL; + goto out_free_dev; + } + /* We can't allocate more than MAX_ORDER pages */ + rd_max_sectors = (1ULL << MAX_ORDER) << PAGE_SECTORS_SHIFT; + if ((rd_blksize >> SECTOR_SHIFT) > rd_max_sectors) { + pr_err("rd_blocksize too large\n"); + err = -EINVAL; + goto out_free_dev; + } + brd->brd_sector_shift = ilog2(rd_blksize); + brd->brd_sector_size = rd_blksize; xa_init(&brd->brd_folios); @@ -334,15 +360,9 @@ static int brd_alloc(int i) disk->private_data = brd; strscpy(disk->disk_name, buf, DISK_NAME_LEN); set_capacity(disk, rd_size * 2); - - /* - * This is so fdisk will align partitions on 4k, because of - * direct_access API needing 4k alignment, returning a PFN - * (This is only a problem on very small devices <= 4M, - * otherwise fdisk will align on 1M. Regardless this call - * is harmless) - */ - blk_queue_physical_block_size(disk->queue, PAGE_SIZE); + + blk_queue_physical_block_size(disk->queue, rd_blksize); + blk_queue_max_hw_sectors(disk->queue, rd_max_sectors); /* Tell the block layer that this is not a rotational device */ blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); From patchwork Mon Sep 18 11:05:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F8FACD343C for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241340AbjIRLGN (ORCPT ); Mon, 18 Sep 2023 07:06:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237382AbjIRLF1 (ORCPT ); Mon, 18 Sep 2023 07:05:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E855E6; Mon, 18 Sep 2023 04:05:22 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7FEE021AB5; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6w4JGP4ZAJgEQ0CQlDyJBIWo8/sjcn8nHyYU2QwWMn8=; b=SNVcuFDMM+tjaY0aZOxGKhu1/ySJ3PJqSZ2USKwgGMjgAO8LUzJEVGrEz4uWtz/el+FVoR H3VaaCmlWyBRSDX7bp3A7VqBJdX0ToKvaogaetJV5NbMk0qfhSC7MdK3iIM4u9dCIuMuqQ ZPaqALrbsTwA5JUUXaVt1FzLJNY4riY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6w4JGP4ZAJgEQ0CQlDyJBIWo8/sjcn8nHyYU2QwWMn8=; b=1LaVmJMsp6PjF29N3PPd5t5+s6o2nQa3FGwv5ysq50aBsC8UaP8yeJqPW8d5mySRoROHsh 5MvMZm6znij8DlCQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 692E92C15D; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 6C9C951CD15D; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 16/18] brd: make logical sector size configurable Date: Mon, 18 Sep 2023 13:05:08 +0200 Message-Id: <20230918110510.66470-17-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a module option 'rd_logical_blksize' to allow the user to change the logical sector size of the RAM disks. Signed-off-by: Hannes Reinecke --- drivers/block/brd.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 0c5f3dbbb77c..e2e364255902 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -45,6 +45,8 @@ struct brd_device { u64 brd_nr_folios; unsigned int brd_sector_shift; unsigned int brd_sector_size; + unsigned int brd_logical_sector_shift; + unsigned int brd_logical_sector_size; }; #define BRD_SECTOR_SHIFT(b) ((b)->brd_sector_shift - SECTOR_SHIFT) @@ -242,8 +244,8 @@ static void brd_submit_bio(struct bio *bio) int err; /* Don't support un-aligned buffer */ - WARN_ON_ONCE((iter.offset & (SECTOR_SIZE - 1)) || - (len & (SECTOR_SIZE - 1))); + WARN_ON_ONCE((iter.offset & (brd->brd_logical_sector_size - 1)) || + (len & (brd->brd_logical_sector_size - 1))); err = brd_do_folio(brd, iter.folio, len, iter.offset, bio->bi_opf, sector); @@ -285,6 +287,10 @@ static unsigned int rd_blksize = PAGE_SIZE; module_param(rd_blksize, uint, 0444); MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes."); +static unsigned int rd_logical_blksize = SECTOR_SIZE; +module_param(rd_logical_blksize, uint, 0444); +MODULE_PARM_DESC(rd_logical_blksize, "Logical blocksize of each RAM disk in bytes."); + MODULE_LICENSE("GPL"); MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR); MODULE_ALIAS("rd"); @@ -342,6 +348,21 @@ static int brd_alloc(int i) brd->brd_sector_shift = ilog2(rd_blksize); brd->brd_sector_size = rd_blksize; + if (!is_power_of_2(rd_logical_blksize)) { + pr_err("rd_logical_blksize %d is not supported\n", + rd_logical_blksize); + err = -EINVAL; + goto out_free_dev; + } + if (rd_logical_blksize > rd_blksize) { + pr_err("rd_logical_blksize %d larger than rd_blksize %d\n", + rd_logical_blksize, rd_blksize); + err = -EINVAL; + goto out_free_dev; + } + brd->brd_logical_sector_shift = ilog2(rd_logical_blksize); + brd->brd_logical_sector_size = rd_logical_blksize; + xa_init(&brd->brd_folios); snprintf(buf, DISK_NAME_LEN, "ram%d", i); @@ -362,6 +383,7 @@ static int brd_alloc(int i) set_capacity(disk, rd_size * 2); blk_queue_physical_block_size(disk->queue, rd_blksize); + blk_queue_logical_block_size(disk->queue, rd_logical_blksize); blk_queue_max_hw_sectors(disk->queue, rd_max_sectors); /* Tell the block layer that this is not a rotational device */ From patchwork Mon Sep 18 11:05:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF456CD343F for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241412AbjIRLGV (ORCPT ); Mon, 18 Sep 2023 07:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236692AbjIRLF1 (ORCPT ); Mon, 18 Sep 2023 07:05:27 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9745AE1; Mon, 18 Sep 2023 04:05:21 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8E6021FE02; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7YxTD9ivwBqDlU0rUH4B43A6drfBPCpobX7r4lclL8s=; b=y5VrsQtZSyfCP0fSu9yQrUFJnRPQU53VfudrMl94CnYtrz5TIfHfzLfmNemC2t/AtTNnZR gnI60raF0lCn37KIw2Iam3XuijU36LGZLadTiA1DMOkc5OatFR+NPqgz7jAlWM/JjhnKye zkOKceM5BXwg+69ZGxZbHQBWsnDP4mo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7YxTD9ivwBqDlU0rUH4B43A6drfBPCpobX7r4lclL8s=; b=GErq9oHTLI0nfJVFCYTBNOF/uty0XP64JJAoJ1/rADTpUiVNKEh86z+59qNaQteBSRF2Ep i8R5YbfLFdXUQdDA== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 79AA22C166; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 72C7551CD15F; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke Subject: [PATCH 17/18] xfs: remove check for block sizes smaller than PAGE_SIZE Date: Mon, 18 Sep 2023 13:05:09 +0200 Message-Id: <20230918110510.66470-18-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org We now support block sizes larger than PAGE_SIZE, so this check is pointless. Signed-off-by: Hannes Reinecke --- fs/xfs/xfs_super.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 1f77014c6e1a..67dcdd4dcf2d 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1651,18 +1651,6 @@ xfs_fs_fill_super( goto out_free_sb; } - /* - * Until this is fixed only page-sized or smaller data blocks work. - */ - if (mp->m_sb.sb_blocksize > PAGE_SIZE) { - xfs_warn(mp, - "File system with blocksize %d bytes. " - "Only pagesize (%ld) or less will currently work.", - mp->m_sb.sb_blocksize, PAGE_SIZE); - error = -ENOSYS; - goto out_free_sb; - } - /* Ensure this filesystem fits in the page cache limits */ if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) || xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) { From patchwork Mon Sep 18 11:05:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 13389447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1615ECD3437 for ; Mon, 18 Sep 2023 11:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241335AbjIRLGJ (ORCPT ); Mon, 18 Sep 2023 07:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237389AbjIRLF2 (ORCPT ); Mon, 18 Sep 2023 07:05:28 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F632100; Mon, 18 Sep 2023 04:05:22 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8345921AB7; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D5QLmYcyiXCClm9oSal5AbLNc763FLILvTTexvLDtfw=; b=ZCSXK1SLt/Lfx4XzX4fIMcBfywjX7G9r/cC/rhMFkS2ddSGBKQiUpRcMl8Tv7sPrABU6Op UuOKQXhBGtUQbJXz73R+SoeQZ67521Ul/PbZUrTMZqByZQzG0HvQ3R+Z1Q/flgYr+rd7ov hCZwuvcyKVojvz0yjjEvdQWmxa1fdes= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695035117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D5QLmYcyiXCClm9oSal5AbLNc763FLILvTTexvLDtfw=; b=oiwuijSI3YH9IQAqPcKjx+5SZRpDIArylIaQqai6E/s3AiIYrBFa7aXAqocgcMGO7J6qtf g8lQh1Dlf3sDVPAw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 6D48D2C161; Mon, 18 Sep 2023 11:05:17 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 79D7751CD161; Mon, 18 Sep 2023 13:05:17 +0200 (CEST) From: Hannes Reinecke To: Matthew Wilcox Cc: Luis Chamberlain , Christoph Hellwig , Jens Axboe , Pankaj Raghav , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 18/18] nvme: enable logical block size > PAGE_SIZE Date: Mon, 18 Sep 2023 13:05:10 +0200 Message-Id: <20230918110510.66470-19-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230918110510.66470-1-hare@suse.de> References: <20230918110510.66470-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Pankaj Raghav Don't set the capacity to zero for when logical block size > PAGE_SIZE as the block device with iomap aops support allocating block cache with a minimum folio order. Signed-off-by: Pankaj Raghav --- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f3a01b79148c..e72f1b1ee27a 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1889,7 +1889,7 @@ static void nvme_update_disk_info(struct gendisk *disk, * The block layer can't support LBA sizes larger than the page size * yet, so catch this early and don't allow block I/O. */ - if (ns->lba_shift > PAGE_SHIFT) { + if ((ns->lba_shift > PAGE_SHIFT) && IS_ENABLED(CONFIG_BUFFER_HEAD)) { capacity = 0; bs = (1 << 9); }