Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757644AbZFALdS (ORCPT ); Mon, 1 Jun 2009 07:33:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755774AbZFALdJ (ORCPT ); Mon, 1 Jun 2009 07:33:09 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:33492 "EHLO fmmailgate02.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755509AbZFALdJ (ORCPT ); Mon, 1 Jun 2009 07:33:09 -0400 From: Goswin von Brederlow To: Jan Kara Cc: Pavel Machek , LKML , npiggin@suse.de, linux-ext4@vger.kernel.org Subject: Re: [PATCH 03/11] vfs: Add better VFS support for page_mkwrite when blocksize < pagesize References: <1243429268-3028-1-git-send-email-jack@suse.cz> <1243429268-3028-4-git-send-email-jack@suse.cz> <20090530112324.GD1395@ucw.cz> <20090601094402.GA14373@duck.suse.cz> Date: Mon, 01 Jun 2009 13:33:08 +0200 In-Reply-To: <20090601094402.GA14373@duck.suse.cz> (Jan Kara's message of "Mon, 1 Jun 2009 11:44:02 +0200") Message-ID: <87y6scqjd7.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.22 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Provags-ID: V01U2FsdGVkX19Ya5GPdrr4HdsMMnmD0/7lK3/YqnXEUaTBU+Vz jn38m0YMTvuPpNxxyR8uQ3vhNMBXXNstaUKwBZYt7QXy4P0SiE CJuA+eCkY= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2587 Lines: 54 Jan Kara writes: > On Sat 30-05-09 13:23:24, Pavel Machek wrote: >> Hi! >> >> > On filesystems where blocksize < pagesize the situation is more complicated. >> > Think for example that blocksize = 1024, pagesize = 4096 and a process does: >> > ftruncate(fd, 0); >> > pwrite(fd, buf, 1024, 0); >> > map = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED, fd, 0); >> > map[0] = 'a'; ----> page_mkwrite() for index 0 is called >> > ftruncate(fd, 10000); /* or even pwrite(fd, buf, 1, 10000) */ >> > fsync(fd); ----> writepage() for index 0 is called >> > >> > At the moment page_mkwrite() is called, filesystem can allocate only one block >> > for the page because i_size == 1024. Otherwise it would create blocks beyond >> > i_size which is generally undesirable. But later at writepage() time, we would >> > like to have blocks allocated for the whole page (and in principle we have to >> > allocate them because user could have filled the page with data after the >> > second ftruncate()). This patch introduces a framework which allows filesystems >> > to handle this with a reasonable effort. >> >> What happens when you do above sequence on today's kernels? Oops? 3000 >> bytes of random junk in file? ...? > Depends on the filesystem. For example on ext4, you'll see a WARN_ON and the data > won't be written. Some filesystems may just try to map blocks and possibly > hit deadlock or something like that. Filesystems like ext2 / ext3 / > reiserfs generally don't care because so far they allocate blocks on writepage > time (which has the problem that you can write data via mmap and kernel > will later discard them because it hits ENOSPC or quota limit). That's > actually what I was trying to fix originally. > > Honza man mmap: A file is mapped in multiples of the page size. For a file that is not a multiple of the page size, the remaining memory is zeroed when mapped, and writes to that region are not written out to the file. The effect of changing the size of the underlying file of a mapping on the pages that correspond to added or removed regions of the file is unspecified. Whatever happens happens. The above code is just wrong, as in unspecified behaviour. What happens if you ftruncate() before mmap()? MfG Goswin -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/