Skip to content

Commit b817e22

Browse files
Jia Zhubrauner
authored andcommitted
cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode
Don't trigger EPOLLIN when there are only reopening read requests in xarray. Suggested-by: Xin Yin <[email protected]> Signed-off-by: Jia Zhu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jingbo Xu <[email protected]> Reviewed-by: David Howells <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 0a7e54c commit b817e22

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

fs/cachefiles/daemon.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,24 @@ static __poll_t cachefiles_daemon_poll(struct file *file,
355355
struct poll_table_struct *poll)
356356
{
357357
struct cachefiles_cache *cache = file->private_data;
358+
XA_STATE(xas, &cache->reqs, 0);
359+
struct cachefiles_req *req;
358360
__poll_t mask;
359361

360362
poll_wait(file, &cache->daemon_pollwq, poll);
361363
mask = 0;
362364

363365
if (cachefiles_in_ondemand_mode(cache)) {
364-
if (!xa_empty(&cache->reqs))
365-
mask |= EPOLLIN;
366+
if (!xa_empty(&cache->reqs)) {
367+
rcu_read_lock();
368+
xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) {
369+
if (!cachefiles_ondemand_is_reopening_read(req)) {
370+
mask |= EPOLLIN;
371+
break;
372+
}
373+
}
374+
rcu_read_unlock();
375+
}
366376
} else {
367377
if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))
368378
mask |= EPOLLIN;

fs/cachefiles/internal.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ cachefiles_ondemand_set_object_##_state(struct cachefiles_object *object) \
329329
CACHEFILES_OBJECT_STATE_FUNCS(open, OPEN);
330330
CACHEFILES_OBJECT_STATE_FUNCS(close, CLOSE);
331331
CACHEFILES_OBJECT_STATE_FUNCS(reopening, REOPENING);
332+
333+
static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req)
334+
{
335+
return cachefiles_ondemand_object_is_reopening(req->object) &&
336+
req->msg.opcode == CACHEFILES_OP_READ;
337+
}
338+
332339
#else
333340
static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
334341
char __user *_buffer, size_t buflen)
@@ -359,6 +366,11 @@ static inline int cachefiles_ondemand_init_obj_info(struct cachefiles_object *ob
359366
static inline void cachefiles_ondemand_deinit_obj_info(struct cachefiles_object *obj)
360367
{
361368
}
369+
370+
static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *req)
371+
{
372+
return false;
373+
}
362374
#endif
363375

364376
/*

0 commit comments

Comments
 (0)