[3/5] KVM: Shrink struct kvm_mmu_memory_cache

Message ID 20230213163351.30704-4-minipli@grsecurity.net
State New
Headers
Series [1/5] KVM: x86: Shrink struct kvm_pmu |

Commit Message

Mathias Krause Feb. 13, 2023, 4:33 p.m. UTC
  Move 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.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
 include/linux/kvm_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Sean Christopherson Feb. 13, 2023, 5:08 p.m. UTC | #1
On Mon, Feb 13, 2023, Mathias Krause wrote:
> Move 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.
> 
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> ---
>  include/linux/kvm_types.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
> index 76de36e56cdf..8e4f8fa31457 100644
> --- a/include/linux/kvm_types.h
> +++ b/include/linux/kvm_types.h
> @@ -92,10 +92,10 @@ struct gfn_to_pfn_cache {
>   */
>  struct kvm_mmu_memory_cache {
>  	int nobjs;
> +	int capacity;
>  	gfp_t gfp_zero;
>  	gfp_t gfp_custom;
>  	struct kmem_cache *kmem_cache;
> -	int capacity;
>  	void **objects;

If we touch this, I vote to do a more aggressive cleanup and place nobjs next
to objects, e.g.

struct kvm_mmu_memory_cache {
	gfp_t gfp_zero;
	gfp_t gfp_custom;
	struct kmem_cache *kmem_cache;
	int capacity;
	int nobjs;
	void **objects;
};
  
Mathias Krause Feb. 14, 2023, 12:20 p.m. UTC | #2
On 13.02.23 18:08, Sean Christopherson wrote:
> On Mon, Feb 13, 2023, Mathias Krause wrote:
>> Move 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.
>>
>> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
>> ---
>>  include/linux/kvm_types.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
>> index 76de36e56cdf..8e4f8fa31457 100644
>> --- a/include/linux/kvm_types.h
>> +++ b/include/linux/kvm_types.h
>> @@ -92,10 +92,10 @@ struct gfn_to_pfn_cache {
>>   */
>>  struct kvm_mmu_memory_cache {
>>  	int nobjs;
>> +	int capacity;
>>  	gfp_t gfp_zero;
>>  	gfp_t gfp_custom;
>>  	struct kmem_cache *kmem_cache;
>> -	int capacity;
>>  	void **objects;
> 
> If we touch this, I vote to do a more aggressive cleanup and place nobjs next
> to objects, e.g.
> 
> struct kvm_mmu_memory_cache {
> 	gfp_t gfp_zero;
> 	gfp_t gfp_custom;
> 	struct kmem_cache *kmem_cache;
> 	int capacity;
> 	int nobjs;
> 	void **objects;
> };

Ok
  

Patch

diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index 76de36e56cdf..8e4f8fa31457 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -92,10 +92,10 @@  struct gfn_to_pfn_cache {
  */
 struct kvm_mmu_memory_cache {
 	int nobjs;
+	int capacity;
 	gfp_t gfp_zero;
 	gfp_t gfp_custom;
 	struct kmem_cache *kmem_cache;
-	int capacity;
 	void **objects;
 };
 #endif