[Devel] [PATCH vz7] Create debugfs file with virtio balloon usage information
Alexander Atanasov
alexander.atanasov at virtuozzo.com
Fri Sep 23 11:03:25 MSK 2022
Hello,
On 22.09.22 20:45, Konstantin Khorenko wrote:
> On 05.09.2022 16:01, Konstantin Khorenko wrote:
>>> +static int virtio_balloon_debug_show(struct seq_file *f, void *offset)
>>> +{
>>> + struct virtio_balloon *vb = f->private;
>>> + u64 inflated_kb = vb->num_pages << (VIRTIO_BALLOON_PFN_SHIFT - 10);
>>
>> /*
>> * Balloon device works in 4K page units. So each page is pointed
>> to by
>> * multiple balloon pages. All memory counters in this driver are
>> in balloon
>> * page units.
>> */
>> #define VIRTIO_BALLOON_PAGES_PER_PAGE (unsigned)(PAGE_SIZE >>
>> VIRTIO_BALLOON_PFN_SHIFT)
>>
>> /* Size of a PFN in the balloon interface. */
>> #define VIRTIO_BALLOON_PFN_SHIFT 12
>>
>> Taking into account defines above, i think the proper code should be:
>> /* "+2" here because we want the value in kilobytes */
>> u64 inflated_kb = vb->num_pages << (PAGE_SHIFT -
>> VIRTIO_BALLOON_PFN_SHIFT + 2);
>>
>> As it's said VIRTIO_BALLOON_PAGE cannot be larger than PAGE_SIZE,
>> so if we imagine VIRTIO_BALLOON_PFN_SHIFT is defined to, say, 10, the
>> original code
>> "<< (VIRTIO_BALLOON_PFN_SHIFT - 10)" will definitely work wrong.
>
> And please, address this comment as well.
num_pages is accounted in balloon pages, so to make the calculation we
use only the VIRTIO_BALLOON_PFN_SHIFT.
So it is num_pages << (CONVERT TO BYTES - CONVERT TO KILO BYTES).
Using PAGE_SHIFT will be:
12 - 12 + 2 will do the same but if at some point they start to differ
the calculation will go wrong because it is mixing units - host vs
ballon page shifts.
--
Regards,
Alexander Atanasov
More information about the Devel
mailing list