* [PATCH] arm: Do not add padding alignment for hugetlbfs backed memory
@ 2023-04-05 11:09 Suzuki K Poulose
2023-04-05 11:22 ` Marc Zyngier
2023-04-06 15:51 ` Will Deacon
0 siblings, 2 replies; 3+ messages in thread
From: Suzuki K Poulose @ 2023-04-05 11:09 UTC (permalink / raw)
To: will; +Cc: kvmarm, linux-arm-kernel, alexandru.elisei, maz, Suzuki K Poulose
The arm code tries to align the memory allocation size to 2M to potentially
make use of the transparent hugepages. But this would be problematic if we
try to allocate from the hugetlbfs, where the allocation size could be more than
2M. Given we support upto 1G, let use leave it to the user to align the
requested memory when hugetlbfs is used.
Without the patch:
$ echo 1 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
$ mount -t hugetlbfs -o pagesize=1G none /root/hugemem/
$ lkvm run -m 1024 --hugetlbfs /root/hugemem/ ...
# lkvm run -k ... -m 1024 -c 6
Fatal: Can't ftruncate for mem mapping size 1075838976
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
arm/kvm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arm/kvm.c b/arm/kvm.c
index d51cc15d..9f958232 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -37,7 +37,9 @@ void kvm__init_ram(struct kvm *kvm)
* 2M trumps 64K, so let's go with that.
*/
kvm->ram_size = kvm->cfg.ram_size;
- kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
+ kvm->arch.ram_alloc_size = kvm->ram_size;
+ if (!kvm->cfg.hugetlbfs_path)
+ kvm->arch.ram_alloc_size += SZ_2M;
kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm,
kvm->cfg.hugetlbfs_path,
kvm->arch.ram_alloc_size);
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] arm: Do not add padding alignment for hugetlbfs backed memory
2023-04-05 11:09 [PATCH] arm: Do not add padding alignment for hugetlbfs backed memory Suzuki K Poulose
@ 2023-04-05 11:22 ` Marc Zyngier
2023-04-06 15:51 ` Will Deacon
1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2023-04-05 11:22 UTC (permalink / raw)
To: Suzuki K Poulose; +Cc: will, kvmarm, linux-arm-kernel, alexandru.elisei
On Wed, 05 Apr 2023 12:09:05 +0100,
Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> The arm code tries to align the memory allocation size to 2M to potentially
> make use of the transparent hugepages. But this would be problematic if we
> try to allocate from the hugetlbfs, where the allocation size could be more than
> 2M. Given we support upto 1G, let use leave it to the user to align the
> requested memory when hugetlbfs is used.
>
> Without the patch:
> $ echo 1 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
> $ mount -t hugetlbfs -o pagesize=1G none /root/hugemem/
> $ lkvm run -m 1024 --hugetlbfs /root/hugemem/ ...
> # lkvm run -k ... -m 1024 -c 6
> Fatal: Can't ftruncate for mem mapping size 1075838976
>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
> arm/kvm.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arm/kvm.c b/arm/kvm.c
> index d51cc15d..9f958232 100644
> --- a/arm/kvm.c
> +++ b/arm/kvm.c
> @@ -37,7 +37,9 @@ void kvm__init_ram(struct kvm *kvm)
> * 2M trumps 64K, so let's go with that.
> */
> kvm->ram_size = kvm->cfg.ram_size;
> - kvm->arch.ram_alloc_size = kvm->ram_size + SZ_2M;
> + kvm->arch.ram_alloc_size = kvm->ram_size;
> + if (!kvm->cfg.hugetlbfs_path)
> + kvm->arch.ram_alloc_size += SZ_2M;
> kvm->arch.ram_alloc_start = mmap_anon_or_hugetlbfs(kvm,
> kvm->cfg.hugetlbfs_path,
> kvm->arch.ram_alloc_size);
Seems sensible. For hugetlbfs, we're guaranteed that the memory is
aligned, so no need for any additional alignment (which is what this
+2MB was about).
Acked-by: Marc Zyngier <maz@kernel.org>
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm: Do not add padding alignment for hugetlbfs backed memory
2023-04-05 11:09 [PATCH] arm: Do not add padding alignment for hugetlbfs backed memory Suzuki K Poulose
2023-04-05 11:22 ` Marc Zyngier
@ 2023-04-06 15:51 ` Will Deacon
1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2023-04-06 15:51 UTC (permalink / raw)
To: Suzuki K Poulose
Cc: catalin.marinas, kernel-team, Will Deacon, maz, alexandru.elisei,
linux-arm-kernel, kvmarm
On Wed, 5 Apr 2023 12:09:05 +0100, Suzuki K Poulose wrote:
> The arm code tries to align the memory allocation size to 2M to potentially
> make use of the transparent hugepages. But this would be problematic if we
> try to allocate from the hugetlbfs, where the allocation size could be more than
> 2M. Given we support upto 1G, let use leave it to the user to align the
> requested memory when hugetlbfs is used.
>
> Without the patch:
> $ echo 1 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
> $ mount -t hugetlbfs -o pagesize=1G none /root/hugemem/
> $ lkvm run -m 1024 --hugetlbfs /root/hugemem/ ...
> # lkvm run -k ... -m 1024 -c 6
> Fatal: Can't ftruncate for mem mapping size 1075838976
>
> [...]
Applied to kvmtool (master), thanks!
[1/1] arm: Do not add padding alignment for hugetlbfs backed memory
https://git.kernel.org/will/kvmtool/c/77b108c6a6f1
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-06 15:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-05 11:09 [PATCH] arm: Do not add padding alignment for hugetlbfs backed memory Suzuki K Poulose
2023-04-05 11:22 ` Marc Zyngier
2023-04-06 15:51 ` Will Deacon
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).