[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v1 09/13] util/mmap-alloc: Implement resizable mmaps
From: |
David Hildenbrand |
Subject: |
Re: [PATCH v1 09/13] util/mmap-alloc: Implement resizable mmaps |
Date: |
Thu, 6 Feb 2020 14:22:55 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 |
On 06.02.20 13:08, Richard Henderson wrote:
> On 2/3/20 6:31 PM, David Hildenbrand wrote:
>> +void *qemu_ram_mmap_resize(void *ptr, int fd, size_t old_size, size_t
>> new_size,
>> + bool shared, bool is_pmem)
>> {
>> const size_t pagesize = mmap_pagesize(fd);
>>
>> /* we can only map whole pages */
>> - size = QEMU_ALIGN_UP(size, pagesize);
>> + old_size = QEMU_ALIGN_UP(old_size, pagesize);
>> + new_size = QEMU_ALIGN_UP(new_size, pagesize);
>> +
>> + /* we support actually resizable memory regions only on Linux */
>> + if (old_size < new_size) {
>> + /* populate the missing piece into the reserved area */
>> + ptr = mmap_populate(ptr + old_size, new_size - old_size, fd,
>> old_size,
>> + shared, is_pmem);
>> + } else if (old_size > new_size) {
>> + /* discard this piece, keeping the area reserved (should never
>> fail) */
>> + ptr = mmap_reserve(ptr + new_size, old_size - new_size, fd);
>> + }
>> + return ptr;
>> +}
>
> What does the return value indicate?
> Is it just for != MAP_FAILED?
It indicates if resizing succeeded. In a previous version I returned an
int via
ptr == MAP_FAILED ? -errno : 0;
Populating will usually only fail because we're out of memory.
Populating and reserving *might* fail if we are out of VMAs in the
kernel. VMA merging will make sure that the number of VMAs will not
explode (usually 2-3 VMAs for one resizable region: populated VMA +
Reserved VMA + Guard page VMA). But once we would be close to the VMA
limit, it could happen - but it's highly unlikely.
> Assuming an assert isn't viable, are we better off with a boolean return?
> With
> an Error **ptr?
either that or an int. What do you prefer?
Thanks!
--
Thanks,
David / dhildenb
- [PATCH v1 05/13] util/mmap-alloc: Factor out calculation of pagesize to mmap_pagesize(), (continued)
- [PATCH v1 05/13] util/mmap-alloc: Factor out calculation of pagesize to mmap_pagesize(), David Hildenbrand, 2020/02/03
- [PATCH v1 07/13] util/mmap-alloc: Factor out populating of memory to mmap_populate(), David Hildenbrand, 2020/02/03
- [PATCH v1 10/13] numa: Introduce ram_block_notify_resized() and ram_block_notifiers_support_resize(), David Hildenbrand, 2020/02/03
- [PATCH v1 09/13] util/mmap-alloc: Implement resizable mmaps, David Hildenbrand, 2020/02/03
- Re: [PATCH v1 09/13] util/mmap-alloc: Implement resizable mmaps, Murilo Opsfelder Araújo, 2020/02/06
- [PATCH v1 08/13] util/mmap-alloc: Prepare for resizable mmaps, David Hildenbrand, 2020/02/03
- Re: [PATCH v1 08/13] util/mmap-alloc: Prepare for resizable mmaps, David Hildenbrand, 2020/02/06
Re: [PATCH v1 08/13] util/mmap-alloc: Prepare for resizable mmaps, Richard Henderson, 2020/02/06