<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/include/linux/fscache-cache.h, branch v4.4.2</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.4.2</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.4.2'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2015-04-02T13:28:53Z</updated>
<entry>
<title>FS-Cache: Retain the netfs context in the retrieval op earlier</title>
<updated>2015-04-02T13:28:53Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2015-02-24T10:05:29Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=4a47132ff472a0c2c5441baeb50cf97f2580bc43'/>
<id>urn:sha1:4a47132ff472a0c2c5441baeb50cf97f2580bc43</id>
<content type='text'>
Now that the retrieval operation may be disposed of by fscache_put_operation()
before we actually set the context, the retrieval-specific cleanup operation
can produce a NULL-pointer dereference when it tries to unconditionally clean
up the netfs context.

Given that it is expected that we'll get at least as far as the place where we
currently set the context pointer and it is unlikely we'll go through the
error handling paths prior to that point, retain the context right from the
point that the retrieval op is allocated.

Concomitant to this, we need to retain the cookie pointer in the retrieval op
also so that we can call the netfs to release its context in the release
method.

In addition, we might now get into fscache_release_retrieval_op() with the op
only initialised.  To this end, set the operation to DEAD only after the
release method has been called and skip the n_pages test upon cleanup if the
op is still in the INITIALISED state.

Without these changes, the following oops might be seen:

	BUG: unable to handle kernel NULL pointer dereference at 00000000000000b8
	...
	RIP: 0010:[&lt;ffffffffa0089c98&gt;] fscache_release_retrieval_op+0xae/0x100
	...
	Call Trace:
	 [&lt;ffffffffa0088560&gt;] fscache_put_operation+0x117/0x2e0
	 [&lt;ffffffffa008b8f5&gt;] __fscache_read_or_alloc_pages+0x351/0x3ac
	 [&lt;ffffffffa00b761f&gt;] __nfs_readpages_from_fscache+0x59/0xbf [nfs]
	 [&lt;ffffffffa00b06c5&gt;] nfs_readpages+0x10c/0x185 [nfs]
	 [&lt;ffffffff81124925&gt;] ? alloc_pages_current+0x119/0x13e
	 [&lt;ffffffff810ee5fd&gt;] ? __page_cache_alloc+0xfb/0x10a
	 [&lt;ffffffff810f87f8&gt;] __do_page_cache_readahead+0x188/0x22c
	 [&lt;ffffffff810f8b3a&gt;] ondemand_readahead+0x29e/0x2af
	 [&lt;ffffffff810f8c92&gt;] page_cache_sync_readahead+0x38/0x3a
	 [&lt;ffffffff810ef337&gt;] generic_file_read_iter+0x1a2/0x55a
	 [&lt;ffffffffa00a9dff&gt;] ? nfs_revalidate_mapping+0xd6/0x288 [nfs]
	 [&lt;ffffffffa00a6a23&gt;] nfs_file_read+0x49/0x70 [nfs]
	 [&lt;ffffffff811363be&gt;] new_sync_read+0x78/0x9c
	 [&lt;ffffffff81137164&gt;] __vfs_read+0x13/0x38
	 [&lt;ffffffff8113721e&gt;] vfs_read+0x95/0x121
	 [&lt;ffffffff811372f6&gt;] SyS_read+0x4c/0x8a
	 [&lt;ffffffff81557a52&gt;] system_call_fastpath+0x12/0x17

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: Jeff Layton &lt;jeff.layton@primarydata.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: The operation cancellation method needs calling in more places</title>
<updated>2015-04-02T13:28:53Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2015-02-24T10:05:29Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=d3b97ca4a99e4e6c78f5a21c968eadf5c8ba9971'/>
<id>urn:sha1:d3b97ca4a99e4e6c78f5a21c968eadf5c8ba9971</id>
<content type='text'>
Any time an incomplete operation is cancelled, the operation cancellation
function needs to be called to clean up.  This is currently being passed
directly to some of the functions that might want to call it, but not all.

