* [PATCH 1/1] vhost scsi: allocate vhost_scsi with GFP_NOWAIT to avoid delay
@ 2021-01-21 5:03 Dongli Zhang
2021-01-21 9:00 ` Jason Wang
0 siblings, 1 reply; 3+ messages in thread
From: Dongli Zhang @ 2021-01-21 5:03 UTC (permalink / raw)
To: virtualization, kvm, netdev
Cc: linux-kernel, mst, jasowang, pbonzini, stefanha, joe.jin,
aruna.ramakrishna
The size of 'struct vhost_scsi' is order-10 (~2.3MB). It may take long time
delay by kzalloc() to compact memory pages when there is a lack of
high-order pages. As a result, there is latency to create a VM (with
vhost-scsi) or to hotadd vhost-scsi-based storage.
The prior commit 595cb754983d ("vhost/scsi: use vmalloc for order-10
allocation") prefers to fallback only when really needed, while this patch
changes allocation to GFP_NOWAIT in order to avoid the delay caused by
memory page compact.
Cc: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
Cc: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
Another option is to rework by reducing the size of 'struct vhost_scsi',
e.g., by replacing inline vhost_scsi.vqs with just memory pointers while
each vhost_scsi.vqs[i] should be allocated separately. Please let me
know if that option is better.
drivers/vhost/scsi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 4ce9f00ae10e..85eaa4e883f4 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1814,7 +1814,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
struct vhost_virtqueue **vqs;
int r = -ENOMEM, i;
- vs = kzalloc(sizeof(*vs), GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL);
+ vs = kzalloc(sizeof(*vs), GFP_NOWAIT | __GFP_NOWARN);
if (!vs) {
vs = vzalloc(sizeof(*vs));
if (!vs)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] vhost scsi: allocate vhost_scsi with GFP_NOWAIT to avoid delay
2021-01-21 5:03 [PATCH 1/1] vhost scsi: allocate vhost_scsi with GFP_NOWAIT to avoid delay Dongli Zhang
@ 2021-01-21 9:00 ` Jason Wang
2021-01-23 8:01 ` Dongli Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2021-01-21 9:00 UTC (permalink / raw)
To: Dongli Zhang, virtualization, kvm, netdev
Cc: linux-kernel, mst, pbonzini, stefanha, joe.jin, aruna.ramakrishna
On 2021/1/21 13:03, Dongli Zhang wrote:
> The size of 'struct vhost_scsi' is order-10 (~2.3MB). It may take long time
> delay by kzalloc() to compact memory pages when there is a lack of
> high-order pages. As a result, there is latency to create a VM (with
> vhost-scsi) or to hotadd vhost-scsi-based storage.
>
> The prior commit 595cb754983d ("vhost/scsi: use vmalloc for order-10
> allocation") prefers to fallback only when really needed, while this patch
> changes allocation to GFP_NOWAIT in order to avoid the delay caused by
> memory page compact.
>
> Cc: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
> Cc: Joe Jin <joe.jin@oracle.com>
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
> ---
> Another option is to rework by reducing the size of 'struct vhost_scsi',
> e.g., by replacing inline vhost_scsi.vqs with just memory pointers while
> each vhost_scsi.vqs[i] should be allocated separately. Please let me
> know if that option is better.
>
> drivers/vhost/scsi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 4ce9f00ae10e..85eaa4e883f4 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -1814,7 +1814,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
> struct vhost_virtqueue **vqs;
> int r = -ENOMEM, i;
>
> - vs = kzalloc(sizeof(*vs), GFP_KERNEL | __GFP_NOWARN | __GFP_RETRY_MAYFAIL);
> + vs = kzalloc(sizeof(*vs), GFP_NOWAIT | __GFP_NOWARN);
> if (!vs) {
> vs = vzalloc(sizeof(*vs));
> if (!vs)
Can we use kvzalloc?
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] vhost scsi: allocate vhost_scsi with GFP_NOWAIT to avoid delay
2021-01-21 9:00 ` Jason Wang
@ 2021-01-23 8:01 ` Dongli Zhang
0 siblings, 0 replies; 3+ messages in thread
From: Dongli Zhang @ 2021-01-23 8:01 UTC (permalink / raw)
To: Jason Wang, virtualization, kvm, netdev
Cc: linux-kernel, mst, pbonzini, stefanha, joe.jin, aruna.ramakrishna
On 1/21/21 1:00 AM, Jason Wang wrote:
>
> On 2021/1/21 13:03, Dongli Zhang wrote:
>> The size of 'struct vhost_scsi' is order-10 (~2.3MB). It may take long time
>> delay by kzalloc() to compact memory pages when there is a lack of
>> high-order pages. As a result, there is latency to create a VM (with
>> vhost-scsi) or to hotadd vhost-scsi-based storage.
>>
>> The prior commit 595cb754983d ("vhost/scsi: use vmalloc for order-10
>> allocation") prefers to fallback only when really needed, while this patch
>> changes allocation to GFP_NOWAIT in order to avoid the delay caused by
>> memory page compact.
>>
>> Cc: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
>> Cc: Joe Jin <joe.jin@oracle.com>
>> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
>> ---
>> Another option is to rework by reducing the size of 'struct vhost_scsi',
>> e.g., by replacing inline vhost_scsi.vqs with just memory pointers while
>> each vhost_scsi.vqs[i] should be allocated separately. Please let me
>> know if that option is better.
>>
>> drivers/vhost/scsi.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
>> index 4ce9f00ae10e..85eaa4e883f4 100644
>> --- a/drivers/vhost/scsi.c
>> +++ b/drivers/vhost/scsi.c
>> @@ -1814,7 +1814,7 @@ static int vhost_scsi_open(struct inode *inode, struct
>> file *f)
>> struct vhost_virtqueue **vqs;
>> int r = -ENOMEM, i;
>> - vs = kzalloc(sizeof(*vs), GFP_KERNEL | __GFP_NOWARN |
>> __GFP_RETRY_MAYFAIL);
>> + vs = kzalloc(sizeof(*vs), GFP_NOWAIT | __GFP_NOWARN);
>> if (!vs) {
>> vs = vzalloc(sizeof(*vs));
>> if (!vs)
>
>
> Can we use kvzalloc?
>
Thank you very much for the suggestion.
To use 'GFP_NOWAIT' will avoid any direct compact in __alloc_pages_slowpath(),
while to use kvzalloc() will just avoid retrying direct compact for multiple times.
Although the latter will still do direct compact (without retry), I think it is
better than the former using GFP_NOWAIT.
I will send v2 with kvzalloc().
Thank you very much!
Dongli Zhang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-23 8:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 5:03 [PATCH 1/1] vhost scsi: allocate vhost_scsi with GFP_NOWAIT to avoid delay Dongli Zhang
2021-01-21 9:00 ` Jason Wang
2021-01-23 8:01 ` Dongli Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).