07 Apr, 2010

1 commit

  • Order the debugfs statistics correctly. The values displayed through a
    seq_printf() statement should be in the same order as the names in the
    format string.

    In the 'Lookups' line, objects created ('crt=') and lookups timed out
    ('tmo=') have their values transposed.

    Signed-off-by: David Howells
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Howells
     

20 Nov, 2009

8 commits

  • Catch an overly long wait for an old, dying active object when we want to
    replace it with a new one. The probability is that all the slow-work threads
    are hogged, and the delete can't get a look in.

    What we do instead is:

    (1) if there's nothing in the slow work queue, we sleep until either the dying
    object has finished dying or there is something in the slow work queue
    behind which we can queue our object.

    (2) if there is something in the slow work queue, we return ETIMEDOUT to
    fscache_lookup_object(), which then puts us back on the slow work queue,
    presumably behind the deletion that we're blocked by. We are then
    deferred for a while until we work our way back through the queue -
    without blocking a slow-work thread unnecessarily.

    A backtrace similar to the following may appear in the log without this patch:

    INFO: task kslowd004:5711 blocked for more than 120 seconds.
    "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    kslowd004 D 0000000000000000 0 5711 2 0x00000080
    ffff88000340bb80 0000000000000046 ffff88002550d000 0000000000000000
    ffff88002550d000 0000000000000007 ffff88000340bfd8 ffff88002550d2a8
    000000000000ddf0 00000000000118c0 00000000000118c0 ffff88002550d2a8
    Call Trace:
    [] ? trace_hardirqs_on+0xd/0xf
    [] ? cachefiles_wait_bit+0x0/0xd [cachefiles]
    [] cachefiles_wait_bit+0x9/0xd [cachefiles]
    [] __wait_on_bit+0x43/0x76
    [] ? ext3_xattr_get+0x1ec/0x270
    [] out_of_line_wait_on_bit+0x69/0x74
    [] ? cachefiles_wait_bit+0x0/0xd [cachefiles]
    [] ? wake_bit_function+0x0/0x2e
    [] cachefiles_mark_object_active+0x203/0x23b [cachefiles]
    [] cachefiles_walk_to_object+0x558/0x827 [cachefiles]
    [] cachefiles_lookup_object+0xac/0x12a [cachefiles]
    [] fscache_lookup_object+0x1c7/0x214 [fscache]
    [] fscache_object_state_machine+0xa5/0x52d [fscache]
    [] fscache_object_slow_work_execute+0x5f/0xa0 [fscache]
    [] slow_work_execute+0x18f/0x2d1
    [] slow_work_thread+0x1c5/0x308
    [] ? autoremove_wake_function+0x0/0x34
    [] ? slow_work_thread+0x0/0x308
    [] kthread+0x7a/0x82
    [] child_rip+0xa/0x20
    [] ? restore_args+0x0/0x30
    [] ? kthread+0x0/0x82
    [] ? child_rip+0x0/0x20
    1 lock held by kslowd004/5711:
    #0: (&sb->s_type->i_mutex_key#7/1){+.+.+.}, at: [] cachefiles_walk_to_object+0x1b3/0x827 [cachefiles]

    Signed-off-by: David Howells

    David Howells
     
  • Start processing an object's operations when that object moves into the DYING
    state as the object cannot be destroyed until all its outstanding operations
    have completed.

    Furthermore, make sure that read and allocation operations handle being woken
    up on a dead object. Such events are recorded in the Allocs.abt and
    Retrvls.abt statistics as viewable through /proc/fs/fscache/stats.

    The code for waiting for object activation for the read and allocation
    operations is also extracted into its own function as it is much the same in
    all cases, differing only in the stats incremented.

    Signed-off-by: David Howells

    David Howells
     
  • Add a stat counter to count retirement events rather than ordinary release
    events (the retire argument to fscache_relinquish_cookie()).

    Signed-off-by: David Howells

    David Howells
     
  • Handle netfs pages that the vmscan algorithm wants to evict from the pagecache
    under OOM conditions, but that are waiting for write to the cache. Under these
    conditions, vmscan calls the releasepage() function of the netfs, asking if a
    page can be discarded.

    The problem is typified by the following trace of a stuck process:

    kslowd005 D 0000000000000000 0 4253 2 0x00000080
    ffff88001b14f370 0000000000000046 ffff880020d0d000 0000000000000007
    0000000000000006 0000000000000001 ffff88001b14ffd8 ffff880020d0d2a8
    000000000000ddf0 00000000000118c0 00000000000118c0 ffff880020d0d2a8
    Call Trace:
    [] __fscache_wait_on_page_write+0x8b/0xa7 [fscache]
    [] ? autoremove_wake_function+0x0/0x34
    [] ? __fscache_check_page_write+0x63/0x70 [fscache]
    [] nfs_fscache_release_page+0x4e/0xc4 [nfs]
    [] nfs_release_page+0x3c/0x41 [nfs]
    [] try_to_release_page+0x32/0x3b
    [] shrink_page_list+0x316/0x4ac
    [] shrink_inactive_list+0x392/0x67c
    [] ? __mutex_unlock_slowpath+0x100/0x10b
    [] ? trace_hardirqs_on_caller+0x10c/0x130
    [] ? mutex_unlock+0x9/0xb
    [] shrink_list+0x8d/0x8f
    [] shrink_zone+0x278/0x33c
    [] ? ktime_get_ts+0xad/0xba
    [] try_to_free_pages+0x22e/0x392
    [] ? isolate_pages_global+0x0/0x212
    [] __alloc_pages_nodemask+0x3dc/0x5cf
    [] grab_cache_page_write_begin+0x65/0xaa
    [] ext3_write_begin+0x78/0x1eb
    [] generic_file_buffered_write+0x109/0x28c
    [] ? current_fs_time+0x22/0x29
    [] __generic_file_aio_write+0x350/0x385
    [] ? generic_file_aio_write+0x4a/0xae
    [] generic_file_aio_write+0x60/0xae
    [] do_sync_write+0xe3/0x120
    [] ? autoremove_wake_function+0x0/0x34
    [] ? __dentry_open+0x1a5/0x2b8
    [] ? dentry_open+0x82/0x89
    [] cachefiles_write_page+0x298/0x335 [cachefiles]
    [] fscache_write_op+0x178/0x2c2 [fscache]
    [] fscache_op_execute+0x7a/0xd1 [fscache]
    [] slow_work_execute+0x18f/0x2d1
    [] slow_work_thread+0x1c5/0x308
    [] ? autoremove_wake_function+0x0/0x34
    [] ? slow_work_thread+0x0/0x308
    [] kthread+0x7a/0x82
    [] child_rip+0xa/0x20
    [] ? restore_args+0x0/0x30
    [] ? tg_shares_up+0x171/0x227
    [] ? kthread+0x0/0x82
    [] ? child_rip+0x0/0x20

    In the above backtrace, the following is happening:

    (1) A page storage operation is being executed by a slow-work thread
    (fscache_write_op()).

    (2) FS-Cache farms the operation out to the cache to perform
    (cachefiles_write_page()).

    (3) CacheFiles is then calling Ext3 to perform the actual write, using Ext3's
    standard write (do_sync_write()) under KERNEL_DS directly from the netfs
    page.

    (4) However, for Ext3 to perform the write, it must allocate some memory, in
    particular, it must allocate at least one page cache page into which it
    can copy the data from the netfs page.

    (5) Under OOM conditions, the memory allocator can't immediately come up with
    a page, so it uses vmscan to find something to discard
    (try_to_free_pages()).

    (6) vmscan finds a clean netfs page it might be able to discard (possibly the
    one it's trying to write out).

    (7) The netfs is called to throw the page away (nfs_release_page()) - but it's
    called with __GFP_WAIT, so the netfs decides to wait for the store to
    complete (__fscache_wait_on_page_write()).

    (8) This blocks a slow-work processing thread - possibly against itself.

    The system ends up stuck because it can't write out any netfs pages to the
    cache without allocating more memory.

    To avoid this, we make FS-Cache cancel some writes that aren't in the middle of
    actually being performed. This means that some data won't make it into the
    cache this time. To support this, a new FS-Cache function is added
    fscache_maybe_release_page() that replaces what the netfs releasepage()
    functions used to do with respect to the cache.

    The decisions fscache_maybe_release_page() makes are counted and displayed
    through /proc/fs/fscache/stats on a line labelled "VmScan". There are four
    counters provided: "nos=N" - pages that weren't pending storage; "gon=N" -
    pages that were pending storage when we first looked, but weren't by the time
    we got the object lock; "bsy=N" - pages that we ignored as they were actively
    being written when we looked; and "can=N" - pages that we cancelled the storage
    of.

    What I'd really like to do is alter the behaviour of the cancellation
    heuristics, depending on how necessary it is to expel pages. If there are
    plenty of other pages that aren't waiting to be written to the cache that
    could be ejected first, then it would be nice to hold up on immediate
    cancellation of cache writes - but I don't see a way of doing that.

    Signed-off-by: David Howells

    David Howells
     
  • FS-Cache doesn't correctly handle the netfs requesting a read from the cache
    on an object that failed or was withdrawn by the cache. A trace similar to
    the following might be seen:

    CacheFiles: Lookup failed error -105
    [exe ] unexpected submission OP165afe [OBJ6cac OBJECT_LC_DYING]
    [exe ] objstate=OBJECT_LC_DYING [OBJECT_LC_DYING]
    [exe ] objflags=0
    [exe ] objevent=9 [fffffffffffffffb]
    [exe ] ops=0 inp=0 exc=0
    Pid: 6970, comm: exe Not tainted 2.6.32-rc6-cachefs #50
    Call Trace:
    [] fscache_submit_op+0x3ff/0x45a [fscache]
    [] __fscache_read_or_alloc_pages+0x187/0x3c4 [fscache]
    [] ? nfs_readpage_from_fscache_complete+0x0/0x66 [nfs]
    [] __nfs_readpages_from_fscache+0x7e/0x176 [nfs]
    [] ? __alloc_pages_nodemask+0x11c/0x5cf
    [] nfs_readpages+0x114/0x1d7 [nfs]
    [] __do_page_cache_readahead+0x15f/0x1ec
    [] ? __do_page_cache_readahead+0x73/0x1ec
    [] ra_submit+0x1c/0x20
    [] ondemand_readahead+0x227/0x23a
    [] page_cache_sync_readahead+0x17/0x19
    [] generic_file_aio_read+0x236/0x5a0
    [] nfs_file_read+0xe4/0xf3 [nfs]
    [] do_sync_read+0xe3/0x120
    [] ? _spin_unlock_irq+0x2b/0x31
    [] ? autoremove_wake_function+0x0/0x34
    [] ? selinux_file_permission+0x5d/0x10f
    [] ? thread_return+0x3e/0x101
    [] ? security_file_permission+0x11/0x13
    [] vfs_read+0xaa/0x16f
    [] ? trace_hardirqs_on_caller+0x10c/0x130
    [] sys_read+0x45/0x6c
    [] system_call_fastpath+0x16/0x1b

    The object state might also be OBJECT_DYING or OBJECT_WITHDRAWING.

    This should be handled by simply rejecting the new operation with ENOBUFS.
    There's no need to log an error for it. Events of this type now appear in the
    stats file under Ops:rej.

    Signed-off-by: David Howells

    David Howells
     
  • FS-Cache has two structs internally for keeping track of the internal state of
    a cached file: the fscache_cookie struct, which represents the netfs's state,
    and fscache_object struct, which represents the cache's state. Each has a
    pointer that points to the other (when both are in existence), and each has a
    spinlock for pointer maintenance.

    Since netfs operations approach these structures from the cookie side, they get
    the cookie lock first, then the object lock. Cache operations, on the other
    hand, approach from the object side, and get the object lock first. It is not
    then permitted for a cache operation to get the cookie lock whilst it is
    holding the object lock lest deadlock occur; instead, it must do one of two
    things:

    (1) increment the cookie usage counter, drop the object lock and then get both
    locks in order, or

    (2) simply hold the object lock as certain parts of the cookie may not be
    altered whilst the object lock is held.

    It is also not permitted to follow either pointer without holding the lock at
    the end you start with. To break the pointers between the cookie and the
    object, both locks must be held.

    fscache_write_op(), however, violates the locking rules: It attempts to get the
    cookie lock without (a) checking that the cookie pointer is a valid pointer,
    and (b) holding the object lock to protect the cookie pointer whilst it follows
    it. This is so that it can access the pending page store tree without
    interference from __fscache_write_page().

    This is fixed by splitting the cookie lock, such that the page store tracking
    tree is protected by its own lock, and checking that the cookie pointer is
    non-NULL before we attempt to follow it whilst holding the object lock.

    The new lock is subordinate to both the cookie lock and the object lock, and so
    should be taken after those.

    Signed-off-by: David Howells

    David Howells
     
  • Permit the operations to retrieve data from the cache or to allocate space in
    the cache for future writes to be interrupted whilst they're waiting for
    permission for the operation to proceed. Typically this wait occurs whilst the
    cache object is being looked up on disk in the background.

    If an interruption occurs, and the operation has not yet been given the
    go-ahead to run, the operation is dequeued and cancelled, and control returns
    to the read operation of the netfs routine with none of the requested pages
    having been read or in any way marked as known by the cache.

    This means that the initial wait is done interruptibly rather than
    uninterruptibly.

    In addition, extra stats values are made available to show the number of ops
    cancelled and the number of cache space allocations interrupted.

    Signed-off-by: David Howells

    David Howells
     
  • Count entries to and exits from cache operation table functions. Maintain
    these as a single counter that's added to or removed from as appropriate.

    Signed-off-by: David Howells

    David Howells
     

03 Apr, 2009

1 commit

  • Make FS-Cache create its /proc interface and present various statistical
    information through it. Also provide the functions for updating this
    information.

    These features are enabled by:

    CONFIG_FSCACHE_PROC
    CONFIG_FSCACHE_STATS
    CONFIG_FSCACHE_HISTOGRAM

    The /proc directory for FS-Cache is also exported so that caching modules can
    add their own statistics there too.

    The FS-Cache module is loadable at this point, and the statistics files can be
    examined by userspace:

    cat /proc/fs/fscache/stats
    cat /proc/fs/fscache/histogram

    Signed-off-by: David Howells
    Acked-by: Steve Dickson
    Acked-by: Trond Myklebust
    Acked-by: Al Viro
    Tested-by: Daire Byrne

    David Howells