Instead, pass the cancellation method pointer to the fscache_operation_init()
and have that cache it in the operation struct.  Further, plug in a dummy
cancellation handler if the caller declines to set one as this allows us to
call the function unconditionally (the extra overhead isn't worth bothering
about as we don't expect to be calling this typically).

The cancellation method must thence be called everywhere the CANCELLED state
is set.  Note that we call it *before* setting the CANCELLED state such that
the method can use the old state value to guide its operation.

fscache_do_cancel_retrieval() needs moving higher up in the sources so that
the init function can use it now.

Without this, the following oops may be seen:

	FS-Cache: Assertion failed
	FS-Cache: 3 == 0 is false
	------------[ cut here ]------------
	kernel BUG at ../fs/fscache/page.c:261!
	...
	RIP: 0010:[&lt;ffffffffa0089c1b&gt;]  fscache_release_retrieval_op+0x77/0x100
	 [&lt;ffffffffa008853d&gt;] fscache_put_operation+0x114/0x2da
	 [&lt;ffffffffa008b8c2&gt;] __fscache_read_or_alloc_pages+0x358/0x3b3
	 [&lt;ffffffffa00b761f&gt;] __nfs_readpages_from_fscache+0x59/0xbf [nfs]
	 [&lt;ffffffffa00b06c5&gt;] nfs_readpages+0x10c/0x185 [nfs]
	 [&lt;ffffffff81124925&gt;] ? alloc_pages_current+0x119/0x13e
	 [&lt;ffffffff810ee5fd&gt;] ? __page_cache_alloc+0xfb/0x10a
	 [&lt;ffffffff810f87f8&gt;] __do_page_cache_readahead+0x188/0x22c
	 [&lt;ffffffff810f8b3a&gt;] ondemand_readahead+0x29e/0x2af
	 [&lt;ffffffff810f8c92&gt;] page_cache_sync_readahead+0x38/0x3a
	 [&lt;ffffffff810ef337&gt;] generic_file_read_iter+0x1a2/0x55a
	 [&lt;ffffffffa00a9dff&gt;] ? nfs_revalidate_mapping+0xd6/0x288 [nfs]
	 [&lt;ffffffffa00a6a23&gt;] nfs_file_read+0x49/0x70 [nfs]
	 [&lt;ffffffff811363be&gt;] new_sync_read+0x78/0x9c
	 [&lt;ffffffff81137164&gt;] __vfs_read+0x13/0x38
	 [&lt;ffffffff8113721e&gt;] vfs_read+0x95/0x121
	 [&lt;ffffffff811372f6&gt;] SyS_read+0x4c/0x8a
	 [&lt;ffffffff81557a52&gt;] system_call_fastpath+0x12/0x17

The assertion is showing that the remaining number of pages (n_pages) is not 0
when the operation is being released.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: Jeff Layton &lt;jeff.layton@primarydata.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: Out of line fscache_operation_init()</title>
<updated>2015-04-02T13:28:53Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2015-02-25T13:26:39Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=1339ec98e32b4bc8efb6fbb71c006a465130aaba'/>
<id>urn:sha1:1339ec98e32b4bc8efb6fbb71c006a465130aaba</id>
<content type='text'>
Out of line fscache_operation_init() so that it can access internal FS-Cache
features, such as stats, in a later commit.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: Jeff Layton &lt;jeff.layton@primarydata.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: fscache_object_is_dead() has wrong logic, kill it</title>
<updated>2015-04-02T13:28:53Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2015-02-24T10:52:51Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=87021526300f1a292dd966e141e183630ac95317'/>
<id>urn:sha1:87021526300f1a292dd966e141e183630ac95317</id>
<content type='text'>
fscache_object_is_dead() returns true only if the object is marked dead and
the cache got an I/O error.  This should be a logical OR instead.  Since two
of the callers got split up into handling for separate subcases, expand the
other callers and kill the function.  This is probably the right thing to do
anyway since one of the subcases isn't about the object at all, but rather
about the cache.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: Jeff Layton &lt;jeff.layton@primarydata.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: When submitting an op, cancel it if the target object is dying</title>
<updated>2015-04-02T13:28:53Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2015-02-24T10:05:27Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=30ceec6284129662efc3a1e7675b2bd857a046fe'/>
<id>urn:sha1:30ceec6284129662efc3a1e7675b2bd857a046fe</id>
<content type='text'>
When submitting an operation, prefer to cancel the operation immediately
rather than queuing it for later processing if the object is marked as dying
(ie. the object state machine has reached the KILL_OBJECT state).

Whilst we're at it, change the series of related test_bit() calls into a
READ_ONCE() and bitwise-AND operators to reduce the number of load
instructions (test_bit() has a volatile address).

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: Jeff Layton &lt;jeff.layton@primarydata.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: Count culled objects and objects rejected due to lack of space</title>
<updated>2015-02-24T10:05:27Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2015-02-19T23:47:31Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=182d919b84902eece162c63ed3d476c8016b4197'/>
<id>urn:sha1:182d919b84902eece162c63ed3d476c8016b4197</id>
<content type='text'>
Count the number of objects that get culled by the cache backend and the
number of objects that the cache backend declines to instantiate due to lack
of space in the cache.

These numbers are made available through /proc/fs/fscache/stats

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-by: Steve Dickson &lt;steved@redhat.com&gt;
Acked-by: Jeff Layton &lt;jeff.layton@primarydata.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: Provide the ability to enable/disable cookies</title>
<updated>2013-09-27T17:40:25Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-09-20T23:09:31Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=94d30ae90a00cafe686c1057be57f4885f963abf'/>
<id>urn:sha1:94d30ae90a00cafe686c1057be57f4885f963abf</id>
<content type='text'>
Provide the ability to enable and disable fscache cookies.  A disabled cookie
will reject or ignore further requests to:

	Acquire a child cookie
	Invalidate and update backing objects
	Check the consistency of a backing object
	Allocate storage for backing page
	Read backing pages
	Write to backing pages

but still allows:

	Checks/waits on the completion of already in-progress objects
	Uncaching of pages
	Relinquishment of cookies

Two new operations are provided:

 (1) Disable a cookie:

	void fscache_disable_cookie(struct fscache_cookie *cookie,
				    bool invalidate);

     If the cookie is not already disabled, this locks the cookie against other
     dis/enablement ops, marks the cookie as being disabled, discards or
     invalidates any backing objects and waits for cessation of activity on any
     associated object.

     This is a wrapper around a chunk split out of fscache_relinquish_cookie(),
     but it reinitialises the cookie such that it can be reenabled.

     All possible failures are handled internally.  The caller should consider
     calling fscache_uncache_all_inode_pages() afterwards to make sure all page
     markings are cleared up.

 (2) Enable a cookie:

	void fscache_enable_cookie(struct fscache_cookie *cookie,
				   bool (*can_enable)(void *data),
				   void *data)

     If the cookie is not already enabled, this locks the cookie against other
     dis/enablement ops, invokes can_enable() and, if the cookie is not an
     index cookie, will begin the procedure of acquiring backing objects.

     The optional can_enable() function is passed the data argument and returns
     a ruling as to whether or not enablement should actually be permitted to
     begin.

     All possible failures are handled internally.  The cookie will only be
     marked as enabled if provisional backing objects are allocated.

A later patch will introduce these to NFS.  Cookie enablement during nfs_open()
is then contingent on i_writecount &lt;= 0.  can_enable() checks for a race
between open(O_RDONLY) and open(O_WRONLY/O_RDWR).  This simplifies NFS's cookie
handling and allows us to get rid of open(O_RDONLY) accidentally introducing
caching to an inode that's open for writing already.

One operation has its API modified:

 (3) Acquire a cookie.

	struct fscache_cookie *fscache_acquire_cookie(
		struct fscache_cookie *parent,
		const struct fscache_cookie_def *def,
		void *netfs_data,
		bool enable);

     This now has an additional argument that indicates whether the requested
     cookie should be enabled by default.  It doesn't need the can_enable()
     function because the caller must prevent multiple calls for the same netfs
     object and it doesn't need to take the enablement lock because no one else
     can get at the cookie before this returns.

Signed-off-by: David Howells &lt;dhowells@redhat.com
</content>
</entry>
<entry>
<title>FS-Cache: Add use/unuse/wake cookie wrappers</title>
<updated>2013-09-27T17:40:25Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-09-20T23:09:31Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8fb883f3e30065529e4f35d4b4f355193dcdb7a2'/>
<id>urn:sha1:8fb883f3e30065529e4f35d4b4f355193dcdb7a2</id>
<content type='text'>
Add wrapper functions for dealing with cookie-&gt;n_active:

 (*) __fscache_use_cookie() to increment it.

 (*) __fscache_unuse_cookie() to decrement and test against zero.

 (*) __fscache_wake_unused_cookie() to wake up anyone waiting for it to reach
     zero.

The second and third are split so that the third can be done after cookie-&gt;lock
has been released in case the waiter wakes up whilst we're still holding it and
tries to get it.

We will need to wake-on-zero once the cookie disablement patch is applied
because it will then be possible to see n_active become zero without the cookie
being relinquished.

Also move the cookie usement out of fscache_attr_changed_op() and into
fscache_attr_changed() and the operation struct so that cookie disablement
will be able to track it.

Whilst we're at it, only increment n_active if we're about to do
fscache_submit_op() so that we don't have to deal with undoing it if anything
earlier fails.  Possibly this should be moved into fscache_submit_op() which
could look at FSCACHE_OP_UNUSE_COOKIE.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: Add interface to check consistency of a cached object</title>
<updated>2013-09-06T08:17:30Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-08-21T21:29:38Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=da9803bc8812f5bd3b26baaa90e515b843c65ff7'/>
<id>urn:sha1:da9803bc8812f5bd3b26baaa90e515b843c65ff7</id>
<content type='text'>
Extend the fscache netfs API so that the netfs can ask as to whether a cache
object is up to date with respect to its corresponding netfs object:

	int fscache_check_consistency(struct fscache_cookie *cookie)

This will call back to the netfs to check whether the auxiliary data associated
with a cookie is correct.  It returns 0 if it is and -ESTALE if it isn't; it
may also return -ENOMEM and -ERESTARTSYS.

The backends now have to implement a mandatory operation pointer:

	int (*check_consistency)(struct fscache_object *object)

that corresponds to the above API call.  FS-Cache takes care of pinning the
object and the cookie in memory and managing this call with respect to the
object state.

Original-author: Hongyi Jia &lt;jiayisuse@gmail.com&gt;
Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
cc: Hongyi Jia &lt;jiayisuse@gmail.com&gt;
cc: Milosz Tanski &lt;milosz@adfin.com&gt;
</content>
</entry>
<entry>
<title>FS-Cache: The retrieval remaining-pages counter needs to be atomic_t</title>
<updated>2013-06-19T13:16:47Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-05-21T12:44:15Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=1bb4b7f98f361132ea322834515334d95b93c184'/>
<id>urn:sha1:1bb4b7f98f361132ea322834515334d95b93c184</id>
<content type='text'>
struct fscache_retrieval contains a count of the number of pages that still
need some processing (n_pages).  This is decremented as the pages are
processed.

However, this needs to be atomic as fscache_retrieval_complete() (I think) just
occasionally may be called from cachefiles_read_backing_file() and
cachefiles_read_copier() simultaneously.

This happens when an fscache_read_or_alloc_pages() request containing a lot of
pages (say a couple of hundred) is being processed.  The read on each backing
page is dispatched individually because we need to insert a monitor into the
waitqueue to catch when the read completes.  However, under low-memory
conditions, we might be forced to wait in the allocator - and this gives the
I/O on the backing page a chance to complete first.

When the I/O completes, fscache_enqueue_retrieval() chucks the retrieval onto
the workqueue without waiting for the operation to finish the initial I/O
dispatch (we want to release any pages we can as soon as we can), thus both can
end up running simultaneously and potentially attempting to partially complete
the retrieval simultaneously (ENOMEM may occur, backing pages may already be in
the page cache).

This was demonstrated by parallelling the non-atomic counter with an atomic
counter and printing both of them when the assertion fails.  At this point, the
atomic counter has reached zero, but the non-atomic counter has not.

To fix this, make the counter an atomic_t.

This results in the following bug appearing

	FS-Cache: Assertion failed
	3 == 5 is false
	------------[ cut here ]------------
	kernel BUG at fs/fscache/operation.c:421!

or

	FS-Cache: Assertion failed
	3 == 5 is false
	------------[ cut here ]------------
	kernel BUG at fs/fscache/operation.c:414!

With a backtrace like the following:

RIP: 0010:[&lt;ffffffffa0211b1d&gt;] fscache_put_operation+0x1ad/0x240 [fscache]
Call Trace:
 [&lt;ffffffffa0213185&gt;] fscache_retrieval_work+0x55/0x270 [fscache]
 [&lt;ffffffffa0213130&gt;] ? fscache_retrieval_work+0x0/0x270 [fscache]
 [&lt;ffffffff81090b10&gt;] worker_thread+0x170/0x2a0
 [&lt;ffffffff81096d10&gt;] ? autoremove_wake_function+0x0/0x40
 [&lt;ffffffff810909a0&gt;] ? worker_thread+0x0/0x2a0
 [&lt;ffffffff81096966&gt;] kthread+0x96/0xa0
 [&lt;ffffffff8100c0ca&gt;] child_rip+0xa/0x20
 [&lt;ffffffff810968d0&gt;] ? kthread+0x0/0xa0
 [&lt;ffffffff8100c0c0&gt;] ? child_rip+0x0/0x20

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Reviewed-and-tested-By: Milosz Tanski &lt;milosz@adfin.com&gt;
Acked-by: Jeff Layton &lt;jlayton@redhat.com&gt;
</content>
</entry>
</feed>
