mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-04 19:17:34 +00:00
dm: block_if: support bypassing the Service VM's page cache
This patch adds an acrn-dm option `nocache` to bypass the Service VM's page cache. - By default, the Service VM's page cache is utilized. - If `nocache` is specified in acrn-dm parameters, the Service VM's page cache would be bypassed (opening the file/block with O_DIRECT flag). Example to bypass the Service VM's page cache: `add_virtual_device 5 virtio-blk iothread,mq=2,/dev/nvme2n1,writeback,nocache` Tracked-On: #8612 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
parent
63d41a75fa
commit
e2da306755
@ -829,6 +829,7 @@ blockif_open(const char *optstr, const char *ident, int queue_num, struct iothre
|
||||
int max_discard_sectors, max_discard_seg, discard_sector_alignment;
|
||||
off_t probe_arg[] = {0, 0};
|
||||
int aio_mode;
|
||||
int bypass_host_cache, open_flag;
|
||||
|
||||
pthread_once(&blockif_once, blockif_init);
|
||||
|
||||
@ -850,6 +851,9 @@ blockif_open(const char *optstr, const char *ident, int queue_num, struct iothre
|
||||
/* writethru is on by default */
|
||||
writeback = 0;
|
||||
|
||||
/* By default, do NOT bypass Service VM's page cache. */
|
||||
bypass_host_cache = 0;
|
||||
|
||||
candiscard = 0;
|
||||
|
||||
if (queue_num <= 0)
|
||||
@ -874,6 +878,8 @@ blockif_open(const char *optstr, const char *ident, int queue_num, struct iothre
|
||||
writeback = 0;
|
||||
else if (!strcmp(cp, "ro"))
|
||||
ro = 1;
|
||||
else if (!strcmp(cp, "nocache"))
|
||||
bypass_host_cache = 1;
|
||||
else if (!strncmp(cp, "discard", strlen("discard"))) {
|
||||
strsep(&cp, "=");
|
||||
if (cp != NULL) {
|
||||
@ -933,8 +939,12 @@ blockif_open(const char *optstr, const char *ident, int queue_num, struct iothre
|
||||
* after file is opened. Instead, we call fsync() after each write
|
||||
* operation to emulate it.
|
||||
*/
|
||||
open_flag = (ro ? O_RDONLY : O_RDWR);
|
||||
if (bypass_host_cache == 1) {
|
||||
open_flag |= O_DIRECT;
|
||||
}
|
||||
fd = open(nopt, open_flag);
|
||||
|
||||
fd = open(nopt, ro ? O_RDONLY : O_RDWR);
|
||||
if (fd < 0 && !ro) {
|
||||
/* Attempt a r/w fail with a r/o open */
|
||||
fd = open(nopt, O_RDONLY);
|
||||
|
Loading…
Reference in New Issue
Block a user