From patchwork Fri Aug 21 12:46:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11729381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB96A739 for ; Fri, 21 Aug 2020 12:46:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A833A207DA for ; Fri, 21 Aug 2020 12:46:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QGRpdUwh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728648AbgHUMqU (ORCPT ); Fri, 21 Aug 2020 08:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbgHUMqT (ORCPT ); Fri, 21 Aug 2020 08:46:19 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC5E5C061386; Fri, 21 Aug 2020 05:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Vi3dyhpPSVNnBr48T2kaEEh7Qye4Ig7BISvbjHctEw0=; b=QGRpdUwhth/vk2kfzS4El5ylUD BkM9qk50FGJKptB4nhswOJaFrLDBMi9mG0s5ej6AgGVhkfhvVO0Fvkav9WvB1c0xezl7xAZmdWvXd c8R88e5DcqFIkvzSHbRCCZWxXjmLqT07FU5slIVOcC341Bx292RRrXd6XL7mWYu7sauFZi/WzIDNh YaTbsADUP9MuAKWNuU8N1jckWml7VqzWECPW4c2qskYhgiqPZ7yFpVAvrohjQ3kMkUs0DfcnedVr2 dBXGC9CVs46HsbPXb4kFggl9ycKDGEWTqbo8AMmgxA+tRJuaUt+//27YAYIxOh5IkognmSvm/Ekcd 630iIJ1A==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k96Qt-0002hM-TT; Fri, 21 Aug 2020 12:46:12 +0000 From: "Matthew Wilcox (Oracle)" To: Yu Kuai , hch@infradead.org, darrick.wong@oracle.com, david@fromorbit.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 1/3] iomap: Use kzalloc to allocate iomap_page Date: Fri, 21 Aug 2020 13:46:04 +0100 Message-Id: <20200821124606.10165-1-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200821124424.GQ17456@casper.infradead.org> References: <20200821124424.GQ17456@casper.infradead.org> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org We can skip most of the initialisation, although spinlocks still need explicit initialisation as architectures may use a non-zero value to indicate unlocked. The comment is no longer useful as attach_page_private() handles the refcount now. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 13d5cdab8dcd..639d54a4177e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -49,16 +49,8 @@ iomap_page_create(struct inode *inode, struct page *page) if (iop || i_blocks_per_page(inode, page) <= 1) return iop; - iop = kmalloc(sizeof(*iop), GFP_NOFS | __GFP_NOFAIL); - atomic_set(&iop->read_count, 0); - atomic_set(&iop->write_count, 0); + iop = kzalloc(sizeof(*iop), GFP_NOFS | __GFP_NOFAIL); spin_lock_init(&iop->uptodate_lock); - bitmap_zero(iop->uptodate, PAGE_SIZE / SECTOR_SIZE); - - /* - * migrate_page_move_mapping() assumes that pages with private data have - * their count elevated by 1. - */ attach_page_private(page, iop); return iop; } From patchwork Fri Aug 21 12:46:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11729379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8670D739 for ; Fri, 21 Aug 2020 12:46:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64C27207DA for ; Fri, 21 Aug 2020 12:46:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XH+MQDTH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728697AbgHUMq2 (ORCPT ); Fri, 21 Aug 2020 08:46:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728657AbgHUMqU (ORCPT ); Fri, 21 Aug 2020 08:46:20 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7CDC061385; Fri, 21 Aug 2020 05:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sW/lmAUNObsQf0xR5kBTl1oS2J9NZWgwGdTe/goMtJc=; b=XH+MQDTHFsZE57LVURtyeRxmYw 6/dfXxrWnHJJkt4XbykeOx8FHKU/mulEfjrbmUdSev/mDoncXGheSwvLhvt1XjOYBtQD5yVSOrAIA NxakaZhPd3Z6EF7YA9mWcLIfyJnyo7KwbLV+a8s3nWmoT+uu9x/ACkN7T2UhsLsctYixJN0cbAA4J 8s2Z97w7AJ3sli3NRgjM3vsJR/XuT8obN90aSEFR5CNVJeH6hTjcSdBruxVfnfe7bjXvy/Gme/2VC EoSGqZJe271uQU/8HDBb5uwK+WukB4Pv8UW3j1GxCjd0ccKj6K+ebSBjnYxDRKSCo6gz7ch8JS3x2 73v9DwEQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k96Qu-0002hP-Cm; Fri, 21 Aug 2020 12:46:12 +0000 From: "Matthew Wilcox (Oracle)" To: Yu Kuai , hch@infradead.org, darrick.wong@oracle.com, david@fromorbit.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 2/3] iomap: Use bitmap ops to set uptodate bits Date: Fri, 21 Aug 2020 13:46:05 +0100 Message-Id: <20200821124606.10165-2-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200821124606.10165-1-willy@infradead.org> References: <20200821124424.GQ17456@casper.infradead.org> <20200821124606.10165-1-willy@infradead.org> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Now that the bitmap is protected by a spinlock, we can use the more efficient bitmap ops instead of individual test/set bit ops. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 639d54a4177e..dbf9572dabe9 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -134,19 +134,11 @@ iomap_iop_set_range_uptodate(struct page *page, unsigned off, unsigned len) struct inode *inode = page->mapping->host; unsigned first = off >> inode->i_blkbits; unsigned last = (off + len - 1) >> inode->i_blkbits; - bool uptodate = true; unsigned long flags; - unsigned int i; spin_lock_irqsave(&iop->uptodate_lock, flags); - for (i = 0; i < i_blocks_per_page(inode, page); i++) { - if (i >= first && i <= last) - set_bit(i, iop->uptodate); - else if (!test_bit(i, iop->uptodate)) - uptodate = false; - } - - if (uptodate) + bitmap_set(iop->uptodate, first, last - first + 1); + if (bitmap_full(iop->uptodate, i_blocks_per_page(inode, page))) SetPageUptodate(page); spin_unlock_irqrestore(&iop->uptodate_lock, flags); } From patchwork Fri Aug 21 12:46:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11729371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8093C16B1 for ; Fri, 21 Aug 2020 12:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69D5B2078D for ; Fri, 21 Aug 2020 12:46:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bGBUXsVQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728600AbgHUMqT (ORCPT ); Fri, 21 Aug 2020 08:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725935AbgHUMqS (ORCPT ); Fri, 21 Aug 2020 08:46:18 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE919C061385; Fri, 21 Aug 2020 05:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Xw2XPdlhUARRfiex9KVuJH1KdQXCJM8rMs3N5Y9w1yI=; b=bGBUXsVQvmysMuH/LyUNH0kXlQ GiqNpYzUnvtFuYVrktImM2WlypAA8HAeFr9hwOuaQoRVA/T3fiAn+6zO1k+uSv2LNtiFQqrYrXCRO vEF5oDFWfwO7EnbBPDPHGdNEMJ81bpqH9iNnu4u6FndU36xmEfRFJaqAZZkakVIe+msMs9+G5s5dF MIEY+2pdgQiL0NJKc9nE/XPK4kg617GV8EqZ/Uch0UWLm81ZskfNXcEaYdUdtGWLPmR84hZP84ZGg SyvxhUyAVH+g+eEevLj9Ks1Kt6OKKZfepiT3zS4nLVOIYhFsAcx65Ed9SVAXCc/Jymv63U1Akj5r+ JBWvlNPg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k96Qu-0002hU-O1; Fri, 21 Aug 2020 12:46:12 +0000 From: "Matthew Wilcox (Oracle)" To: Yu Kuai , hch@infradead.org, darrick.wong@oracle.com, david@fromorbit.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 3/3] iomap: Support arbitrarily many blocks per page Date: Fri, 21 Aug 2020 13:46:06 +0100 Message-Id: <20200821124606.10165-3-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200821124606.10165-1-willy@infradead.org> References: <20200821124424.GQ17456@casper.infradead.org> <20200821124606.10165-1-willy@infradead.org> MIME-Version: 1.0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Size the uptodate array dynamically and add a few debugging assertions. Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index dbf9572dabe9..844e95cacea8 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -22,18 +22,19 @@ #include "../internal.h" /* - * Structure allocated for each page when block size < PAGE_SIZE to track + * Structure allocated for each page when block size < page size to track * sub-page uptodate status and I/O completions. */ struct iomap_page { atomic_t read_count; atomic_t write_count; spinlock_t uptodate_lock; - DECLARE_BITMAP(uptodate, PAGE_SIZE / 512); + unsigned long uptodate[]; }; static inline struct iomap_page *to_iomap_page(struct page *page) { + VM_BUG_ON_PGFLAGS(PageTail(page), page); if (page_has_private(page)) return (struct iomap_page *)page_private(page); return NULL; @@ -45,11 +46,13 @@ static struct iomap_page * iomap_page_create(struct inode *inode, struct page *page) { struct iomap_page *iop = to_iomap_page(page); + unsigned int nr_blocks = i_blocks_per_page(inode, page); - if (iop || i_blocks_per_page(inode, page) <= 1) + if (iop || nr_blocks <= 1) return iop; - iop = kzalloc(sizeof(*iop), GFP_NOFS | __GFP_NOFAIL); + iop = kzalloc(struct_size(iop, uptodate, BITS_TO_LONGS(nr_blocks)), + GFP_NOFS | __GFP_NOFAIL); spin_lock_init(&iop->uptodate_lock); attach_page_private(page, iop); return iop; @@ -59,11 +62,14 @@ static void iomap_page_release(struct page *page) { struct iomap_page *iop = detach_page_private(page); + unsigned int nr_blocks = i_blocks_per_page(page->mapping->host, page); if (!iop) return; WARN_ON_ONCE(atomic_read(&iop->read_count)); WARN_ON_ONCE(atomic_read(&iop->write_count)); + WARN_ON_ONCE(bitmap_full(iop->uptodate, nr_blocks) != + PageUptodate(page)); kfree(iop); }