Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp783446ybf; Sat, 29 Feb 2020 16:07:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyJmFQ95mf07VgFViplYtglemTz6U/3cgfUBLCXut150kTu8U4iS01YckyhRzU4QTEWATZ8 X-Received: by 2002:aca:ab0c:: with SMTP id u12mr4352177oie.171.1583021241670; Sat, 29 Feb 2020 16:07:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583021241; cv=none; d=google.com; s=arc-20160816; b=bd5LDcfBnhn859/NtWZGX/NojbVzG0vGwANMUaT35Vg1F7o0VPRQwDqHL/0ySa5mF/ lEfz/EaYrvHd/9Gmadlb9JB2xWD5mSp4FFUQdE/9n1caLD9dmRaLmSTryCmM8GnTs58m iVS95MOL8L2/ot5oSbQSHnTZMSwx4GykgBgWkAiS4/4IOTITgHxdsrw3z2EIgTNHOiVR l3srzMQcyjVgHuIzMsr6M/b1RBISBz4ENT577DS038EZkMKQtOZ6Dr43cFB5pDORtB5i EGMzpY5LMz1kc1mia7AOYdZ7ecpKI5X+RfhoAbkReN8O3flLnyKroOcql0ViQr/R6NOo H/zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=X/4nfQ3uFtiBjdqnh1ROPsLGnp3pJhWE0Uj3XI/VnnI=; b=tPed261B4XED51PJ7873rqAEZZRMMqoXXF/pgk/9CbUb4r+h4X72x7LCK1l6EVv4sq p1vpyQQyUELkqGWOQe/qFNyAgsw8DdP+iMYdZjdl8Vdo7lXZRV3LE8TSegQ7ogDQ9Xcz mawVu8bSXpxrw1817ofzVy46tscl3D2oAzzpqJuPqWphqwCwI+r2sXNSSu4y6rJshaq+ Vp1s0nLenY2GDik+WC4rX1DsViIGkI+yApvaUFTVdC1UnOFTa/QGy9E05sIcMWkoLRNn J7Y3GSkae4KOoMEW0ZQXuRjztfocCZcqqDWRotnkyUALpln2zj3KJArLcsa7oPUc9k/H Uzkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si4191124oth.158.2020.02.29.16.07.09; Sat, 29 Feb 2020 16:07:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727247AbgCAAHE (ORCPT + 99 others); Sat, 29 Feb 2020 19:07:04 -0500 Received: from mail104.syd.optusnet.com.au ([211.29.132.246]:60139 "EHLO mail104.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727174AbgCAAHD (ORCPT ); Sat, 29 Feb 2020 19:07:03 -0500 Received: from dread.disaster.area (pa49-195-202-68.pa.nsw.optusnet.com.au [49.195.202.68]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 3E1C17EAD0F; Sun, 1 Mar 2020 11:06:55 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1j8C8D-00053a-FV; Sun, 01 Mar 2020 11:06:53 +1100 Date: Sun, 1 Mar 2020 11:06:53 +1100 From: Dave Chinner To: Andreas Dilger Cc: Kirill Tkhai , Christoph Hellwig , Theodore Ts'o , Alexander Viro , Mike Snitzer , Jan Kara , Eric Biggers , riteshh@linux.ibm.com, krisman@collabora.com, surajjs@amazon.com, dmonakhov@gmail.com, mbobrowski@mbobrowski.org, Eric Whitney , sblbir@amazon.com, Khazhismel Kumykov , linux-ext4 , Linux Kernel Mailing List , Linux FS Devel Subject: Re: [PATCH RFC 5/5] ext4: Add fallocate2() support Message-ID: <20200301000653.GS10737@dread.disaster.area> References: <158272427715.281342.10873281294835953645.stgit@localhost.localdomain> <158272447616.281342.14858371265376818660.stgit@localhost.localdomain> <20200226155521.GA24724@infradead.org> <06f9b82c-a519-7053-ec68-a549e02c6f6c@virtuozzo.com> <4933D88C-2A2D-4ACA-823E-BDFEE0CE143F@dilger.ca> <20200228211610.GQ10737@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=LYdCFQXi c=1 sm=1 tr=0 a=mqTaRPt+QsUAtUurwE173Q==:117 a=mqTaRPt+QsUAtUurwE173Q==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=SS2py6AdgQ4A:10 a=7-415B0cAAAA:8 a=TYBLyS7eAAAA:8 a=d3t3XxdUcUBxI7EExOIA:9 a=vG0tVmWIGI90jERS:21 a=ssZfECPllHHjBRnG:21 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 a=zvYvwCWiE4KgVXXeO06c:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 29, 2020 at 01:12:52PM -0700, Andreas Dilger wrote: > On Feb 28, 2020, at 2:16 PM, Dave Chinner wrote: > > > > On Fri, Feb 28, 2020 at 08:35:19AM -0700, Andreas Dilger wrote: > >> On Feb 27, 2020, at 5:24 AM, Kirill Tkhai wrote: > >>> > >>> So, this interface is 3-in-1: > >>> > >>> 1)finds a placement for inodes extents; > >> > >> The target allocation size would be sum(size of inodes), which should > >> be relatively small in your case). > >> > >>> 2)assigns this space to some temporary donor inode; > >> > >> Maybe yes, or just reserves that space from being allocated by anyone. > >> > >>> 3)calls ext4_move_extents() for each of them. > >> > >> ... using the target space that was reserved earlier > >> > >>> Do I understand you right? > >> > >> Correct. That is my "5 minutes thinking about an interface for grouping > >> small files together without exposing kernel internals" proposal for this. > > > > You don't need any special kernel interface with XFS for this. It is > > simply: > > > > mkdir tmpdir > > create O_TMPFILEs in tmpdir > > > > Now all the tmpfiles you create and their data will be co-located > > around the location of the tmpdir inode. This is the natural > > placement policy of the filesystem. i..e the filesystem assumes that > > files in the same directory are all related, so will be accessed > > together and so should be located in relatively close proximity to > > each other. > > Sure, this will likely get inodes allocate _close_ to each other on > ext4 as well (the new directory will preferentially be located in a > group that has free space), but it doesn't necessarily result in > all of the files being packed densely. For 1MB+4KB and 1MB-4KB files > they will still prefer to be aligned on 1MB boundaries rather than > packed together. Userspace can control that, too, simply by choosing to relocate only small files into a single directory, then relocating the large files in a separate set of operations after flushing the small files and having the packed tightly. Seriously, userspace has a *lot* of control of how data is located and packed simply by grouping the IO it wants to be written together into the same logical groups (i.e. directories) in the same temporal IO domain... > >>> Can we introduce a flag, that some of inode is unmovable? > >> > >> There are very few flags left in the ext4_inode->i_flags for use. > >> You could use "IMMUTABLE" or "APPEND_ONLY" to mean that, but they > >> also have other semantics. The EXT4_NOTAIL_FL is for not merging the > >> tail of a file, but ext4 doesn't have tails (that was in Reiserfs), > >> so we might consider it a generic "do not merge" flag if set? > > > > Indeed, thanks to XFS, ext4 already has an interface that can be > > used to set/clear a "no defrag" flag such as you are asking for. > > It's the FS_XFLAG_NODEFRAG bit in the FS_IOC_FS[GS]ETXATTR ioctl. > > In XFS, that manages the XFS_DIFLAG_NODEFRAG on-disk inode flag, > > and it has special meaning for directories. From the 'man 3 xfsctl' > > man page where this interface came from: > > > > Bit 13 (0x2000) - XFS_XFLAG_NODEFRAG > > No defragment file bit - the file should be skipped during a > > defragmentation operation. When applied to a directory, > > new files and directories created will inherit the no-defrag > > bit. > > The interface is not the limiting factor here, but rather the number > of flags available in the inode. Yes, that's an internal ext4 issue, not a userspace API problem. > Since chattr/lsattr from e2fsprogs > was used as "common ground" for a few years, there are a number of > flags in the namespace that don't actually have any meaning for ext4. Yes, that's a shitty API bed that extN made for itself, isn't it? We've sucked at API design for a long, long time. :/ But the chattr userspace application is also irrelevant to the problem at hand: it already uses the FS_IOC_FS[GS]ETXATTR ioctl interface for changing project quota IDs and the per-inode inheritance flag. Hence how it manages the new flag is irrelevant, but it also means we can't change the definition or behaviour of existing flags it controls regardless of what filesystem those flags act on. > One of those flags is: > > #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */ > > This was added for Reiserfs, but it is not used by any other filesystem, > so generalizing it slightly to mean "no migrate" is reasonable. That > doesn't affect Reiserfs in any way, and it would still be possible to > also wire up the XFS_XFLAG_NODEFRAG bit to be stored as that flag. Yes, ext4 could do that, but we are not allowed to redefine long standing userspace API flags to mean something completely different. That's effectively what you are proposing here if you allow ext4 to manipulate the same on-disk flag via both FS_NOTAIL_FL and FS_XFLAG_NODEFRAG. ie. the FS_NOTAIL_FL flag is manipulated by FS_IOC_[GS]ETFLAGS and is marked both as user visible and modifiable by ext4 even though ti does nothing. IOWs, to redefine this on-disk flag we would also need to have EXT4_IOC_GETFLAGS / EXT4_IOC_SETFLAGS reject attempts to set/clear FS_NOTAIL_FL with EOPNOTSUPP or EINVAL. Which we then risk breaking applications that use this flag even though ext4 does not implement anything other than setting/clearing the flag on demand. IOWs, we cannot change the meaning of the EXT4_NOTAIL_FL on disk flag, because that either changes the user visible behaviour of the on-disk flag or it changes the definition of a userspace API flag to mean something it was never meant to mean. Neither of those things are acceptible changes to make to a generic userspace API. > It wouldn't be any issue at all to chose an arbitrary unused flag to > store this in ext4 inode internally, except that chattr/lsattr are used > by a variety of different filesystems, so whatever flag is chosen will > immediately also apply to any other filesystem that users use those > tools on. The impact on userspace is only a problem if you re-use a flag ext4 already exposes to userspace. And that is not allowed if it causes the userspace API to be globally redefined for everyone. Which, clearly, it would. Cheers, Dave. -- Dave Chinner david@fromorbit.com