1. 31 3月, 2017 1 次提交
  2. 03 3月, 2017 1 次提交
    • D
      statx: Add a system call to make enhanced file info available · a528d35e
      David Howells 提交于
      Add a system call to make extended file information available, including
      file creation and some attribute flags where available through the
      underlying filesystem.
      
      The getattr inode operation is altered to take two additional arguments: a
      u32 request_mask and an unsigned int flags that indicate the
      synchronisation mode.  This change is propagated to the vfs_getattr*()
      function.
      
      Functions like vfs_stat() are now inline wrappers around new functions
      vfs_statx() and vfs_statx_fd() to reduce stack usage.
      
      ========
      OVERVIEW
      ========
      
      The idea was initially proposed as a set of xattrs that could be retrieved
      with getxattr(), but the general preference proved to be for a new syscall
      with an extended stat structure.
      
      A number of requests were gathered for features to be included.  The
      following have been included:
      
       (1) Make the fields a consistent size on all arches and make them large.
      
       (2) Spare space, request flags and information flags are provided for
           future expansion.
      
       (3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
           __s64).
      
       (4) Creation time: The SMB protocol carries the creation time, which could
           be exported by Samba, which will in turn help CIFS make use of
           FS-Cache as that can be used for coherency data (stx_btime).
      
           This is also specified in NFSv4 as a recommended attribute and could
           be exported by NFSD [Steve French].
      
       (5) Lightweight stat: Ask for just those details of interest, and allow a
           netfs (such as NFS) to approximate anything not of interest, possibly
           without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
           Dilger] (AT_STATX_DONT_SYNC).
      
       (6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
           its cached attributes are up to date [Trond Myklebust]
           (AT_STATX_FORCE_SYNC).
      
      And the following have been left out for future extension:
      
       (7) Data version number: Could be used by userspace NFS servers [Aneesh
           Kumar].
      
           Can also be used to modify fill_post_wcc() in NFSD which retrieves
           i_version directly, but has just called vfs_getattr().  It could get
           it from the kstat struct if it used vfs_xgetattr() instead.
      
           (There's disagreement on the exact semantics of a single field, since
           not all filesystems do this the same way).
      
       (8) BSD stat compatibility: Including more fields from the BSD stat such
           as creation time (st_btime) and inode generation number (st_gen)
           [Jeremy Allison, Bernd Schubert].
      
       (9) Inode generation number: Useful for FUSE and userspace NFS servers
           [Bernd Schubert].
      
           (This was asked for but later deemed unnecessary with the
           open-by-handle capability available and caused disagreement as to
           whether it's a security hole or not).
      
      (10) Extra coherency data may be useful in making backups [Andreas Dilger].
      
           (No particular data were offered, but things like last backup
           timestamp, the data version number and the DOS archive bit would come
           into this category).
      
      (11) Allow the filesystem to indicate what it can/cannot provide: A
           filesystem can now say it doesn't support a standard stat feature if
           that isn't available, so if, for instance, inode numbers or UIDs don't
           exist or are fabricated locally...
      
           (This requires a separate system call - I have an fsinfo() call idea
           for this).
      
      (12) Store a 16-byte volume ID in the superblock that can be returned in
           struct xstat [Steve French].
      
           (Deferred to fsinfo).
      
      (13) Include granularity fields in the time data to indicate the
           granularity of each of the times (NFSv4 time_delta) [Steve French].
      
           (Deferred to fsinfo).
      
      (14) FS_IOC_GETFLAGS value.  These could be translated to BSD's st_flags.
           Note that the Linux IOC flags are a mess and filesystems such as Ext4
           define flags that aren't in linux/fs.h, so translation in the kernel
           may be a necessity (or, possibly, we provide the filesystem type too).
      
           (Some attributes are made available in stx_attributes, but the general
           feeling was that the IOC flags were to ext[234]-specific and shouldn't
           be exposed through statx this way).
      
      (15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
           Michael Kerrisk].
      
           (Deferred, probably to fsinfo.  Finding out if there's an ACL or
           seclabal might require extra filesystem operations).
      
      (16) Femtosecond-resolution timestamps [Dave Chinner].
      
           (A __reserved field has been left in the statx_timestamp struct for
           this - if there proves to be a need).
      
      (17) A set multiple attributes syscall to go with this.
      
      ===============
      NEW SYSTEM CALL
      ===============
      
      The new system call is:
      
      	int ret = statx(int dfd,
      			const char *filename,
      			unsigned int flags,
      			unsigned int mask,
      			struct statx *buffer);
      
      The dfd, filename and flags parameters indicate the file to query, in a
      similar way to fstatat().  There is no equivalent of lstat() as that can be
      emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags.  There is
      also no equivalent of fstat() as that can be emulated by passing a NULL
      filename to statx() with the fd of interest in dfd.
      
      Whether or not statx() synchronises the attributes with the backing store
      can be controlled by OR'ing a value into the flags argument (this typically
      only affects network filesystems):
      
       (1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
           respect.
      
       (2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
           its attributes with the server - which might require data writeback to
           occur to get the timestamps correct.
      
       (3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
           network filesystem.  The resulting values should be considered
           approximate.
      
      mask is a bitmask indicating the fields in struct statx that are of
      interest to the caller.  The user should set this to STATX_BASIC_STATS to
      get the basic set returned by stat().  It should be noted that asking for
      more information may entail extra I/O operations.
      
      buffer points to the destination for the data.  This must be 256 bytes in
      size.
      
      ======================
      MAIN ATTRIBUTES RECORD
      ======================
      
      The following structures are defined in which to return the main attribute
      set:
      
      	struct statx_timestamp {
      		__s64	tv_sec;
      		__s32	tv_nsec;
      		__s32	__reserved;
      	};
      
      	struct statx {
      		__u32	stx_mask;
      		__u32	stx_blksize;
      		__u64	stx_attributes;
      		__u32	stx_nlink;
      		__u32	stx_uid;
      		__u32	stx_gid;
      		__u16	stx_mode;
      		__u16	__spare0[1];
      		__u64	stx_ino;
      		__u64	stx_size;
      		__u64	stx_blocks;
      		__u64	__spare1[1];
      		struct statx_timestamp	stx_atime;
      		struct statx_timestamp	stx_btime;
      		struct statx_timestamp	stx_ctime;
      		struct statx_timestamp	stx_mtime;
      		__u32	stx_rdev_major;
      		__u32	stx_rdev_minor;
      		__u32	stx_dev_major;
      		__u32	stx_dev_minor;
      		__u64	__spare2[14];
      	};
      
      The defined bits in request_mask and stx_mask are:
      
      	STATX_TYPE		Want/got stx_mode & S_IFMT
      	STATX_MODE		Want/got stx_mode & ~S_IFMT
      	STATX_NLINK		Want/got stx_nlink
      	STATX_UID		Want/got stx_uid
      	STATX_GID		Want/got stx_gid
      	STATX_ATIME		Want/got stx_atime{,_ns}
      	STATX_MTIME		Want/got stx_mtime{,_ns}
      	STATX_CTIME		Want/got stx_ctime{,_ns}
      	STATX_INO		Want/got stx_ino
      	STATX_SIZE		Want/got stx_size
      	STATX_BLOCKS		Want/got stx_blocks
      	STATX_BASIC_STATS	[The stuff in the normal stat struct]
      	STATX_BTIME		Want/got stx_btime{,_ns}
      	STATX_ALL		[All currently available stuff]
      
      stx_btime is the file creation time, stx_mask is a bitmask indicating the
      data provided and __spares*[] are where as-yet undefined fields can be
      placed.
      
      Time fields are structures with separate seconds and nanoseconds fields
      plus a reserved field in case we want to add even finer resolution.  Note
      that times will be negative if before 1970; in such a case, the nanosecond
      fields will also be negative if not zero.
      
      The bits defined in the stx_attributes field convey information about a
      file, how it is accessed, where it is and what it does.  The following
      attributes map to FS_*_FL flags and are the same numerical value:
      
      	STATX_ATTR_COMPRESSED		File is compressed by the fs
      	STATX_ATTR_IMMUTABLE		File is marked immutable
      	STATX_ATTR_APPEND		File is append-only
      	STATX_ATTR_NODUMP		File is not to be dumped
      	STATX_ATTR_ENCRYPTED		File requires key to decrypt in fs
      
      Within the kernel, the supported flags are listed by:
      
      	KSTAT_ATTR_FS_IOC_FLAGS
      
      [Are any other IOC flags of sufficient general interest to be exposed
      through this interface?]
      
      New flags include:
      
      	STATX_ATTR_AUTOMOUNT		Object is an automount trigger
      
      These are for the use of GUI tools that might want to mark files specially,
      depending on what they are.
      
      Fields in struct statx come in a number of classes:
      
       (0) stx_dev_*, stx_blksize.
      
           These are local system information and are always available.
      
       (1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
           stx_size, stx_blocks.
      
           These will be returned whether the caller asks for them or not.  The
           corresponding bits in stx_mask will be set to indicate whether they
           actually have valid values.
      
           If the caller didn't ask for them, then they may be approximated.  For
           example, NFS won't waste any time updating them from the server,
           unless as a byproduct of updating something requested.
      
           If the values don't actually exist for the underlying object (such as
           UID or GID on a DOS file), then the bit won't be set in the stx_mask,
           even if the caller asked for the value.  In such a case, the returned
           value will be a fabrication.
      
           Note that there are instances where the type might not be valid, for
           instance Windows reparse points.
      
       (2) stx_rdev_*.
      
           This will be set only if stx_mode indicates we're looking at a
           blockdev or a chardev, otherwise will be 0.
      
       (3) stx_btime.
      
           Similar to (1), except this will be set to 0 if it doesn't exist.
      
      =======
      TESTING
      =======
      
      The following test program can be used to test the statx system call:
      
      	samples/statx/test-statx.c
      
      Just compile and run, passing it paths to the files you want to examine.
      The file is built automatically if CONFIG_SAMPLES is enabled.
      
      Here's some example output.  Firstly, an NFS directory that crosses to
      another FSID.  Note that the AUTOMOUNT attribute is set because transiting
      this directory will cause d_automount to be invoked by the VFS.
      
      	[root@andromeda ~]# /tmp/test-statx -A /warthog/data
      	statx(/warthog/data) = 0
      	results=7ff
      	  Size: 4096            Blocks: 8          IO Block: 1048576  directory
      	Device: 00:26           Inode: 1703937     Links: 125
      	Access: (3777/drwxrwxrwx)  Uid:     0   Gid:  4041
      	Access: 2016-11-24 09:02:12.219699527+0000
      	Modify: 2016-11-17 10:44:36.225653653+0000
      	Change: 2016-11-17 10:44:36.225653653+0000
      	Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
      
      Secondly, the result of automounting on that directory.
      
      	[root@andromeda ~]# /tmp/test-statx /warthog/data
      	statx(/warthog/data) = 0
      	results=7ff
      	  Size: 4096            Blocks: 8          IO Block: 1048576  directory
      	Device: 00:27           Inode: 2           Links: 125
      	Access: (3777/drwxrwxrwx)  Uid:     0   Gid:  4041
      	Access: 2016-11-24 09:02:12.219699527+0000
      	Modify: 2016-11-17 10:44:36.225653653+0000
      	Change: 2016-11-17 10:44:36.225653653+0000
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      a528d35e
  3. 02 3月, 2017 1 次提交
  4. 28 2月, 2017 1 次提交
  5. 20 2月, 2017 1 次提交
  6. 14 2月, 2017 1 次提交
    • M
      block/loop: fix race between I/O and set_status · ecdd0959
      Ming Lei 提交于
      Inside set_status, transfer need to setup again, so
      we have to drain IO before the transition, otherwise
      oops may be triggered like the following:
      
      	divide error: 0000 [#1] SMP KASAN
      	CPU: 0 PID: 2935 Comm: loop7 Not tainted 4.10.0-rc7+ #213
      	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs
      	01/01/2011
      	task: ffff88006ba1e840 task.stack: ffff880067338000
      	RIP: 0010:transfer_xor+0x1d1/0x440 drivers/block/loop.c:110
      	RSP: 0018:ffff88006733f108 EFLAGS: 00010246
      	RAX: 0000000000000000 RBX: ffff8800688d7000 RCX: 0000000000000059
      	RDX: 0000000000000000 RSI: 1ffff1000d743f43 RDI: ffff880068891c08
      	RBP: ffff88006733f160 R08: ffff8800688d7001 R09: 0000000000000000
      	R10: 0000000000000000 R11: 0000000000000000 R12: ffff8800688d7000
      	R13: ffff880067b7d000 R14: dffffc0000000000 R15: 0000000000000000
      	FS:  0000000000000000(0000) GS:ffff88006d000000(0000)
      	knlGS:0000000000000000
      	CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      	CR2: 00000000006c17e0 CR3: 0000000066e3b000 CR4: 00000000001406f0
      	Call Trace:
      	 lo_do_transfer drivers/block/loop.c:251 [inline]
      	 lo_read_transfer drivers/block/loop.c:392 [inline]
      	 do_req_filebacked drivers/block/loop.c:541 [inline]
      	 loop_handle_cmd drivers/block/loop.c:1677 [inline]
      	 loop_queue_work+0xda0/0x49b0 drivers/block/loop.c:1689
      	 kthread_worker_fn+0x4c3/0xa30 kernel/kthread.c:630
      	 kthread+0x326/0x3f0 kernel/kthread.c:227
      	 ret_from_fork+0x31/0x40 arch/x86/entry/entry_64.S:430
      	Code: 03 83 e2 07 41 29 df 42 0f b6 04 30 4d 8d 44 24 01 38 d0 7f 08
      	84 c0 0f 85 62 02 00 00 44 89 f8 41 0f b6 48 ff 25 ff 01 00 00 99 <f7>
      	7d c8 48 63 d2 48 03 55 d0 48 89 d0 48 89 d7 48 c1 e8 03 83
      	RIP: transfer_xor+0x1d1/0x440 drivers/block/loop.c:110 RSP:
      	ffff88006733f108
      	---[ end trace 0166f7bd3b0c0933 ]---
      Reported-by: NDmitry Vyukov <dvyukov@google.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NMing Lei <tom.leiming@gmail.com>
      Tested-by: NDmitry Vyukov <dvyukov@google.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      ecdd0959
  7. 25 12月, 2016 1 次提交
  8. 15 11月, 2016 1 次提交
  9. 12 10月, 2016 1 次提交
    • P
      kthread: kthread worker API cleanup · 3989144f
      Petr Mladek 提交于
      A good practice is to prefix the names of functions by the name
      of the subsystem.
      
      The kthread worker API is a mix of classic kthreads and workqueues.  Each
      worker has a dedicated kthread.  It runs a generic function that process
      queued works.  It is implemented as part of the kthread subsystem.
      
      This patch renames the existing kthread worker API to use
      the corresponding name from the workqueues API prefixed by
      kthread_:
      
      __init_kthread_worker()		-> __kthread_init_worker()
      init_kthread_worker()		-> kthread_init_worker()
      init_kthread_work()		-> kthread_init_work()
      insert_kthread_work()		-> kthread_insert_work()
      queue_kthread_work()		-> kthread_queue_work()
      flush_kthread_work()		-> kthread_flush_work()
      flush_kthread_worker()		-> kthread_flush_worker()
      
      Note that the names of DEFINE_KTHREAD_WORK*() macros stay
      as they are. It is common that the "DEFINE_" prefix has
      precedence over the subsystem names.
      
      Note that INIT() macros and init() functions use different
      naming scheme. There is no good solution. There are several
      reasons for this solution:
      
        + "init" in the function names stands for the verb "initialize"
          aka "initialize worker". While "INIT" in the macro names
          stands for the noun "INITIALIZER" aka "worker initializer".
      
        + INIT() macros are used only in DEFINE() macros
      
        + init() functions are used close to the other kthread()
          functions. It looks much better if all the functions
          use the same scheme.
      
        + There will be also kthread_destroy_worker() that will
          be used close to kthread_cancel_work(). It is related
          to the init() function. Again it looks better if all
          functions use the same naming scheme.
      
        + there are several precedents for such init() function
          names, e.g. amd_iommu_init_device(), free_area_init_node(),
          jump_label_init_type(),  regmap_init_mmio_clk(),
      
        + It is not an argument but it was inconsistent even before.
      
      [arnd@arndb.de: fix linux-next merge conflict]
       Link: http://lkml.kernel.org/r/20160908135724.1311726-1-arnd@arndb.de
      Link: http://lkml.kernel.org/r/1470754545-17632-3-git-send-email-pmladek@suse.comSuggested-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
      Cc: Josh Triplett <josh@joshtriplett.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Michal Hocko <mhocko@suse.cz>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3989144f
  10. 15 9月, 2016 1 次提交
  11. 05 8月, 2016 2 次提交
  12. 13 7月, 2016 1 次提交
  13. 08 6月, 2016 3 次提交
  14. 15 4月, 2016 1 次提交
    • M
      block: loop: fix filesystem corruption in case of aio/dio · a7297a6a
      Ming Lei 提交于
      Starting from commit e36f6204(block: split bios to max possible length),
      block core starts to split bio in the middle of bvec.
      
      Unfortunately loop dio/aio doesn't consider this situation, and
      always treat 'iter.iov_offset' as zero. Then filesystem corruption
      is observed.
      
      This patch figures out the offset of the base bvevc via
      'bio->bi_iter.bi_bvec_done' and fixes the issue by passing the offset
      to iov iterator.
      
      Fixes: e36f6204 (block: split bios to max possible length)
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: stable@vger.kernel.org (4.5)
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      a7297a6a
  15. 13 4月, 2016 1 次提交
  16. 01 10月, 2015 1 次提交
  17. 24 9月, 2015 5 次提交
    • M
      block: loop: support DIO & AIO · bc07c10a
      Ming Lei 提交于
      There are at least 3 advantages to use direct I/O and AIO on
      read/write loop's backing file:
      
      1) double cache can be avoided, then memory usage gets
      decreased a lot
      
      2) not like user space direct I/O, there isn't cost of
      pinning pages
      
      3) avoid context switch for obtaining good throughput
      - in buffered file read, random I/O top throughput is often obtained
      only if they are submitted concurrently from lots of tasks; but for
      sequential I/O, most of times they can be hit from page cache, so
      concurrent submissions often introduce unnecessary context switch
      and can't improve throughput much. There was such discussion[1]
      to use non-blocking I/O to improve the problem for application.
      - with direct I/O and AIO, concurrent submissions can be
      avoided and random read throughput can't be affected meantime
      
      xfstests(-g auto, ext4) is basically passed when running with
      direct I/O(aio), one exception is generic/232, but it failed in
      loop buffered I/O(4.2-rc6-next-20150814) too.
      
      Follows the fio test result for performance purpose:
      	4 jobs fio test inside ext4 file system over loop block
      
      1) How to run
      	- KVM: 4 VCPUs, 2G RAM
      	- linux kernel: 4.2-rc6-next-20150814(base) with the patchset
      	- the loop block is over one image on SSD.
      	- linux psync, 4 jobs, size 1500M, ext4 over loop block
      	- test result: IOPS from fio output
      
      2) Throughput(IOPS) becomes a bit better with direct I/O(aio)
              -------------------------------------------------------------
              test cases          |randread   |read   |randwrite  |write  |
              -------------------------------------------------------------
              base                |8015       |113811 |67442      |106978
              -------------------------------------------------------------
              base+loop aio       |8136       |125040 |67811      |111376
              -------------------------------------------------------------
      
      - somehow, it should be caused by more page cache avaiable for
      application or one extra page copy is avoided in case of direct I/O
      
      3) context switch
              - context switch decreased by ~50% with loop direct I/O(aio)
      	compared with loop buffered I/O(4.2-rc6-next-20150814)
      
      4) memory usage from /proc/meminfo
              -------------------------------------------------------------
                                         | Buffers       | Cached
              -------------------------------------------------------------
              base                       | > 760MB       | ~950MB
              -------------------------------------------------------------
              base+loop direct I/O(aio)  | < 5MB         | ~1.6GB
              -------------------------------------------------------------
      
      - so there are much more page caches available for application with
      direct I/O
      
      [1] https://lwn.net/Articles/612483/Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      bc07c10a
    • M
      block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO · ab1cb278
      Ming Lei 提交于
      If loop block is mounted via 'mount -o loop', it isn't easy
      to pass file descriptor opened as O_DIRECT, so this patch
      introduces a new command to support direct IO for this case.
      
      Cc: linux-api@vger.kernel.org
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      ab1cb278
    • M
      block: loop: prepare for supporing direct IO · 2e5ab5f3
      Ming Lei 提交于
      This patches provides one interface for enabling direct IO
      from user space:
      
      	- userspace(such as losetup) can pass 'file' which is
      	opened/fcntl as O_DIRECT
      
      Also __loop_update_dio() is introduced to check if direct I/O
      can be used on current loop setting.
      
      The last big change is to introduce LO_FLAGS_DIRECT_IO flag
      for userspace to know if direct IO is used to access backing
      file.
      
      Cc: linux-api@vger.kernel.org
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      2e5ab5f3
    • M
      block: loop: use kthread_work · e03a3d7a
      Ming Lei 提交于
      The following patch will use dio/aio to submit IO to backing file,
      then it needn't to schedule IO concurrently from work, so
      use kthread_work for decreasing context switch cost a lot.
      
      For non-AIO case, single thread has been used for long long time,
      and it was just converted to work in v4.0, which has caused performance
      regression for fedora live booting already. In discussion[1], even
      though submitting I/O via work concurrently can improve random read IO
      throughput, meantime it might hurt sequential read IO performance, so
      better to restore to single thread behaviour.
      
      For the following AIO support, it is better to use multi hw-queue
      with per-hwq kthread than current work approach suppose there is so
      high performance requirement for loop.
      
      [1] http://marc.info/?t=143082678400002&r=1&w=2Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      e03a3d7a
    • M
      block: loop: set QUEUE_FLAG_NOMERGES for request queue of loop · 5b5e20f4
      Ming Lei 提交于
      It doesn't make sense to enable merge because the I/O
      submitted to backing file is handled page by page.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      5b5e20f4
  18. 17 7月, 2015 1 次提交
  19. 24 6月, 2015 1 次提交
  20. 20 5月, 2015 3 次提交
    • J
      loop: remove (now) unused 'out' label · 6a927007
      Jens Axboe 提交于
      gcc, righfully, complains:
      
      drivers/block/loop.c:1369:1: warning: label 'out' defined but not used [-Wunused-label]
      
      Kill it.
      Signed-off-by: NJens Axboe <axboe@fb.com>
      6a927007
    • M
      block: loop: fix another reread part failure · 06f0e9e6
      Ming Lei 提交于
      loop_clr_fd() can be run piggyback with lo_release(), and
      under this situation, reread partition may always fail because
      bd_mutex has been held already.
      
      This patch detects the situation by the reference count, and
      call __blkdev_reread_part() to avoid acquiring the lock again.
      
      In the meantime, this patch switches to new kernel APIs
      of blkdev_reread_part() and __blkdev_reread_part().
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Tested-by: NJarod Wilson <jarod@redhat.com>
      Acked-by: NJarod Wilson <jarod@redhat.com>
      Signed-off-by: NJarod Wilson <jarod@redhat.com>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      06f0e9e6
    • M
      block: loop: don't hold lo_ctl_mutex in lo_open · f8933667
      Ming Lei 提交于
      The lo_ctl_mutex is held for running all ioctl handlers, and
      in some ioctl handlers, ioctl_by_bdev(BLKRRPART) is called for
      rereading partitions, which requires bd_mutex.
      
      So it is easy to cause failure because trylock(bd_mutex) may
      fail inside blkdev_reread_part(), and follows the lock context:
      
      blkid or other application:
      	->open()
      		->mutex_lock(bd_mutex)
      		->lo_open()
      			->mutex_lock(lo_ctl_mutex)
      
      losetup(set fd ioctl):
      	->mutex_lock(lo_ctl_mutex)
      	->ioctl_by_bdev(BLKRRPART)
      		->trylock(bd_mutex)
      
      This patch trys to eliminate the ABBA lock dependency by removing
      lo_ctl_mutext in lo_open() with the following approach:
      
      1) make lo_refcnt as atomic_t and avoid acquiring lo_ctl_mutex in lo_open():
      	- for open vs. add/del loop, no any problem because of loop_index_mutex
      	- freeze request queue during clr_fd, so I/O can't come until
      	  clearing fd is completed, like the effect of holding lo_ctl_mutex
      	  in lo_open
      	- both open() and release() have been serialized by bd_mutex already
      
      2) don't hold lo_ctl_mutex for decreasing/checking lo_refcnt in
      lo_release(), then lo_ctl_mutex is only required for the last release.
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Tested-by: NJarod Wilson <jarod@redhat.com>
      Acked-by: NJarod Wilson <jarod@redhat.com>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      f8933667
  21. 06 5月, 2015 2 次提交
    • M
      block: loop: avoiding too many pending per work I/O · 4d4e41ae
      Ming Lei 提交于
      If there are too many pending per work I/O, too many
      high priority work thread can be generated so that
      system performance can be effected.
      
      This patch limits the max_active parameter of workqueue as 16.
      
      This patch fixes Fedora 22 live booting performance
      regression when it is booted from squashfs over dm
      based on loop, and looks the following reasons are
      related with the problem:
      
      - not like other filesyststems(such as ext4), squashfs
      is a bit special, and I observed that increasing I/O jobs
      to access file in squashfs only improve I/O performance a
      little, but it can make big difference for ext4
      
      - nested loop: both squashfs.img and ext3fs.img are mounted
      as loop block, and ext3fs.img is inside the squashfs
      
      - during booting, lots of tasks may run concurrently
      
      Fixes: b5dd2f60
      Cc: stable@vger.kernel.org (v4.0)
      Cc: Justin M. Forbes <jforbes@fedoraproject.org>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Acked-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      4d4e41ae
    • M
      block: loop: convert to per-device workqueue · f4aa4c7b
      Ming Lei 提交于
      Documentation/workqueue.txt:
      	If there is dependency among multiple work items used
      	during memory reclaim, they should be queued to separate
      	wq each with WQ_MEM_RECLAIM.
      
      Loop devices can be stacked, so we have to convert to per-device
      workqueue. One example is Fedora live CD.
      
      Fixes: b5dd2f60
      Cc: stable@vger.kernel.org (v4.0)
      Cc: Justin M. Forbes <jforbes@fedoraproject.org>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Acked-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      f4aa4c7b
  22. 28 4月, 2015 1 次提交
    • N
      block: destroy bdi before blockdev is unregistered. · 6cd18e71
      NeilBrown 提交于
      Because of the peculiar way that md devices are created (automatically
      when the device node is opened), a new device can be created and
      registered immediately after the
      	blk_unregister_region(disk_devt(disk), disk->minors);
      call in del_gendisk().
      
      Therefore it is important that all visible artifacts of the previous
      device are removed before this call.  In particular, the 'bdi'.
      
      Since:
      commit c4db59d3
      Author: Christoph Hellwig <hch@lst.de>
          fs: don't reassign dirty inodes to default_backing_dev_info
      
      moved the
         device_unregister(bdi->dev);
      call from bdi_unregister() to bdi_destroy() it has been quite easy to
      lose a race and have a new (e.g.) "md127" be created after the
      blk_unregister_region() call and before bdi_destroy() is ultimately
      called by the final 'put_disk', which must come after del_gendisk().
      
      The new device finds that the bdi name is already registered in sysfs
      and complains
      
      > [ 9627.630029] WARNING: CPU: 18 PID: 3330 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x5a/0x70()
      > [ 9627.630032] sysfs: cannot create duplicate filename '/devices/virtual/bdi/9:127'
      
      We can fix this by moving the bdi_destroy() call out of
      blk_release_queue() (which can happen very late when a refcount
      reaches zero) and into blk_cleanup_queue() - which happens exactly when the md
      device driver calls it.
      
      Then it is only necessary for md to call blk_cleanup_queue() before
      del_gendisk().  As loop.c devices are also created on demand by
      opening the device node, we make the same change there.
      
      Fixes: c4db59d3Reported-by: NAzat Khuzhin <a3at.mail@gmail.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: stable@vger.kernel.org (v4.0)
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      6cd18e71
  23. 16 4月, 2015 1 次提交
  24. 12 4月, 2015 1 次提交
  25. 03 1月, 2015 5 次提交
    • J
      loop: add blk-mq.h include · 78e367a3
      Jens Axboe 提交于
      Looks like we pull it in through other ways on x86, but we fail
      on sparc:
      
      In file included from drivers/block/cryptoloop.c:30:0:
      drivers/block/loop.h:63:24: error: field 'tag_set' has incomplete type
      struct blk_mq_tag_set tag_set;
      
      Add the include to loop.h, kill it from loop.c.
      Signed-off-by: NJens Axboe <axboe@fb.com>
      78e367a3
    • M
      block: loop: don't handle REQ_FUA explicitly · af65aa8e
      Ming Lei 提交于
      block core handles REQ_FUA by its flush state machine, so
      won't do it in loop explicitly.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      af65aa8e
    • M
      block: loop: introduce lo_discard() and lo_req_flush() · cf655d95
      Ming Lei 提交于
      No behaviour change, just move the handling for REQ_DISCARD
      and REQ_FLUSH in these two functions.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      cf655d95
    • M
      block: loop: say goodby to bio · 30112013
      Ming Lei 提交于
      Switch to block request completely.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      30112013
    • M
      block: loop: improve performance via blk-mq · b5dd2f60
      Ming Lei 提交于
      The conversion is a bit straightforward, and use work queue to
      dispatch requests of loop block, and one big change is that requests
      is submitted to backend file/device concurrently with work queue,
      so throughput may get improved much. Given write requests over same
      file are often run exclusively, so don't handle them concurrently for
      avoiding extra context switch cost, possible lock contention and work
      schedule cost. Also with blk-mq, there is opportunity to get loop I/O
      merged before submitting to backend file/device.
      
      In the following test:
      	- base: v3.19-rc2-2041231
      	- loop over file in ext4 file system on SSD disk
      	- bs: 4k, libaio, io depth: 64, O_DIRECT, num of jobs: 1
      	- throughput: IOPS
      
      	------------------------------------------------------
      	|            | base      | base with loop-mq | delta |
      	------------------------------------------------------
      	| randread   | 1740      | 25318             | +1355%|
      	------------------------------------------------------
      	| read       | 42196     | 51771             | +22.6%|
      	-----------------------------------------------------
      	| randwrite  | 35709     | 34624             | -3%   |
      	-----------------------------------------------------
      	| write      | 39137     | 40326             | +3%   |
      	-----------------------------------------------------
      
      So loop-mq can improve throughput for both read and randread, meantime,
      performance of write and randwrite isn't hurted basically.
      
      Another benefit is that loop driver code gets simplified
      much after blk-mq conversion, and the patch can be thought as
      cleanup too.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      b5dd2f60
  26. 18 4月, 2014 1 次提交