From patchwork Wed May 9 07:48:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10388321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F8F460170 for ; Wed, 9 May 2018 07:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5075B28E05 for ; Wed, 9 May 2018 07:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4556928E56; Wed, 9 May 2018 07:48:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B124428E2B for ; Wed, 9 May 2018 07:48:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 014AB6B033F; Wed, 9 May 2018 03:48:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EE0DC6B0341; Wed, 9 May 2018 03:48:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D594C6B0342; Wed, 9 May 2018 03:48:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 8ACB46B033F for ; Wed, 9 May 2018 03:48:55 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id e18-v6so16274427pgt.3 for ; Wed, 09 May 2018 00:48:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=9RbDDh81xe4UwtYu730ckp4rkxMF7Vf/hOU9wtADM/w=; b=Fauff1oeOEfju8ptqs0RgTA7xXx1YNBwEeqLQ1GgNjKPwYpXELtHBWxWvmYEdBvuTb qQ+chFC+0LcVGeOU9q/lXA5NJ6nuN5qnA2kHD8r4/Xzqn4R+bC9Eip7O1jrkuNxBEPe5 28lvGX2Pi5UAwQFfUudKRDH0Gs/hmilb+fYl6GE0uFnOQFmqmkOeBc4jHKVh/espWWjO 9ZottKmR2ciwxtf0DAb2L6b0o++sgugbW5YReg4V/YRo9e7fJb32JVjJNH7fyXL+pMQu nqESF8pRWYkCaeQsRx1Xjtzve9QWKEYPc25hPWflnEq4DwPMgM6SQOumD6bEag6Ofia1 LRng== X-Gm-Message-State: ALQs6tC+nPGHrmKH1/piv4ySHxXzVCq4oOPYJ9wmvufHZLRRNAV6r5ss ++n5PtVpOqj4SznWEtJuMiWLRFb+AewnmERemlcL4XYLdXLCXIuvINxnICIQXHUuT5quLteDYQF bUb2ZsTC7UvJ0k0Fv/ZpMmdBOZyD3Wb6gJVUoOGRVcICXtzB0skggj3l0u7aZ8qs= X-Received: by 2002:a17:902:7782:: with SMTP id o2-v6mr45830290pll.247.1525852135254; Wed, 09 May 2018 00:48:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoDDiGfDCitaqxJRYU4+kHma4u0QeBGbENZReRtun8ft/z+Cfjshqn96X16XAKprT2fe40F X-Received: by 2002:a17:902:7782:: with SMTP id o2-v6mr45830267pll.247.1525852134535; Wed, 09 May 2018 00:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525852134; cv=none; d=google.com; s=arc-20160816; b=jXxY7U9qBpZuTXx5s4CjrWn4CBgNmZ5K82I2ZsuLhT79IkwUQU7LKz9ZyD4pal+x3X ILZxp1S6smYMZEoHwFoXl1o0VVWbQxrRAPp/1gcPxPJMHQ/8k/eXEFGOkLrz3yHvbG/M feQpBnQjo3kAKuM3n2QPxWWoDwM+4QCyistQVruCJvGxSQehTmS8GYg9OCBZ36SS6Qhu J8j0YLPUInPJzaKu5ETPUZqBGx6wECz2Ao5fnRT83W156DwyH6QWnDhr00qr6voGuLOz P06Geq2v35x+X3K/f9SKKqtMWaCyO01jFbfpSQNGgxRVIGE5aFc/sVwdOoqsLTN2dmXh UZ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9RbDDh81xe4UwtYu730ckp4rkxMF7Vf/hOU9wtADM/w=; b=YzF+I7NJDuQdwvACAvGnZsor97avPFVDuyDjJeenACdTvFGB4fVYkqHc96yENEiH/v gQWoyr7OpgtEZeP5O8IhZai3mPKflbxbU/qHJI3bhtfcR5dH+7ZMv9teTDp80iWPtufy lQ1BIwDKpnxNvLGP0fdYczDRMAQczx55Gmfx3ioN9vXajm7fusvq/QFis7V98rVvTtIA BO7yF+AADgZzmWR+4fmh8H0iQzJK2kCZe1DgTXbyshlxbWt+k4bCV1lSmTH23Z+P72/V 3ux9tLhhSthtrk2ylSJqdnhz0Hpwxfl6/SYbtbs1RjvVFDhFI/DdHYPt3q3Js/zRuCe0 XVQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=eONpnZtF; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id u71-v6si21637241pgc.20.2018.05.09.00.48.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 00:48:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=eONpnZtF; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9RbDDh81xe4UwtYu730ckp4rkxMF7Vf/hOU9wtADM/w=; b=eONpnZtFzDrrdpQGFongvDIzG OgZ4TclnMSU7WAwJpXzG/go5sL1C+K1ccRhzIpzsdlgOgFob1XejkaqQjR42f0hIZLj4rmEozyrmA qA4QPkCnKGB//3gOuvWMGWlhB2PX6Te8TPu6JJXpMfhSJXzrFNI2gIHWZqrJSa3qD95GbTHMIl4fz A026XI1rzsvuvKgOWu3YviXbvY7AMHn75OfaHIQxANSmBpkLLRJm2MwMlq1ioVWvlVV7V123L7I1X UiMtqVD2mUnQHgDgY0eMpU2DXskjwfRFE1eI0GsM4RVROuJafibLYMrrJBAMYvVMM4DLo5SUmwxbZ IZ3J8RjuA==; Received: from 213-225-15-246.nat.highway.a1.net ([213.225.15.246] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGJqH-0001E9-DE; Wed, 09 May 2018 07:48:53 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/33] fs: use ->is_partially_uptodate in page_cache_seek_hole_data Date: Wed, 9 May 2018 09:48:02 +0200 Message-Id: <20180509074830.16196-6-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509074830.16196-1-hch@lst.de> References: <20180509074830.16196-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This way the implementation doesn't depend on buffer_head internals. Signed-off-by: Christoph Hellwig --- fs/iomap.c | 83 +++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index a739f3f995d9..b3592183b1a0 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -593,31 +593,54 @@ EXPORT_SYMBOL_GPL(iomap_fiemap); * * Returns the offset within the file on success, and -ENOENT otherwise. */ -static loff_t -page_seek_hole_data(struct page *page, loff_t lastoff, int whence) +static bool +page_seek_hole_data(struct inode *inode, struct page *page, loff_t *lastoff, + int whence) { - loff_t offset = page_offset(page); - struct buffer_head *bh, *head; + const struct address_space_operations *ops = inode->i_mapping->a_ops; + unsigned int bsize = i_blocksize(inode), off; bool seek_data = whence == SEEK_DATA; + loff_t poff = page_offset(page); - if (lastoff < offset) - lastoff = offset; - - bh = head = page_buffers(page); - do { - offset += bh->b_size; - if (lastoff >= offset) - continue; + if (WARN_ON_ONCE(*lastoff >= poff + PAGE_SIZE)) + return false; + if (*lastoff < poff) { /* - * Any buffer with valid data in it should have BH_Uptodate set. + * Last offset smaller than the start of the page means we found + * a hole: */ - if (buffer_uptodate(bh) == seek_data) - return lastoff; + if (whence == SEEK_HOLE) + return true; + *lastoff = poff; + } - lastoff = offset; - } while ((bh = bh->b_this_page) != head); - return -ENOENT; + /* + * Just check the page unless we can and should check block ranges: + */ + if (bsize == PAGE_SIZE || !ops->is_partially_uptodate) { + if (PageUptodate(page) == seek_data) + return true; + return false; + } + + lock_page(page); + if (unlikely(page->mapping != inode->i_mapping)) + goto out_unlock_not_found; + + for (off = 0; off < PAGE_SIZE; off += bsize) { + if ((*lastoff & ~PAGE_MASK) >= off + bsize) + continue; + if (ops->is_partially_uptodate(page, off, bsize) == seek_data) { + unlock_page(page); + return true; + } + *lastoff = poff + off + bsize; + } + +out_unlock_not_found: + unlock_page(page); + return false; } /* @@ -654,30 +677,8 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, for (i = 0; i < nr_pages; i++) { struct page *page = pvec.pages[i]; - /* - * At this point, the page may be truncated or - * invalidated (changing page->mapping to NULL), or - * even swizzled back from swapper_space to tmpfs file - * mapping. However, page->index will not change - * because we have a reference on the page. - * - * If current page offset is beyond where we've ended, - * we've found a hole. - */ - if (whence == SEEK_HOLE && - lastoff < page_offset(page)) + if (page_seek_hole_data(inode, page, &lastoff, whence)) goto check_range; - - lock_page(page); - if (likely(page->mapping == inode->i_mapping) && - page_has_buffers(page)) { - lastoff = page_seek_hole_data(page, lastoff, whence); - if (lastoff >= 0) { - unlock_page(page); - goto check_range; - } - } - unlock_page(page); lastoff = page_offset(page) + PAGE_SIZE; } pagevec_release(&pvec);