KVM: Minor structure layout changes
v2 cover KVM: Minor structure layout changes
v1: https://lore.kernel.org/kvm/[email protected]/
This used to be a more exhaustive patch set shrinking kvm_vcpu's size. But we concluded that this would be too fragile to maintain and would require a more radical layout change to group often used members together instead of chopping off individual padding bytes.
The remaining two patches are nonetheless useful, as they either make the structure layout a more natural fit (as for kvm_pmu, putting the version atop) or removing pointless padding (kvm_mmu_memory_cache).
Please apply!
Thanks,
Mathias Krause (2):
KVM: x86: Shrink struct kvm_pmu
KVM: Shrink struct kvm_mmu_memory_cache
arch/x86/include/asm/kvm_host.h | 2 +- include/linux/kvm_types.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.1
PATCH v2 1/2 KVM: x86: Shrink struct kvm_pmu
Move the 'version' member to the beginning of the structure to reuse an existing hole instead of introducing another one.
This allows us to save 8 bytes for 64 bit builds.
--- arch/x86/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -516,6 +516,7 @@ struct kvm_pmc {#define KVM_PMC_MAX_FIXED 3#define KVM_AMD_PMC_MAX_GENERIC 6struct kvm_pmu { +u8 version;unsigned nr_arch_gp_counters;unsigned nr_arch_fixed_counters;unsigned available_event_types;
@@ -528,7 +529,6 @@ struct kvm_pmu {u64 global_ovf_ctrl_mask;u64 reserved_bits;u64 raw_event_mask; -u8 version;struct kvm_pmc gp_counters[KVM_INTEL_PMC_MAX_GENERIC ];struct kvm_pmc fixed_counters[KVM_PMC_MAX_FIXED ];struct irq_work irq_work;
Signature · 1 line
2.39.1
PATCH v2 2/2 KVM: Shrink struct kvm_mmu_memory_cache
In reply to Mathias KrauseMove the 'capacity' member around to make use of the padding hole on 64 bit systems instead of introducing yet another one.
This allows us to save 8 bytes per instance for 64 bit builds of which, e.g., x86's struct kvm_vcpu_arch has a few.
---
v2: use order as suggested by Sean
include/linux/kvm_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kvm_types.h +1 -1
@@ -91,11 +91,11 @@ struct gfn_to_pfn_cache {* is topped up (__kvm_mmu_topup_memory_cache()). */ struct kvm_mmu_memory_cache { -int nobjs;gfp_t gfp_zero;gfp_t gfp_custom;struct kmem_cache *kmem_cache;int capacity; +int nobjs;void **objects; };#endif
Signature · 1 line
2.39.1
Sean Christopherson
maintainerRe: [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache
Quoted 1 line · Mathias Krause
Move the 'capacity' member around to make use of the padding hole on 64
Nit, 'nobjs' is the field that gets moved in this version. No need for another version, I can fix up when applying.
If no one objects, I'll plan on taking this through kvm-x86/generic.
Re: [PATCH v2 2/2] KVM: Shrink struct kvm_mmu_memory_cache
Quoted 5 lines · Sean Christopherson
Quoted 1 line · Mathias Krause
Move the 'capacity' member around to make use of the padding hole on 64
Nit, 'nobjs' is the field that gets moved in this version. No need for another version, I can fix up when applying.
Ahh, forgot to update the changelog after switching the layout. But as it was 'nobjs' next to 'capacity' for both variants, I wrongly thought there's no need to. But sure, you're right.
Quoted 2 lines
If no one objects, I'll plan on taking this through kvm-x86/generic.
Thanks,
Mathias
Quoted 8 lines · Mathias Krause
v1: https://lore.kernel.org/kvm/[email protected]/
This used to be a more exhaustive patch set shrinking kvm_vcpu's size. But we concluded that this would be too fragile to maintain and would require a more radical layout change to group often used members together instead of chopping off individual padding bytes.
[...]
Applied patch 1 to kvm-x86 pmu, and patch 2 to generic, thanks!
[1/2] KVM: x86: Shrink struct kvm_pmu
https://github.com/kvm-x86/linux/commit/12aad9164763 [2/2] KVM: Shrink struct kvm_mmu_memory_cache https://github.com/kvm-x86/linux/commit/f530b531fb9e
--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes