Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1958518lqb; Mon, 27 May 2024 03:22:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUuc/WH134WHiVZTH/QVoODcMRsQJT4VWUOcs+WUvvhq3zgocCu1+L3duEK+pe2W3M48De1PusOBQC+5w06z34ClVPec1CE5ulvVj+kzg== X-Google-Smtp-Source: AGHT+IGd5P4H4FMs7lKz1fB6Wb/HUBG4Tu0xsjWUhUADoVwfjOlnEZER+X2XKj8Gp1a80UDdfktg X-Received: by 2002:a17:902:ea04:b0:1f4:5d87:ffb3 with SMTP id d9443c01a7336-1f45d8807d6mr77270405ad.17.1716805377067; Mon, 27 May 2024 03:22:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716805377; cv=pass; d=google.com; s=arc-20160816; b=OsNowr0ZVjlB5YzvJzw5VDugnXyjh25jhqVXZxP1ZKgaS3HDXkwBqctj5po/xvfXi7 kVn1QZH1QtosVV4fzk5zEnV17Cd4vBWXaP0VdGIfJWNNmcVzGC9s580sbhJAda2qQnlv FCqpNPr5LSOUGyceeog3e3TMc1zL62lRLlFOG/naCI8YpfIZY7kJuvda6JWVKbhlN0tu dIc0rK8OPnKn9TCjy0vok/V0h1MlA0z+rSiR1yjERR3Bc4z3coYsuutpJifiXdRNStbd ZZPi0EtAlbX13BHxuw65vvVfC5VZppG0rzYAIEol0Q1z+5pJaeJDuNycg4V9ALA+SUJD 085Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=WI6C9+b2g94XUuTE6v9Ffjhvj5tcV3uNbr1C4tqljNc=; fh=3Wr29jXv6iPkZYjwaYL6q+6TCktAqh1vz8SKNv/UqxM=; b=B/WyuVASJYBtK545qTkPwlBPNvVV1VyJnrxX3jHggQ68q/R++bwNGrBlr0hW9lmOyG KGH1opELKe0iVYe9C8Ap+FT2Z4Teu1tpVwBE+FCnn2pFDJ+70LGJDOgSxvh5uZdYXEp9 L+1UxSZHESJ1FyDwCfGHSlSyRPi7uaswl8CCB2T74K+sboYOXaDrTntHzlaSpteTACyC KMnne646LL0EtR4VpG69ELCwITLbZ5EFvKcUFfODetTatMWUMj2iCW2vacfAbP0JtPAG wBHf/AaoAmsyNSH0gT32u7AexhTvuJyGOp/DpiDMGZ55O87Drb3uxqDrS6V8IGW9DxPF fZMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=cestc.cn); spf=pass (google.com: domain of linux-kernel+bounces-190409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190409-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f45ad459easi49776945ad.638.2024.05.27.03.22.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 03:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=cestc.cn); spf=pass (google.com: domain of linux-kernel+bounces-190409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190409-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 27896B23612 for ; Mon, 27 May 2024 10:15:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E01B13AD30; Mon, 27 May 2024 10:15:10 +0000 (UTC) Received: from smtp.cecloud.com (unknown [1.203.97.240]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB7A913AD34; Mon, 27 May 2024 10:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=1.203.97.240 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716804909; cv=none; b=utJbKqmwmbGZyNcA+1anEXKtmnf7hZIC/mMOLH99/WifiYqCP0vmS2TjDxIp09SiFwMTBUybe+RTTtgIOJd/e0dE7eSoBsgBMMw1ENwVVTU9iD8eNka9uEZRpJt7G4Vb2fIG28xDzUNXC64UqUQDXQ7Ug41oEDfmP6czUjowwcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716804909; c=relaxed/simple; bh=t4855T7zRAAyXJTGdNBnjyzLLE/1b84BjFAew89mgrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IiX0C7q/8CJOoNw8dP7WxVoCCSCCam3JmO6RJcPJCetcZbrCmtbPAhgy11uhQFvQ9ioBaOfg7pPdIvf3HLzMYCHMbt5iA7ybzpZbbJsN4SfXOUq0FsCf6GBWI7hT7tqNCQZ7vIzBEvQKoIUtdLF8bHSC7lGGDHwFGSyYqf0JsRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cestc.cn; spf=pass smtp.mailfrom=cestc.cn; arc=none smtp.client-ip=1.203.97.240 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cestc.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cestc.cn Received: from localhost (localhost [127.0.0.1]) by smtp.cecloud.com (Postfix) with ESMTP id 24381900112; Mon, 27 May 2024 18:09:10 +0800 (CST) X-MAIL-GRAY:0 X-MAIL-DELIVERY:1 X-ANTISPAM-LEVEL:2 X-ABS-CHECKED:0 Received: from localhost.localdomain (unknown [111.48.58.12]) by smtp.cecloud.com (postfix) whith ESMTP id P894637T281473226436976S1716804548742756_; Mon, 27 May 2024 18:09:10 +0800 (CST) X-IP-DOMAINF:1 X-RL-SENDER:liuwei09@cestc.cn X-SENDER:liuwei09@cestc.cn X-LOGIN-NAME:liuwei09@cestc.cn X-FST-TO:axboe@kernel.dk X-RCPT-COUNT:9 X-LOCAL-RCPT-COUNT:1 X-MUTI-DOMAIN-COUNT:0 X-SENDER-IP:111.48.58.12 X-ATTACHMENT-NUM:0 X-UNIQUE-TAG: X-System-Flag:0 From: Liu Wei To: axboe@kernel.dk Cc: akpm@linux-foundation.org, hch@lst.de, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, liuwei09@cestc.cn, rgoldwyn@suse.com, willy@infradead.org Subject: Re: [PATCH] mm/filemap: invalidating pages is still necessary when io with IOCB_NOWAIT Date: Mon, 27 May 2024 18:09:08 +0800 Message-ID: <20240527100908.49913-1-liuwei09@cestc.cn> X-Mailer: git-send-email 2.42.1 In-Reply-To: <024b9a30-ad3b-4063-b5c8-e6c948ad6b2e@kernel.dk> References: <024b9a30-ad3b-4063-b5c8-e6c948ad6b2e@kernel.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit I am a newer, thanks for the reminder. > > >> when we issuing AIO with direct I/O and IOCB_NOWAIT on a block device, the > >> process context will not be blocked. > >> > >> However, if the device already has page cache in memory, EAGAIN will be > >> returned. And even when trying to reissue the AIO with direct I/O and > >> IOCB_NOWAIT again, we consistently receive EAGAIN. > > -EAGAIN doesn't mean "just try again and it'll work". > > >> Maybe a better way to deal with it: filemap_fdatawrite_range dirty pages > >> with WB_SYNC_NONE flag, and invalidate_mapping_pages unmapped pages at > >> the same time. > >> > >> Signed-off-by: Liu Wei > >> --- > >> mm/filemap.c | 9 ++++++++- > >> 1 file changed, 8 insertions(+), 1 deletion(-) > >> > >> diff --git a/mm/filemap.c b/mm/filemap.c > >> index 30de18c4fd28..1852a00caf31 100644 > >> --- a/mm/filemap.c > >> +++ b/mm/filemap.c > >> @@ -2697,8 +2697,15 @@ int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) > >> > >> if (iocb->ki_flags & IOCB_NOWAIT) { > >> /* we could block if there are any pages in the range */ > >> - if (filemap_range_has_page(mapping, pos, end)) > >> + if (filemap_range_has_page(mapping, pos, end)) { > >> + if (mapping_needs_writeback(mapping)) { > >> + __filemap_fdatawrite_range(mapping, > >> + pos, end, WB_SYNC_NONE); > >> + } > > I don't think WB_SYNC_NONE tells it not to block, it just says not to > wait for it... So this won't work as-is. Yes, but I think an asynchronous writex-back is better than simply return EAGAIN. By using __filemap_fdatawrite_range to trigger a writeback, subsequent retries may have a higher chance of success. > > >> + invalidate_mapping_pages(mapping, > >> + pos >> PAGE_SHIFT, end >> PAGE_SHIFT); > >> return -EAGAIN; > >> + } > >> } else { > >> ret = filemap_write_and_wait_range(mapping, pos, end); > >> if (ret) > >> -- > >> 2.42.1 > >> > >> > >>