Skip to content

Commit

Permalink
Merge tag 'fscache-fixes-20220831' of git://git.kernel.org/pub/scm/li…
Browse files Browse the repository at this point in the history
…nux/kernel/git/dhowells/linux-fs

Pull fscache/cachefiles fixes from David Howells:

 - Fix kdoc on fscache_use/unuse_cookie().

 - Fix the error returned by cachefiles_ondemand_copen() from an upcall
   result.

 - Fix the distribution of requests in on-demand mode in cachefiles to
   be fairer by cycling through them rather than picking the one with
   the lowest ID each time (IDs being reused).

* tag 'fscache-fixes-20220831' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
  cachefiles: make on-demand request distribution fairer
  cachefiles: fix error return code in cachefiles_ondemand_copen()
  fscache: fix misdocumented parameter
  • Loading branch information
torvalds committed Aug 31, 2022
2 parents a1f7642 + 1122f40 commit c5e4d5e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions fs/cachefiles/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct cachefiles_cache {
char *tag; /* cache binding tag */
refcount_t unbind_pincount;/* refcount to do daemon unbind */
struct xarray reqs; /* xarray of pending on-demand requests */
unsigned long req_id_next;
struct xarray ondemand_ids; /* xarray for ondemand_id allocation */
u32 ondemand_id_next;
};
Expand Down
22 changes: 16 additions & 6 deletions fs/cachefiles/ondemand.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)

/* fail OPEN request if daemon reports an error */
if (size < 0) {
if (!IS_ERR_VALUE(size))
size = -EINVAL;
req->error = size;
if (!IS_ERR_VALUE(size)) {
req->error = -EINVAL;
ret = -EINVAL;
} else {
req->error = size;
ret = 0;
}
goto out;
}

Expand Down Expand Up @@ -238,14 +242,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
unsigned long id = 0;
size_t n;
int ret = 0;
XA_STATE(xas, &cache->reqs, 0);
XA_STATE(xas, &cache->reqs, cache->req_id_next);

/*
* Search for a request that has not ever been processed, to prevent
* requests from being processed repeatedly.
* Cyclically search for a request that has not ever been processed,
* to prevent requests from being processed repeatedly, and make
* request distribution fair.
*/
xa_lock(&cache->reqs);
req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW);
if (!req && cache->req_id_next > 0) {
xas_set(&xas, 0);
req = xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW);
}
if (!req) {
xa_unlock(&cache->reqs);
return 0;
Expand All @@ -260,6 +269,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
}

xas_clear_mark(&xas, CACHEFILES_REQ_NEW);
cache->req_id_next = xas.xa_index + 1;
xa_unlock(&cache->reqs);

id = xas.xa_index;
Expand Down
4 changes: 2 additions & 2 deletions include/linux/fscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ struct fscache_cookie *fscache_acquire_cookie(struct fscache_volume *volume,

/**
* fscache_use_cookie - Request usage of cookie attached to an object
* @object: Object description
* @cookie: The cookie representing the cache object
* @will_modify: If cache is expected to be modified locally
*
* Request usage of the cookie attached to an object. The caller should tell
Expand All @@ -274,7 +274,7 @@ static inline void fscache_use_cookie(struct fscache_cookie *cookie,

/**
* fscache_unuse_cookie - Cease usage of cookie attached to an object
* @object: Object description
* @cookie: The cookie representing the cache object
* @aux_data: Updated auxiliary data (or NULL)
* @object_size: Revised size of the object (or NULL)
*
Expand Down

0 comments on commit c5e4d5e

Please sign in to comment.