Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp253176pxu; Tue, 5 Jan 2021 09:56:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwN+5EA154E1JdZebR4MuBDi6HCWjaCQuBpSAa+rh+ocRXzh8tgJoev8lf7IvDEj8bAJPe+ X-Received: by 2002:a17:907:20f1:: with SMTP id rh17mr257817ejb.147.1609869388390; Tue, 05 Jan 2021 09:56:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609869388; cv=none; d=google.com; s=arc-20160816; b=pUJ3xDGofsj4f5N/vZ6+wP/1O6RT48gOyZWCsYrgFgja7p+f57pgN3udp/nqbKCHbT QAiiwoYV5Uo8C1VsNActAPgrsAEDnuDP6QH0e3c8knuG43AaFFI/5UzHwYLZ6VqsQIKg 9O6rCDtCxb56g7ahW7A/Cg+/kvSUPjC0d2hgzElUA/BIFvEGj1+FBjh/MAM+8jErityC lWvjWqxE5JnmwavSs6G6dlVcnhhcyzLeiIUwTVod2uah1UYvZjE7eab83irhUcBd+LfS PiOvpu7MlXSbEChF2bMoUsoCnn2be/C5Dejlgo+EbNQTG06ixWfad0jufhsJE93UfdNj o5ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=xb7BBeqI4sG4CKFJUiK3zSVsx2LbQIPh85pSRMX8Ksc=; b=qM7pT7UAXselTgkeUqs0cRs5f40blKy1/QdYvrdszlHn6v4nMKmumVpoy339Ou1fvd +UwYAMV5kt9TV0k/Z6eOaOuZ5syHSbGuG3WZhG2gayK/fWZ+k0tgix7Ir9NZrfVDSZuH 324hIb0Nv0SOLIsuDpfYHaejaS/XKvs1unoidRveO+KRANraROSUJJg86Y3ddMM64LqJ v/d4VzwwU9KVJhuepkpGVs5v+ImTtRT587DFPrmZIu2xSz5vyTfG4xynwUsce4dNYbII Kknk7XfPihe9BkUOYMnt29EmVKvVugIk8IJGNz4o9VVsdOkj89t85EeZlNKfxnVRyA63 Kb4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 a15si88137ejd.293.2021.01.05.09.56.01; Tue, 05 Jan 2021 09:56:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729936AbhAERya (ORCPT + 99 others); Tue, 5 Jan 2021 12:54:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:52138 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725838AbhAERya (ORCPT ); Tue, 5 Jan 2021 12:54:30 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A83EBAD4E; Tue, 5 Jan 2021 17:53:48 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 32DC31E07FD; Tue, 5 Jan 2021 18:53:48 +0100 (CET) Date: Tue, 5 Jan 2021 18:53:48 +0100 From: Jan Kara To: Chengguang Xu Cc: jack@suse.com, linux-ext4@vger.kernel.org Subject: Re: [PATCH] ext2: implement ->page_mkwrite Message-ID: <20210105175348.GE15080@quack2.suse.cz> References: <20201218132757.279685-1-cgxu519@mykernel.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201218132757.279685-1-cgxu519@mykernel.net> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri 18-12-20 21:27:57, Chengguang Xu wrote: > Currently ext2 uses generic mmap operations for non DAX file and > filemap_page_mkwrite() does not check the block allocation for > shared writable mmapped area on pagefault. In some cases like > disk space exhaustion or disk quota limitation, it will cause silent > data loss. This patch tries to check and do block preallocation on > pagefault if necessary and explicitly return error to user when > allocation failure. > > Signed-off-by: Chengguang Xu Thanks for the patch and sorry for the delay in replying. I agree there's the problem you describe but I'm not sure whether we should fix it. ext2 has been like this since the beginning so well over 20 years. Allocating blocks on write fault has the unwelcome impact that the file layout is likely going to be much worse (much more fragmented) - I remember getting some reports about performance regressions from users back when I did a similar change for ext3. And so I'm reluctant to change behavior of such an old legacy filesystem as ext2... Honza > --- > fs/ext2/file.c | 40 ++++++++++++++++++++++++++++++++++++---- > 1 file changed, 36 insertions(+), 4 deletions(-) > > diff --git a/fs/ext2/file.c b/fs/ext2/file.c > index 96044f5dbc0e..a34119415ef1 100644 > --- a/fs/ext2/file.c > +++ b/fs/ext2/file.c > @@ -25,10 +25,34 @@ > #include > #include > #include > +#include > #include "ext2.h" > #include "xattr.h" > #include "acl.h" > > +vm_fault_t ext2_page_mkwrite(struct vm_fault *vmf) > +{ > + struct vm_area_struct *vma = vmf->vma; > + struct inode *inode = file_inode(vma->vm_file); > + int err; > + > + if (unlikely(IS_IMMUTABLE(inode))) > + return VM_FAULT_SIGBUS; > + > + sb_start_pagefault(inode->i_sb); > + file_update_time(vma->vm_file); > + err = block_page_mkwrite(vma, vmf, ext2_get_block); > + sb_end_pagefault(inode->i_sb); > + > + return block_page_mkwrite_return(err); > +} > + > +const struct vm_operations_struct ext2_vm_ops = { > + .fault = filemap_fault, > + .map_pages = filemap_map_pages, > + .page_mkwrite = ext2_page_mkwrite, > +}; > + > #ifdef CONFIG_FS_DAX > static ssize_t ext2_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) > { > @@ -123,15 +147,23 @@ static const struct vm_operations_struct ext2_dax_vm_ops = { > > static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma) > { > + file_accessed(file); > if (!IS_DAX(file_inode(file))) > - return generic_file_mmap(file, vma); > + vma->vm_ops = &ext2_vm_ops; > + else > + vma->vm_ops = &ext2_dax_vm_ops; > > - file_accessed(file); > - vma->vm_ops = &ext2_dax_vm_ops; > return 0; > } > + > #else > -#define ext2_file_mmap generic_file_mmap > +static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma) > +{ > + file_accessed(file); > + vma->vm_ops = &ext2_vm_ops; > + return 0; > +} > + > #endif > > /* > -- > 2.18.4 > -- Jan Kara SUSE Labs, CR