Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1589639pxf; Fri, 9 Apr 2021 12:12:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZZmnQ8tC91b9T8K3x4Vh8Nvkq5+Xch204ntjYZl7MSwn5g8dIfcBkWDFza85lsvn62dfv X-Received: by 2002:a17:902:e803:b029:e9:1f79:2427 with SMTP id u3-20020a170902e803b02900e91f792427mr14476599plg.21.1617995568724; Fri, 09 Apr 2021 12:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617995568; cv=none; d=google.com; s=arc-20160816; b=PBsGa1aKWAuHJnaUeGwLOAUrxfsJRzabpw+kFdZ9zXO9nw4utu2MmKdeR8u7ujgtmp hr25Bk/DjPHixT4IzkR/tgCk43BLa/FhRpM6DCpC9i3lJ8a+jNLC1AkdFHMqNs4jSHEM kxXMimJOvH7yceZNVRwHXjotvaoprAl9bIS7ZoIwCwxBKXMwJxwTh4WK9+LgWojalrdy XlCWwOHDEb0k+LsbKgCBdR43Nwy90a1/EgQDSGcxga7KIqel0VwZqOTJkC0oVEsIBxt8 n6Qe+cjOHJVuiXWtvLlwcTOYgk9Qeml5YfGXtlziXJpV02U2DcaIc3mCOaFECEQwe0bR kDHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qADZv5Fn67PTJVuwz8lcte2XJjm+FG0Sug8Zh36p4PY=; b=q1I0kAKa/x3NjgOMVIqZrulpKfhTHlTqApS4xA6LC8y02IAlYyUlJSCUt/sLSobBhi dF/OKuZAPKDHiqzgjul92pgHDKQc9Fnd8pRESfw0X3UvXfSfknq4NstK6zhTbezkEyS8 2w1X9CzGMpjyBC+hT3lwTBOf08wJ1IubXM3D+LY2ZJjO7989HP9y8uboP/5TrjHaa50m ms3xlkIYu58qpJXVpL3nwYyKI7g+nCf0zv+SonZcEFB3sw/OtWg6RM9In1cgYJ/PkbP7 r56/NoeQIhAi5iqs3rCkfL5X5zXyAUb76N/HOjlN3ihl3AI/tPXZ9AL73FRCstHavIEe HgFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=XFScyhoq; 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 m7si4114769pgn.256.2021.04.09.12.12.36; Fri, 09 Apr 2021 12:12:48 -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=pass header.i=@infradead.org header.s=casper.20170209 header.b=XFScyhoq; 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 S234854AbhDITK7 (ORCPT + 99 others); Fri, 9 Apr 2021 15:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234775AbhDITK7 (ORCPT ); Fri, 9 Apr 2021 15:10:59 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FC65C061762; Fri, 9 Apr 2021 12:10:45 -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=qADZv5Fn67PTJVuwz8lcte2XJjm+FG0Sug8Zh36p4PY=; b=XFScyhoquVjrYWp0tnX/frKFsB BdFVrmcS0kZoqo8R9XIzjH0iq8gsLmG08MnPlnOappSlbeRQM8ITvMI9FpV5QBOPSoYfA25aJp/uD LtrvICixwbhkTRKYQrt9cGZ2OMhUWbcJfnIzhGzNWvSbgeesRMZh8MM3AuV2EGUfLTzwb2tjX2zQW rbNudcfDmXyJmAGwHl0isbsdzu4MbZPuPq/jC3SEp4YB4wnaPVO3jS2kwJWbbmNaztutjQJZqe1Dm XqR8aNw+hlsgTpjK+eVrd3+gAglvRVn0Hr2nCBDsFh00C1R/DupwMWPvqH4oMe00pbWYaxRC73mPp iMDginZw==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lUwVE-000oXw-Sz; Fri, 09 Apr 2021 19:09:18 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, Christoph Hellwig , Jeff Layton Subject: [PATCH v7 24/28] mm/writeback: Add wait_on_folio_writeback Date: Fri, 9 Apr 2021 19:51:01 +0100 Message-Id: <20210409185105.188284-25-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210409185105.188284-1-willy@infradead.org> References: <20210409185105.188284-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org wait_on_page_writeback_killable() only has one caller, so convert it to call wait_on_folio_writeback_killable(). For the wait_on_page_writeback() callers, add a compatibility wrapper around wait_on_folio_writeback(). Turning PageWriteback() into FolioWriteback() eliminates a call to compound_head() which saves 8 bytes and 15 bytes in the two functions. That is more than offset by adding the wait_on_page_writeback compatibility wrapper for a net increase in text of 15 bytes. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Acked-by: Jeff Layton --- fs/afs/write.c | 9 ++++---- include/linux/pagemap.h | 3 ++- mm/folio-compat.c | 6 ++++++ mm/page-writeback.c | 48 ++++++++++++++++++++++++++++------------- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index dc66ff15dd16..a1def42e2e45 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -831,7 +831,8 @@ int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) */ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) { - struct page *page = thp_head(vmf->page); + struct folio *folio = page_folio(vmf->page); + struct page *page = &folio->page; struct file *file = vmf->vma->vm_file; struct inode *inode = file_inode(file); struct afs_vnode *vnode = AFS_FS_I(inode); @@ -850,7 +851,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) return VM_FAULT_RETRY; #endif - if (wait_on_page_writeback_killable(page)) + if (wait_on_folio_writeback_killable(folio)) return VM_FAULT_RETRY; if (lock_page_killable(page) < 0) @@ -860,8 +861,8 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) * details the portion of the page we need to write back and we might * need to redirty the page if there's a problem. */ - if (wait_on_page_writeback_killable(page) < 0) { - unlock_page(page); + if (wait_on_folio_writeback_killable(folio) < 0) { + unlock_folio(folio); return VM_FAULT_RETRY; } diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 9bc01429dc25..99331c35c89c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -828,7 +828,8 @@ static inline int wait_on_page_locked_killable(struct page *page) int put_and_wait_on_page_locked(struct page *page, int state); void wait_on_page_writeback(struct page *page); -int wait_on_page_writeback_killable(struct page *page); +void wait_on_folio_writeback(struct folio *folio); +int wait_on_folio_writeback_killable(struct folio *folio); void end_page_writeback(struct page *page); void end_folio_writeback(struct folio *folio); void wait_for_stable_page(struct page *page); diff --git a/mm/folio-compat.c b/mm/folio-compat.c index d1a1dfe52589..6aadecc39fba 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -23,3 +23,9 @@ void end_page_writeback(struct page *page) return end_folio_writeback(page_folio(page)); } EXPORT_SYMBOL(end_page_writeback); + +void wait_on_page_writeback(struct page *page) +{ + return wait_on_folio_writeback(page_folio(page)); +} +EXPORT_SYMBOL_GPL(wait_on_page_writeback); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 0062d5c57d41..8271f9b24b69 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2818,33 +2818,51 @@ int __test_set_page_writeback(struct page *page, bool keep_write) } EXPORT_SYMBOL(__test_set_page_writeback); -/* - * Wait for a page to complete writeback +/** + * wait_on_folio_writeback - Wait for a folio to finish writeback. + * @folio: The folio to wait for. + * + * If the folio is currently being written back to storage, wait for the + * I/O to complete. + * + * Context: Sleeps. Must be called in process context and with + * no spinlocks held. Caller should hold a reference on the folio. + * If the folio is not locked, writeback may start again after writeback + * has finished. */ -void wait_on_page_writeback(struct page *page) +void wait_on_folio_writeback(struct folio *folio) { - while (PageWriteback(page)) { - trace_wait_on_page_writeback(page, page_mapping(page)); - wait_on_page_bit(page, PG_writeback); + while (FolioWriteback(folio)) { + trace_wait_on_page_writeback(&folio->page, folio_mapping(folio)); + wait_on_page_bit(&folio->page, PG_writeback); } } -EXPORT_SYMBOL_GPL(wait_on_page_writeback); +EXPORT_SYMBOL_GPL(wait_on_folio_writeback); -/* - * Wait for a page to complete writeback. Returns -EINTR if we get a - * fatal signal while waiting. +/** + * wait_on_folio_writeback_killable - Wait for a folio to finish writeback. + * @folio: The folio to wait for. + * + * If the folio is currently being written back to storage, wait for the + * I/O to complete or a fatal signal to arrive. + * + * Context: Sleeps. Must be called in process context and with + * no spinlocks held. Caller should hold a reference on the folio. + * If the folio is not locked, writeback may start again after writeback + * has finished. + * Return: 0 on success, -EINTR if we get a fatal signal while waiting. */ -int wait_on_page_writeback_killable(struct page *page) +int wait_on_folio_writeback_killable(struct folio *folio) { - while (PageWriteback(page)) { - trace_wait_on_page_writeback(page, page_mapping(page)); - if (wait_on_page_bit_killable(page, PG_writeback)) + while (FolioWriteback(folio)) { + trace_wait_on_page_writeback(&folio->page, folio_mapping(folio)); + if (wait_on_page_bit_killable(&folio->page, PG_writeback)) return -EINTR; } return 0; } -EXPORT_SYMBOL_GPL(wait_on_page_writeback_killable); +EXPORT_SYMBOL_GPL(wait_on_folio_writeback_killable); /** * wait_for_stable_page() - wait for writeback to finish, if necessary. -- 2.30.2