Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp775851ybg; Wed, 10 Jun 2020 13:25:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrZ/fytGB0rFgt6CsdjDQpWAT0X2l1AmyuLgsvhzFL0x4Xo7K3uhCaC7d8Y46ZMDXgBLtg X-Received: by 2002:a17:907:2052:: with SMTP id pg18mr4912497ejb.513.1591820739890; Wed, 10 Jun 2020 13:25:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591820739; cv=none; d=google.com; s=arc-20160816; b=sKC7RcWr/3aN5mWKAa+T/mcXzxnm6cu9t4aZWC8aIeaP8cUp4Zd2QgZ9dksG25Rgry CGRpEYG6FogJNCj7oj5umql1Hl/is3FXzQ5NQim5cas9WAwmCEDSveIkaw4sxXHpNAKD NkZBuvOCUDhqJxgk6EKLtHXxobVIfCGISu6qap9lf7lwnNGybF+E9Jirf8CmeVSXd7pl iHzd6ju/itLFjH4slyNWz6VFaDbkMRs3z00GnQC0hFqF1IB6nkwyXXqoM1IQcr2TWScR rc1GWhbZF779+iA4GZQhMxAkYHYGpFz4IZAS4qgycWce2CTcSDb7jAjyjjVjCaQGahK2 ItJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RjoGa99XdcmVsHZZNtbX8kRo95MxAX4SaxcEuGmYN1E=; b=vwGKdNNdmkLQs+f6vOkuLMyqegHQlYjz45cT4CrepQhGUaW+NC881hYLav8H2ZiMH8 DtPyvBXFmiBK/ZMMkOpss+VEPzYMed/hefKEt3Xx3GmVLk+xcFZ6gJMgI1q99+LGHSvm YYMMFeJVT8/Ujoh3Ag3Wz1RuxrbnzUoL+g97HZ7AsGR5nOLSMOG4jdu3Mun/hb/W6j0k GoaAdirDnIEE/oD/4X8EBgcQLYW4dm1X2mqkZ1Roc+g0cWHj4+jHfsDVaWKVSCVIC9xO DSBKFppTYQOYIyXrq4qDlJDUaKCM6eBC2qB38h/PxCbsKLqfSPUCyiFhr2mK4iDaIW86 Llpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KUjUe2Eh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b22si354353edx.194.2020.06.10.13.25.17; Wed, 10 Jun 2020 13:25:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KUjUe2Eh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730913AbgFJUQp (ORCPT + 99 others); Wed, 10 Jun 2020 16:16:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730543AbgFJUNt (ORCPT ); Wed, 10 Jun 2020 16:13:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C0BDC008744; Wed, 10 Jun 2020 13:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=RjoGa99XdcmVsHZZNtbX8kRo95MxAX4SaxcEuGmYN1E=; b=KUjUe2EhH1YNoqavI3yyeilX1v AIg9ZnYh349tXQaVUhDpoG2x1xeIRoPraIhW1SltAfmuALJ/GOA1nB+f5BrXqXIFvS3lzpwzB0Zif 7qimYe6y4IaiDQQPu+e60gSu+BJhi9oGwaO7UsGAFUSPiEUGSK02SyWrw4cBI8OrS5u3jvMrKiJ5X qo4bzCcQ5JLAJ16cEp3cBISjz6gk9X95Tc4XH75Uvs7YLr85Toyw6tEjPGrJN5OEQgvvx9KhyV/D/ DQhnNlURXvhxqU+2k/m5VMD72BPFikRsn4xKcWVD3ixS37XhL8hFUta9Y+gDVwnwtTKB2WN9E/7QQ +IxgPI8Q==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj76a-0003V7-2z; Wed, 10 Jun 2020 20:13:48 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 22/51] iomap: Support arbitrarily many blocks per page Date: Wed, 10 Jun 2020 13:13:16 -0700 Message-Id: <20200610201345.13273-23-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200610201345.13273-1-willy@infradead.org> References: <20200610201345.13273-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Matthew Wilcox (Oracle)" Size the uptodate array dynamically. Now that this array is protected by a spinlock, we can use bitmap functions to set the bits in this array instead of a loop around set_bit(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 4d3d0abc1421..1a398af42ed2 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -22,14 +22,14 @@ #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) @@ -45,15 +45,14 @@ 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 = kmalloc(sizeof(*iop), GFP_NOFS | __GFP_NOFAIL); - atomic_set(&iop->read_count, 0); - atomic_set(&iop->write_count, 0); + iop = kzalloc(struct_size(iop, uptodate, BITS_TO_LONGS(nr_blocks)), + 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 @@ -142,19 +141,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); } -- 2.26.2