Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp145220pxv; Thu, 15 Jul 2021 00:49:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmuvJ31pUQGL9RZLotZEjdHq+kzX0BnMAxwsoVxSui4WzLUQ5IlDWZv1AAfvcP9CsqKUZz X-Received: by 2002:a17:906:8808:: with SMTP id zh8mr2245955ejb.213.1626335360820; Thu, 15 Jul 2021 00:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626335360; cv=none; d=google.com; s=arc-20160816; b=iO3utez9Mi/tlWvvRsjWqyI0JEht0zmIW9PkjhKL97h/LWvHLQsnJ2o4gECEn1iCA+ +9U8aXXswrKsPSSDVEwNj9hGD5AumWmTbTrnnDjSEv/tskV+Bu7IRvcuQqX36+qqZg0E GvTTSTmNMVi/Ai3+68xfzrHqPEhrfczfKvrzBbte3u9oB+Xj8n2DCDk704cP5prvD32C 9XjQwL/U1Zx81pJRwyntFgt3S0CO+M09U8oekgJUOcn2M1K60EZNzehmNmzZ8HYcZnEd iqm5uJrZulra5QqLQuC0+mTwks71y5nU+8zhjaOWNhi5Zmo/RyuykqATJEDeLoi4YMU2 4XFg== 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=VA3slxY04uK543T+rs/K2RUbVRf5sutF+JwHtsd+vBA=; b=GYICaoCjhNDAnYJ0NiSYCqrp9GBFutfC3oapCaC1LTY3pUP6+/SKpcYZ0M/03OMWWA EKZOr+xNh1yU8BOjUQvRkhJYHEo/4C5kpa8BB6awAP20HQKLPOWlpncTdhW8MHJwb6aV pRhqK3K/qQO7nodBI3qnVGt0veCZHo14KHXOLj7Tnrjk6Sqix3dLETCviCSJu7QDjS0B g0kzGbKVfynZrV3/9kYIHfgfIRDJHzZOerLxD8YI/CCe7CJf1AhXuaBOkKihVJedLPwZ UAnkSOK0zvXmp9uaBGpm9IiiBjN0wI5NarxTciBnJOHon2IfEDz7dgnzZRSQL80zpvn0 hEXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=RmK0pPc6; 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 h26si6308079edv.304.2021.07.15.00.48.55; Thu, 15 Jul 2021 00:49:20 -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=RmK0pPc6; 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 S238112AbhGOEvc (ORCPT + 99 others); Thu, 15 Jul 2021 00:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbhGOEvc (ORCPT ); Thu, 15 Jul 2021 00:51:32 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA2CC06175F; Wed, 14 Jul 2021 21:48:39 -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=VA3slxY04uK543T+rs/K2RUbVRf5sutF+JwHtsd+vBA=; b=RmK0pPc6HxWCJqWZjRpYZQ3tSX 929sZJPwoZzxcfJdhqnfjQ1P5Rol4iSpqgEnAEg7fXzRwopMwfSbzx0nmIGtUvFWuolX823UArugF MPa9nnWdx1razD8dEoeFlp+wFpjdoTH/rgFpUAZ3uVQ+bxnoQOyvca1qF7+SD6d0T5xz6vg00gCXJ VAFjZRxjfpfqNbLnMgViDbANt31fajmk9LTEMcby2yWAEfjA0ktKxmp6QYV4EL8xdV4HHQTvDpmte 27yin/8ggr8O1D1Kw/FYAZm2SOnkIpzccJpci5WDh9QJVLe2I6Ry6Qh0RL3fgA3ET6SjfygbG8aXu EAC5ZKVA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3tHv-002yjh-Bf; Thu, 15 Jul 2021 04:48:02 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v14 089/138] mm/filemap: Add FGP_STABLE Date: Thu, 15 Jul 2021 04:36:15 +0100 Message-Id: <20210715033704.692967-90-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715033704.692967-1-willy@infradead.org> References: <20210715033704.692967-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow filemap_get_folio() to wait for writeback to complete (if the filesystem wants that behaviour). This is the folio equivalent of grab_cache_page_write_begin(), which is moved into the folio-compat file as a reminder to migrate all the code using it. This paves the way for getting rid of AOP_FLAG_NOFS once grab_cache_page_write_begin() is removed. Kernel grows by 11 bytes. filemap_get_folio() grows by 33 bytes but grab_cache_page_write_begin() shrinks by 22 bytes to make up for it. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 1 + mm/filemap.c | 25 +++---------------------- mm/folio-compat.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index b24933eced18..83c1a798265f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -301,6 +301,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, #define FGP_FOR_MMAP 0x00000040 #define FGP_HEAD 0x00000080 #define FGP_ENTRY 0x00000100 +#define FGP_STABLE 0x00000200 struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, int fgp_flags, gfp_t gfp); diff --git a/mm/filemap.c b/mm/filemap.c index 061e285aae21..0434c5a55fec 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1817,6 +1817,7 @@ static void *mapping_get_entry(struct address_space *mapping, pgoff_t index) * * %FGP_WRITE - The page will be written to by the caller. * * %FGP_NOFS - __GFP_FS will get cleared in gfp. * * %FGP_NOWAIT - Don't get blocked by page lock. + * * %FGP_STABLE - Wait for the folio to be stable (finished writeback) * * If %FGP_LOCK or %FGP_CREAT are specified then the function may sleep even * if the %GFP flags specified for %FGP_CREAT are atomic. @@ -1867,6 +1868,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio_clear_idle(folio); } + if (fgp_flags & FGP_STABLE) + folio_wait_stable(folio); no_page: if (!folio && (fgp_flags & FGP_CREAT)) { int err; @@ -3590,28 +3593,6 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) } EXPORT_SYMBOL(generic_file_direct_write); -/* - * Find or create a page at the given pagecache position. Return the locked - * page. This function is specifically for buffered writes. - */ -struct page *grab_cache_page_write_begin(struct address_space *mapping, - pgoff_t index, unsigned flags) -{ - struct page *page; - int fgp_flags = FGP_LOCK|FGP_WRITE|FGP_CREAT; - - if (flags & AOP_FLAG_NOFS) - fgp_flags |= FGP_NOFS; - - page = pagecache_get_page(mapping, index, fgp_flags, - mapping_gfp_mask(mapping)); - if (page) - wait_for_stable_page(page); - - return page; -} -EXPORT_SYMBOL(grab_cache_page_write_begin); - ssize_t generic_perform_write(struct file *file, struct iov_iter *i, loff_t pos) { diff --git a/mm/folio-compat.c b/mm/folio-compat.c index e833e680e944..5b6ae1da314e 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -116,6 +116,7 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping, } EXPORT_SYMBOL(add_to_page_cache_lru); +noinline struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, int fgp_flags, gfp_t gfp) { @@ -127,3 +128,15 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, return folio_file_page(folio, index); } EXPORT_SYMBOL(pagecache_get_page); + +struct page *grab_cache_page_write_begin(struct address_space *mapping, + pgoff_t index, unsigned flags) +{ + unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE; + + if (flags & AOP_FLAG_NOFS) + fgp_flags |= FGP_NOFS; + return pagecache_get_page(mapping, index, fgp_flags, + mapping_gfp_mask(mapping)); +} +EXPORT_SYMBOL(grab_cache_page_write_begin); -- 2.30.2