From patchwork Mon Oct 28 10:03:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 11215067 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A413813B1 for ; Mon, 28 Oct 2019 10:03:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6223A21479 for ; Mon, 28 Oct 2019 10:03:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=yandex-team.ru header.i=@yandex-team.ru header.b="hDzAQS0k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6223A21479 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=yandex-team.ru Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9E3326B0003; Mon, 28 Oct 2019 06:03:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 992116B0006; Mon, 28 Oct 2019 06:03:10 -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 8A7916B0007; Mon, 28 Oct 2019 06:03:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 643106B0003 for ; Mon, 28 Oct 2019 06:03:10 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id E0310180ACC5A for ; Mon, 28 Oct 2019 10:03:09 +0000 (UTC) X-FDA: 76092755298.09.river18_8ff41637a5b37 X-Spam-Summary: 2,0,0,1a749c4f2a499157,d41d8cd98f00b204,khlebnikov@yandex-team.ru,::akpm@linux-foundation.org:linux-kernel@vger.kernel.org:viro@zeniv.linux.org.uk:linux-fsdevel@vger.kernel.org:jack@suse.cz,RULES_HIT:41:152:355:379:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3870:3871:3872:3874:4321:5007:6261:6653:7903:8660:9036:9207:10004:10400:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12760:13069:13148:13208:13229:13230:13311:13357:14096:14097:14181:14394:14687:14721:14922:21067:21080:21451:21627:30012:30054:30090,0,RBL:5.45.199.163:@yandex-team.ru:.lbl8.mailshell.net-62.2.3.100 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:27,LUA_SUMMARY:none X-HE-Tag: river18_8ff41637a5b37 X-Filterd-Recvd-Size: 3740 Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net [5.45.199.163]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Oct 2019 10:03:09 +0000 (UTC) Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 49ECD2E14B4; Mon, 28 Oct 2019 13:03:07 +0300 (MSK) Received: from sas2-62907d92d1d8.qloud-c.yandex.net (sas2-62907d92d1d8.qloud-c.yandex.net [2a02:6b8:c08:b895:0:640:6290:7d92]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id x5ouwLMN6C-36Bu083s; Mon, 28 Oct 2019 13:03:07 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1572256987; bh=4OZ/cmyE0nwmb5VhPhQYX1h9cuI6Q3M2Dc2YOIwAr+s=; h=Message-ID:Date:To:From:Subject:Cc; b=hDzAQS0kyLoTyPqaa2LyHXzZ5VuU8o6Akdba0LfJSK4HM9D75q+Ydsbhj3HAmu6WC kCB+dh8Pt2GgBPIvuu4Q9Z8kcRpkoWT3h42OwmwAQDp/UcpL8oQJ7kLMxBiENvPSmO fMLVYBaY3S+b+nK9QwPYiZI8p12vsQpFBqChAqLQ= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:148a:8f3:5b61:9f4]) by sas2-62907d92d1d8.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA id TPsiflps2c-36VmtF2T; Mon, 28 Oct 2019 13:03:06 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH] fs: warn if stale pagecache is left after direct write From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Alexander Viro Cc: linux-fsdevel@vger.kernel.org, Jan Kara Date: Mon, 28 Oct 2019 13:03:06 +0300 Message-ID: <157225698620.5453.17655271871684298255.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: Function generic_file_direct_write() tries to invalidate pagecache after O_DIRECT write. Unlike to similar code in dio_complete() this silently ignores error returned from invalidate_inode_pages2_range(). According to comment this code here because not all filesystems call dio_complete() or do proper invalidation after O_DIRECT write. Noticeable case is a blkdev_direct_IO(). This patch calls dio_warn_stale_pagecache() if invalidation fails. Also this skips invalidation for async writes (written == -EIOCBQUEUED). Async write should call dio_complete() later, when write completes. Signed-off-by: Konstantin Khlebnikov --- mm/filemap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 92abf5f348a9..1fa8d587ef78 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3222,11 +3222,15 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) * Most of the time we do not need this since dio_complete() will do * the invalidation for us. However there are some file systems that * do not end up with dio_complete() being called, so let's not break - * them by removing it completely + * them by removing it completely. + * + * Noticeable case is a blkdev_direct_IO(). + * + * Skip invalidation for async writes or if mapping has no pages. */ - if (mapping->nrpages) - invalidate_inode_pages2_range(mapping, - pos >> PAGE_SHIFT, end); + if (written > 0 && mapping->nrpages && + invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end)) + dio_warn_stale_pagecache(file); if (written > 0) { pos += written;