2018-06-06 05:42:14 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2006-09-28 04:52:15 +04:00
|
|
|
* Copyright (c) 2000-2006 Silicon Graphics, Inc.
|
2005-11-02 06:58:39 +03:00
|
|
|
* All Rights Reserved.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2006-11-11 10:03:49 +03:00
|
|
|
#include "xfs.h"
|
2006-10-20 10:28:16 +04:00
|
|
|
#include <linux/backing-dev.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-06-29 05:25:35 +03:00
|
|
|
#include "xfs_shared.h"
|
2014-11-28 06:25:04 +03:00
|
|
|
#include "xfs_format.h"
|
2013-10-23 03:50:10 +04:00
|
|
|
#include "xfs_log_format.h"
|
2013-08-12 14:49:32 +04:00
|
|
|
#include "xfs_trans_resv.h"
|
2013-10-23 03:50:10 +04:00
|
|
|
#include "xfs_sb.h"
|
2009-03-03 22:48:37 +03:00
|
|
|
#include "xfs_mount.h"
|
2009-12-15 02:14:59 +03:00
|
|
|
#include "xfs_trace.h"
|
2013-10-23 03:50:10 +04:00
|
|
|
#include "xfs_log.h"
|
2020-06-30 00:48:47 +03:00
|
|
|
#include "xfs_log_recover.h"
|
2020-06-30 00:48:46 +03:00
|
|
|
#include "xfs_trans.h"
|
|
|
|
#include "xfs_buf_item.h"
|
2017-10-31 22:04:49 +03:00
|
|
|
#include "xfs_errortag.h"
|
2017-10-18 00:16:29 +03:00
|
|
|
#include "xfs_error.h"
|
2009-03-03 22:48:37 +03:00
|
|
|
|
2007-02-10 10:34:56 +03:00
|
|
|
static kmem_zone_t *xfs_buf_zone;
|
2005-06-21 09:14:01 +04:00
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
#define xb_to_gfp(flags) \
|
2012-04-23 09:58:56 +04:00
|
|
|
((((flags) & XBF_READ_AHEAD) ? __GFP_NORETRY : GFP_NOFS) | __GFP_NOWARN)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-10-18 09:21:29 +03:00
|
|
|
/*
|
|
|
|
* Locking orders
|
|
|
|
*
|
|
|
|
* xfs_buf_ioacct_inc:
|
|
|
|
* xfs_buf_ioacct_dec:
|
|
|
|
* b_sema (caller holds)
|
|
|
|
* b_lock
|
|
|
|
*
|
|
|
|
* xfs_buf_stale:
|
|
|
|
* b_sema (caller holds)
|
|
|
|
* b_lock
|
|
|
|
* lru_lock
|
|
|
|
*
|
|
|
|
* xfs_buf_rele:
|
|
|
|
* b_lock
|
|
|
|
* pag_buf_lock
|
|
|
|
* lru_lock
|
|
|
|
*
|
|
|
|
* xfs_buftarg_wait_rele
|
|
|
|
* lru_lock
|
|
|
|
* b_lock (trylock due to inversion)
|
|
|
|
*
|
|
|
|
* xfs_buftarg_isolate
|
|
|
|
* lru_lock
|
|
|
|
* b_lock (trylock due to inversion)
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-01-25 20:42:24 +03:00
|
|
|
static inline int
|
|
|
|
xfs_buf_is_vmapped(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Return true if the buffer is vmapped.
|
|
|
|
*
|
2012-04-23 09:59:07 +04:00
|
|
|
* b_addr is null if the buffer is not mapped, but the code is clever
|
|
|
|
* enough to know it doesn't have to map a single page, so the check has
|
|
|
|
* to be both for b_addr and bp->b_page_count > 1.
|
2010-01-25 20:42:24 +03:00
|
|
|
*/
|
2012-04-23 09:59:07 +04:00
|
|
|
return bp->b_addr && bp->b_page_count > 1;
|
2010-01-25 20:42:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
xfs_buf_vmap_len(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
return (bp->b_page_count * PAGE_SIZE) - bp->b_offset;
|
|
|
|
}
|
|
|
|
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
/*
|
|
|
|
* Bump the I/O in flight count on the buftarg if we haven't yet done so for
|
|
|
|
* this buffer. The count is incremented once per buffer (per hold cycle)
|
|
|
|
* because the corresponding decrement is deferred to buffer release. Buffers
|
|
|
|
* can undergo I/O multiple times in a hold-release cycle and per buffer I/O
|
|
|
|
* tracking adds unnecessary overhead. This is used for sychronization purposes
|
|
|
|
* with unmount (see xfs_wait_buftarg()), so all we really need is a count of
|
|
|
|
* in-flight buffers.
|
|
|
|
*
|
|
|
|
* Buffers that are never released (e.g., superblock, iclog buffers) must set
|
|
|
|
* the XBF_NO_IOACCT flag before I/O submission. Otherwise, the buftarg count
|
|
|
|
* never reaches zero and unmount hangs indefinitely.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
xfs_buf_ioacct_inc(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
2017-05-31 18:22:52 +03:00
|
|
|
if (bp->b_flags & XBF_NO_IOACCT)
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
ASSERT(bp->b_flags & XBF_ASYNC);
|
2017-05-31 18:22:52 +03:00
|
|
|
spin_lock(&bp->b_lock);
|
|
|
|
if (!(bp->b_state & XFS_BSTATE_IN_FLIGHT)) {
|
|
|
|
bp->b_state |= XFS_BSTATE_IN_FLIGHT;
|
|
|
|
percpu_counter_inc(&bp->b_target->bt_io_count);
|
|
|
|
}
|
|
|
|
spin_unlock(&bp->b_lock);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the in-flight state on a buffer about to be released to the LRU or
|
|
|
|
* freed and unaccount from the buftarg.
|
|
|
|
*/
|
|
|
|
static inline void
|
2017-05-31 18:22:52 +03:00
|
|
|
__xfs_buf_ioacct_dec(
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
2017-06-08 18:23:07 +03:00
|
|
|
lockdep_assert_held(&bp->b_lock);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
|
2017-05-31 18:22:52 +03:00
|
|
|
if (bp->b_state & XFS_BSTATE_IN_FLIGHT) {
|
|
|
|
bp->b_state &= ~XFS_BSTATE_IN_FLIGHT;
|
|
|
|
percpu_counter_dec(&bp->b_target->bt_io_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
xfs_buf_ioacct_dec(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
spin_lock(&bp->b_lock);
|
|
|
|
__xfs_buf_ioacct_dec(bp);
|
|
|
|
spin_unlock(&bp->b_lock);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
}
|
|
|
|
|
2010-12-02 08:30:55 +03:00
|
|
|
/*
|
|
|
|
* When we mark a buffer stale, we remove the buffer from the LRU and clear the
|
|
|
|
* b_lru_ref count so that the buffer is freed immediately when the buffer
|
|
|
|
* reference count falls to zero. If the buffer is already on the LRU, we need
|
|
|
|
* to remove the reference that LRU holds on the buffer.
|
|
|
|
*
|
|
|
|
* This prevents build-up of stale buffers on the LRU.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_buf_stale(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
|
|
|
|
2010-12-02 08:30:55 +03:00
|
|
|
bp->b_flags |= XBF_STALE;
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the delwri status so that a delwri queue walker will not
|
|
|
|
* flush this buffer to disk now that it is stale. The delwri queue has
|
|
|
|
* a reference to the buffer, so this is safe to do.
|
|
|
|
*/
|
|
|
|
bp->b_flags &= ~_XBF_DELWRI_Q;
|
|
|
|
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
/*
|
|
|
|
* Once the buffer is marked stale and unlocked, a subsequent lookup
|
|
|
|
* could reset b_flags. There is no guarantee that the buffer is
|
|
|
|
* unaccounted (released to LRU) before that occurs. Drop in-flight
|
|
|
|
* status now to preserve accounting consistency.
|
|
|
|
*/
|
2013-08-28 04:18:06 +04:00
|
|
|
spin_lock(&bp->b_lock);
|
2017-05-31 18:22:52 +03:00
|
|
|
__xfs_buf_ioacct_dec(bp);
|
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
atomic_set(&bp->b_lru_ref, 0);
|
|
|
|
if (!(bp->b_state & XFS_BSTATE_DISPOSE) &&
|
2013-08-28 04:18:05 +04:00
|
|
|
(list_lru_del(&bp->b_target->bt_lru, &bp->b_lru)))
|
|
|
|
atomic_dec(&bp->b_hold);
|
|
|
|
|
2010-12-02 08:30:55 +03:00
|
|
|
ASSERT(atomic_read(&bp->b_hold) >= 1);
|
2013-08-28 04:18:06 +04:00
|
|
|
spin_unlock(&bp->b_lock);
|
2010-12-02 08:30:55 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
static int
|
|
|
|
xfs_buf_get_maps(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
int map_count)
|
|
|
|
{
|
|
|
|
ASSERT(bp->b_maps == NULL);
|
|
|
|
bp->b_map_count = map_count;
|
|
|
|
|
|
|
|
if (map_count == 1) {
|
2012-12-05 03:18:02 +04:00
|
|
|
bp->b_maps = &bp->__b_map;
|
2012-06-22 12:50:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp->b_maps = kmem_zalloc(map_count * sizeof(struct xfs_buf_map),
|
|
|
|
KM_NOFS);
|
|
|
|
if (!bp->b_maps)
|
2014-06-25 08:58:08 +04:00
|
|
|
return -ENOMEM;
|
2012-06-22 12:50:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees b_pages if it was allocated.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
xfs_buf_free_maps(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
2012-12-05 03:18:02 +04:00
|
|
|
if (bp->b_maps != &bp->__b_map) {
|
2012-06-22 12:50:09 +04:00
|
|
|
kmem_free(bp->b_maps);
|
|
|
|
bp->b_maps = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 04:01:15 +03:00
|
|
|
static int
|
2012-06-22 12:50:09 +04:00
|
|
|
_xfs_buf_alloc(
|
2011-10-10 20:52:48 +04:00
|
|
|
struct xfs_buftarg *target,
|
2012-06-22 12:50:09 +04:00
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
2020-01-24 04:01:15 +03:00
|
|
|
xfs_buf_flags_t flags,
|
|
|
|
struct xfs_buf **bpp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-10-10 20:52:48 +04:00
|
|
|
struct xfs_buf *bp;
|
2012-06-22 12:50:09 +04:00
|
|
|
int error;
|
|
|
|
int i;
|
2011-10-10 20:52:48 +04:00
|
|
|
|
2020-01-24 04:01:15 +03:00
|
|
|
*bpp = NULL;
|
2020-07-22 19:23:10 +03:00
|
|
|
bp = kmem_cache_zalloc(xfs_buf_zone, GFP_NOFS | __GFP_NOFAIL);
|
2011-10-10 20:52:48 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2012-04-23 09:59:05 +04:00
|
|
|
* We don't want certain flags to appear in b_flags unless they are
|
|
|
|
* specifically set by later operations on the buffer.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2012-04-23 09:59:07 +04:00
|
|
|
flags &= ~(XBF_UNMAPPED | XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD);
|
2006-01-11 07:39:08 +03:00
|
|
|
|
|
|
|
atomic_set(&bp->b_hold, 1);
|
2010-12-02 08:30:55 +03:00
|
|
|
atomic_set(&bp->b_lru_ref, 1);
|
2008-08-13 10:36:11 +04:00
|
|
|
init_completion(&bp->b_iowait);
|
2010-12-02 08:30:55 +03:00
|
|
|
INIT_LIST_HEAD(&bp->b_lru);
|
2006-01-11 07:39:08 +03:00
|
|
|
INIT_LIST_HEAD(&bp->b_list);
|
2018-01-25 00:38:49 +03:00
|
|
|
INIT_LIST_HEAD(&bp->b_li_list);
|
2010-09-07 18:33:15 +04:00
|
|
|
sema_init(&bp->b_sema, 0); /* held, no waiters */
|
2013-08-28 04:18:06 +04:00
|
|
|
spin_lock_init(&bp->b_lock);
|
2006-01-11 07:39:08 +03:00
|
|
|
bp->b_target = target;
|
2019-06-29 05:27:29 +03:00
|
|
|
bp->b_mount = target->bt_mount;
|
2012-06-22 12:50:09 +04:00
|
|
|
bp->b_flags = flags;
|
2012-04-23 09:58:50 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2012-04-23 09:58:52 +04:00
|
|
|
* Set length and io_length to the same value initially.
|
|
|
|
* I/O routines should use io_length, which will be the same in
|
2005-04-17 02:20:36 +04:00
|
|
|
* most cases but may be reset (e.g. XFS recovery).
|
|
|
|
*/
|
2012-06-22 12:50:09 +04:00
|
|
|
error = xfs_buf_get_maps(bp, nmaps);
|
|
|
|
if (error) {
|
2019-11-14 23:43:04 +03:00
|
|
|
kmem_cache_free(xfs_buf_zone, bp);
|
2020-01-24 04:01:15 +03:00
|
|
|
return error;
|
2012-06-22 12:50:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bp->b_bn = map[0].bm_bn;
|
|
|
|
bp->b_length = 0;
|
|
|
|
for (i = 0; i < nmaps; i++) {
|
|
|
|
bp->b_maps[i].bm_bn = map[i].bm_bn;
|
|
|
|
bp->b_maps[i].bm_len = map[i].bm_len;
|
|
|
|
bp->b_length += map[i].bm_len;
|
|
|
|
}
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
atomic_set(&bp->b_pin_count, 0);
|
|
|
|
init_waitqueue_head(&bp->b_waiters);
|
|
|
|
|
2019-06-29 05:27:29 +03:00
|
|
|
XFS_STATS_INC(bp->b_mount, xb_create);
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_init(bp, _RET_IP_);
|
2011-10-10 20:52:48 +04:00
|
|
|
|
2020-01-24 04:01:15 +03:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-11 07:39:08 +03:00
|
|
|
* Allocate a page array capable of holding a specified number
|
|
|
|
* of pages, and point the page buf at it.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
STATIC int
|
2006-01-11 07:39:08 +03:00
|
|
|
_xfs_buf_get_pages(
|
|
|
|
xfs_buf_t *bp,
|
2014-04-14 13:01:20 +04:00
|
|
|
int page_count)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
/* Make sure that we have a page list */
|
2006-01-11 07:39:08 +03:00
|
|
|
if (bp->b_pages == NULL) {
|
|
|
|
bp->b_page_count = page_count;
|
|
|
|
if (page_count <= XB_PAGES) {
|
|
|
|
bp->b_pages = bp->b_page_array;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
2006-01-11 07:39:08 +03:00
|
|
|
bp->b_pages = kmem_alloc(sizeof(struct page *) *
|
2012-04-23 09:58:56 +04:00
|
|
|
page_count, KM_NOFS);
|
2006-01-11 07:39:08 +03:00
|
|
|
if (bp->b_pages == NULL)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-01-11 07:39:08 +03:00
|
|
|
memset(bp->b_pages, 0, sizeof(struct page *) * page_count);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-11 07:39:08 +03:00
|
|
|
* Frees b_pages if it was allocated.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
STATIC void
|
2006-01-11 07:39:08 +03:00
|
|
|
_xfs_buf_free_pages(
|
2005-04-17 02:20:36 +04:00
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2006-01-11 07:39:08 +03:00
|
|
|
if (bp->b_pages != bp->b_page_array) {
|
2008-05-19 10:31:57 +04:00
|
|
|
kmem_free(bp->b_pages);
|
2009-12-15 02:11:57 +03:00
|
|
|
bp->b_pages = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Releases the specified buffer.
|
|
|
|
*
|
|
|
|
* The modification state of any associated pages is left unchanged.
|
2013-08-07 14:10:59 +04:00
|
|
|
* The buffer must not be on any hash - use xfs_buf_rele instead for
|
2005-04-17 02:20:36 +04:00
|
|
|
* hashed and refcounted buffers
|
|
|
|
*/
|
2019-10-25 08:25:37 +03:00
|
|
|
static void
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_free(
|
2005-04-17 02:20:36 +04:00
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_free(bp, _RET_IP_);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-12-02 08:30:55 +03:00
|
|
|
ASSERT(list_empty(&bp->b_lru));
|
|
|
|
|
2011-03-26 01:16:45 +03:00
|
|
|
if (bp->b_flags & _XBF_PAGES) {
|
2005-04-17 02:20:36 +04:00
|
|
|
uint i;
|
|
|
|
|
2010-01-25 20:42:24 +03:00
|
|
|
if (xfs_buf_is_vmapped(bp))
|
2010-03-16 21:55:56 +03:00
|
|
|
vm_unmap_ram(bp->b_addr - bp->b_offset,
|
|
|
|
bp->b_page_count);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-28 05:03:13 +04:00
|
|
|
for (i = 0; i < bp->b_page_count; i++) {
|
|
|
|
struct page *page = bp->b_pages[i];
|
|
|
|
|
2011-03-26 01:16:45 +03:00
|
|
|
__free_page(page);
|
2006-09-28 05:03:13 +04:00
|
|
|
}
|
2020-03-25 06:10:28 +03:00
|
|
|
if (current->reclaim_state)
|
|
|
|
current->reclaim_state->reclaimed_slab +=
|
|
|
|
bp->b_page_count;
|
2011-03-26 01:16:45 +03:00
|
|
|
} else if (bp->b_flags & _XBF_KMEM)
|
|
|
|
kmem_free(bp->b_addr);
|
2009-12-15 02:11:57 +03:00
|
|
|
_xfs_buf_free_pages(bp);
|
2012-06-22 12:50:09 +04:00
|
|
|
xfs_buf_free_maps(bp);
|
2019-11-14 23:43:04 +03:00
|
|
|
kmem_cache_free(xfs_buf_zone, bp);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-26 01:16:45 +03:00
|
|
|
* Allocates all the pages for buffer in question and builds it's page list.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
STATIC int
|
2011-03-26 01:16:45 +03:00
|
|
|
xfs_buf_allocate_memory(
|
2005-04-17 02:20:36 +04:00
|
|
|
xfs_buf_t *bp,
|
|
|
|
uint flags)
|
|
|
|
{
|
2012-04-23 09:58:52 +04:00
|
|
|
size_t size;
|
2005-04-17 02:20:36 +04:00
|
|
|
size_t nbytes, offset;
|
2006-01-11 07:39:08 +03:00
|
|
|
gfp_t gfp_mask = xb_to_gfp(flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned short page_count, i;
|
2012-04-23 09:58:53 +04:00
|
|
|
xfs_off_t start, end;
|
2005-04-17 02:20:36 +04:00
|
|
|
int error;
|
2019-10-05 02:38:44 +03:00
|
|
|
xfs_km_flags_t kmflag_mask = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assure zeroed buffer for non-read cases.
|
|
|
|
*/
|
|
|
|
if (!(flags & XBF_READ)) {
|
|
|
|
kmflag_mask |= KM_ZERO;
|
|
|
|
gfp_mask |= __GFP_ZERO;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-03-26 01:16:45 +03:00
|
|
|
/*
|
|
|
|
* for buffers that are contained within a single page, just allocate
|
|
|
|
* the memory from the heap - there's no need for the complexity of
|
|
|
|
* page arrays to keep allocation down to order 0.
|
|
|
|
*/
|
2012-04-23 09:58:53 +04:00
|
|
|
size = BBTOB(bp->b_length);
|
|
|
|
if (size < PAGE_SIZE) {
|
xfs: add kmem_alloc_io()
Memory we use to submit for IO needs strict alignment to the
underlying driver contraints. Worst case, this is 512 bytes. Given
that all allocations for IO are always a power of 2 multiple of 512
bytes, the kernel heap provides natural alignment for objects of
these sizes and that suffices.
Until, of course, memory debugging of some kind is turned on (e.g.
red zones, poisoning, KASAN) and then the alignment of the heap
objects is thrown out the window. Then we get weird IO errors and
data corruption problems because drivers don't validate alignment
and do the wrong thing when passed unaligned memory buffers in bios.
TO fix this, introduce kmem_alloc_io(), which will guaranteeat least
512 byte alignment of buffers for IO, even if memory debugging
options are turned on. It is assumed that the minimum allocation
size will be 512 bytes, and that sizes will be power of 2 mulitples
of 512 bytes.
Use this everywhere we allocate buffers for IO.
This no longer fails with log recovery errors when KASAN is enabled
due to the brd driver not handling unaligned memory buffers:
# mkfs.xfs -f /dev/ram0 ; mount /dev/ram0 /mnt/test
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2019-08-26 22:08:39 +03:00
|
|
|
int align_mask = xfs_buftarg_dma_alignment(bp->b_target);
|
2019-10-05 02:38:44 +03:00
|
|
|
bp->b_addr = kmem_alloc_io(size, align_mask,
|
|
|
|
KM_NOFS | kmflag_mask);
|
2011-03-26 01:16:45 +03:00
|
|
|
if (!bp->b_addr) {
|
|
|
|
/* low memory - use alloc_page loop instead */
|
|
|
|
goto use_alloc_page;
|
|
|
|
}
|
|
|
|
|
2012-04-23 09:58:53 +04:00
|
|
|
if (((unsigned long)(bp->b_addr + size - 1) & PAGE_MASK) !=
|
2011-03-26 01:16:45 +03:00
|
|
|
((unsigned long)bp->b_addr & PAGE_MASK)) {
|
|
|
|
/* b_addr spans two pages - use alloc_page instead */
|
|
|
|
kmem_free(bp->b_addr);
|
|
|
|
bp->b_addr = NULL;
|
|
|
|
goto use_alloc_page;
|
|
|
|
}
|
|
|
|
bp->b_offset = offset_in_page(bp->b_addr);
|
|
|
|
bp->b_pages = bp->b_page_array;
|
xfs: add kmem_alloc_io()
Memory we use to submit for IO needs strict alignment to the
underlying driver contraints. Worst case, this is 512 bytes. Given
that all allocations for IO are always a power of 2 multiple of 512
bytes, the kernel heap provides natural alignment for objects of
these sizes and that suffices.
Until, of course, memory debugging of some kind is turned on (e.g.
red zones, poisoning, KASAN) and then the alignment of the heap
objects is thrown out the window. Then we get weird IO errors and
data corruption problems because drivers don't validate alignment
and do the wrong thing when passed unaligned memory buffers in bios.
TO fix this, introduce kmem_alloc_io(), which will guaranteeat least
512 byte alignment of buffers for IO, even if memory debugging
options are turned on. It is assumed that the minimum allocation
size will be 512 bytes, and that sizes will be power of 2 mulitples
of 512 bytes.
Use this everywhere we allocate buffers for IO.
This no longer fails with log recovery errors when KASAN is enabled
due to the brd driver not handling unaligned memory buffers:
# mkfs.xfs -f /dev/ram0 ; mount /dev/ram0 /mnt/test
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2019-08-26 22:08:39 +03:00
|
|
|
bp->b_pages[0] = kmem_to_page(bp->b_addr);
|
2011-03-26 01:16:45 +03:00
|
|
|
bp->b_page_count = 1;
|
2012-04-23 09:59:07 +04:00
|
|
|
bp->b_flags |= _XBF_KMEM;
|
2011-03-26 01:16:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
use_alloc_page:
|
2012-12-05 03:18:02 +04:00
|
|
|
start = BBTOB(bp->b_maps[0].bm_bn) >> PAGE_SHIFT;
|
|
|
|
end = (BBTOB(bp->b_maps[0].bm_bn + bp->b_length) + PAGE_SIZE - 1)
|
2012-06-22 12:50:08 +04:00
|
|
|
>> PAGE_SHIFT;
|
2012-04-23 09:58:53 +04:00
|
|
|
page_count = end - start;
|
2014-04-14 13:01:20 +04:00
|
|
|
error = _xfs_buf_get_pages(bp, page_count);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (unlikely(error))
|
|
|
|
return error;
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
offset = bp->b_offset;
|
2011-03-26 01:16:45 +03:00
|
|
|
bp->b_flags |= _XBF_PAGES;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
for (i = 0; i < bp->b_page_count; i++) {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct page *page;
|
|
|
|
uint retries = 0;
|
2011-03-26 01:16:45 +03:00
|
|
|
retry:
|
|
|
|
page = alloc_page(gfp_mask);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (unlikely(page == NULL)) {
|
2006-01-11 07:39:08 +03:00
|
|
|
if (flags & XBF_READ_AHEAD) {
|
|
|
|
bp->b_page_count = i;
|
2014-06-25 08:58:08 +04:00
|
|
|
error = -ENOMEM;
|
2011-03-26 01:16:45 +03:00
|
|
|
goto out_free_pages;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This could deadlock.
|
|
|
|
*
|
|
|
|
* But until all the XFS lowlevel code is revamped to
|
|
|
|
* handle buffer allocation failures we can't do much.
|
|
|
|
*/
|
|
|
|
if (!(++retries % 100))
|
2011-03-07 02:00:35 +03:00
|
|
|
xfs_err(NULL,
|
2015-10-12 07:41:29 +03:00
|
|
|
"%s(%u) possible memory allocation deadlock in %s (mode:0x%x)",
|
|
|
|
current->comm, current->pid,
|
2008-04-10 06:19:21 +04:00
|
|
|
__func__, gfp_mask);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-06-29 05:27:29 +03:00
|
|
|
XFS_STATS_INC(bp->b_mount, xb_page_retries);
|
2009-07-09 16:52:32 +04:00
|
|
|
congestion_wait(BLK_RW_ASYNC, HZ/50);
|
2005-04-17 02:20:36 +04:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2019-06-29 05:27:29 +03:00
|
|
|
XFS_STATS_INC(bp->b_mount, xb_page_found);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-03-26 01:16:45 +03:00
|
|
|
nbytes = min_t(size_t, size, PAGE_SIZE - offset);
|
2005-04-17 02:20:36 +04:00
|
|
|
size -= nbytes;
|
2006-01-11 07:39:08 +03:00
|
|
|
bp->b_pages[i] = page;
|
2005-04-17 02:20:36 +04:00
|
|
|
offset = 0;
|
|
|
|
}
|
2011-03-26 01:16:45 +03:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-03-26 01:16:45 +03:00
|
|
|
out_free_pages:
|
|
|
|
for (i = 0; i < bp->b_page_count; i++)
|
|
|
|
__free_page(bp->b_pages[i]);
|
2017-01-26 07:24:57 +03:00
|
|
|
bp->b_flags &= ~_XBF_PAGES;
|
2005-04-17 02:20:36 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-31 05:57:33 +04:00
|
|
|
* Map buffer into kernel address-space if necessary.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
STATIC int
|
2006-01-11 07:39:08 +03:00
|
|
|
_xfs_buf_map_pages(
|
2005-04-17 02:20:36 +04:00
|
|
|
xfs_buf_t *bp,
|
|
|
|
uint flags)
|
|
|
|
{
|
2011-03-26 01:16:45 +03:00
|
|
|
ASSERT(bp->b_flags & _XBF_PAGES);
|
2006-01-11 07:39:08 +03:00
|
|
|
if (bp->b_page_count == 1) {
|
2011-03-26 01:16:45 +03:00
|
|
|
/* A single page buffer is always mappable */
|
2006-01-11 07:39:08 +03:00
|
|
|
bp->b_addr = page_address(bp->b_pages[0]) + bp->b_offset;
|
2012-04-23 09:59:07 +04:00
|
|
|
} else if (flags & XBF_UNMAPPED) {
|
|
|
|
bp->b_addr = NULL;
|
|
|
|
} else {
|
2011-03-26 01:13:42 +03:00
|
|
|
int retried = 0;
|
2017-05-04 00:53:19 +03:00
|
|
|
unsigned nofs_flag;
|
2014-03-07 09:19:14 +04:00
|
|
|
|
|
|
|
/*
|
2019-11-08 00:24:52 +03:00
|
|
|
* vm_map_ram() will allocate auxiliary structures (e.g.
|
2014-03-07 09:19:14 +04:00
|
|
|
* pagetables) with GFP_KERNEL, yet we are likely to be under
|
|
|
|
* GFP_NOFS context here. Hence we need to tell memory reclaim
|
2017-05-04 00:53:19 +03:00
|
|
|
* that we are in such a context via PF_MEMALLOC_NOFS to prevent
|
2014-03-07 09:19:14 +04:00
|
|
|
* memory reclaim re-entering the filesystem here and
|
|
|
|
* potentially deadlocking.
|
|
|
|
*/
|
2017-05-04 00:53:19 +03:00
|
|
|
nofs_flag = memalloc_nofs_save();
|
2011-03-26 01:13:42 +03:00
|
|
|
do {
|
|
|
|
bp->b_addr = vm_map_ram(bp->b_pages, bp->b_page_count,
|
2020-06-02 07:51:27 +03:00
|
|
|
-1);
|
2011-03-26 01:13:42 +03:00
|
|
|
if (bp->b_addr)
|
|
|
|
break;
|
|
|
|
vm_unmap_aliases();
|
|
|
|
} while (retried++ <= 1);
|
2017-05-04 00:53:19 +03:00
|
|
|
memalloc_nofs_restore(nofs_flag);
|
2011-03-26 01:13:42 +03:00
|
|
|
|
|
|
|
if (!bp->b_addr)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENOMEM;
|
2006-01-11 07:39:08 +03:00
|
|
|
bp->b_addr += bp->b_offset;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finding and Reading Buffers
|
|
|
|
*/
|
2016-12-07 09:36:36 +03:00
|
|
|
static int
|
|
|
|
_xfs_buf_obj_cmp(
|
|
|
|
struct rhashtable_compare_arg *arg,
|
|
|
|
const void *obj)
|
|
|
|
{
|
|
|
|
const struct xfs_buf_map *map = arg->key;
|
|
|
|
const struct xfs_buf *bp = obj;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The key hashing in the lookup path depends on the key being the
|
|
|
|
* first element of the compare_arg, make sure to assert this.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(offsetof(struct xfs_buf_map, bm_bn) != 0);
|
|
|
|
|
|
|
|
if (bp->b_bn != map->bm_bn)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (unlikely(bp->b_length != map->bm_len)) {
|
|
|
|
/*
|
|
|
|
* found a block number match. If the range doesn't
|
|
|
|
* match, the only way this is allowed is if the buffer
|
|
|
|
* in the cache is stale and the transaction that made
|
|
|
|
* it stale has not yet committed. i.e. we are
|
|
|
|
* reallocating a busy extent. Skip this buffer and
|
|
|
|
* continue searching for an exact match.
|
|
|
|
*/
|
|
|
|
ASSERT(bp->b_flags & XBF_STALE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rhashtable_params xfs_buf_hash_params = {
|
|
|
|
.min_size = 32, /* empty AGs have minimal footprint */
|
|
|
|
.nelem_hint = 16,
|
|
|
|
.key_len = sizeof(xfs_daddr_t),
|
|
|
|
.key_offset = offsetof(struct xfs_buf, b_bn),
|
|
|
|
.head_offset = offsetof(struct xfs_buf, b_rhash_head),
|
|
|
|
.automatic_shrinking = true,
|
|
|
|
.obj_cmpfn = _xfs_buf_obj_cmp,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
xfs_buf_hash_init(
|
|
|
|
struct xfs_perag *pag)
|
|
|
|
{
|
|
|
|
spin_lock_init(&pag->pag_buf_lock);
|
|
|
|
return rhashtable_init(&pag->pag_buf_hash, &xfs_buf_hash_params);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xfs_buf_hash_destroy(
|
|
|
|
struct xfs_perag *pag)
|
|
|
|
{
|
|
|
|
rhashtable_destroy(&pag->pag_buf_hash);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
2018-04-18 18:25:21 +03:00
|
|
|
* Look up a buffer in the buffer cache and return it referenced and locked
|
|
|
|
* in @found_bp.
|
|
|
|
*
|
|
|
|
* If @new_bp is supplied and we have a lookup miss, insert @new_bp into the
|
|
|
|
* cache.
|
|
|
|
*
|
|
|
|
* If XBF_TRYLOCK is set in @flags, only try to lock the buffer and return
|
|
|
|
* -EAGAIN if we fail to lock it.
|
|
|
|
*
|
|
|
|
* Return values are:
|
|
|
|
* -EFSCORRUPTED if have been supplied with an invalid address
|
|
|
|
* -EAGAIN on trylock failure
|
|
|
|
* -ENOENT if we fail to find a match and @new_bp was NULL
|
|
|
|
* 0, with @found_bp:
|
|
|
|
* - @new_bp if we inserted it into the cache
|
|
|
|
* - the buffer we found and locked.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2018-04-18 18:25:21 +03:00
|
|
|
static int
|
|
|
|
xfs_buf_find(
|
2012-04-23 09:58:49 +04:00
|
|
|
struct xfs_buftarg *btp,
|
2012-06-22 12:50:09 +04:00
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_flags_t flags,
|
2018-04-18 18:25:21 +03:00
|
|
|
struct xfs_buf *new_bp,
|
|
|
|
struct xfs_buf **found_bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-09-24 13:59:04 +04:00
|
|
|
struct xfs_perag *pag;
|
|
|
|
xfs_buf_t *bp;
|
2016-12-07 09:36:36 +03:00
|
|
|
struct xfs_buf_map cmap = { .bm_bn = map[0].bm_bn };
|
2013-01-21 16:53:52 +04:00
|
|
|
xfs_daddr_t eofs;
|
2012-06-22 12:50:09 +04:00
|
|
|
int i;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-04-18 18:25:21 +03:00
|
|
|
*found_bp = NULL;
|
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
for (i = 0; i < nmaps; i++)
|
2016-12-07 09:36:36 +03:00
|
|
|
cmap.bm_len += map[i].bm_len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Check for IOs smaller than the sector size / not sector aligned */
|
2016-12-07 09:36:36 +03:00
|
|
|
ASSERT(!(BBTOB(cmap.bm_len) < btp->bt_meta_sectorsize));
|
|
|
|
ASSERT(!(BBTOB(cmap.bm_bn) & (xfs_off_t)btp->bt_meta_sectormask));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-01-21 16:53:52 +04:00
|
|
|
/*
|
|
|
|
* Corrupted block numbers can get through to here, unfortunately, so we
|
|
|
|
* have to check that the buffer falls within the filesystem bounds.
|
|
|
|
*/
|
|
|
|
eofs = XFS_FSB_TO_BB(btp->bt_mount, btp->bt_mount->m_sb.sb_dblocks);
|
2016-12-07 09:36:36 +03:00
|
|
|
if (cmap.bm_bn < 0 || cmap.bm_bn >= eofs) {
|
2013-01-21 16:53:52 +04:00
|
|
|
xfs_alert(btp->bt_mount,
|
2018-01-08 22:39:18 +03:00
|
|
|
"%s: daddr 0x%llx out of range, EOFS 0x%llx",
|
2016-12-07 09:36:36 +03:00
|
|
|
__func__, cmap.bm_bn, eofs);
|
xfs: rework remote attr CRCs
Note: this changes the on-disk remote attribute format. I assert
that this is OK to do as CRCs are marked experimental and the first
kernel it is included in has not yet reached release yet. Further,
the userspace utilities are still evolving and so anyone using this
stuff right now is a developer or tester using volatile filesystems
for testing this feature. Hence changing the format right now to
save longer term pain is the right thing to do.
The fundamental change is to move from a header per extent in the
attribute to a header per filesytem block in the attribute. This
means there are more header blocks and the parsing of the attribute
data is slightly more complex, but it has the advantage that we
always know the size of the attribute on disk based on the length of
the data it contains.
This is where the header-per-extent method has problems. We don't
know the size of the attribute on disk without first knowing how
many extents are used to hold it. And we can't tell from a
mapping lookup, either, because remote attributes can be allocated
contiguously with other attribute blocks and so there is no obvious
way of determining the actual size of the atribute on disk short of
walking and mapping buffers.
The problem with this approach is that if we map a buffer
incorrectly (e.g. we make the last buffer for the attribute data too
long), we then get buffer cache lookup failure when we map it
correctly. i.e. we get a size mismatch on lookup. This is not
necessarily fatal, but it's a cache coherency problem that can lead
to returning the wrong data to userspace or writing the wrong data
to disk. And debug kernels will assert fail if this occurs.
I found lots of niggly little problems trying to fix this issue on a
4k block size filesystem, finally getting it to pass with lots of
fixes. The thing is, 1024 byte filesystems still failed, and it was
getting really complex handling all the corner cases that were
showing up. And there were clearly more that I hadn't found yet.
It is complex, fragile code, and if we don't fix it now, it will be
complex, fragile code forever more.
Hence the simple fix is to add a header to each filesystem block.
This gives us the same relationship between the attribute data
length and the number of blocks on disk as we have without CRCs -
it's a linear mapping and doesn't require us to guess anything. It
is simple to implement, too - the remote block count calculated at
lookup time can be used by the remote attribute set/get/remove code
without modification for both CRC and non-CRC filesystems. The world
becomes sane again.
Because the copy-in and copy-out now need to iterate over each
filesystem block, I moved them into helper functions so we separate
the block mapping and buffer manupulations from the attribute data
and CRC header manipulations. The code becomes much clearer as a
result, and it is a lot easier to understand and debug. It also
appears to be much more robust - once it worked on 4k block size
filesystems, it has worked without failure on 1k block size
filesystems, too.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
(cherry picked from commit ad1858d77771172e08016890f0eb2faedec3ecee)
2013-05-21 12:02:08 +04:00
|
|
|
WARN_ON(1);
|
2018-04-18 18:25:21 +03:00
|
|
|
return -EFSCORRUPTED;
|
2013-01-21 16:53:52 +04:00
|
|
|
}
|
|
|
|
|
2010-09-24 13:59:04 +04:00
|
|
|
pag = xfs_perag_get(btp->bt_mount,
|
2016-12-07 09:36:36 +03:00
|
|
|
xfs_daddr_to_agno(btp->bt_mount, cmap.bm_bn));
|
2010-09-24 13:59:04 +04:00
|
|
|
|
|
|
|
spin_lock(&pag->pag_buf_lock);
|
2016-12-07 09:36:36 +03:00
|
|
|
bp = rhashtable_lookup_fast(&pag->pag_buf_hash, &cmap,
|
|
|
|
xfs_buf_hash_params);
|
|
|
|
if (bp) {
|
|
|
|
atomic_inc(&bp->b_hold);
|
|
|
|
goto found;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No match found */
|
2018-04-18 18:25:21 +03:00
|
|
|
if (!new_bp) {
|
2015-10-12 10:21:22 +03:00
|
|
|
XFS_STATS_INC(btp->bt_mount, xb_miss_locked);
|
2010-09-24 13:59:04 +04:00
|
|
|
spin_unlock(&pag->pag_buf_lock);
|
|
|
|
xfs_perag_put(pag);
|
2018-04-18 18:25:21 +03:00
|
|
|
return -ENOENT;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2018-04-18 18:25:21 +03:00
|
|
|
|
|
|
|
/* the buffer keeps the perag reference until it is freed */
|
|
|
|
new_bp->b_pag = pag;
|
|
|
|
rhashtable_insert_fast(&pag->pag_buf_hash, &new_bp->b_rhash_head,
|
|
|
|
xfs_buf_hash_params);
|
|
|
|
spin_unlock(&pag->pag_buf_lock);
|
|
|
|
*found_bp = new_bp;
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
found:
|
2010-09-24 13:59:04 +04:00
|
|
|
spin_unlock(&pag->pag_buf_lock);
|
|
|
|
xfs_perag_put(pag);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-07-08 16:36:19 +04:00
|
|
|
if (!xfs_buf_trylock(bp)) {
|
|
|
|
if (flags & XBF_TRYLOCK) {
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_rele(bp);
|
2015-10-12 10:21:22 +03:00
|
|
|
XFS_STATS_INC(btp->bt_mount, xb_busy_locked);
|
2018-04-18 18:25:21 +03:00
|
|
|
return -EAGAIN;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2011-07-08 16:36:19 +04:00
|
|
|
xfs_buf_lock(bp);
|
2015-10-12 10:21:22 +03:00
|
|
|
XFS_STATS_INC(btp->bt_mount, xb_get_locked_waited);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-03-26 01:16:45 +03:00
|
|
|
/*
|
|
|
|
* if the buffer is stale, clear all the external state associated with
|
|
|
|
* it. We need to keep flags such as how we allocated the buffer memory
|
|
|
|
* intact here.
|
|
|
|
*/
|
2006-01-11 07:39:08 +03:00
|
|
|
if (bp->b_flags & XBF_STALE) {
|
|
|
|
ASSERT((bp->b_flags & _XBF_DELWRI_Q) == 0);
|
2012-04-23 09:59:07 +04:00
|
|
|
bp->b_flags &= _XBF_KMEM | _XBF_PAGES;
|
2012-11-14 10:54:40 +04:00
|
|
|
bp->b_ops = NULL;
|
2005-09-05 02:33:35 +04:00
|
|
|
}
|
2009-12-15 02:14:59 +03:00
|
|
|
|
|
|
|
trace_xfs_buf_find(bp, flags, _RET_IP_);
|
2015-10-12 10:21:22 +03:00
|
|
|
XFS_STATS_INC(btp->bt_mount, xb_get_locked);
|
2018-04-18 18:25:21 +03:00
|
|
|
*found_bp = bp;
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2018-04-18 18:25:20 +03:00
|
|
|
struct xfs_buf *
|
|
|
|
xfs_buf_incore(
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
xfs_daddr_t blkno,
|
|
|
|
size_t numblks,
|
|
|
|
xfs_buf_flags_t flags)
|
|
|
|
{
|
2018-04-18 18:25:21 +03:00
|
|
|
struct xfs_buf *bp;
|
|
|
|
int error;
|
2018-04-18 18:25:20 +03:00
|
|
|
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
|
2018-04-18 18:25:21 +03:00
|
|
|
|
|
|
|
error = xfs_buf_find(target, &map, 1, flags, NULL, &bp);
|
|
|
|
if (error)
|
|
|
|
return NULL;
|
|
|
|
return bp;
|
2018-04-18 18:25:20 +03:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2011-09-30 08:45:02 +04:00
|
|
|
* Assembles a buffer covering the specified range. The code is optimised for
|
|
|
|
* cache hits, as metadata intensive workloads will see 3 orders of magnitude
|
|
|
|
* more hits than misses.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2020-01-24 04:01:15 +03:00
|
|
|
int
|
2012-06-22 12:50:10 +04:00
|
|
|
xfs_buf_get_map(
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
2020-01-24 04:01:15 +03:00
|
|
|
xfs_buf_flags_t flags,
|
|
|
|
struct xfs_buf **bpp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-09-30 08:45:02 +04:00
|
|
|
struct xfs_buf *bp;
|
|
|
|
struct xfs_buf *new_bp;
|
2011-03-26 01:16:45 +03:00
|
|
|
int error = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-01-24 04:01:15 +03:00
|
|
|
*bpp = NULL;
|
2018-04-18 18:25:21 +03:00
|
|
|
error = xfs_buf_find(target, map, nmaps, flags, NULL, &bp);
|
2020-01-24 04:01:15 +03:00
|
|
|
if (!error)
|
2011-09-30 08:45:02 +04:00
|
|
|
goto found;
|
2020-01-24 04:01:15 +03:00
|
|
|
if (error != -ENOENT)
|
|
|
|
return error;
|
2011-09-30 08:45:02 +04:00
|
|
|
|
2020-01-24 04:01:15 +03:00
|
|
|
error = _xfs_buf_alloc(target, map, nmaps, flags, &new_bp);
|
|
|
|
if (error)
|
2020-01-24 04:01:15 +03:00
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-04-23 09:58:45 +04:00
|
|
|
error = xfs_buf_allocate_memory(new_bp, flags);
|
|
|
|
if (error) {
|
2012-06-22 12:50:09 +04:00
|
|
|
xfs_buf_free(new_bp);
|
2020-01-24 04:01:15 +03:00
|
|
|
return error;
|
2012-04-23 09:58:45 +04:00
|
|
|
}
|
|
|
|
|
2018-04-18 18:25:21 +03:00
|
|
|
error = xfs_buf_find(target, map, nmaps, flags, new_bp, &bp);
|
|
|
|
if (error) {
|
2012-04-23 09:58:45 +04:00
|
|
|
xfs_buf_free(new_bp);
|
2020-01-24 04:01:15 +03:00
|
|
|
return error;
|
2011-09-30 08:45:02 +04:00
|
|
|
}
|
|
|
|
|
2012-04-23 09:58:45 +04:00
|
|
|
if (bp != new_bp)
|
|
|
|
xfs_buf_free(new_bp);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-09-30 08:45:02 +04:00
|
|
|
found:
|
2012-04-23 09:59:07 +04:00
|
|
|
if (!bp->b_addr) {
|
2006-01-11 07:39:08 +03:00
|
|
|
error = _xfs_buf_map_pages(bp, flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (unlikely(error)) {
|
2020-02-21 18:40:44 +03:00
|
|
|
xfs_warn_ratelimited(target->bt_mount,
|
|
|
|
"%s: failed to map %u pages", __func__,
|
|
|
|
bp->b_page_count);
|
2012-04-23 09:58:54 +04:00
|
|
|
xfs_buf_relse(bp);
|
2020-01-24 04:01:15 +03:00
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:03:44 +03:00
|
|
|
/*
|
|
|
|
* Clear b_error if this is a lookup from a caller that doesn't expect
|
|
|
|
* valid data to be found in the buffer.
|
|
|
|
*/
|
|
|
|
if (!(flags & XBF_READ))
|
|
|
|
xfs_buf_ioerror(bp, 0);
|
|
|
|
|
2015-10-12 10:21:22 +03:00
|
|
|
XFS_STATS_INC(target->bt_mount, xb_get);
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_get(bp, flags, _RET_IP_);
|
2020-01-24 04:01:15 +03:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-12-03 14:20:26 +03:00
|
|
|
STATIC int
|
|
|
|
_xfs_buf_read(
|
|
|
|
xfs_buf_t *bp,
|
|
|
|
xfs_buf_flags_t flags)
|
|
|
|
{
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
ASSERT(!(flags & XBF_WRITE));
|
2012-12-05 03:18:02 +04:00
|
|
|
ASSERT(bp->b_maps[0].bm_bn != XFS_BUF_DADDR_NULL);
|
2008-12-03 14:20:26 +03:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD);
|
2011-07-08 16:36:32 +04:00
|
|
|
bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | XBF_READ_AHEAD);
|
2008-12-03 14:20:26 +03:00
|
|
|
|
2018-07-12 08:26:35 +03:00
|
|
|
return xfs_buf_submit(bp);
|
2008-12-03 14:20:26 +03:00
|
|
|
}
|
|
|
|
|
2018-10-18 09:20:30 +03:00
|
|
|
/*
|
2019-02-06 20:25:29 +03:00
|
|
|
* Reverify a buffer found in cache without an attached ->b_ops.
|
2019-02-04 01:03:59 +03:00
|
|
|
*
|
2019-02-06 20:25:29 +03:00
|
|
|
* If the caller passed an ops structure and the buffer doesn't have ops
|
|
|
|
* assigned, set the ops and use it to verify the contents. If verification
|
|
|
|
* fails, clear XBF_DONE. We assume the buffer has no recorded errors and is
|
|
|
|
* already in XBF_DONE state on entry.
|
2019-02-04 01:03:59 +03:00
|
|
|
*
|
2019-02-06 20:25:29 +03:00
|
|
|
* Under normal operations, every in-core buffer is verified on read I/O
|
|
|
|
* completion. There are two scenarios that can lead to in-core buffers without
|
|
|
|
* an assigned ->b_ops. The first is during log recovery of buffers on a V4
|
|
|
|
* filesystem, though these buffers are purged at the end of recovery. The
|
|
|
|
* other is online repair, which intentionally reads with a NULL buffer ops to
|
|
|
|
* run several verifiers across an in-core buffer in order to establish buffer
|
|
|
|
* type. If repair can't establish that, the buffer will be left in memory
|
|
|
|
* with NULL buffer ops.
|
2018-10-18 09:20:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2019-02-06 20:25:29 +03:00
|
|
|
xfs_buf_reverify(
|
2018-10-18 09:20:30 +03:00
|
|
|
struct xfs_buf *bp,
|
|
|
|
const struct xfs_buf_ops *ops)
|
|
|
|
{
|
|
|
|
ASSERT(bp->b_flags & XBF_DONE);
|
|
|
|
ASSERT(bp->b_error == 0);
|
|
|
|
|
|
|
|
if (!ops || bp->b_ops)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bp->b_ops = ops;
|
|
|
|
bp->b_ops->verify_read(bp);
|
|
|
|
if (bp->b_error)
|
|
|
|
bp->b_flags &= ~XBF_DONE;
|
|
|
|
return bp->b_error;
|
|
|
|
}
|
|
|
|
|
2020-01-24 04:01:16 +03:00
|
|
|
int
|
2012-06-22 12:50:10 +04:00
|
|
|
xfs_buf_read_map(
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
2012-11-12 15:54:01 +04:00
|
|
|
xfs_buf_flags_t flags,
|
2020-01-24 04:01:16 +03:00
|
|
|
struct xfs_buf **bpp,
|
2020-01-24 04:01:20 +03:00
|
|
|
const struct xfs_buf_ops *ops,
|
|
|
|
xfs_failaddr_t fa)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-06-22 12:50:10 +04:00
|
|
|
struct xfs_buf *bp;
|
2020-01-24 04:01:15 +03:00
|
|
|
int error;
|
2006-01-11 07:39:08 +03:00
|
|
|
|
|
|
|
flags |= XBF_READ;
|
2020-01-24 04:01:16 +03:00
|
|
|
*bpp = NULL;
|
2006-01-11 07:39:08 +03:00
|
|
|
|
2020-01-24 04:01:15 +03:00
|
|
|
error = xfs_buf_get_map(target, map, nmaps, flags, &bp);
|
|
|
|
if (error)
|
2020-01-24 04:01:16 +03:00
|
|
|
return error;
|
2009-12-15 02:14:59 +03:00
|
|
|
|
2018-10-18 09:20:30 +03:00
|
|
|
trace_xfs_buf_read(bp, flags, _RET_IP_);
|
|
|
|
|
|
|
|
if (!(bp->b_flags & XBF_DONE)) {
|
2020-01-24 04:01:16 +03:00
|
|
|
/* Initiate the buffer read and wait. */
|
2018-10-18 09:20:30 +03:00
|
|
|
XFS_STATS_INC(target->bt_mount, xb_get_read);
|
|
|
|
bp->b_ops = ops;
|
2020-01-24 04:01:16 +03:00
|
|
|
error = _xfs_buf_read(bp, flags);
|
|
|
|
|
|
|
|
/* Readahead iodone already dropped the buffer, so exit. */
|
|
|
|
if (flags & XBF_ASYNC)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* Buffer already read; all we need to do is check it. */
|
|
|
|
error = xfs_buf_reverify(bp, ops);
|
|
|
|
|
|
|
|
/* Readahead already finished; drop the buffer and exit. */
|
|
|
|
if (flags & XBF_ASYNC) {
|
|
|
|
xfs_buf_relse(bp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We do not want read in the flags */
|
|
|
|
bp->b_flags &= ~XBF_READ;
|
|
|
|
ASSERT(bp->b_ops != NULL || ops == NULL);
|
2018-10-18 09:20:30 +03:00
|
|
|
}
|
|
|
|
|
2020-01-24 04:01:16 +03:00
|
|
|
/*
|
|
|
|
* If we've had a read error, then the contents of the buffer are
|
|
|
|
* invalid and should not be used. To ensure that a followup read tries
|
|
|
|
* to pull the buffer from disk again, we clear the XBF_DONE flag and
|
|
|
|
* mark the buffer stale. This ensures that anyone who has a current
|
|
|
|
* reference to the buffer will interpret it's contents correctly and
|
|
|
|
* future cache lookups will also treat it as an empty, uninitialised
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
if (error) {
|
|
|
|
if (!XFS_FORCED_SHUTDOWN(target->bt_mount))
|
2020-01-24 04:01:20 +03:00
|
|
|
xfs_buf_ioerror_alert(bp, fa);
|
2018-10-18 09:20:30 +03:00
|
|
|
|
2020-01-24 04:01:16 +03:00
|
|
|
bp->b_flags &= ~XBF_DONE;
|
|
|
|
xfs_buf_stale(bp);
|
2018-10-18 09:20:30 +03:00
|
|
|
xfs_buf_relse(bp);
|
2020-01-24 04:01:16 +03:00
|
|
|
|
|
|
|
/* bad CRC means corrupted metadata */
|
|
|
|
if (error == -EFSBADCRC)
|
|
|
|
error = -EFSCORRUPTED;
|
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-24 04:01:16 +03:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-11 07:39:08 +03:00
|
|
|
* If we are not low on memory then do the readahead in a deadlock
|
|
|
|
* safe manner.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
void
|
2012-06-22 12:50:10 +04:00
|
|
|
xfs_buf_readahead_map(
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
struct xfs_buf_map *map,
|
2012-11-12 15:54:01 +04:00
|
|
|
int nmaps,
|
2012-11-14 10:54:40 +04:00
|
|
|
const struct xfs_buf_ops *ops)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2020-01-24 04:01:16 +03:00
|
|
|
struct xfs_buf *bp;
|
|
|
|
|
2017-02-02 17:56:53 +03:00
|
|
|
if (bdi_read_congested(target->bt_bdev->bd_bdi))
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
2012-06-22 12:50:10 +04:00
|
|
|
xfs_buf_read_map(target, map, nmaps,
|
2020-01-24 04:01:20 +03:00
|
|
|
XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD, &bp, ops,
|
|
|
|
__this_address);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-09-24 15:58:31 +04:00
|
|
|
/*
|
|
|
|
* Read an uncached buffer from disk. Allocates and returns a locked
|
|
|
|
* buffer containing the disk contents or nothing.
|
|
|
|
*/
|
2014-10-02 03:05:32 +04:00
|
|
|
int
|
2010-09-24 15:58:31 +04:00
|
|
|
xfs_buf_read_uncached(
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
xfs_daddr_t daddr,
|
2012-04-23 09:58:49 +04:00
|
|
|
size_t numblks,
|
2012-11-12 15:54:01 +04:00
|
|
|
int flags,
|
2014-10-02 03:05:32 +04:00
|
|
|
struct xfs_buf **bpp,
|
2012-11-14 10:54:40 +04:00
|
|
|
const struct xfs_buf_ops *ops)
|
2010-09-24 15:58:31 +04:00
|
|
|
{
|
2012-11-12 15:54:02 +04:00
|
|
|
struct xfs_buf *bp;
|
2020-01-24 04:01:17 +03:00
|
|
|
int error;
|
2010-09-24 15:58:31 +04:00
|
|
|
|
2014-10-02 03:05:32 +04:00
|
|
|
*bpp = NULL;
|
|
|
|
|
2020-01-24 04:01:17 +03:00
|
|
|
error = xfs_buf_get_uncached(target, numblks, flags, &bp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2010-09-24 15:58:31 +04:00
|
|
|
|
|
|
|
/* set up the buffer for a read IO */
|
2012-06-22 12:50:09 +04:00
|
|
|
ASSERT(bp->b_map_count == 1);
|
2014-10-02 03:05:32 +04:00
|
|
|
bp->b_bn = XFS_BUF_DADDR_NULL; /* always null for uncached buffers */
|
2012-06-22 12:50:09 +04:00
|
|
|
bp->b_maps[0].bm_bn = daddr;
|
2012-06-22 12:50:08 +04:00
|
|
|
bp->b_flags |= XBF_READ;
|
2012-11-14 10:54:40 +04:00
|
|
|
bp->b_ops = ops;
|
2010-09-24 15:58:31 +04:00
|
|
|
|
2018-07-12 08:26:35 +03:00
|
|
|
xfs_buf_submit(bp);
|
2014-10-02 03:05:32 +04:00
|
|
|
if (bp->b_error) {
|
2020-01-24 04:01:17 +03:00
|
|
|
error = bp->b_error;
|
2013-12-17 12:03:52 +04:00
|
|
|
xfs_buf_relse(bp);
|
2014-10-02 03:05:32 +04:00
|
|
|
return error;
|
2013-12-17 12:03:52 +04:00
|
|
|
}
|
2014-10-02 03:05:32 +04:00
|
|
|
|
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2020-01-24 04:01:17 +03:00
|
|
|
int
|
2010-09-24 14:07:47 +04:00
|
|
|
xfs_buf_get_uncached(
|
|
|
|
struct xfs_buftarg *target,
|
2012-04-23 09:58:49 +04:00
|
|
|
size_t numblks,
|
2020-01-24 04:01:17 +03:00
|
|
|
int flags,
|
|
|
|
struct xfs_buf **bpp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-04-23 09:58:49 +04:00
|
|
|
unsigned long page_count;
|
2007-05-14 12:23:50 +04:00
|
|
|
int error, i;
|
2012-06-22 12:50:09 +04:00
|
|
|
struct xfs_buf *bp;
|
|
|
|
DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-01-24 04:01:17 +03:00
|
|
|
*bpp = NULL;
|
|
|
|
|
2016-07-20 04:13:43 +03:00
|
|
|
/* flags might contain irrelevant bits, pass only what we care about */
|
2020-01-24 04:01:15 +03:00
|
|
|
error = _xfs_buf_alloc(target, &map, 1, flags & XBF_NO_IOACCT, &bp);
|
|
|
|
if (error)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto fail;
|
|
|
|
|
2012-04-23 09:58:49 +04:00
|
|
|
page_count = PAGE_ALIGN(numblks << BBSHIFT) >> PAGE_SHIFT;
|
2014-04-14 13:01:20 +04:00
|
|
|
error = _xfs_buf_get_pages(bp, page_count);
|
2007-05-14 12:23:50 +04:00
|
|
|
if (error)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto fail_free_buf;
|
|
|
|
|
2007-05-14 12:23:50 +04:00
|
|
|
for (i = 0; i < page_count; i++) {
|
2010-09-24 14:07:47 +04:00
|
|
|
bp->b_pages[i] = alloc_page(xb_to_gfp(flags));
|
2020-01-24 04:01:17 +03:00
|
|
|
if (!bp->b_pages[i]) {
|
|
|
|
error = -ENOMEM;
|
2007-05-14 12:23:50 +04:00
|
|
|
goto fail_free_mem;
|
2020-01-24 04:01:17 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2007-05-14 12:23:50 +04:00
|
|
|
bp->b_flags |= _XBF_PAGES;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-04-23 09:59:07 +04:00
|
|
|
error = _xfs_buf_map_pages(bp, 0);
|
2007-05-14 12:23:50 +04:00
|
|
|
if (unlikely(error)) {
|
2011-03-07 02:00:35 +03:00
|
|
|
xfs_warn(target->bt_mount,
|
2013-10-12 05:59:05 +04:00
|
|
|
"%s: failed to map pages", __func__);
|
2005-04-17 02:20:36 +04:00
|
|
|
goto fail_free_mem;
|
2007-05-14 12:23:50 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-24 14:07:47 +04:00
|
|
|
trace_xfs_buf_get_uncached(bp, _RET_IP_);
|
2020-01-24 04:01:17 +03:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2007-05-14 12:23:50 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
fail_free_mem:
|
2007-05-14 12:23:50 +04:00
|
|
|
while (--i >= 0)
|
|
|
|
__free_page(bp->b_pages[i]);
|
2007-05-24 09:21:11 +04:00
|
|
|
_xfs_buf_free_pages(bp);
|
2005-04-17 02:20:36 +04:00
|
|
|
fail_free_buf:
|
2012-06-22 12:50:09 +04:00
|
|
|
xfs_buf_free_maps(bp);
|
2019-11-14 23:43:04 +03:00
|
|
|
kmem_cache_free(xfs_buf_zone, bp);
|
2005-04-17 02:20:36 +04:00
|
|
|
fail:
|
2020-01-24 04:01:17 +03:00
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Increment reference count on buffer, to hold the buffer concurrently
|
|
|
|
* with another thread which may release (free) the buffer asynchronously.
|
|
|
|
* Must hold the buffer already to call this function.
|
|
|
|
*/
|
|
|
|
void
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_hold(
|
|
|
|
xfs_buf_t *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_hold(bp, _RET_IP_);
|
2006-01-11 07:39:08 +03:00
|
|
|
atomic_inc(&bp->b_hold);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
* Release a hold on the specified buffer. If the hold count is 1, the buffer is
|
|
|
|
* placed on LRU or freed (depending on b_lru_ref).
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
void
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_rele(
|
|
|
|
xfs_buf_t *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-09-24 13:59:04 +04:00
|
|
|
struct xfs_perag *pag = bp->b_pag;
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
bool release;
|
|
|
|
bool freebuf = false;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_rele(bp, _RET_IP_);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-24 13:59:04 +04:00
|
|
|
if (!pag) {
|
2010-12-02 08:30:55 +03:00
|
|
|
ASSERT(list_empty(&bp->b_lru));
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
if (atomic_dec_and_test(&bp->b_hold)) {
|
|
|
|
xfs_buf_ioacct_dec(bp);
|
2006-02-01 04:14:52 +03:00
|
|
|
xfs_buf_free(bp);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
}
|
2006-02-01 04:14:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-13 09:42:10 +04:00
|
|
|
ASSERT(atomic_read(&bp->b_hold) > 0);
|
2013-08-28 04:18:06 +04:00
|
|
|
|
2018-10-18 09:21:29 +03:00
|
|
|
/*
|
|
|
|
* We grab the b_lock here first to serialise racing xfs_buf_rele()
|
|
|
|
* calls. The pag_buf_lock being taken on the last reference only
|
|
|
|
* serialises against racing lookups in xfs_buf_find(). IOWs, the second
|
|
|
|
* to last reference we drop here is not serialised against the last
|
|
|
|
* reference until we take bp->b_lock. Hence if we don't grab b_lock
|
|
|
|
* first, the last "release" reference can win the race to the lock and
|
|
|
|
* free the buffer before the second-to-last reference is processed,
|
|
|
|
* leading to a use-after-free scenario.
|
|
|
|
*/
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
spin_lock(&bp->b_lock);
|
2018-10-18 09:21:29 +03:00
|
|
|
release = atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
if (!release) {
|
|
|
|
/*
|
|
|
|
* Drop the in-flight state if the buffer is already on the LRU
|
|
|
|
* and it holds the only reference. This is racy because we
|
|
|
|
* haven't acquired the pag lock, but the use of _XBF_IN_FLIGHT
|
|
|
|
* ensures the decrement occurs only once per-buf.
|
|
|
|
*/
|
|
|
|
if ((atomic_read(&bp->b_hold) == 1) && !list_empty(&bp->b_lru))
|
2017-05-31 18:22:52 +03:00
|
|
|
__xfs_buf_ioacct_dec(bp);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the last reference has been dropped ... */
|
2017-05-31 18:22:52 +03:00
|
|
|
__xfs_buf_ioacct_dec(bp);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
if (!(bp->b_flags & XBF_STALE) && atomic_read(&bp->b_lru_ref)) {
|
|
|
|
/*
|
|
|
|
* If the buffer is added to the LRU take a new reference to the
|
|
|
|
* buffer for the LRU and clear the (now stale) dispose list
|
|
|
|
* state flag
|
|
|
|
*/
|
|
|
|
if (list_lru_add(&bp->b_target->bt_lru, &bp->b_lru)) {
|
|
|
|
bp->b_state &= ~XFS_BSTATE_DISPOSE;
|
|
|
|
atomic_inc(&bp->b_hold);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
spin_unlock(&pag->pag_buf_lock);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* most of the time buffers will already be removed from the
|
|
|
|
* LRU, so optimise that case by checking for the
|
|
|
|
* XFS_BSTATE_DISPOSE flag indicating the last list the buffer
|
|
|
|
* was on was the disposal list
|
|
|
|
*/
|
|
|
|
if (!(bp->b_state & XFS_BSTATE_DISPOSE)) {
|
|
|
|
list_lru_del(&bp->b_target->bt_lru, &bp->b_lru);
|
|
|
|
} else {
|
|
|
|
ASSERT(list_empty(&bp->b_lru));
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
|
|
|
|
ASSERT(!(bp->b_flags & _XBF_DELWRI_Q));
|
2016-12-07 09:36:36 +03:00
|
|
|
rhashtable_remove_fast(&pag->pag_buf_hash, &bp->b_rhash_head,
|
|
|
|
xfs_buf_hash_params);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
spin_unlock(&pag->pag_buf_lock);
|
|
|
|
xfs_perag_put(pag);
|
|
|
|
freebuf = true;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
spin_unlock(&bp->b_lock);
|
|
|
|
|
|
|
|
if (freebuf)
|
|
|
|
xfs_buf_free(bp);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-03-26 01:16:45 +03:00
|
|
|
* Lock a buffer object, if it is not already locked.
|
2010-11-30 07:16:16 +03:00
|
|
|
*
|
|
|
|
* If we come across a stale, pinned, locked buffer, we know that we are
|
|
|
|
* being asked to lock a buffer that has been reallocated. Because it is
|
|
|
|
* pinned, we know that the log has not been pushed to disk and hence it
|
|
|
|
* will still be locked. Rather than continuing to have trylock attempts
|
|
|
|
* fail until someone else pushes the log, push it ourselves before
|
|
|
|
* returning. This means that the xfsaild will not get stuck trying
|
|
|
|
* to push on stale inode buffers.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
int
|
2011-07-08 16:36:19 +04:00
|
|
|
xfs_buf_trylock(
|
|
|
|
struct xfs_buf *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int locked;
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
locked = down_trylock(&bp->b_sema) == 0;
|
2018-08-10 23:56:25 +03:00
|
|
|
if (locked)
|
2016-06-21 04:53:28 +03:00
|
|
|
trace_xfs_buf_trylock(bp, _RET_IP_);
|
2018-08-10 23:56:25 +03:00
|
|
|
else
|
2016-06-21 04:53:28 +03:00
|
|
|
trace_xfs_buf_trylock_fail(bp, _RET_IP_);
|
2011-07-08 16:36:19 +04:00
|
|
|
return locked;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-26 01:16:45 +03:00
|
|
|
* Lock a buffer object.
|
xfs: Improve scalability of busy extent tracking
When we free a metadata extent, we record it in the per-AG busy
extent array so that it is not re-used before the freeing
transaction hits the disk. This array is fixed size, so when it
overflows we make further allocation transactions synchronous
because we cannot track more freed extents until those transactions
hit the disk and are completed. Under heavy mixed allocation and
freeing workloads with large log buffers, we can overflow this array
quite easily.
Further, the array is sparsely populated, which means that inserts
need to search for a free slot, and array searches often have to
search many more slots that are actually used to check all the
busy extents. Quite inefficient, really.
To enable this aspect of extent freeing to scale better, we need
a structure that can grow dynamically. While in other areas of
XFS we have used radix trees, the extents being freed are at random
locations on disk so are better suited to being indexed by an rbtree.
So, use a per-AG rbtree indexed by block number to track busy
extents. This incures a memory allocation when marking an extent
busy, but should not occur too often in low memory situations. This
should scale to an arbitrary number of extents so should not be a
limitation for features such as in-memory aggregation of
transactions.
However, there are still situations where we can't avoid allocating
busy extents (such as allocation from the AGFL). To minimise the
overhead of such occurences, we need to avoid doing a synchronous
log force while holding the AGF locked to ensure that the previous
transactions are safely on disk before we use the extent. We can do
this by marking the transaction doing the allocation as synchronous
rather issuing a log force.
Because of the locking involved and the ordering of transactions,
the synchronous transaction provides the same guarantees as a
synchronous log force because it ensures that all the prior
transactions are already on disk when the synchronous transaction
hits the disk. i.e. it preserves the free->allocate order of the
extent correctly in recovery.
By doing this, we avoid holding the AGF locked while log writes are
in progress, hence reducing the length of time the lock is held and
therefore we increase the rate at which we can allocate and free
from the allocation group, thereby increasing overall throughput.
The only problem with this approach is that when a metadata buffer is
marked stale (e.g. a directory block is removed), then buffer remains
pinned and locked until the log goes to disk. The issue here is that
if that stale buffer is reallocated in a subsequent transaction, the
attempt to lock that buffer in the transaction will hang waiting
the log to go to disk to unlock and unpin the buffer. Hence if
someone tries to lock a pinned, stale, locked buffer we need to
push on the log to get it unlocked ASAP. Effectively we are trading
off a guaranteed log force for a much less common trigger for log
force to occur.
Ideally we should not reallocate busy extents. That is a much more
complex fix to the problem as it involves direct intervention in the
allocation btree searches in many places. This is left to a future
set of modifications.
Finally, now that we track busy extents in allocated memory, we
don't need the descriptors in the transaction structure to point to
them. We can replace the complex busy chunk infrastructure with a
simple linked list of busy extents. This allows us to remove a large
chunk of code, making the overall change a net reduction in code
size.
Signed-off-by: Dave Chinner <david@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
2010-05-21 06:07:08 +04:00
|
|
|
*
|
|
|
|
* If we come across a stale, pinned, locked buffer, we know that we
|
|
|
|
* are being asked to lock a buffer that has been reallocated. Because
|
|
|
|
* it is pinned, we know that the log has not been pushed to disk and
|
|
|
|
* hence it will still be locked. Rather than sleeping until someone
|
|
|
|
* else pushes the log, push it ourselves before trying to get the lock.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2006-01-11 07:39:08 +03:00
|
|
|
void
|
|
|
|
xfs_buf_lock(
|
2011-07-08 16:36:19 +04:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_lock(bp, _RET_IP_);
|
|
|
|
|
xfs: Improve scalability of busy extent tracking
When we free a metadata extent, we record it in the per-AG busy
extent array so that it is not re-used before the freeing
transaction hits the disk. This array is fixed size, so when it
overflows we make further allocation transactions synchronous
because we cannot track more freed extents until those transactions
hit the disk and are completed. Under heavy mixed allocation and
freeing workloads with large log buffers, we can overflow this array
quite easily.
Further, the array is sparsely populated, which means that inserts
need to search for a free slot, and array searches often have to
search many more slots that are actually used to check all the
busy extents. Quite inefficient, really.
To enable this aspect of extent freeing to scale better, we need
a structure that can grow dynamically. While in other areas of
XFS we have used radix trees, the extents being freed are at random
locations on disk so are better suited to being indexed by an rbtree.
So, use a per-AG rbtree indexed by block number to track busy
extents. This incures a memory allocation when marking an extent
busy, but should not occur too often in low memory situations. This
should scale to an arbitrary number of extents so should not be a
limitation for features such as in-memory aggregation of
transactions.
However, there are still situations where we can't avoid allocating
busy extents (such as allocation from the AGFL). To minimise the
overhead of such occurences, we need to avoid doing a synchronous
log force while holding the AGF locked to ensure that the previous
transactions are safely on disk before we use the extent. We can do
this by marking the transaction doing the allocation as synchronous
rather issuing a log force.
Because of the locking involved and the ordering of transactions,
the synchronous transaction provides the same guarantees as a
synchronous log force because it ensures that all the prior
transactions are already on disk when the synchronous transaction
hits the disk. i.e. it preserves the free->allocate order of the
extent correctly in recovery.
By doing this, we avoid holding the AGF locked while log writes are
in progress, hence reducing the length of time the lock is held and
therefore we increase the rate at which we can allocate and free
from the allocation group, thereby increasing overall throughput.
The only problem with this approach is that when a metadata buffer is
marked stale (e.g. a directory block is removed), then buffer remains
pinned and locked until the log goes to disk. The issue here is that
if that stale buffer is reallocated in a subsequent transaction, the
attempt to lock that buffer in the transaction will hang waiting
the log to go to disk to unlock and unpin the buffer. Hence if
someone tries to lock a pinned, stale, locked buffer we need to
push on the log to get it unlocked ASAP. Effectively we are trading
off a guaranteed log force for a much less common trigger for log
force to occur.
Ideally we should not reallocate busy extents. That is a much more
complex fix to the problem as it involves direct intervention in the
allocation btree searches in many places. This is left to a future
set of modifications.
Finally, now that we track busy extents in allocated memory, we
don't need the descriptors in the transaction structure to point to
them. We can replace the complex busy chunk infrastructure with a
simple linked list of busy extents. This allows us to remove a large
chunk of code, making the overall change a net reduction in code
size.
Signed-off-by: Dave Chinner <david@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
2010-05-21 06:07:08 +04:00
|
|
|
if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE))
|
2019-06-29 05:27:29 +03:00
|
|
|
xfs_log_force(bp->b_mount, 0);
|
2006-01-11 07:39:08 +03:00
|
|
|
down(&bp->b_sema);
|
2009-12-15 02:14:59 +03:00
|
|
|
|
|
|
|
trace_xfs_buf_lock_done(bp, _RET_IP_);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_unlock(
|
2011-07-08 16:36:19 +04:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2017-04-21 22:40:44 +03:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
up(&bp->b_sema);
|
2009-12-15 02:14:59 +03:00
|
|
|
trace_xfs_buf_unlock(bp, _RET_IP_);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
STATIC void
|
|
|
|
xfs_buf_wait_unpin(
|
|
|
|
xfs_buf_t *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
DECLARE_WAITQUEUE (wait, current);
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
if (atomic_read(&bp->b_pin_count) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
add_wait_queue(&bp->b_waiters, &wait);
|
2005-04-17 02:20:36 +04:00
|
|
|
for (;;) {
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
2006-01-11 07:39:08 +03:00
|
|
|
if (atomic_read(&bp->b_pin_count) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
2011-03-10 10:52:07 +03:00
|
|
|
io_schedule();
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-01-11 07:39:08 +03:00
|
|
|
remove_wait_queue(&bp->b_waiters, &wait);
|
2005-04-17 02:20:36 +04:00
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
}
|
|
|
|
|
2020-09-01 20:55:44 +03:00
|
|
|
static void
|
|
|
|
xfs_buf_ioerror_alert_ratelimited(
|
2020-09-01 20:55:29 +03:00
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
static unsigned long lasttime;
|
|
|
|
static struct xfs_buftarg *lasttarg;
|
|
|
|
|
|
|
|
if (bp->b_target != lasttarg ||
|
|
|
|
time_after(jiffies, (lasttime + 5*HZ))) {
|
|
|
|
lasttime = jiffies;
|
|
|
|
xfs_buf_ioerror_alert(bp, __this_address);
|
|
|
|
}
|
|
|
|
lasttarg = bp->b_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Account for this latest trip around the retry handler, and decide if
|
|
|
|
* we've failed enough times to constitute a permanent failure.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
xfs_buf_ioerror_permanent(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
struct xfs_error_cfg *cfg)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = bp->b_mount;
|
|
|
|
|
|
|
|
if (cfg->max_retries != XFS_ERR_RETRY_FOREVER &&
|
|
|
|
++bp->b_retries > cfg->max_retries)
|
|
|
|
return true;
|
|
|
|
if (cfg->retry_timeout != XFS_ERR_RETRY_FOREVER &&
|
|
|
|
time_after(jiffies, cfg->retry_timeout + bp->b_first_retry_time))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* At unmount we may treat errors differently */
|
|
|
|
if ((mp->m_flags & XFS_MOUNT_UNMOUNTING) && mp->m_fail_unmount)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On a sync write or shutdown we just want to stale the buffer and let the
|
|
|
|
* caller handle the error in bp->b_error appropriately.
|
|
|
|
*
|
|
|
|
* If the write was asynchronous then no one will be looking for the error. If
|
|
|
|
* this is the first failure of this type, clear the error state and write the
|
|
|
|
* buffer out again. This means we always retry an async write failure at least
|
|
|
|
* once, but we also need to set the buffer up to behave correctly now for
|
|
|
|
* repeated failures.
|
|
|
|
*
|
|
|
|
* If we get repeated async write failures, then we take action according to the
|
|
|
|
* error configuration we have been set up to use.
|
|
|
|
*
|
|
|
|
* Multi-state return value:
|
|
|
|
*
|
|
|
|
* XBF_IOEND_FINISH: run callback completions
|
|
|
|
* XBF_IOEND_DONE: resubmitted immediately, do not run any completions
|
|
|
|
* XBF_IOEND_FAIL: transient error, run failure callback completions and then
|
|
|
|
* release the buffer
|
|
|
|
*/
|
|
|
|
enum xfs_buf_ioend_disposition {
|
|
|
|
XBF_IOEND_FINISH,
|
|
|
|
XBF_IOEND_DONE,
|
|
|
|
XBF_IOEND_FAIL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum xfs_buf_ioend_disposition
|
|
|
|
xfs_buf_ioend_disposition(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = bp->b_mount;
|
|
|
|
struct xfs_error_cfg *cfg;
|
|
|
|
|
|
|
|
if (likely(!bp->b_error))
|
|
|
|
return XBF_IOEND_FINISH;
|
|
|
|
|
2020-09-01 20:55:44 +03:00
|
|
|
/*
|
|
|
|
* If we've already decided to shutdown the filesystem because of I/O
|
|
|
|
* errors, there's no point in giving this a retry.
|
|
|
|
*/
|
|
|
|
if (XFS_FORCED_SHUTDOWN(mp))
|
|
|
|
goto out_stale;
|
|
|
|
|
|
|
|
xfs_buf_ioerror_alert_ratelimited(bp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronous writes will have callers process the error.
|
|
|
|
*/
|
|
|
|
if (!(bp->b_flags & XBF_ASYNC))
|
2020-09-01 20:55:29 +03:00
|
|
|
goto out_stale;
|
|
|
|
|
|
|
|
trace_xfs_buf_iodone_async(bp, _RET_IP_);
|
|
|
|
|
|
|
|
cfg = xfs_error_get_cfg(mp, XFS_ERR_METADATA, bp->b_error);
|
2020-09-01 20:55:45 +03:00
|
|
|
if (bp->b_last_error != bp->b_error ||
|
|
|
|
!(bp->b_flags & (XBF_STALE | XBF_WRITE_FAIL))) {
|
|
|
|
bp->b_last_error = bp->b_error;
|
|
|
|
if (cfg->retry_timeout != XFS_ERR_RETRY_FOREVER &&
|
|
|
|
!bp->b_first_retry_time)
|
|
|
|
bp->b_first_retry_time = jiffies;
|
|
|
|
goto resubmit;
|
2020-09-01 20:55:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Permanent error - we need to trigger a shutdown if we haven't already
|
|
|
|
* to indicate that inconsistency will result from this action.
|
|
|
|
*/
|
|
|
|
if (xfs_buf_ioerror_permanent(bp, cfg)) {
|
|
|
|
xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
|
|
|
|
goto out_stale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Still considered a transient error. Caller will schedule retries. */
|
2020-09-01 20:55:45 +03:00
|
|
|
if (bp->b_flags & _XBF_INODES)
|
|
|
|
xfs_buf_inode_io_fail(bp);
|
|
|
|
else if (bp->b_flags & _XBF_DQUOTS)
|
|
|
|
xfs_buf_dquot_io_fail(bp);
|
|
|
|
else
|
|
|
|
ASSERT(list_empty(&bp->b_li_list));
|
|
|
|
xfs_buf_ioerror(bp, 0);
|
|
|
|
xfs_buf_relse(bp);
|
2020-09-01 20:55:29 +03:00
|
|
|
return XBF_IOEND_FAIL;
|
|
|
|
|
2020-09-01 20:55:45 +03:00
|
|
|
resubmit:
|
|
|
|
xfs_buf_ioerror(bp, 0);
|
|
|
|
bp->b_flags |= (XBF_WRITE | XBF_DONE | XBF_WRITE_FAIL);
|
|
|
|
xfs_buf_submit(bp);
|
|
|
|
return XBF_IOEND_DONE;
|
2020-09-01 20:55:29 +03:00
|
|
|
out_stale:
|
|
|
|
xfs_buf_stale(bp);
|
|
|
|
bp->b_flags |= XBF_DONE;
|
|
|
|
trace_xfs_buf_error_relse(bp, _RET_IP_);
|
|
|
|
return XBF_IOEND_FINISH;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-09-01 20:55:20 +03:00
|
|
|
static void
|
2014-10-02 03:04:22 +04:00
|
|
|
xfs_buf_ioend(
|
|
|
|
struct xfs_buf *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-10-02 03:04:22 +04:00
|
|
|
bool read = bp->b_flags & XBF_READ;
|
|
|
|
|
|
|
|
trace_xfs_buf_iodone(bp, _RET_IP_);
|
2012-11-14 10:54:40 +04:00
|
|
|
|
|
|
|
bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_READ_AHEAD);
|
2013-02-27 06:25:54 +04:00
|
|
|
|
2014-10-02 03:04:31 +04:00
|
|
|
/*
|
|
|
|
* Pull in IO completion errors now. We are guaranteed to be running
|
|
|
|
* single threaded, so we don't need the lock to read b_io_error.
|
|
|
|
*/
|
|
|
|
if (!bp->b_error && bp->b_io_error)
|
|
|
|
xfs_buf_ioerror(bp, bp->b_io_error);
|
|
|
|
|
2020-06-30 00:48:47 +03:00
|
|
|
if (read) {
|
|
|
|
if (!bp->b_error && bp->b_ops)
|
|
|
|
bp->b_ops->verify_read(bp);
|
|
|
|
if (!bp->b_error)
|
|
|
|
bp->b_flags |= XBF_DONE;
|
2020-09-01 20:55:20 +03:00
|
|
|
} else if (bp->b_flags & _XBF_LOGRECOVERY) {
|
|
|
|
/*
|
|
|
|
* If this is a log recovery buffer, we aren't doing
|
|
|
|
* transactional I/O yet so we need to let the log recovery code
|
|
|
|
* handle I/O completions:
|
|
|
|
*/
|
2020-06-30 00:48:47 +03:00
|
|
|
xlog_recover_iodone(bp);
|
2020-09-01 20:55:20 +03:00
|
|
|
} else {
|
|
|
|
if (!bp->b_error) {
|
|
|
|
bp->b_flags &= ~XBF_WRITE_FAIL;
|
|
|
|
bp->b_flags |= XBF_DONE;
|
|
|
|
}
|
2020-06-30 00:48:46 +03:00
|
|
|
|
2020-09-01 20:55:29 +03:00
|
|
|
switch (xfs_buf_ioend_disposition(bp)) {
|
|
|
|
case XBF_IOEND_DONE:
|
|
|
|
return;
|
|
|
|
case XBF_IOEND_FAIL:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the retry state */
|
|
|
|
bp->b_last_error = 0;
|
|
|
|
bp->b_retries = 0;
|
|
|
|
bp->b_first_retry_time = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that for things like remote attribute buffers, there may
|
|
|
|
* not be a buffer log item here, so processing the buffer log
|
|
|
|
* item must remain optional.
|
|
|
|
*/
|
|
|
|
if (bp->b_log_item)
|
|
|
|
xfs_buf_item_done(bp);
|
|
|
|
|
2020-09-01 20:55:20 +03:00
|
|
|
if (bp->b_flags & _XBF_INODES)
|
|
|
|
xfs_buf_inode_iodone(bp);
|
|
|
|
else if (bp->b_flags & _XBF_DQUOTS)
|
|
|
|
xfs_buf_dquot_iodone(bp);
|
2020-06-30 00:48:46 +03:00
|
|
|
}
|
2020-09-01 20:55:44 +03:00
|
|
|
|
|
|
|
if (bp->b_flags & XBF_ASYNC)
|
|
|
|
xfs_buf_relse(bp);
|
|
|
|
else
|
|
|
|
complete(&bp->b_iowait);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 03:04:22 +04:00
|
|
|
static void
|
|
|
|
xfs_buf_ioend_work(
|
|
|
|
struct work_struct *work)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-10-02 03:04:22 +04:00
|
|
|
struct xfs_buf *bp =
|
2014-12-04 01:43:17 +03:00
|
|
|
container_of(work, xfs_buf_t, b_ioend_work);
|
2009-12-15 02:14:59 +03:00
|
|
|
|
2014-10-02 03:04:22 +04:00
|
|
|
xfs_buf_ioend(bp);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-01-04 08:10:42 +03:00
|
|
|
static void
|
2014-10-02 03:04:22 +04:00
|
|
|
xfs_buf_ioend_async(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
2014-12-04 01:43:17 +03:00
|
|
|
INIT_WORK(&bp->b_ioend_work, xfs_buf_ioend_work);
|
2019-06-29 05:27:29 +03:00
|
|
|
queue_work(bp->b_mount->m_buf_workqueue, &bp->b_ioend_work);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-08 21:51:02 +03:00
|
|
|
__xfs_buf_ioerror(
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_t *bp,
|
2018-01-08 21:51:02 +03:00
|
|
|
int error,
|
|
|
|
xfs_failaddr_t failaddr)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-06-25 08:58:08 +04:00
|
|
|
ASSERT(error <= 0 && error >= -1000);
|
|
|
|
bp->b_error = error;
|
2018-01-08 21:51:02 +03:00
|
|
|
trace_xfs_buf_ioerror(bp, error, failaddr);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-10-10 20:52:49 +04:00
|
|
|
void
|
|
|
|
xfs_buf_ioerror_alert(
|
|
|
|
struct xfs_buf *bp,
|
2020-01-24 04:01:20 +03:00
|
|
|
xfs_failaddr_t func)
|
2011-10-10 20:52:49 +04:00
|
|
|
{
|
2020-05-06 23:25:21 +03:00
|
|
|
xfs_buf_alert_ratelimited(bp, "XFS: metadata IO error",
|
|
|
|
"metadata I/O error in \"%pS\" at daddr 0x%llx len %d error %d",
|
|
|
|
func, (uint64_t)XFS_BUF_ADDR(bp),
|
|
|
|
bp->b_length, -bp->b_error);
|
2011-10-10 20:52:49 +04:00
|
|
|
}
|
|
|
|
|
2020-05-06 23:25:19 +03:00
|
|
|
/*
|
|
|
|
* To simulate an I/O failure, the buffer must be locked and held with at least
|
|
|
|
* three references. The LRU reference is dropped by the stale call. The buf
|
|
|
|
* item reference is dropped via ioend processing. The third reference is owned
|
|
|
|
* by the caller and is dropped on I/O completion if the buffer is XBF_ASYNC.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_buf_ioend_fail(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
bp->b_flags &= ~XBF_DONE;
|
|
|
|
xfs_buf_stale(bp);
|
|
|
|
xfs_buf_ioerror(bp, -EIO);
|
|
|
|
xfs_buf_ioend(bp);
|
2011-10-10 20:52:49 +04:00
|
|
|
}
|
|
|
|
|
2012-07-13 10:24:10 +04:00
|
|
|
int
|
|
|
|
xfs_bwrite(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
|
|
|
|
|
|
|
bp->b_flags |= XBF_WRITE;
|
2014-10-02 03:04:56 +04:00
|
|
|
bp->b_flags &= ~(XBF_ASYNC | XBF_READ | _XBF_DELWRI_Q |
|
2020-05-06 23:25:20 +03:00
|
|
|
XBF_DONE);
|
2012-07-13 10:24:10 +04:00
|
|
|
|
2018-07-12 08:26:35 +03:00
|
|
|
error = xfs_buf_submit(bp);
|
2019-06-29 05:27:29 +03:00
|
|
|
if (error)
|
|
|
|
xfs_force_shutdown(bp->b_mount, SHUTDOWN_META_IO_ERROR);
|
2012-07-13 10:24:10 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2016-05-18 03:56:41 +03:00
|
|
|
static void
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_bio_end_io(
|
2015-07-20 16:29:37 +03:00
|
|
|
struct bio *bio)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2016-05-18 03:56:41 +03:00
|
|
|
struct xfs_buf *bp = (struct xfs_buf *)bio->bi_private;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-05-06 23:29:19 +03:00
|
|
|
if (!bio->bi_status &&
|
|
|
|
(bp->b_flags & XBF_WRITE) && (bp->b_flags & XBF_ASYNC) &&
|
2020-05-08 18:50:52 +03:00
|
|
|
XFS_TEST_ERROR(false, bp->b_mount, XFS_ERRTAG_BUF_IOERROR))
|
2020-05-06 23:29:19 +03:00
|
|
|
bio->bi_status = BLK_STS_IOERR;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-11-12 15:09:46 +04:00
|
|
|
/*
|
|
|
|
* don't overwrite existing errors - otherwise we can lose errors on
|
|
|
|
* buffers that require multiple bios to complete.
|
|
|
|
*/
|
2017-06-03 10:38:06 +03:00
|
|
|
if (bio->bi_status) {
|
|
|
|
int error = blk_status_to_errno(bio->bi_status);
|
|
|
|
|
|
|
|
cmpxchg(&bp->b_io_error, 0, error);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-11-12 15:09:46 +04:00
|
|
|
if (!bp->b_error && xfs_buf_is_vmapped(bp) && (bp->b_flags & XBF_READ))
|
2010-01-25 20:42:24 +03:00
|
|
|
invalidate_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp));
|
|
|
|
|
2014-10-02 03:04:22 +04:00
|
|
|
if (atomic_dec_and_test(&bp->b_io_remaining) == 1)
|
|
|
|
xfs_buf_ioend_async(bp);
|
2005-04-17 02:20:36 +04:00
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
static void
|
|
|
|
xfs_buf_ioapply_map(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
int map,
|
|
|
|
int *buf_offset,
|
|
|
|
int *count,
|
2019-10-28 18:41:42 +03:00
|
|
|
int op)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-06-22 12:50:09 +04:00
|
|
|
int page_index;
|
|
|
|
int total_nr_pages = bp->b_page_count;
|
|
|
|
int nr_pages;
|
|
|
|
struct bio *bio;
|
|
|
|
sector_t sector = bp->b_maps[map].bm_bn;
|
|
|
|
int size;
|
|
|
|
int offset;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
/* skip the pages in the buffer before the start offset */
|
|
|
|
page_index = 0;
|
|
|
|
offset = *buf_offset;
|
|
|
|
while (offset >= PAGE_SIZE) {
|
|
|
|
page_index++;
|
|
|
|
offset -= PAGE_SIZE;
|
2005-11-02 02:26:59 +03:00
|
|
|
}
|
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
/*
|
|
|
|
* Limit the IO size to the length of the current vector, and update the
|
|
|
|
* remaining IO count for the next time around.
|
|
|
|
*/
|
|
|
|
size = min_t(int, BBTOB(bp->b_maps[map].bm_len), *count);
|
|
|
|
*count -= size;
|
|
|
|
*buf_offset += size;
|
2011-07-26 19:06:44 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
next_chunk:
|
2006-01-11 07:39:08 +03:00
|
|
|
atomic_inc(&bp->b_io_remaining);
|
2016-05-30 16:34:33 +03:00
|
|
|
nr_pages = min(total_nr_pages, BIO_MAX_PAGES);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
bio = bio_alloc(GFP_NOIO, nr_pages);
|
2017-08-23 20:10:32 +03:00
|
|
|
bio_set_dev(bio, bp->b_target->bt_bdev);
|
2013-10-12 02:44:27 +04:00
|
|
|
bio->bi_iter.bi_sector = sector;
|
2006-01-11 07:39:08 +03:00
|
|
|
bio->bi_end_io = xfs_buf_bio_end_io;
|
|
|
|
bio->bi_private = bp;
|
2019-10-28 18:41:42 +03:00
|
|
|
bio->bi_opf = op;
|
2011-03-26 01:16:45 +03:00
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
for (; size && nr_pages; nr_pages--, page_index++) {
|
2011-03-26 01:16:45 +03:00
|
|
|
int rbytes, nbytes = PAGE_SIZE - offset;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (nbytes > size)
|
|
|
|
nbytes = size;
|
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
rbytes = bio_add_page(bio, bp->b_pages[page_index], nbytes,
|
|
|
|
offset);
|
2006-01-11 07:39:08 +03:00
|
|
|
if (rbytes < nbytes)
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
offset = 0;
|
2012-04-23 09:58:52 +04:00
|
|
|
sector += BTOBB(nbytes);
|
2005-04-17 02:20:36 +04:00
|
|
|
size -= nbytes;
|
|
|
|
total_nr_pages--;
|
|
|
|
}
|
|
|
|
|
2013-10-12 02:44:27 +04:00
|
|
|
if (likely(bio->bi_iter.bi_size)) {
|
2010-01-25 20:42:24 +03:00
|
|
|
if (xfs_buf_is_vmapped(bp)) {
|
|
|
|
flush_kernel_vmap_range(bp->b_addr,
|
|
|
|
xfs_buf_vmap_len(bp));
|
|
|
|
}
|
2016-06-05 22:31:41 +03:00
|
|
|
submit_bio(bio);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (size)
|
|
|
|
goto next_chunk;
|
|
|
|
} else {
|
2012-11-12 15:09:46 +04:00
|
|
|
/*
|
|
|
|
* This is guaranteed not to be the last io reference count
|
2014-10-02 03:05:14 +04:00
|
|
|
* because the caller (xfs_buf_submit) holds a count itself.
|
2012-11-12 15:09:46 +04:00
|
|
|
*/
|
|
|
|
atomic_dec(&bp->b_io_remaining);
|
2014-06-25 08:58:08 +04:00
|
|
|
xfs_buf_ioerror(bp, -EIO);
|
2010-07-20 11:52:59 +04:00
|
|
|
bio_put(bio);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2012-06-22 12:50:09 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC void
|
|
|
|
_xfs_buf_ioapply(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
struct blk_plug plug;
|
2016-06-05 22:31:57 +03:00
|
|
|
int op;
|
2012-06-22 12:50:09 +04:00
|
|
|
int offset;
|
|
|
|
int size;
|
|
|
|
int i;
|
|
|
|
|
2013-03-12 16:30:34 +04:00
|
|
|
/*
|
|
|
|
* Make sure we capture only current IO errors rather than stale errors
|
|
|
|
* left over from previous use of the buffer (e.g. failed readahead).
|
|
|
|
*/
|
|
|
|
bp->b_error = 0;
|
|
|
|
|
2012-06-22 12:50:09 +04:00
|
|
|
if (bp->b_flags & XBF_WRITE) {
|
2016-06-05 22:31:57 +03:00
|
|
|
op = REQ_OP_WRITE;
|
2012-11-14 10:54:40 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the write verifier callback function if it exists. If
|
|
|
|
* this function fails it will mark the buffer with an error and
|
|
|
|
* the IO should not be dispatched.
|
|
|
|
*/
|
|
|
|
if (bp->b_ops) {
|
|
|
|
bp->b_ops->verify_write(bp);
|
|
|
|
if (bp->b_error) {
|
2019-06-29 05:27:29 +03:00
|
|
|
xfs_force_shutdown(bp->b_mount,
|
2012-11-14 10:54:40 +04:00
|
|
|
SHUTDOWN_CORRUPT_INCORE);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-04 06:42:40 +04:00
|
|
|
} else if (bp->b_bn != XFS_BUF_DADDR_NULL) {
|
2019-06-29 05:27:29 +03:00
|
|
|
struct xfs_mount *mp = bp->b_mount;
|
2014-08-04 06:42:40 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* non-crc filesystems don't attach verifiers during
|
|
|
|
* log recovery, so don't warn for such filesystems.
|
|
|
|
*/
|
|
|
|
if (xfs_sb_version_hascrc(&mp->m_sb)) {
|
|
|
|
xfs_warn(mp,
|
2018-01-08 22:39:18 +03:00
|
|
|
"%s: no buf ops on daddr 0x%llx len %d",
|
2014-08-04 06:42:40 +04:00
|
|
|
__func__, bp->b_bn, bp->b_length);
|
2018-01-08 21:51:26 +03:00
|
|
|
xfs_hex_dump(bp->b_addr,
|
|
|
|
XFS_CORRUPTION_DUMP_LEN);
|
2014-08-04 06:42:40 +04:00
|
|
|
dump_stack();
|
|
|
|
}
|
2012-11-14 10:54:40 +04:00
|
|
|
}
|
2012-06-22 12:50:09 +04:00
|
|
|
} else {
|
2016-06-05 22:31:57 +03:00
|
|
|
op = REQ_OP_READ;
|
2019-10-28 18:41:42 +03:00
|
|
|
if (bp->b_flags & XBF_READ_AHEAD)
|
|
|
|
op |= REQ_RAHEAD;
|
2012-06-22 12:50:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we only use the buffer cache for meta-data */
|
2019-10-28 18:41:42 +03:00
|
|
|
op |= REQ_META;
|
2012-06-22 12:50:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk all the vectors issuing IO on them. Set up the initial offset
|
|
|
|
* into the buffer and the desired IO size before we start -
|
|
|
|
* _xfs_buf_ioapply_vec() will modify them appropriately for each
|
|
|
|
* subsequent call.
|
|
|
|
*/
|
|
|
|
offset = bp->b_offset;
|
2019-06-29 05:27:28 +03:00
|
|
|
size = BBTOB(bp->b_length);
|
2012-06-22 12:50:09 +04:00
|
|
|
blk_start_plug(&plug);
|
|
|
|
for (i = 0; i < bp->b_map_count; i++) {
|
2019-10-28 18:41:42 +03:00
|
|
|
xfs_buf_ioapply_map(bp, i, &offset, &size, op);
|
2012-06-22 12:50:09 +04:00
|
|
|
if (bp->b_error)
|
|
|
|
break;
|
|
|
|
if (size <= 0)
|
|
|
|
break; /* all done */
|
|
|
|
}
|
|
|
|
blk_finish_plug(&plug);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 03:05:14 +04:00
|
|
|
/*
|
2018-07-12 08:26:35 +03:00
|
|
|
* Wait for I/O completion of a sync buffer and return the I/O error code.
|
2014-10-02 03:05:14 +04:00
|
|
|
*/
|
2018-07-12 08:26:34 +03:00
|
|
|
static int
|
2018-07-12 08:26:35 +03:00
|
|
|
xfs_buf_iowait(
|
2014-10-02 03:05:14 +04:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-12 08:26:35 +03:00
|
|
|
ASSERT(!(bp->b_flags & XBF_ASYNC));
|
|
|
|
|
|
|
|
trace_xfs_buf_iowait(bp, _RET_IP_);
|
|
|
|
wait_for_completion(&bp->b_iowait);
|
|
|
|
trace_xfs_buf_iowait_done(bp, _RET_IP_);
|
|
|
|
|
|
|
|
return bp->b_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer I/O submission path, read or write. Asynchronous submission transfers
|
|
|
|
* the buffer lock ownership and the current reference to the IO. It is not
|
|
|
|
* safe to reference the buffer after a call to this function unless the caller
|
|
|
|
* holds an additional reference itself.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
__xfs_buf_submit(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
bool wait)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
2014-10-02 03:05:14 +04:00
|
|
|
trace_xfs_buf_submit(bp, _RET_IP_);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
ASSERT(!(bp->b_flags & _XBF_DELWRI_Q));
|
2014-10-02 03:05:14 +04:00
|
|
|
|
|
|
|
/* on shutdown we stale and complete the buffer immediately */
|
2019-06-29 05:27:29 +03:00
|
|
|
if (XFS_FORCED_SHUTDOWN(bp->b_mount)) {
|
2020-05-06 23:25:19 +03:00
|
|
|
xfs_buf_ioend_fail(bp);
|
2018-07-12 08:26:34 +03:00
|
|
|
return -EIO;
|
2014-10-02 03:05:14 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-07-12 08:26:35 +03:00
|
|
|
/*
|
|
|
|
* Grab a reference so the buffer does not go away underneath us. For
|
|
|
|
* async buffers, I/O completion drops the callers reference, which
|
|
|
|
* could occur before submission returns.
|
|
|
|
*/
|
|
|
|
xfs_buf_hold(bp);
|
|
|
|
|
2011-08-23 12:28:03 +04:00
|
|
|
if (bp->b_flags & XBF_WRITE)
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_wait_unpin(bp);
|
2014-10-02 03:04:11 +04:00
|
|
|
|
2014-10-02 03:04:31 +04:00
|
|
|
/* clear the internal error state to avoid spurious errors */
|
|
|
|
bp->b_io_error = 0;
|
|
|
|
|
2014-04-17 02:15:28 +04:00
|
|
|
/*
|
2014-10-02 03:04:11 +04:00
|
|
|
* Set the count to 1 initially, this will stop an I/O completion
|
|
|
|
* callout which happens before we have started all the I/O from calling
|
|
|
|
* xfs_buf_ioend too early.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2006-01-11 07:39:08 +03:00
|
|
|
atomic_set(&bp->b_io_remaining, 1);
|
2018-07-12 08:26:34 +03:00
|
|
|
if (bp->b_flags & XBF_ASYNC)
|
|
|
|
xfs_buf_ioacct_inc(bp);
|
2006-01-11 07:39:08 +03:00
|
|
|
_xfs_buf_ioapply(bp);
|
2014-10-02 03:04:11 +04:00
|
|
|
|
2014-04-17 02:15:28 +04:00
|
|
|
/*
|
2014-10-02 03:05:14 +04:00
|
|
|
* If _xfs_buf_ioapply failed, we can get back here with only the IO
|
|
|
|
* reference we took above. If we drop it to zero, run completion so
|
|
|
|
* that we don't return to the caller with completion still pending.
|
2014-04-17 02:15:28 +04:00
|
|
|
*/
|
2014-10-02 03:04:22 +04:00
|
|
|
if (atomic_dec_and_test(&bp->b_io_remaining) == 1) {
|
2018-07-12 08:26:34 +03:00
|
|
|
if (bp->b_error || !(bp->b_flags & XBF_ASYNC))
|
2014-10-02 03:04:22 +04:00
|
|
|
xfs_buf_ioend(bp);
|
|
|
|
else
|
|
|
|
xfs_buf_ioend_async(bp);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-07-12 08:26:35 +03:00
|
|
|
if (wait)
|
|
|
|
error = xfs_buf_iowait(bp);
|
2018-07-12 08:26:35 +03:00
|
|
|
|
2014-10-02 03:05:14 +04:00
|
|
|
/*
|
2018-07-12 08:26:35 +03:00
|
|
|
* Release the hold that keeps the buffer referenced for the entire
|
|
|
|
* I/O. Note that if the buffer is async, it is not safe to reference
|
|
|
|
* after this release.
|
2014-10-02 03:05:14 +04:00
|
|
|
*/
|
|
|
|
xfs_buf_rele(bp);
|
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2015-06-22 02:44:29 +03:00
|
|
|
void *
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_offset(
|
2015-06-22 02:44:29 +03:00
|
|
|
struct xfs_buf *bp,
|
2005-04-17 02:20:36 +04:00
|
|
|
size_t offset)
|
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
|
2012-04-23 09:59:07 +04:00
|
|
|
if (bp->b_addr)
|
2011-07-23 03:40:15 +04:00
|
|
|
return bp->b_addr + offset;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
offset += bp->b_offset;
|
2011-03-26 01:16:45 +03:00
|
|
|
page = bp->b_pages[offset >> PAGE_SHIFT];
|
2015-06-22 02:44:29 +03:00
|
|
|
return page_address(page) + (offset & (PAGE_SIZE-1));
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-12 18:59:59 +03:00
|
|
|
xfs_buf_zero(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
size_t boff,
|
|
|
|
size_t bsize)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-04-23 09:58:53 +04:00
|
|
|
size_t bend;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
bend = boff + bsize;
|
|
|
|
while (boff < bend) {
|
2012-04-23 09:58:53 +04:00
|
|
|
struct page *page;
|
|
|
|
int page_index, page_offset, csize;
|
|
|
|
|
|
|
|
page_index = (boff + bp->b_offset) >> PAGE_SHIFT;
|
|
|
|
page_offset = (boff + bp->b_offset) & ~PAGE_MASK;
|
|
|
|
page = bp->b_pages[page_index];
|
|
|
|
csize = min_t(size_t, PAGE_SIZE - page_offset,
|
2019-06-29 05:27:28 +03:00
|
|
|
BBTOB(bp->b_length) - boff);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-04-23 09:58:53 +04:00
|
|
|
ASSERT((csize + page_offset) <= PAGE_SIZE);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-06-12 18:59:59 +03:00
|
|
|
memset(page_address(page) + page_offset, 0, csize);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
boff += csize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 20:37:54 +03:00
|
|
|
/*
|
|
|
|
* Log a message about and stale a buffer that a caller has decided is corrupt.
|
|
|
|
*
|
|
|
|
* This function should be called for the kinds of metadata corruption that
|
|
|
|
* cannot be detect from a verifier, such as incorrect inter-block relationship
|
|
|
|
* data. Do /not/ call this function from a verifier function.
|
|
|
|
*
|
|
|
|
* The buffer must be XBF_DONE prior to the call. Afterwards, the buffer will
|
|
|
|
* be marked stale, but b_error will not be set. The caller is responsible for
|
|
|
|
* releasing the buffer or fixing it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
__xfs_buf_mark_corrupt(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
xfs_failaddr_t fa)
|
|
|
|
{
|
|
|
|
ASSERT(bp->b_flags & XBF_DONE);
|
|
|
|
|
2020-03-11 20:37:54 +03:00
|
|
|
xfs_buf_corruption_error(bp, fa);
|
2020-03-11 20:37:54 +03:00
|
|
|
xfs_buf_stale(bp);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2006-01-11 07:39:08 +03:00
|
|
|
* Handling of buffer targets (buftargs).
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-12-02 08:30:55 +03:00
|
|
|
* Wait for any bufs with callbacks that have been submitted but have not yet
|
|
|
|
* returned. These buffers will have an elevated hold count, so wait on those
|
|
|
|
* while freeing all the buffers only held by the LRU.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2013-08-28 04:18:05 +04:00
|
|
|
static enum lru_status
|
|
|
|
xfs_buftarg_wait_rele(
|
|
|
|
struct list_head *item,
|
2015-02-13 01:59:35 +03:00
|
|
|
struct list_lru_one *lru,
|
2013-08-28 04:18:05 +04:00
|
|
|
spinlock_t *lru_lock,
|
|
|
|
void *arg)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2013-08-28 04:18:05 +04:00
|
|
|
struct xfs_buf *bp = container_of(item, struct xfs_buf, b_lru);
|
2013-08-28 04:18:06 +04:00
|
|
|
struct list_head *dispose = arg;
|
2010-12-02 08:30:55 +03:00
|
|
|
|
2013-08-28 04:18:05 +04:00
|
|
|
if (atomic_read(&bp->b_hold) > 1) {
|
2013-08-28 04:18:06 +04:00
|
|
|
/* need to wait, so skip it this pass */
|
2013-08-28 04:18:05 +04:00
|
|
|
trace_xfs_buf_wait_buftarg(bp, _RET_IP_);
|
2013-08-28 04:18:06 +04:00
|
|
|
return LRU_SKIP;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2013-08-28 04:18:06 +04:00
|
|
|
if (!spin_trylock(&bp->b_lock))
|
|
|
|
return LRU_SKIP;
|
2013-08-28 04:18:05 +04:00
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
/*
|
|
|
|
* clear the LRU reference count so the buffer doesn't get
|
|
|
|
* ignored in xfs_buf_rele().
|
|
|
|
*/
|
|
|
|
atomic_set(&bp->b_lru_ref, 0);
|
|
|
|
bp->b_state |= XFS_BSTATE_DISPOSE;
|
2015-02-13 01:59:35 +03:00
|
|
|
list_lru_isolate_move(lru, item, dispose);
|
2013-08-28 04:18:06 +04:00
|
|
|
spin_unlock(&bp->b_lock);
|
|
|
|
return LRU_REMOVED;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2013-08-28 04:18:05 +04:00
|
|
|
void
|
|
|
|
xfs_wait_buftarg(
|
|
|
|
struct xfs_buftarg *btp)
|
|
|
|
{
|
2013-08-28 04:18:06 +04:00
|
|
|
LIST_HEAD(dispose);
|
2020-05-06 23:25:21 +03:00
|
|
|
int loop = 0;
|
|
|
|
bool write_fail = false;
|
2013-08-28 04:18:06 +04:00
|
|
|
|
xfs: log mount failures don't wait for buffers to be released
Recently I've been seeing xfs/051 fail on 1k block size filesystems.
Trying to trace the events during the test lead to the problem going
away, indicating that it was a race condition that lead to this
ASSERT failure:
XFS: Assertion failed: atomic_read(&pag->pag_ref) == 0, file: fs/xfs/xfs_mount.c, line: 156
.....
[<ffffffff814e1257>] xfs_free_perag+0x87/0xb0
[<ffffffff814e21b9>] xfs_mountfs+0x4d9/0x900
[<ffffffff814e5dff>] xfs_fs_fill_super+0x3bf/0x4d0
[<ffffffff811d8800>] mount_bdev+0x180/0x1b0
[<ffffffff814e3ff5>] xfs_fs_mount+0x15/0x20
[<ffffffff811d90a8>] mount_fs+0x38/0x170
[<ffffffff811f4347>] vfs_kern_mount+0x67/0x120
[<ffffffff811f7018>] do_mount+0x218/0xd60
[<ffffffff811f7e5b>] SyS_mount+0x8b/0xd0
When I finally caught it with tracing enabled, I saw that AG 2 had
an elevated reference count and a buffer was responsible for it. I
tracked down the specific buffer, and found that it was missing the
final reference count release that would put it back on the LRU and
hence be found by xfs_wait_buftarg() calls in the log mount failure
handling.
The last four traces for the buffer before the assert were (trimmed
for relevance)
kworker/0:1-5259 xfs_buf_iodone: hold 2 lock 0 flags ASYNC
kworker/0:1-5259 xfs_buf_ioerror: hold 2 lock 0 error -5
mount-7163 xfs_buf_lock_done: hold 2 lock 0 flags ASYNC
mount-7163 xfs_buf_unlock: hold 2 lock 1 flags ASYNC
This is an async write that is completing, so there's nobody waiting
for it directly. Hence we call xfs_buf_relse() once all the
processing is complete. That does:
static inline void xfs_buf_relse(xfs_buf_t *bp)
{
xfs_buf_unlock(bp);
xfs_buf_rele(bp);
}
Now, it's clear that mount is waiting on the buffer lock, and that
it has been released by xfs_buf_relse() and gained by mount. This is
expected, because at this point the mount process is in
xfs_buf_delwri_submit() waiting for all the IO it submitted to
complete.
The mount process, however, is waiting on the lock for the buffer
because it is in xfs_buf_delwri_submit(). This waits for IO
completion, but it doesn't wait for the buffer reference owned by
the IO to go away. The mount process collects all the completions,
fails the log recovery, and the higher level code then calls
xfs_wait_buftarg() to free all the remaining buffers in the
filesystem.
The issue is that on unlocking the buffer, the scheduler has decided
that the mount process has higher priority than the the kworker
thread that is running the IO completion, and so immediately
switched contexts to the mount process from the semaphore unlock
code, hence preventing the kworker thread from finishing the IO
completion and releasing the IO reference to the buffer.
Hence by the time that xfs_wait_buftarg() is run, the buffer still
has an active reference and so isn't on the LRU list that the
function walks to free the remaining buffers. Hence we miss that
buffer and continue onwards to tear down the mount structures,
at which time we get find a stray reference count on the perag
structure. On a non-debug kernel, this will be ignored and the
structure torn down and freed. Hence when the kworker thread is then
rescheduled and the buffer released and freed, it will access a
freed perag structure.
The problem here is that when the log mount fails, we still need to
quiesce the log to ensure that the IO workqueues have returned to
idle before we run xfs_wait_buftarg(). By synchronising the
workqueues, we ensure that all IO completions are fully processed,
not just to the point where buffers have been unlocked. This ensures
we don't end up in the situation above.
cc: <stable@vger.kernel.org> # 3.18
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-01-19 00:28:10 +03:00
|
|
|
/*
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
* First wait on the buftarg I/O count for all in-flight buffers to be
|
|
|
|
* released. This is critical as new buffers do not make the LRU until
|
|
|
|
* they are released.
|
|
|
|
*
|
|
|
|
* Next, flush the buffer workqueue to ensure all completion processing
|
|
|
|
* has finished. Just waiting on buffer locks is not sufficient for
|
|
|
|
* async IO as the reference count held over IO is not released until
|
|
|
|
* after the buffer lock is dropped. Hence we need to ensure here that
|
|
|
|
* all reference counts have been dropped before we start walking the
|
|
|
|
* LRU list.
|
xfs: log mount failures don't wait for buffers to be released
Recently I've been seeing xfs/051 fail on 1k block size filesystems.
Trying to trace the events during the test lead to the problem going
away, indicating that it was a race condition that lead to this
ASSERT failure:
XFS: Assertion failed: atomic_read(&pag->pag_ref) == 0, file: fs/xfs/xfs_mount.c, line: 156
.....
[<ffffffff814e1257>] xfs_free_perag+0x87/0xb0
[<ffffffff814e21b9>] xfs_mountfs+0x4d9/0x900
[<ffffffff814e5dff>] xfs_fs_fill_super+0x3bf/0x4d0
[<ffffffff811d8800>] mount_bdev+0x180/0x1b0
[<ffffffff814e3ff5>] xfs_fs_mount+0x15/0x20
[<ffffffff811d90a8>] mount_fs+0x38/0x170
[<ffffffff811f4347>] vfs_kern_mount+0x67/0x120
[<ffffffff811f7018>] do_mount+0x218/0xd60
[<ffffffff811f7e5b>] SyS_mount+0x8b/0xd0
When I finally caught it with tracing enabled, I saw that AG 2 had
an elevated reference count and a buffer was responsible for it. I
tracked down the specific buffer, and found that it was missing the
final reference count release that would put it back on the LRU and
hence be found by xfs_wait_buftarg() calls in the log mount failure
handling.
The last four traces for the buffer before the assert were (trimmed
for relevance)
kworker/0:1-5259 xfs_buf_iodone: hold 2 lock 0 flags ASYNC
kworker/0:1-5259 xfs_buf_ioerror: hold 2 lock 0 error -5
mount-7163 xfs_buf_lock_done: hold 2 lock 0 flags ASYNC
mount-7163 xfs_buf_unlock: hold 2 lock 1 flags ASYNC
This is an async write that is completing, so there's nobody waiting
for it directly. Hence we call xfs_buf_relse() once all the
processing is complete. That does:
static inline void xfs_buf_relse(xfs_buf_t *bp)
{
xfs_buf_unlock(bp);
xfs_buf_rele(bp);
}
Now, it's clear that mount is waiting on the buffer lock, and that
it has been released by xfs_buf_relse() and gained by mount. This is
expected, because at this point the mount process is in
xfs_buf_delwri_submit() waiting for all the IO it submitted to
complete.
The mount process, however, is waiting on the lock for the buffer
because it is in xfs_buf_delwri_submit(). This waits for IO
completion, but it doesn't wait for the buffer reference owned by
the IO to go away. The mount process collects all the completions,
fails the log recovery, and the higher level code then calls
xfs_wait_buftarg() to free all the remaining buffers in the
filesystem.
The issue is that on unlocking the buffer, the scheduler has decided
that the mount process has higher priority than the the kworker
thread that is running the IO completion, and so immediately
switched contexts to the mount process from the semaphore unlock
code, hence preventing the kworker thread from finishing the IO
completion and releasing the IO reference to the buffer.
Hence by the time that xfs_wait_buftarg() is run, the buffer still
has an active reference and so isn't on the LRU list that the
function walks to free the remaining buffers. Hence we miss that
buffer and continue onwards to tear down the mount structures,
at which time we get find a stray reference count on the perag
structure. On a non-debug kernel, this will be ignored and the
structure torn down and freed. Hence when the kworker thread is then
rescheduled and the buffer released and freed, it will access a
freed perag structure.
The problem here is that when the log mount fails, we still need to
quiesce the log to ensure that the IO workqueues have returned to
idle before we run xfs_wait_buftarg(). By synchronising the
workqueues, we ensure that all IO completions are fully processed,
not just to the point where buffers have been unlocked. This ensures
we don't end up in the situation above.
cc: <stable@vger.kernel.org> # 3.18
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-01-19 00:28:10 +03:00
|
|
|
*/
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
while (percpu_counter_sum(&btp->bt_io_count))
|
|
|
|
delay(100);
|
2016-08-26 09:01:59 +03:00
|
|
|
flush_workqueue(btp->bt_mount->m_buf_workqueue);
|
xfs: log mount failures don't wait for buffers to be released
Recently I've been seeing xfs/051 fail on 1k block size filesystems.
Trying to trace the events during the test lead to the problem going
away, indicating that it was a race condition that lead to this
ASSERT failure:
XFS: Assertion failed: atomic_read(&pag->pag_ref) == 0, file: fs/xfs/xfs_mount.c, line: 156
.....
[<ffffffff814e1257>] xfs_free_perag+0x87/0xb0
[<ffffffff814e21b9>] xfs_mountfs+0x4d9/0x900
[<ffffffff814e5dff>] xfs_fs_fill_super+0x3bf/0x4d0
[<ffffffff811d8800>] mount_bdev+0x180/0x1b0
[<ffffffff814e3ff5>] xfs_fs_mount+0x15/0x20
[<ffffffff811d90a8>] mount_fs+0x38/0x170
[<ffffffff811f4347>] vfs_kern_mount+0x67/0x120
[<ffffffff811f7018>] do_mount+0x218/0xd60
[<ffffffff811f7e5b>] SyS_mount+0x8b/0xd0
When I finally caught it with tracing enabled, I saw that AG 2 had
an elevated reference count and a buffer was responsible for it. I
tracked down the specific buffer, and found that it was missing the
final reference count release that would put it back on the LRU and
hence be found by xfs_wait_buftarg() calls in the log mount failure
handling.
The last four traces for the buffer before the assert were (trimmed
for relevance)
kworker/0:1-5259 xfs_buf_iodone: hold 2 lock 0 flags ASYNC
kworker/0:1-5259 xfs_buf_ioerror: hold 2 lock 0 error -5
mount-7163 xfs_buf_lock_done: hold 2 lock 0 flags ASYNC
mount-7163 xfs_buf_unlock: hold 2 lock 1 flags ASYNC
This is an async write that is completing, so there's nobody waiting
for it directly. Hence we call xfs_buf_relse() once all the
processing is complete. That does:
static inline void xfs_buf_relse(xfs_buf_t *bp)
{
xfs_buf_unlock(bp);
xfs_buf_rele(bp);
}
Now, it's clear that mount is waiting on the buffer lock, and that
it has been released by xfs_buf_relse() and gained by mount. This is
expected, because at this point the mount process is in
xfs_buf_delwri_submit() waiting for all the IO it submitted to
complete.
The mount process, however, is waiting on the lock for the buffer
because it is in xfs_buf_delwri_submit(). This waits for IO
completion, but it doesn't wait for the buffer reference owned by
the IO to go away. The mount process collects all the completions,
fails the log recovery, and the higher level code then calls
xfs_wait_buftarg() to free all the remaining buffers in the
filesystem.
The issue is that on unlocking the buffer, the scheduler has decided
that the mount process has higher priority than the the kworker
thread that is running the IO completion, and so immediately
switched contexts to the mount process from the semaphore unlock
code, hence preventing the kworker thread from finishing the IO
completion and releasing the IO reference to the buffer.
Hence by the time that xfs_wait_buftarg() is run, the buffer still
has an active reference and so isn't on the LRU list that the
function walks to free the remaining buffers. Hence we miss that
buffer and continue onwards to tear down the mount structures,
at which time we get find a stray reference count on the perag
structure. On a non-debug kernel, this will be ignored and the
structure torn down and freed. Hence when the kworker thread is then
rescheduled and the buffer released and freed, it will access a
freed perag structure.
The problem here is that when the log mount fails, we still need to
quiesce the log to ensure that the IO workqueues have returned to
idle before we run xfs_wait_buftarg(). By synchronising the
workqueues, we ensure that all IO completions are fully processed,
not just to the point where buffers have been unlocked. This ensures
we don't end up in the situation above.
cc: <stable@vger.kernel.org> # 3.18
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-01-19 00:28:10 +03:00
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
/* loop until there is nothing left on the lru list. */
|
|
|
|
while (list_lru_count(&btp->bt_lru)) {
|
2013-08-28 04:18:05 +04:00
|
|
|
list_lru_walk(&btp->bt_lru, xfs_buftarg_wait_rele,
|
2013-08-28 04:18:06 +04:00
|
|
|
&dispose, LONG_MAX);
|
|
|
|
|
|
|
|
while (!list_empty(&dispose)) {
|
|
|
|
struct xfs_buf *bp;
|
|
|
|
bp = list_first_entry(&dispose, struct xfs_buf, b_lru);
|
|
|
|
list_del_init(&bp->b_lru);
|
xfs: abort metadata writeback on permanent errors
If we are doing aysnc writeback of metadata, we can get write errors
but have nobody to report them to. At the moment, we simply attempt
to reissue the write from io completion in the hope that it's a
transient error.
When it's not a transient error, the buffer is stuck forever in
this loop, and we cannot break out of it. Eventually, unmount will
hang because the AIL cannot be emptied and everything goes downhill
from them.
To solve this problem, only retry the write IO once before aborting
it. We don't throw the buffer away because some transient errors can
last minutes (e.g. FC path failover) or even hours (thin
provisioned devices that have run out of backing space) before they
go away. Hence we really want to keep trying until we can't try any
more.
Because the buffer was not cleaned, however, it does not get removed
from the AIL and hence the next pass across the AIL will start IO on
it again. As such, we still get the "retry forever" semantics that
we currently have, but we allow other access to the buffer in the
mean time. Meanwhile the filesystem can continue to modify the
buffer and relog it, so the IO errors won't hang the log or the
filesystem.
Now when we are pushing the AIL, we can see all these "permanent IO
error" buffers and we can issue a warning about failures before we
retry the IO. We can also catch these buffers when unmounting an
issue a corruption warning, too.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ben Myers <bpm@sgi.com>
2013-12-12 09:34:38 +04:00
|
|
|
if (bp->b_flags & XBF_WRITE_FAIL) {
|
2020-05-06 23:25:21 +03:00
|
|
|
write_fail = true;
|
|
|
|
xfs_buf_alert_ratelimited(bp,
|
|
|
|
"XFS: Corruption Alert",
|
2018-01-08 22:39:18 +03:00
|
|
|
"Corruption Alert: Buffer at daddr 0x%llx had permanent write failures!",
|
xfs: abort metadata writeback on permanent errors
If we are doing aysnc writeback of metadata, we can get write errors
but have nobody to report them to. At the moment, we simply attempt
to reissue the write from io completion in the hope that it's a
transient error.
When it's not a transient error, the buffer is stuck forever in
this loop, and we cannot break out of it. Eventually, unmount will
hang because the AIL cannot be emptied and everything goes downhill
from them.
To solve this problem, only retry the write IO once before aborting
it. We don't throw the buffer away because some transient errors can
last minutes (e.g. FC path failover) or even hours (thin
provisioned devices that have run out of backing space) before they
go away. Hence we really want to keep trying until we can't try any
more.
Because the buffer was not cleaned, however, it does not get removed
from the AIL and hence the next pass across the AIL will start IO on
it again. As such, we still get the "retry forever" semantics that
we currently have, but we allow other access to the buffer in the
mean time. Meanwhile the filesystem can continue to modify the
buffer and relog it, so the IO errors won't hang the log or the
filesystem.
Now when we are pushing the AIL, we can see all these "permanent IO
error" buffers and we can issue a warning about failures before we
retry the IO. We can also catch these buffers when unmounting an
issue a corruption warning, too.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ben Myers <bpm@sgi.com>
2013-12-12 09:34:38 +04:00
|
|
|
(long long)bp->b_bn);
|
|
|
|
}
|
2013-08-28 04:18:06 +04:00
|
|
|
xfs_buf_rele(bp);
|
|
|
|
}
|
|
|
|
if (loop++ != 0)
|
|
|
|
delay(100);
|
|
|
|
}
|
2020-05-06 23:25:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If one or more failed buffers were freed, that means dirty metadata
|
|
|
|
* was thrown away. This should only ever happen after I/O completion
|
|
|
|
* handling has elevated I/O error(s) to permanent failures and shuts
|
|
|
|
* down the fs.
|
|
|
|
*/
|
|
|
|
if (write_fail) {
|
|
|
|
ASSERT(XFS_FORCED_SHUTDOWN(btp->bt_mount));
|
|
|
|
xfs_alert(btp->bt_mount,
|
|
|
|
"Please run xfs_repair to determine the extent of the problem.");
|
|
|
|
}
|
2013-08-28 04:18:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum lru_status
|
|
|
|
xfs_buftarg_isolate(
|
|
|
|
struct list_head *item,
|
2015-02-13 01:59:35 +03:00
|
|
|
struct list_lru_one *lru,
|
2013-08-28 04:18:05 +04:00
|
|
|
spinlock_t *lru_lock,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
struct xfs_buf *bp = container_of(item, struct xfs_buf, b_lru);
|
|
|
|
struct list_head *dispose = arg;
|
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
/*
|
|
|
|
* we are inverting the lru lock/bp->b_lock here, so use a trylock.
|
|
|
|
* If we fail to get the lock, just skip it.
|
|
|
|
*/
|
|
|
|
if (!spin_trylock(&bp->b_lock))
|
|
|
|
return LRU_SKIP;
|
2013-08-28 04:18:05 +04:00
|
|
|
/*
|
|
|
|
* Decrement the b_lru_ref count unless the value is already
|
|
|
|
* zero. If the value is already zero, we need to reclaim the
|
|
|
|
* buffer, otherwise it gets another trip through the LRU.
|
|
|
|
*/
|
2018-03-07 04:07:44 +03:00
|
|
|
if (atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
|
2013-08-28 04:18:06 +04:00
|
|
|
spin_unlock(&bp->b_lock);
|
2013-08-28 04:18:05 +04:00
|
|
|
return LRU_ROTATE;
|
2013-08-28 04:18:06 +04:00
|
|
|
}
|
2013-08-28 04:18:05 +04:00
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
bp->b_state |= XFS_BSTATE_DISPOSE;
|
2015-02-13 01:59:35 +03:00
|
|
|
list_lru_isolate_move(lru, item, dispose);
|
2013-08-28 04:18:06 +04:00
|
|
|
spin_unlock(&bp->b_lock);
|
2013-08-28 04:18:05 +04:00
|
|
|
return LRU_REMOVED;
|
|
|
|
}
|
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
static unsigned long
|
2013-08-28 04:18:05 +04:00
|
|
|
xfs_buftarg_shrink_scan(
|
2010-11-30 09:27:57 +03:00
|
|
|
struct shrinker *shrink,
|
2011-05-25 04:12:27 +04:00
|
|
|
struct shrink_control *sc)
|
2006-01-11 07:37:58 +03:00
|
|
|
{
|
2010-11-30 09:27:57 +03:00
|
|
|
struct xfs_buftarg *btp = container_of(shrink,
|
|
|
|
struct xfs_buftarg, bt_shrinker);
|
2010-12-02 08:30:55 +03:00
|
|
|
LIST_HEAD(dispose);
|
2013-08-28 04:18:06 +04:00
|
|
|
unsigned long freed;
|
2010-12-02 08:30:55 +03:00
|
|
|
|
list_lru: introduce list_lru_shrink_{count,walk}
Kmem accounting of memcg is unusable now, because it lacks slab shrinker
support. That means when we hit the limit we will get ENOMEM w/o any
chance to recover. What we should do then is to call shrink_slab, which
would reclaim old inode/dentry caches from this cgroup. This is what
this patch set is intended to do.
Basically, it does two things. First, it introduces the notion of
per-memcg slab shrinker. A shrinker that wants to reclaim objects per
cgroup should mark itself as SHRINKER_MEMCG_AWARE. Then it will be
passed the memory cgroup to scan from in shrink_control->memcg. For
such shrinkers shrink_slab iterates over the whole cgroup subtree under
the target cgroup and calls the shrinker for each kmem-active memory
cgroup.
Secondly, this patch set makes the list_lru structure per-memcg. It's
done transparently to list_lru users - everything they have to do is to
tell list_lru_init that they want memcg-aware list_lru. Then the
list_lru will automatically distribute objects among per-memcg lists
basing on which cgroup the object is accounted to. This way to make FS
shrinkers (icache, dcache) memcg-aware we only need to make them use
memcg-aware list_lru, and this is what this patch set does.
As before, this patch set only enables per-memcg kmem reclaim when the
pressure goes from memory.limit, not from memory.kmem.limit. Handling
memory.kmem.limit is going to be tricky due to GFP_NOFS allocations, and
it is still unclear whether we will have this knob in the unified
hierarchy.
This patch (of 9):
NUMA aware slab shrinkers use the list_lru structure to distribute
objects coming from different NUMA nodes to different lists. Whenever
such a shrinker needs to count or scan objects from a particular node,
it issues commands like this:
count = list_lru_count_node(lru, sc->nid);
freed = list_lru_walk_node(lru, sc->nid, isolate_func,
isolate_arg, &sc->nr_to_scan);
where sc is an instance of the shrink_control structure passed to it
from vmscan.
To simplify this, let's add special list_lru functions to be used by
shrinkers, list_lru_shrink_count() and list_lru_shrink_walk(), which
consolidate the nid and nr_to_scan arguments in the shrink_control
structure.
This will also allow us to avoid patching shrinkers that use list_lru
when we make shrink_slab() per-memcg - all we will have to do is extend
the shrink_control structure to include the target memcg and make
list_lru_shrink_{count,walk} handle this appropriately.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Suggested-by: Dave Chinner <david@fromorbit.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Greg Thelen <gthelen@google.com>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-02-13 01:58:47 +03:00
|
|
|
freed = list_lru_shrink_walk(&btp->bt_lru, sc,
|
|
|
|
xfs_buftarg_isolate, &dispose);
|
2010-12-02 08:30:55 +03:00
|
|
|
|
|
|
|
while (!list_empty(&dispose)) {
|
2013-08-28 04:18:05 +04:00
|
|
|
struct xfs_buf *bp;
|
2010-12-02 08:30:55 +03:00
|
|
|
bp = list_first_entry(&dispose, struct xfs_buf, b_lru);
|
|
|
|
list_del_init(&bp->b_lru);
|
|
|
|
xfs_buf_rele(bp);
|
|
|
|
}
|
|
|
|
|
2013-08-28 04:18:05 +04:00
|
|
|
return freed;
|
|
|
|
}
|
|
|
|
|
2013-08-28 04:18:06 +04:00
|
|
|
static unsigned long
|
2013-08-28 04:18:05 +04:00
|
|
|
xfs_buftarg_shrink_count(
|
|
|
|
struct shrinker *shrink,
|
|
|
|
struct shrink_control *sc)
|
|
|
|
{
|
|
|
|
struct xfs_buftarg *btp = container_of(shrink,
|
|
|
|
struct xfs_buftarg, bt_shrinker);
|
list_lru: introduce list_lru_shrink_{count,walk}
Kmem accounting of memcg is unusable now, because it lacks slab shrinker
support. That means when we hit the limit we will get ENOMEM w/o any
chance to recover. What we should do then is to call shrink_slab, which
would reclaim old inode/dentry caches from this cgroup. This is what
this patch set is intended to do.
Basically, it does two things. First, it introduces the notion of
per-memcg slab shrinker. A shrinker that wants to reclaim objects per
cgroup should mark itself as SHRINKER_MEMCG_AWARE. Then it will be
passed the memory cgroup to scan from in shrink_control->memcg. For
such shrinkers shrink_slab iterates over the whole cgroup subtree under
the target cgroup and calls the shrinker for each kmem-active memory
cgroup.
Secondly, this patch set makes the list_lru structure per-memcg. It's
done transparently to list_lru users - everything they have to do is to
tell list_lru_init that they want memcg-aware list_lru. Then the
list_lru will automatically distribute objects among per-memcg lists
basing on which cgroup the object is accounted to. This way to make FS
shrinkers (icache, dcache) memcg-aware we only need to make them use
memcg-aware list_lru, and this is what this patch set does.
As before, this patch set only enables per-memcg kmem reclaim when the
pressure goes from memory.limit, not from memory.kmem.limit. Handling
memory.kmem.limit is going to be tricky due to GFP_NOFS allocations, and
it is still unclear whether we will have this knob in the unified
hierarchy.
This patch (of 9):
NUMA aware slab shrinkers use the list_lru structure to distribute
objects coming from different NUMA nodes to different lists. Whenever
such a shrinker needs to count or scan objects from a particular node,
it issues commands like this:
count = list_lru_count_node(lru, sc->nid);
freed = list_lru_walk_node(lru, sc->nid, isolate_func,
isolate_arg, &sc->nr_to_scan);
where sc is an instance of the shrink_control structure passed to it
from vmscan.
To simplify this, let's add special list_lru functions to be used by
shrinkers, list_lru_shrink_count() and list_lru_shrink_walk(), which
consolidate the nid and nr_to_scan arguments in the shrink_control
structure.
This will also allow us to avoid patching shrinkers that use list_lru
when we make shrink_slab() per-memcg - all we will have to do is extend
the shrink_control structure to include the target memcg and make
list_lru_shrink_{count,walk} handle this appropriately.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Suggested-by: Dave Chinner <david@fromorbit.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Greg Thelen <gthelen@google.com>
Cc: Glauber Costa <glommer@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-02-13 01:58:47 +03:00
|
|
|
return list_lru_shrink_count(&btp->bt_lru, sc);
|
2006-01-11 07:37:58 +03:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
void
|
|
|
|
xfs_free_buftarg(
|
2009-03-03 22:48:37 +03:00
|
|
|
struct xfs_buftarg *btp)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-11-30 09:27:57 +03:00
|
|
|
unregister_shrinker(&btp->bt_shrinker);
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0);
|
|
|
|
percpu_counter_destroy(&btp->bt_io_count);
|
2013-08-28 04:18:18 +04:00
|
|
|
list_lru_destroy(&btp->bt_lru);
|
2010-11-30 09:27:57 +03:00
|
|
|
|
2016-12-09 08:49:54 +03:00
|
|
|
xfs_blkdev_issue_flush(btp);
|
2006-01-11 07:37:58 +03:00
|
|
|
|
2008-05-19 10:31:57 +04:00
|
|
|
kmem_free(btp);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2013-11-14 00:53:45 +04:00
|
|
|
int
|
|
|
|
xfs_setsize_buftarg(
|
2005-04-17 02:20:36 +04:00
|
|
|
xfs_buftarg_t *btp,
|
2013-11-14 00:53:45 +04:00
|
|
|
unsigned int sectorsize)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
xfs: allow logical-sector sized O_DIRECT
Some time ago, mkfs.xfs started picking the storage physical
sector size as the default filesystem "sector size" in order
to avoid RMW costs incurred by doing IOs at logical sector
size alignments.
However, this means that for a filesystem made with i.e.
a 4k sector size on an "advanced format" 4k/512 disk,
512-byte direct IOs are no longer allowed. This means
that XFS has essentially turned this AF drive into a hard
4K device, from the filesystem on up.
XFS's mkfs-specified "sector size" is really just controlling
the minimum size & alignment of filesystem metadata.
There is no real need to tightly couple XFS's minimal
metadata size to the minimum allowed direct IO size;
XFS can continue doing metadata in optimal sizes, but
still allow smaller DIOs for apps which issue them,
for whatever reason.
This patch adds a new field to the xfs_buftarg, so that
we now track 2 sizes:
1) The metadata sector size, which is the minimum unit and
alignment of IO which will be performed by metadata operations.
2) The device logical sector size
The first is used internally by the file system for metadata
alignment and IOs.
The second is used for the minimum allowed direct IO alignment.
This has passed xfstests on filesystems made with 4k sectors,
including when run under the patch I sent to ignore
XFS_IOC_DIOINFO, and issue 512 DIOs anyway. I also directly
tested end of block behavior on preallocated, sparse, and
existing files when we do a 512 IO into a 4k file on a
4k-sector filesystem, to be sure there were no unexpected
behaviors.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2014-01-22 02:46:23 +04:00
|
|
|
/* Set up metadata sector size info */
|
2014-01-22 02:45:52 +04:00
|
|
|
btp->bt_meta_sectorsize = sectorsize;
|
|
|
|
btp->bt_meta_sectormask = sectorsize - 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-11 07:39:08 +03:00
|
|
|
if (set_blocksize(btp->bt_bdev, sectorsize)) {
|
2011-03-07 02:00:35 +03:00
|
|
|
xfs_warn(btp->bt_mount,
|
2015-04-13 15:31:37 +03:00
|
|
|
"Cannot set_blocksize to %u on device %pg",
|
|
|
|
sectorsize, btp->bt_bdev);
|
2014-06-25 08:58:08 +04:00
|
|
|
return -EINVAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
xfs: allow logical-sector sized O_DIRECT
Some time ago, mkfs.xfs started picking the storage physical
sector size as the default filesystem "sector size" in order
to avoid RMW costs incurred by doing IOs at logical sector
size alignments.
However, this means that for a filesystem made with i.e.
a 4k sector size on an "advanced format" 4k/512 disk,
512-byte direct IOs are no longer allowed. This means
that XFS has essentially turned this AF drive into a hard
4K device, from the filesystem on up.
XFS's mkfs-specified "sector size" is really just controlling
the minimum size & alignment of filesystem metadata.
There is no real need to tightly couple XFS's minimal
metadata size to the minimum allowed direct IO size;
XFS can continue doing metadata in optimal sizes, but
still allow smaller DIOs for apps which issue them,
for whatever reason.
This patch adds a new field to the xfs_buftarg, so that
we now track 2 sizes:
1) The metadata sector size, which is the minimum unit and
alignment of IO which will be performed by metadata operations.
2) The device logical sector size
The first is used internally by the file system for metadata
alignment and IOs.
The second is used for the minimum allowed direct IO alignment.
This has passed xfstests on filesystems made with 4k sectors,
including when run under the patch I sent to ignore
XFS_IOC_DIOINFO, and issue 512 DIOs anyway. I also directly
tested end of block behavior on preallocated, sparse, and
existing files when we do a 512 IO into a 4k file on a
4k-sector filesystem, to be sure there were no unexpected
behaviors.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2014-01-22 02:46:23 +04:00
|
|
|
/* Set up device logical sector size mask */
|
|
|
|
btp->bt_logical_sectorsize = bdev_logical_block_size(btp->bt_bdev);
|
|
|
|
btp->bt_logical_sectormask = bdev_logical_block_size(btp->bt_bdev) - 1;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-11-14 00:53:45 +04:00
|
|
|
* When allocating the initial buffer target we have not yet
|
|
|
|
* read in the superblock, so don't know what sized sectors
|
|
|
|
* are being used at this early stage. Play safe.
|
2006-01-11 07:39:08 +03:00
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
STATIC int
|
|
|
|
xfs_setsize_buftarg_early(
|
|
|
|
xfs_buftarg_t *btp,
|
|
|
|
struct block_device *bdev)
|
|
|
|
{
|
2014-04-14 13:00:29 +04:00
|
|
|
return xfs_setsize_buftarg(btp, bdev_logical_block_size(bdev));
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
xfs_buftarg_t *
|
|
|
|
xfs_alloc_buftarg(
|
2010-09-22 04:47:20 +04:00
|
|
|
struct xfs_mount *mp,
|
2017-08-25 01:12:50 +03:00
|
|
|
struct block_device *bdev,
|
|
|
|
struct dax_device *dax_dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
xfs_buftarg_t *btp;
|
|
|
|
|
2019-08-26 22:06:22 +03:00
|
|
|
btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-22 04:47:20 +04:00
|
|
|
btp->bt_mount = mp;
|
2006-01-11 07:39:08 +03:00
|
|
|
btp->bt_dev = bdev->bd_dev;
|
|
|
|
btp->bt_bdev = bdev;
|
2017-08-25 01:12:50 +03:00
|
|
|
btp->bt_daxdev = dax_dev;
|
2011-03-26 01:16:45 +03:00
|
|
|
|
2020-05-06 23:25:21 +03:00
|
|
|
/*
|
|
|
|
* Buffer IO error rate limiting. Limit it to no more than 10 messages
|
|
|
|
* per 30 seconds so as to not spam logs too much on repeated errors.
|
|
|
|
*/
|
|
|
|
ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ,
|
|
|
|
DEFAULT_RATELIMIT_BURST);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (xfs_setsize_buftarg_early(btp, bdev))
|
2017-11-23 19:13:40 +03:00
|
|
|
goto error_free;
|
2013-08-28 04:18:18 +04:00
|
|
|
|
|
|
|
if (list_lru_init(&btp->bt_lru))
|
2017-11-23 19:13:40 +03:00
|
|
|
goto error_free;
|
2013-08-28 04:18:18 +04:00
|
|
|
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL))
|
2017-11-23 19:13:40 +03:00
|
|
|
goto error_lru;
|
xfs: track and serialize in-flight async buffers against unmount
Newly allocated XFS metadata buffers are added to the LRU once the hold
count is released, which typically occurs after I/O completion. There is
no other mechanism at current that tracks the existence or I/O state of
a new buffer. Further, readahead I/O tends to be submitted
asynchronously by nature, which means the I/O can remain in flight and
actually complete long after the calling context is gone. This means
that file descriptors or any other holds on the filesystem can be
released, allowing the filesystem to be unmounted while I/O is still in
flight. When I/O completion occurs, core data structures may have been
freed, causing completion to run into invalid memory accesses and likely
to panic.
This problem is reproduced on XFS via directory readahead. A filesystem
is mounted, a directory is opened/closed and the filesystem immediately
unmounted. The open/close cycle triggers a directory readahead that if
delayed long enough, runs buffer I/O completion after the unmount has
completed.
To address this problem, add a mechanism to track all in-flight,
asynchronous buffers using per-cpu counters in the buftarg. The buffer
is accounted on the first I/O submission after the current reference is
acquired and unaccounted once the buffer is returned to the LRU or
freed. Update xfs_wait_buftarg() to wait on all in-flight I/O before
walking the LRU list. Once in-flight I/O has completed and the workqueue
has drained, all new buffers should have been released onto the LRU.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2016-07-20 04:15:28 +03:00
|
|
|
|
2013-08-28 04:18:05 +04:00
|
|
|
btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count;
|
|
|
|
btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan;
|
2010-11-30 09:27:57 +03:00
|
|
|
btp->bt_shrinker.seeks = DEFAULT_SEEKS;
|
2013-08-28 04:18:05 +04:00
|
|
|
btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE;
|
2017-11-23 19:13:40 +03:00
|
|
|
if (register_shrinker(&btp->bt_shrinker))
|
|
|
|
goto error_pcpu;
|
2005-04-17 02:20:36 +04:00
|
|
|
return btp;
|
|
|
|
|
2017-11-23 19:13:40 +03:00
|
|
|
error_pcpu:
|
|
|
|
percpu_counter_destroy(&btp->bt_io_count);
|
|
|
|
error_lru:
|
|
|
|
list_lru_destroy(&btp->bt_lru);
|
|
|
|
error_free:
|
2008-05-19 10:31:57 +04:00
|
|
|
kmem_free(btp);
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-21 22:40:44 +03:00
|
|
|
/*
|
|
|
|
* Cancel a delayed write list.
|
|
|
|
*
|
|
|
|
* Remove each buffer from the list, clear the delwri queue flag and drop the
|
|
|
|
* associated buffer reference.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_buf_delwri_cancel(
|
|
|
|
struct list_head *list)
|
|
|
|
{
|
|
|
|
struct xfs_buf *bp;
|
|
|
|
|
|
|
|
while (!list_empty(list)) {
|
|
|
|
bp = list_first_entry(list, struct xfs_buf, b_list);
|
|
|
|
|
|
|
|
xfs_buf_lock(bp);
|
|
|
|
bp->b_flags &= ~_XBF_DELWRI_Q;
|
|
|
|
list_del_init(&bp->b_list);
|
|
|
|
xfs_buf_relse(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
* Add a buffer to the delayed write list.
|
|
|
|
*
|
|
|
|
* This queues a buffer for writeout if it hasn't already been. Note that
|
|
|
|
* neither this routine nor the buffer list submission functions perform
|
|
|
|
* any internal synchronization. It is expected that the lists are thread-local
|
|
|
|
* to the callers.
|
|
|
|
*
|
|
|
|
* Returns true if we queued up the buffer, or false if it already had
|
|
|
|
* been on the buffer list.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
bool
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_delwri_queue(
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
struct xfs_buf *bp,
|
|
|
|
struct list_head *list)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
2011-08-23 12:28:05 +04:00
|
|
|
ASSERT(!(bp->b_flags & XBF_READ));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
/*
|
|
|
|
* If the buffer is already marked delwri it already is queued up
|
|
|
|
* by someone else for imediate writeout. Just ignore it in that
|
|
|
|
* case.
|
|
|
|
*/
|
|
|
|
if (bp->b_flags & _XBF_DELWRI_Q) {
|
|
|
|
trace_xfs_buf_delwri_queued(bp, _RET_IP_);
|
|
|
|
return false;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
trace_xfs_buf_delwri_queue(bp, _RET_IP_);
|
2010-02-02 02:13:42 +03:00
|
|
|
|
|
|
|
/*
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
* If a buffer gets written out synchronously or marked stale while it
|
|
|
|
* is on a delwri list we lazily remove it. To do this, the other party
|
|
|
|
* clears the _XBF_DELWRI_Q flag but otherwise leaves the buffer alone.
|
|
|
|
* It remains referenced and on the list. In a rare corner case it
|
|
|
|
* might get readded to a delwri list after the synchronous writeout, in
|
|
|
|
* which case we need just need to re-add the flag here.
|
2010-02-02 02:13:42 +03:00
|
|
|
*/
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
bp->b_flags |= _XBF_DELWRI_Q;
|
|
|
|
if (list_empty(&bp->b_list)) {
|
|
|
|
atomic_inc(&bp->b_hold);
|
|
|
|
list_add_tail(&bp->b_list, list);
|
2007-02-10 10:32:29 +03:00
|
|
|
}
|
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
return true;
|
2007-02-10 10:32:29 +03:00
|
|
|
}
|
|
|
|
|
2010-01-26 07:13:25 +03:00
|
|
|
/*
|
|
|
|
* Compare function is more complex than it needs to be because
|
|
|
|
* the return value is only 32 bits and we are doing comparisons
|
|
|
|
* on 64 bit values
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
xfs_buf_cmp(
|
|
|
|
void *priv,
|
|
|
|
struct list_head *a,
|
|
|
|
struct list_head *b)
|
|
|
|
{
|
|
|
|
struct xfs_buf *ap = container_of(a, struct xfs_buf, b_list);
|
|
|
|
struct xfs_buf *bp = container_of(b, struct xfs_buf, b_list);
|
|
|
|
xfs_daddr_t diff;
|
|
|
|
|
2012-12-05 03:18:02 +04:00
|
|
|
diff = ap->b_maps[0].bm_bn - bp->b_maps[0].bm_bn;
|
2010-01-26 07:13:25 +03:00
|
|
|
if (diff < 0)
|
|
|
|
return -1;
|
|
|
|
if (diff > 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-01 10:38:15 +03:00
|
|
|
/*
|
2018-07-12 08:26:34 +03:00
|
|
|
* Submit buffers for write. If wait_list is specified, the buffers are
|
|
|
|
* submitted using sync I/O and placed on the wait list such that the caller can
|
|
|
|
* iowait each buffer. Otherwise async I/O is used and the buffers are released
|
|
|
|
* at I/O completion time. In either case, buffers remain locked until I/O
|
|
|
|
* completes and the buffer is released from the queue.
|
2016-06-01 10:38:15 +03:00
|
|
|
*/
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
static int
|
2016-06-01 10:38:15 +03:00
|
|
|
xfs_buf_delwri_submit_buffers(
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
struct list_head *buffer_list,
|
2016-06-01 10:38:15 +03:00
|
|
|
struct list_head *wait_list)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
struct xfs_buf *bp, *n;
|
|
|
|
int pinned = 0;
|
2016-06-01 10:38:15 +03:00
|
|
|
struct blk_plug plug;
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
|
2016-06-01 10:38:15 +03:00
|
|
|
list_sort(NULL, buffer_list, xfs_buf_cmp);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
|
2016-06-01 10:38:15 +03:00
|
|
|
blk_start_plug(&plug);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
list_for_each_entry_safe(bp, n, buffer_list, b_list) {
|
2016-06-01 10:38:15 +03:00
|
|
|
if (!wait_list) {
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
if (xfs_buf_ispinned(bp)) {
|
|
|
|
pinned++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!xfs_buf_trylock(bp))
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
xfs_buf_lock(bp);
|
|
|
|
}
|
2007-12-07 06:09:02 +03:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
/*
|
|
|
|
* Someone else might have written the buffer synchronously or
|
|
|
|
* marked it stale in the meantime. In that case only the
|
|
|
|
* _XBF_DELWRI_Q flag got cleared, and we have to drop the
|
|
|
|
* reference and remove it from the list here.
|
|
|
|
*/
|
|
|
|
if (!(bp->b_flags & _XBF_DELWRI_Q)) {
|
|
|
|
list_del_init(&bp->b_list);
|
|
|
|
xfs_buf_relse(bp);
|
|
|
|
continue;
|
|
|
|
}
|
2010-01-11 14:49:59 +03:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
trace_xfs_buf_delwri_split(bp, _RET_IP_);
|
2011-03-30 15:05:09 +04:00
|
|
|
|
2014-10-02 03:04:01 +04:00
|
|
|
/*
|
2018-07-12 08:26:34 +03:00
|
|
|
* If we have a wait list, each buffer (and associated delwri
|
|
|
|
* queue reference) transfers to it and is submitted
|
|
|
|
* synchronously. Otherwise, drop the buffer from the delwri
|
|
|
|
* queue and submit async.
|
2014-10-02 03:04:01 +04:00
|
|
|
*/
|
2020-05-06 23:25:20 +03:00
|
|
|
bp->b_flags &= ~_XBF_DELWRI_Q;
|
2018-07-12 08:26:34 +03:00
|
|
|
bp->b_flags |= XBF_WRITE;
|
2016-06-01 10:38:15 +03:00
|
|
|
if (wait_list) {
|
2018-07-12 08:26:34 +03:00
|
|
|
bp->b_flags &= ~XBF_ASYNC;
|
2016-06-01 10:38:15 +03:00
|
|
|
list_move_tail(&bp->b_list, wait_list);
|
2018-07-12 08:26:34 +03:00
|
|
|
} else {
|
|
|
|
bp->b_flags |= XBF_ASYNC;
|
2006-01-11 07:39:08 +03:00
|
|
|
list_del_init(&bp->b_list);
|
2018-07-12 08:26:34 +03:00
|
|
|
}
|
2018-07-12 08:26:35 +03:00
|
|
|
__xfs_buf_submit(bp, false);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
}
|
|
|
|
blk_finish_plug(&plug);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
return pinned;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
* Write out a buffer list asynchronously.
|
|
|
|
*
|
|
|
|
* This will take the @buffer_list, write all non-locked and non-pinned buffers
|
|
|
|
* out and not wait for I/O completion on any of the buffers. This interface
|
|
|
|
* is only safely useable for callers that can track I/O completion by higher
|
|
|
|
* level means, e.g. AIL pushing as the @buffer_list is consumed in this
|
|
|
|
* function.
|
xfs: clear ail delwri queued bufs on unmount of shutdown fs
In the typical unmount case, the AIL is forced out by the unmount
sequence before the xfsaild task is stopped. Since AIL items are
removed on writeback completion, this means that the AIL
->ail_buf_list delwri queue has been drained. This is not always
true in the shutdown case, however.
It's possible for buffers to sit on a delwri queue for a period of
time across submission attempts if said items are locked or have
been relogged and pinned since first added to the queue. If the
attempt to log such an item results in a log I/O error, the error
processing can shutdown the fs, remove the item from the AIL, stale
the buffer (dropping the LRU reference) and clear its delwri queue
state. The latter bit means the buffer will be released from a
delwri queue on the next submission attempt, but this might never
occur if the filesystem has shutdown and the AIL is empty.
This means that such buffers are held indefinitely by the AIL delwri
queue across destruction of the AIL. Aside from being a memory leak,
these buffers can also hold references to in-core perag structures.
The latter problem manifests as a generic/475 failure, reproducing
the following asserts at unmount time:
XFS: Assertion failed: atomic_read(&pag->pag_ref) == 0,
file: fs/xfs/xfs_mount.c, line: 151
XFS: Assertion failed: atomic_read(&pag->pag_ref) == 0,
file: fs/xfs/xfs_mount.c, line: 132
To prevent this problem, clear the AIL delwri queue as a final step
before xfsaild() exit. The !empty state should never occur in the
normal case, so add an assert to catch unexpected problems going
forward.
[dgc: add comment explaining need for xfs_buf_delwri_cancel() after
calling xfs_buf_delwri_submit_nowait().]
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2018-10-18 09:21:49 +03:00
|
|
|
*
|
|
|
|
* Note: this function will skip buffers it would block on, and in doing so
|
|
|
|
* leaves them on @buffer_list so they can be retried on a later pass. As such,
|
|
|
|
* it is up to the caller to ensure that the buffer list is fully submitted or
|
|
|
|
* cancelled appropriately when they are finished with the list. Failure to
|
|
|
|
* cancel or resubmit the list until it is empty will result in leaked buffers
|
|
|
|
* at unmount time.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
int
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
xfs_buf_delwri_submit_nowait(
|
|
|
|
struct list_head *buffer_list)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2016-06-01 10:38:15 +03:00
|
|
|
return xfs_buf_delwri_submit_buffers(buffer_list, NULL);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
/*
|
|
|
|
* Write out a buffer list synchronously.
|
|
|
|
*
|
|
|
|
* This will take the @buffer_list, write all buffers out and wait for I/O
|
|
|
|
* completion on all of the buffers. @buffer_list is consumed by the function,
|
|
|
|
* so callers must have some other way of tracking buffers if they require such
|
|
|
|
* functionality.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xfs_buf_delwri_submit(
|
|
|
|
struct list_head *buffer_list)
|
|
|
|
{
|
2016-06-01 10:38:15 +03:00
|
|
|
LIST_HEAD (wait_list);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
int error = 0, error2;
|
|
|
|
struct xfs_buf *bp;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-06-01 10:38:15 +03:00
|
|
|
xfs_buf_delwri_submit_buffers(buffer_list, &wait_list);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
/* Wait for IO to complete. */
|
2016-06-01 10:38:15 +03:00
|
|
|
while (!list_empty(&wait_list)) {
|
|
|
|
bp = list_first_entry(&wait_list, struct xfs_buf, b_list);
|
2011-03-30 15:05:09 +04:00
|
|
|
|
2010-01-26 07:13:25 +03:00
|
|
|
list_del_init(&bp->b_list);
|
2014-10-02 03:04:01 +04:00
|
|
|
|
2018-07-12 08:26:34 +03:00
|
|
|
/*
|
|
|
|
* Wait on the locked buffer, check for errors and unlock and
|
|
|
|
* release the delwri queue reference.
|
|
|
|
*/
|
|
|
|
error2 = xfs_buf_iowait(bp);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
if (!error)
|
|
|
|
error = error2;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 09:58:39 +04:00
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2017-06-15 07:21:45 +03:00
|
|
|
/*
|
|
|
|
* Push a single buffer on a delwri queue.
|
|
|
|
*
|
|
|
|
* The purpose of this function is to submit a single buffer of a delwri queue
|
|
|
|
* and return with the buffer still on the original queue. The waiting delwri
|
|
|
|
* buffer submission infrastructure guarantees transfer of the delwri queue
|
|
|
|
* buffer reference to a temporary wait list. We reuse this infrastructure to
|
|
|
|
* transfer the buffer back to the original queue.
|
|
|
|
*
|
|
|
|
* Note the buffer transitions from the queued state, to the submitted and wait
|
|
|
|
* listed state and back to the queued state during this call. The buffer
|
|
|
|
* locking and queue management logic between _delwri_pushbuf() and
|
|
|
|
* _delwri_queue() guarantee that the buffer cannot be queued to another list
|
|
|
|
* before returning.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xfs_buf_delwri_pushbuf(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
struct list_head *buffer_list)
|
|
|
|
{
|
|
|
|
LIST_HEAD (submit_list);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ASSERT(bp->b_flags & _XBF_DELWRI_Q);
|
|
|
|
|
|
|
|
trace_xfs_buf_delwri_pushbuf(bp, _RET_IP_);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Isolate the buffer to a new local list so we can submit it for I/O
|
|
|
|
* independently from the rest of the original list.
|
|
|
|
*/
|
|
|
|
xfs_buf_lock(bp);
|
|
|
|
list_move(&bp->b_list, &submit_list);
|
|
|
|
xfs_buf_unlock(bp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delwri submission clears the DELWRI_Q buffer flag and returns with
|
2018-07-12 08:26:34 +03:00
|
|
|
* the buffer on the wait list with the original reference. Rather than
|
2017-06-15 07:21:45 +03:00
|
|
|
* bounce the buffer from a local wait list back to the original list
|
|
|
|
* after I/O completion, reuse the original list as the wait list.
|
|
|
|
*/
|
|
|
|
xfs_buf_delwri_submit_buffers(&submit_list, buffer_list);
|
|
|
|
|
|
|
|
/*
|
2018-07-12 08:26:34 +03:00
|
|
|
* The buffer is now locked, under I/O and wait listed on the original
|
|
|
|
* delwri queue. Wait for I/O completion, restore the DELWRI_Q flag and
|
|
|
|
* return with the buffer unlocked and on the original queue.
|
2017-06-15 07:21:45 +03:00
|
|
|
*/
|
2018-07-12 08:26:34 +03:00
|
|
|
error = xfs_buf_iowait(bp);
|
2017-06-15 07:21:45 +03:00
|
|
|
bp->b_flags |= _XBF_DELWRI_Q;
|
|
|
|
xfs_buf_unlock(bp);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2005-11-02 02:15:05 +03:00
|
|
|
int __init
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2020-03-25 06:10:28 +03:00
|
|
|
xfs_buf_zone = kmem_cache_create("xfs_buf", sizeof(struct xfs_buf), 0,
|
|
|
|
SLAB_HWCACHE_ALIGN |
|
|
|
|
SLAB_RECLAIM_ACCOUNT |
|
|
|
|
SLAB_MEM_SPREAD,
|
|
|
|
NULL);
|
2006-01-11 07:39:08 +03:00
|
|
|
if (!xfs_buf_zone)
|
2009-12-15 02:14:59 +03:00
|
|
|
goto out;
|
2005-11-02 02:15:05 +03:00
|
|
|
|
2005-06-21 09:14:01 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-12-15 02:14:59 +03:00
|
|
|
out:
|
2006-03-14 05:18:19 +03:00
|
|
|
return -ENOMEM;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-01-11 07:39:08 +03:00
|
|
|
xfs_buf_terminate(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2019-11-14 23:43:04 +03:00
|
|
|
kmem_cache_destroy(xfs_buf_zone);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2017-10-18 00:16:29 +03:00
|
|
|
|
|
|
|
void xfs_buf_set_ref(struct xfs_buf *bp, int lru_ref)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set the lru reference count to 0 based on the error injection tag.
|
|
|
|
* This allows userspace to disrupt buffer caching for debug/testing
|
|
|
|
* purposes.
|
|
|
|
*/
|
2019-06-29 05:27:29 +03:00
|
|
|
if (XFS_TEST_ERROR(false, bp->b_mount, XFS_ERRTAG_BUF_LRU_REF))
|
2017-10-18 00:16:29 +03:00
|
|
|
lru_ref = 0;
|
|
|
|
|
|
|
|
atomic_set(&bp->b_lru_ref, lru_ref);
|
|
|
|
}
|
2019-02-07 21:45:46 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify an on-disk magic value against the magic value specified in the
|
|
|
|
* verifier structure. The verifier magic is in disk byte order so the caller is
|
|
|
|
* expected to pass the value directly from disk.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
xfs_verify_magic(
|
|
|
|
struct xfs_buf *bp,
|
2019-02-16 22:47:28 +03:00
|
|
|
__be32 dmagic)
|
2019-02-07 21:45:46 +03:00
|
|
|
{
|
2019-06-29 05:27:29 +03:00
|
|
|
struct xfs_mount *mp = bp->b_mount;
|
2019-02-07 21:45:46 +03:00
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = xfs_sb_version_hascrc(&mp->m_sb);
|
2019-09-26 02:49:37 +03:00
|
|
|
if (WARN_ON(!bp->b_ops || !bp->b_ops->magic[idx]))
|
2019-02-07 21:45:46 +03:00
|
|
|
return false;
|
|
|
|
return dmagic == bp->b_ops->magic[idx];
|
|
|
|
}
|
2019-02-16 22:47:28 +03:00
|
|
|
/*
|
|
|
|
* Verify an on-disk magic value against the magic value specified in the
|
|
|
|
* verifier structure. The verifier magic is in disk byte order so the caller is
|
|
|
|
* expected to pass the value directly from disk.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
xfs_verify_magic16(
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
__be16 dmagic)
|
|
|
|
{
|
2019-06-29 05:27:29 +03:00
|
|
|
struct xfs_mount *mp = bp->b_mount;
|
2019-02-16 22:47:28 +03:00
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = xfs_sb_version_hascrc(&mp->m_sb);
|
2019-09-26 02:49:37 +03:00
|
|
|
if (WARN_ON(!bp->b_ops || !bp->b_ops->magic16[idx]))
|
2019-02-16 22:47:28 +03:00
|
|
|
return false;
|
|
|
|
return dmagic == bp->b_ops->magic16[idx];
|
|
|
|
}
|