From: Wei Liu <wei.liu@kernel.org>
To: mhklinux@outlook.com
Cc: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
boqun.feng@gmail.com, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org
Subject: Re: [PATCH v2 1/1] Drivers: hv: vmbus: Calculate ring buffer size for more efficient use of memory
Date: Fri, 1 Mar 2024 09:25:12 +0000 [thread overview]
Message-ID: <ZeGe-C9SYUYXPa_7@liuwe-devbox-debian-v2> (raw)
In-Reply-To: <20240229004533.313662-1-mhklinux@outlook.com>
On Wed, Feb 28, 2024 at 04:45:33PM -0800, mhkelley58@gmail.com wrote:
> From: Michael Kelley <mhklinux@outlook.com>
>
> The VMBUS_RING_SIZE macro adds space for a ring buffer header to the
> requested ring buffer size. The header size is always 1 page, and so
> its size varies based on the PAGE_SIZE for which the kernel is built.
> If the requested ring buffer size is a large power-of-2 size and the header
> size is small, the resulting size is inefficient in its use of memory.
> For example, a 512 Kbyte ring buffer with a 4 Kbyte page size results in
> a 516 Kbyte allocation, which is rounded to up 1 Mbyte by the memory
> allocator, and wastes 508 Kbytes of memory.
>
> In such situations, the exact size of the ring buffer isn't that important,
> and it's OK to allocate the 4 Kbyte header at the beginning of the 512
> Kbytes, leaving the ring buffer itself with just 508 Kbytes. The memory
> allocation can be 512 Kbytes instead of 1 Mbyte and nothing is wasted.
>
> Update VMBUS_RING_SIZE to implement this approach for "large" ring buffer
> sizes. "Large" is somewhat arbitrarily defined as 8 times the size of
> the ring buffer header (which is of size PAGE_SIZE). For example, for
> 4 Kbyte PAGE_SIZE, ring buffers of 32 Kbytes and larger use the first
> 4 Kbytes as the ring buffer header. For 64 Kbyte PAGE_SIZE, ring buffers
> of 512 Kbytes and larger use the first 64 Kbytes as the ring buffer
> header. In both cases, smaller sizes add space for the header so
> the ring size isn't reduced too much by using part of the space for
> the header. For example, with a 64 Kbyte page size, we don't want
> a 128 Kbyte ring buffer to be reduced to 64 Kbytes by allocating half
> of the space for the header. In such a case, the memory allocation
> is less efficient, but it's the best that can be done.
>
> While the new algorithm slightly changes the amount of space allocated
> for ring buffers by drivers that use VMBUS_RING_SIZE, the devices aren't
> known to be sensitive to small changes in ring buffer size, so there
> shouldn't be any effect.
>
> Fixes: c1135c7fd0e9 ("Drivers: hv: vmbus: Introduce types of GPADL")
> Fixes: 6941f67ad37d ("hv_netvsc: Calculate correct ring size when PAGE_SIZE is not 4 Kbytes")
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218502
> Cc: stable@vger.kernel.org
> Signed-off-by: Michael Kelley <mhklinux@outlook.com>
> Reviewed-by: Saurabh Sengar <ssengar@linux.microsoft.com>
> Reviewed-by: Dexuan Cui <decui@microsoft.com>
> Tested-by: Souradeep Chakrabarti <schakrabarti@linux.microsoft.com>
Applied to hyperv-fixes, thanks!
prev parent reply other threads:[~2024-03-01 9:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 0:45 [PATCH v2 1/1] Drivers: hv: vmbus: Calculate ring buffer size for more efficient use of memory mhkelley58
2024-03-01 9:25 ` Wei Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZeGe-C9SYUYXPa_7@liuwe-devbox-debian-v2 \
--to=wei.liu@kernel.org \
--cc=boqun.feng@gmail.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhklinux@outlook.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.