[PATCH v2 4/6] util/oslib-posix: Avoid creating a single thread with MADV_POPULATE_WRITE

David Hildenbrand posted 6 patches 4 years, 6 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
[PATCH v2 4/6] util/oslib-posix: Avoid creating a single thread with MADV_POPULATE_WRITE
Posted by David Hildenbrand 4 years, 6 months ago
Let's simplify the case when we only want a single thread and don't have
to mess with signal handlers.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 util/oslib-posix.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index a1d309d495..1483e985c6 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -568,6 +568,14 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
     }
 
     if (use_madv_populate_write) {
+        /* Avoid creating a single thread for MADV_POPULATE_WRITE */
+        if (context.num_threads == 1) {
+            if (qemu_madvise(area, hpagesize * numpages,
+                             QEMU_MADV_POPULATE_WRITE)) {
+                return true;
+            }
+            return false;
+        }
         touch_fn = do_madv_populate_write_pages;
     } else {
         touch_fn = do_touch_pages;
-- 
2.31.1


Re: [PATCH v2 4/6] util/oslib-posix: Avoid creating a single thread with MADV_POPULATE_WRITE
Posted by Dr. David Alan Gilbert 4 years, 6 months ago
* David Hildenbrand (david@redhat.com) wrote:
> Let's simplify the case when we only want a single thread and don't have
> to mess with signal handlers.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  util/oslib-posix.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index a1d309d495..1483e985c6 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -568,6 +568,14 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
>      }
>  
>      if (use_madv_populate_write) {
> +        /* Avoid creating a single thread for MADV_POPULATE_WRITE */
> +        if (context.num_threads == 1) {
> +            if (qemu_madvise(area, hpagesize * numpages,
> +                             QEMU_MADV_POPULATE_WRITE)) {

Do you never have to fall back if this particular memory region is the
one that can't do madv?

Dave

> +                return true;
> +            }
> +            return false;
> +        }
>          touch_fn = do_madv_populate_write_pages;
>      } else {
>          touch_fn = do_touch_pages;
> -- 
> 2.31.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


Re: [PATCH v2 4/6] util/oslib-posix: Avoid creating a single thread with MADV_POPULATE_WRITE
Posted by David Hildenbrand 4 years, 6 months ago
On 27.07.21 21:04, Dr. David Alan Gilbert wrote:
> * David Hildenbrand (david@redhat.com) wrote:
>> Let's simplify the case when we only want a single thread and don't have
>> to mess with signal handlers.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>   util/oslib-posix.c | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
>> index a1d309d495..1483e985c6 100644
>> --- a/util/oslib-posix.c
>> +++ b/util/oslib-posix.c
>> @@ -568,6 +568,14 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
>>       }
>>   
>>       if (use_madv_populate_write) {
>> +        /* Avoid creating a single thread for MADV_POPULATE_WRITE */
>> +        if (context.num_threads == 1) {
>> +            if (qemu_madvise(area, hpagesize * numpages,
>> +                             QEMU_MADV_POPULATE_WRITE)) {
> 
> Do you never have to fall back if this particular memory region is the
> one that can't do madv?

We sense upfront, when detecting use_madv_populate_write, whether it's 
supported on this very memory type. So, no need to fallback here.

> 
> Dave

-- 
Thanks,

David / dhildenb


Re: [PATCH v2 4/6] util/oslib-posix: Avoid creating a single thread with MADV_POPULATE_WRITE
Posted by Pankaj Gupta 4 years, 6 months ago
> Let's simplify the case when we only want a single thread and don't have
> to mess with signal handlers.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  util/oslib-posix.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index a1d309d495..1483e985c6 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -568,6 +568,14 @@ static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages,
>      }
>
>      if (use_madv_populate_write) {
> +        /* Avoid creating a single thread for MADV_POPULATE_WRITE */
> +        if (context.num_threads == 1) {
> +            if (qemu_madvise(area, hpagesize * numpages,
> +                             QEMU_MADV_POPULATE_WRITE)) {
> +                return true;
> +            }
> +            return false;
> +        }
>          touch_fn = do_madv_populate_write_pages;
>      } else {
>          touch_fn = do_touch_pages;

Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com>