From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Howells Subject: cat and grep can cause excess page read at EOF Date: Thu, 30 Apr 2009 15:25:28 +0100 Message-ID: <304.1241101528@redhat.com> Cc: dhowells@redhat.com To: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Return-path: Received: from mx2.redhat.com ([66.187.237.31]:45973 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754653AbZD3OZa (ORCPT ); Thu, 30 Apr 2009 10:25:30 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Hi, When reading a file that ends exactly on a page boundary, reading an entire file and relying on read() = 0 to indicate the EOF (such as is done by cat and grep) causes readpage() to be invoked on the filesystem for a page immediately beyond EOF. Is it worth making generic_file_aio_read() note that the EOF has been reached and return 0 immediately, rather than trying to read over the EOF? The problem with doing that might be that filesystems such as NFS2/3 might occasionally miss the fact that a file has been extended on the server. The call chain I see on my testbox is this: [] ? nfs_readpage+0x138/0x16a [nfs] [] ? generic_file_aio_read+0x399/0x55a [] ? do_sync_read+0xce/0x113 [] ? autoremove_wake_function+0x0/0x2e [] ? file_has_perm+0x82/0x8b [] ? vfs_read+0xaa/0x153 [] ? sys_read+0x45/0x6e [] ? system_call_fastpath+0x16/0x1b nfs_readpage() is asked to read page 0x6400 from a 100MB file - which doesn't exist, and so calls nfs_return_empty_page(). David