Commit 5602ffe8 authored by Baokun Li's avatar Baokun Li Committed by Zizhi Wo
Browse files

cachefiles: add support for buffer I/O in ondemand mode

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT



--------------------------------

Make cachefiles support buffer I/O when reading and writing backend files,
which reduces the latency of concurrent reads when there is a local cache.
This can be useful in container batch recovery scenarios.

>>> arm64 nvme:
  ext4 BIO no cache 1399MiB/s, 8t 11.5GiB/s,
           with cache 1t 1880MiB/s, 8t 12.7GiB/s.

thread|type | cache miss | local cache | erofs pagecache |
------+-----+------------+-------------+-----------------|
  1t  | DIO | 243 MiB/s  | 898 MiB/s   | 1907 MiB/s      |
  1t  | BIO | 243 MiB/s  | 1147 MiB/s  | 1894MiB/s       |
                            +27%
------+-----+------------+-------------+-----------------|
  8t  | DIO | 1950 MiB/s | 5155 MiB/s  | 12.8GiB/s       |
  8t  | BIO | 1951 MiB/s | 11.2GiB/s   | 12.6GiB/s       |
                            +122%

>>> x86 HDD:
  ext4 BIO no cache 494MiB/s, 8t 3949MiB/s,
           with cache 1t 1066MiB/s, 8t 8669MiB/s.
thread|type | cache miss | local cache | erofs pagecache |
------+-----+------------+-------------+-----------------|
  1t  | DIO | 228 MiB/s  | 493 MiB/s   | 1133 MiB/s      |
  1t  | BIO | 224 MiB/s  | 858 MiB/s   | 1133 MiB/s      |
                            +74%
------+-----+------------+-------------+-----------------|
  8t  | DIO | 1885 MiB/s | 3893 MiB/s  | 8357 MiB/s      |
  8t  | BIO | 1898 MiB/s | 7948 MiB/s  | 8357 MiB/s      |
                            +104%

The controls are the same as in the lower versions and also affect only
the on-demand mode.

Enable:
 modprobe cachefiles buffered_ondemand=1
 echo 1 > /sys/module/cachefiles/parameters/buffered_ondemand

Disable:
 modprobe cachefiles buffered_ondemand=0
 echo 0 > /sys/module/cachefiles/parameters/buffered_ondemand

Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
Signed-off-by: default avatarZizhi Wo <wozizhi@huawei.com>
parent b49c0e63
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -12,8 +12,12 @@
#include <linux/falloc.h>
#include <linux/sched/mm.h>
#include <trace/events/fscache.h>
#include <linux/module.h>
#include "internal.h"

static bool cachefiles_buffered_ondemand = true;
module_param_named(buffered_ondemand, cachefiles_buffered_ondemand, bool, 0644);

struct cachefiles_kiocb {
	struct kiocb		iocb;
	refcount_t		ki_refcnt;
@@ -78,6 +82,7 @@ static int cachefiles_read(struct netfs_cache_resources *cres,
			   void *term_func_priv)
{
	struct cachefiles_object *object;
	struct cachefiles_cache *cache;
	struct cachefiles_kiocb *ki;
	struct file *file;
	unsigned int old_nofs;
@@ -89,6 +94,7 @@ static int cachefiles_read(struct netfs_cache_resources *cres,

	fscache_count_read();
	object = cachefiles_cres_object(cres);
	cache = object->volume->cache;
	file = cachefiles_cres_file(cres);

	_enter("%pD,%li,%llx,%zx/%llx",
@@ -146,6 +152,9 @@ static int cachefiles_read(struct netfs_cache_resources *cres,
	ki->term_func_priv	= term_func_priv;
	ki->was_async		= true;

	if (cachefiles_in_ondemand_mode(cache) && cachefiles_buffered_ondemand)
		ki->iocb.ki_flags &= ~IOCB_DIRECT;

	if (ki->term_func)
		ki->iocb.ki_complete = cachefiles_read_complete;

@@ -315,6 +324,9 @@ int __cachefiles_write(struct cachefiles_object *object,
	ki->was_async		= true;
	ki->b_writing		= (len + (1 << cache->bshift) - 1) >> cache->bshift;

	if (cachefiles_in_ondemand_mode(cache) && cachefiles_buffered_ondemand)
		ki->iocb.ki_flags &= ~IOCB_DIRECT;

	if (ki->term_func)
		ki->iocb.ki_complete = cachefiles_write_complete;
	atomic_long_add(ki->b_writing, &cache->b_writing);