Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3918652pxj; Tue, 11 May 2021 15:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNlH+iYoaEAEhHThxsD/trYsmC72RBeRPUd+HnmqYVVGsa6eRIk9i5CwqgnRwPPXtxHr5k X-Received: by 2002:a9d:5382:: with SMTP id w2mr27490469otg.153.1620770860415; Tue, 11 May 2021 15:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620770860; cv=none; d=google.com; s=arc-20160816; b=BOY5Yo62MC1X21E8v7AXmsI23codP5+CVa1psjv1lnAF73icFsyaGvuWfo3hFt3mU4 CtMTnUp2AN/TLftvoJ4YalHeSjU9F2ERZxHZuB1L8808NJHzuPSXfuvQiI/NGhbGzSfO mTIpm+zzweiM24ZUSlHKdgUpJ5A5LP2JF//846DcloPatJZf8iIFTyuFAayXOAiIPaiB 4DIzJjFTgWEwduphZ7QThmbfU42UipQOp3lS1Eyf10UMNrG3199A8EcVHkVyoXaBVtTD Cx2f9wv5z0sJDPfPmN/3w09ieCQwg5wh+TplCaTufHR48ryHVMhoVbIO0k0zlbrI07NA wUWA== 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=ax1bb9zulCot9ArOUhosvh+/moRq+yRyWsyGq1jLiM4=; b=NRzlJ3F5wxiS9QzeQudkU60TaNkZxzBmLVv//iLaQdQKtMneGLJkFia0K3J4qviY3k qp2ywRuzTgzkVX+V3M8yFZGzJibCcLXMQGILKNZYS41uwtFKihE/SSafvs29orAt6v+8 FlOVNgakjyHN+S8WrGVW22H/PB7tD3EJ1RrWfU/PUBRiKRasTUYIfQXgxLGHE6pIyjze MYyakYbwYZ4hspeSFfD8bFOD6nHF8TYaynbOduS0V3UusDwOulxP99VK+ScCEe80c3UL oR/I6GB5Uwxs2rRrYen5l6G16zadaAuITXyf9Qew6H2P9XjwZAuF7nS030iXFcq97oEn Bq8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=szzpx1mX; 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 u141si19296891oif.255.2021.05.11.15.07.26; Tue, 11 May 2021 15:07:40 -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=szzpx1mX; 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 S229934AbhEKWH6 (ORCPT + 99 others); Tue, 11 May 2021 18:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbhEKWH5 (ORCPT ); Tue, 11 May 2021 18:07:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE568C061574; Tue, 11 May 2021 15:06:50 -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=ax1bb9zulCot9ArOUhosvh+/moRq+yRyWsyGq1jLiM4=; b=szzpx1mXgQ5KN/HeT/ZFjSTVss 4ta1UENBuQaEIe4krw4duVoZ8FqL9KKLCVuK9q9u+QPAGjkNBZVot4XmHc6vQCXAx9+VU9VFfZTzS lpo99hphy5huhgIuvzcJAmy89aCvBGXnYA21cXCC5h83K/TQ9m6NtBJYN0pMoASpqpsjvlpUJSR2D mrdFi7qKBMPZx7CR4DQrW3yjH+9CLMqxBG+6Cf0H+EwGkPb4Qp567Qogw1PlWP/+Bh++2nCvkQui0 ll4RprmzLQKtoTfFjoml8cQ/eOlAZXbzh/pDFHFTLcCiPsjS/t/7eDF2ncVLc5Q1IfqZGAwgsD/7I IU3ZBmkQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lgaUL-007icN-9a; Tue, 11 May 2021 22:04:29 +0000 From: "Matthew Wilcox (Oracle)" To: akpm@linux-foundation.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Jeff Layton Subject: [PATCH v10 26/33] mm/writeback: Add folio_wait_writeback Date: Tue, 11 May 2021 22:47:28 +0100 Message-Id: <20210511214735.1836149-27-willy@infradead.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511214735.1836149-1-willy@infradead.org> References: <20210511214735.1836149-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 folio_wait_writeback_killable(). For the wait_on_page_writeback() callers, add a compatibility wrapper around folio_wait_writeback(). Turning PageWriteback() into folio_writeback() 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 3edb6204b937..22b1c4d43687 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -832,7 +832,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); @@ -851,7 +852,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) return VM_FAULT_RETRY; #endif - if (wait_on_page_writeback_killable(page)) + if (folio_wait_writeback_killable(folio)) return VM_FAULT_RETRY; if (lock_page_killable(page) < 0) @@ -861,8 +862,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 (folio_wait_writeback_killable(folio) < 0) { + folio_unlock(folio); return VM_FAULT_RETRY; } diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index cbd86c952e25..417efd7edd19 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -752,7 +752,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 folio_wait_writeback(struct folio *folio); +int folio_wait_writeback_killable(struct folio *folio); void end_page_writeback(struct page *page); void folio_end_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 526843d03d58..41275dac7a92 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -23,3 +23,9 @@ void end_page_writeback(struct page *page) return folio_end_writeback(page_folio(page)); } EXPORT_SYMBOL(end_page_writeback); + +void wait_on_page_writeback(struct page *page) +{ + return folio_wait_writeback(page_folio(page)); +} +EXPORT_SYMBOL_GPL(wait_on_page_writeback); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index fe72d5f65688..d7ac428df68a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2813,33 +2813,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 +/** + * folio_wait_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 folio_wait_writeback(struct folio *folio) { - while (PageWriteback(page)) { - trace_wait_on_page_writeback(page, page_mapping(page)); - wait_on_page_bit(page, PG_writeback); + while (folio_writeback(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(folio_wait_writeback); -/* - * Wait for a page to complete writeback. Returns -EINTR if we get a - * fatal signal while waiting. +/** + * folio_wait_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 folio_wait_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 (folio_writeback(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(folio_wait_writeback_killable); /** * wait_for_stable_page() - wait for writeback to finish, if necessary. -- 2.30.2