Hash Page Table resizing for PAPR guests
v2 cover Hash Page Table resizing for PAPR guests
This series implements the guest side of a PAPR ACR which allows a POWER guest's Hashed Page Table (HPT) to be resized at runtime. This is useful when a guest has a very large theoretical maximum RAM, but is likely to only ever be expanded to a modest amount of RAM in practice. Without resizing the HPT has to be sized for the maximum possible guest RAM, which can be very wasteful if that maximum is never reached.
To use this requires a hypervisor/host which also supports the PAPR extension. The only implementation so far is my qemu branch at
https://github.com/dgibson/qemu/tree/upstream/hpt-resize
I expect to merge that code to upstream qemu for qemu-2.9. Note that HPT resizing will so far only work for TCG guests, KVM support is in the works. The guest side code here will not require changing for KVM, however.
An HPT resize can be triggered in one of two ways:
* /sys/kernel/debug/powerpc/pft-size
This debugfs file contains the current size of the HPT (as encoded in the ibm,pft-size) device tree property. Writing to it will cause the guest to attempt an HPT resize to the given value. Note that the current qemu implementation will not allow the guest to resize the HPT to more than 1/64th of guest RAM size.
* Automatically on memory hotplug / unplug
With these patches applied, the guest will automatically attempt to resize its HPT when its RAM size changes due to hotplug events. (When hot adding RAM qemu considers the new size for purposes of the limit mentioned above, so this method can lift the HPT size larger than the former).
Changes since v1:
* Remove two patches which belong with the (upcoming) host side support rather than guest side (and therefore also should go via the kvm tree instead of the powerpc tree)
* Protected the debugfs code with #ifdef CONFIG_DEBUG_FS. Couldn't actually get a compile error myself, but the KVM buildbot did get one.
David Gibson (4):
pseries: Add hypercall wrappers for hash page table resizing
pseries: Add support for hash table resizing
pseries: Advertise HPT resizing support via CAS
pseries: Automatically resize HPT for memory hot add/remove
arch/powerpc/include/asm/book3s/64/mmu-hash.h | 1 + arch/powerpc/include/asm/firmware.h | 5 +- arch/powerpc/include/asm/hvcall.h | 4 +- arch/powerpc/include/asm/plpar_wrappers.h | 12 +++ arch/powerpc/include/asm/prom.h | 1 + arch/powerpc/include/asm/sparsemem.h | 1 + arch/powerpc/kernel/prom_init.c | 2 +- arch/powerpc/mm/hash_utils_64.c | 61 ++++++++++++++ arch/powerpc/mm/mem.c | 4 + arch/powerpc/platforms/pseries/firmware.c | 1 + arch/powerpc/platforms/pseries/lpar.c | 110 ++++++++++++++++++++++++++ 11 files changed, 198 insertions(+), 4 deletions(-)
Signature · 1 line
2.9.3
PATCH v2 1/4 pseries: Add hypercall wrappers for hash page table resizing
This adds the hypercall numbers and wrapper functions for the hash page table resizing hypercalls.
These are experimental "platform specific" values for now, until we have a formal PAPR update.
It also adds a new firmware feature flag to track the presence of the HPT resizing calls.
--- arch/powerpc/include/asm/firmware.h | 5 +++-- arch/powerpc/include/asm/hvcall.h | 4 +++- arch/powerpc/include/asm/plpar_wrappers.h | 12 ++++++++++++ arch/powerpc/platforms/pseries/firmware.c | 1 + 4 files changed, 19 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/firmware.h +3 -2
@@ -42,7 +42,7 @@#define FW_FEATURE_SPLPAR ASM_CONST(0x0000000000100000)#define FW_FEATURE_LPAR ASM_CONST(0x0000000000400000)#define FW_FEATURE_PS3_LV1 ASM_CONST(0x0000000000800000) -/* Free ASM_CONST(0x0000000001000000) */ +#define FW_FEATURE_HPT_RESIZE ASM_CONST(0x0000000001000000)#define FW_FEATURE_CMO ASM_CONST(0x0000000002000000)#define FW_FEATURE_VPHN ASM_CONST(0x0000000004000000)#define FW_FEATURE_XCMO ASM_CONST(0x0000000008000000)
@@ -66,7 +66,8 @@ enum {FW_FEATURE_MULTITCE |FW_FEATURE_SPLPAR |FW_FEATURE_LPAR |FW_FEATURE_CMO |FW_FEATURE_VPHN |FW_FEATURE_XCMO |FW_FEATURE_SET_MODE |FW_FEATURE_BEST_ENERGY | -FW_FEATURE_TYPE1_AFFINITY |FW_FEATURE_PRRN , +FW_FEATURE_TYPE1_AFFINITY |FW_FEATURE_PRRN | +FW_FEATURE_HPT_RESIZE ,FW_FEATURE_PSERIES_ALWAYS =0 ,FW_FEATURE_POWERNV_POSSIBLE =FW_FEATURE_OPAL , FW_FEATURE_POWERNV_ALWAYS = 0,
arch/powerpc/include/asm/hvcall.h +3 -1
@@ -275,7 +275,9 @@#define H_COP 0x304#define H_GET_MPP_X 0x314#define H_SET_MODE 0x31C -#define MAX_HCALL_OPCODE H_SET_MODE +#define H_RESIZE_HPT_PREPARE 0x36C +#define H_RESIZE_HPT_COMMIT 0x370 +#define MAX_HCALL_OPCODE H_RESIZE_HPT_COMMIT/* H_VIOCTL functions */ #define H_GET_VIOA_DUMP_SIZE 0x01
arch/powerpc/include/asm/plpar_wrappers.h +12 -0
@@ -242,6 +242,18 @@ static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,return plpar_hcall_norets (H_PROTECT , flags, ptex, avpn); } +static inline long plpar_resize_hpt_prepare (unsigned long flags, +unsigned long shift) +{ +return plpar_hcall_norets (H_RESIZE_HPT_PREPARE , flags, shift); +} + +static inline long plpar_resize_hpt_commit (unsigned long flags, +unsigned long shift) +{ +return plpar_hcall_norets (H_RESIZE_HPT_COMMIT , flags, shift); +} +static inline long plpar_tce_get (unsigned long liobn,unsigned long ioba,unsigned long *tce_ret) {
arch/powerpc/platforms/pseries/firmware.c +1 -0
@@ -64,6 +64,7 @@ hypertas_fw_features_table[] = { {FW_FEATURE_VPHN, "hcall-vphn"}, {FW_FEATURE_SET_MODE, "hcall-set-mode"}, {FW_FEATURE_BEST_ENERGY, "hcall-best-energy-1*"}, + {FW_FEATURE_HPT_RESIZE, "hcall-hpt-resize"}, };/* Build up the firmware features bitmask using the contents of
Signature · 1 line
2.9.3
Re: [PATCHv2, 1/4] pseries: Add hypercall wrappers for hash page table resizing
Quoted 8 lines · David Gibson
This adds the hypercall numbers and wrapper functions for the hash page table resizing hypercalls.
It also adds a new firmware feature flag to track the presence of the HPT resizing calls.
Signed-off-by David Gibson <[email protected]>Reviewed-by Paul Mackerras <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/64b40ffbc83029f035571cad9727e3
cheers
PATCH v2 2/4 pseries: Add support for hash table resizing
In reply to David GibsonThis adds support for using experimental hypercalls to change the size of the main hash page table while running as a PAPR guest. For now these hypercalls are only in experimental qemu versions.
The interface is two part: first H_RESIZE_HPT_PREPARE is used to allocate and prepare the new hash table. This may be slow, but can be done asynchronously. Then, H_RESIZE_HPT_COMMIT is used to switch to the new hash table. This requires that no CPUs be concurrently updating the HPT, and so must be run under stop_machine().
This also adds a debugfs file which can be used to manually control HPT resizing or testing purposes.
--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 1 + arch/powerpc/mm/hash_utils_64.c | 32 ++++++++ arch/powerpc/platforms/pseries/lpar.c | 110 ++++++++++++++++++++++++++ 3 files changed, 143 insertions(+)
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -0
@@ -153,6 +153,7 @@ struct mmu_hash_ops {unsigned long addr, unsigned char *hpte_slot_array, int psize, int ssize, int local); +int (*resize_hpt)(unsigned long shift);/* * Special for kexec. * To be called in real mode with interrupts disabled. No locks are
arch/powerpc/mm/hash_utils_64.c +32 -0
@@ -35,6 +35,7 @@#include <linux/memblock.h> #include <linux/context_tracking.h> #include <linux/libfdt.h> +#include <linux/debugfs.h> #include <asm/processor.h> #include <asm/pgtable.h>
@@ -1815,3 +1816,34 @@ void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base,/* Finally limit subsequent allocations */ memblock_set_current_limit (ppc64_rma_size); } + +#ifdef CONFIG_DEBUG_FS + +static int ppc64_pft_size_get (void *data,u64 *val) +{ + *val = ppc64_pft_size; +return 0 ; +} + +static int ppc64_pft_size_set (void *data,u64 val) +{ +if (!mmu_hash_ops.resize_hpt) +return -ENODEV ; +return mmu_hash_ops.resize_hpt (val); +} + +DEFINE_SIMPLE_ATTRIBUTE (fops_ppc64_pft_size, + ppc64_pft_size_get, ppc64_pft_size_set,"%llu\n" ); + +static int __init hash64_debugfs (void ) +{ +if (!debugfs_create_file ("pft-size" ,0600 , powerpc_debugfs_root, +NULL , &fops_ppc64_pft_size)) { +pr_err ("lpar: unable to create ppc64_pft_size debugsfs file\n" ); + } + +return 0 ; +} +machine_device_initcall (pseries, hash64_debugfs); + +#endif /* CONFIG_DEBUG_FS */
arch/powerpc/platforms/pseries/lpar.c +110 -0
128 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v2 3/4 pseries: Advertise HPT resizing support via CAS
In reply to David GibsonThe hypervisor needs to know a guest is capable of using the HPT resizing PAPR extension in order to make full advantage of it for memory hotplug.
If the hypervisor knows the guest is HPT resize aware, it can size the initial HPT based on the initial guest RAM size, relying on the guest to resize the HPT when more memory is hot-added. Without this, the hypervisor must size the HPT for the maximum possible guest RAM, which can lead to a huge waste of space if the guest never actually expends to that maximum size.
This patch advertises the guest's support for HPT resizing via the ibm,client-architecture-support OF interface. We use bit 5 of byte 6 of option vector 5 for this purpose (tentatively assigned in in-progress PAPR change request).
--- arch/powerpc/include/asm/prom.h | 1 + arch/powerpc/kernel/prom_init.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/prom.h +1 -0
@@ -151,6 +151,7 @@ struct of_drconf_cell {#define OV5_XCMO 0x0440/* Page Coalescing */ #define OV5_TYPE1_AFFINITY 0x0580/* Type 1 NUMA affinity */ #define OV5_PRRN 0x0540/* Platform Resource Reassignment */ +#define OV5_RESIZE_HPT 0x0601/* Hash Page Table resizing */ #define OV5_PFO_HW_RNG 0x0E80/* PFO Random Number Generator */ #define OV5_PFO_HW_842 0x0E40/* PFO Compression Accelerator */ #define OV5_PFO_HW_ENCR 0x0E20/* PFO Encryption Accelerator */
arch/powerpc/kernel/prom_init.c +1 -1
@@ -713,7 +713,7 @@ unsigned char ibm_architecture_vec[] = {0 , #endifOV5_FEAT (OV5_TYPE1_AFFINITY ) |OV5_FEAT (OV5_PRRN ), -0 , +OV5_FEAT (OV5_RESIZE_HPT ),0 , 0,/* WARNING: The offset of the "number of cores" field below
Signature · 1 line
2.9.3
PATCH v2 4/4 pseries: Automatically resize HPT for memory hot add/remove
In reply to David GibsonWe've now implemented code in the pseries platform to use the new PAPR interface to allow resizing the hash page table (HPT) at runtime.
This patch uses that interface to automatically attempt to resize the HPT when memory is hot added or removed. This tries to always keep the HPT at a reasonable size for our current memory size.
--- arch/powerpc/include/asm/sparsemem.h | 1 + arch/powerpc/mm/hash_utils_64.c | 29 +++++++++++++++++++++++++++++ arch/powerpc/mm/mem.c | 4 ++++ 3 files changed, 34 insertions(+)
arch/powerpc/include/asm/sparsemem.h +1 -0
@@ -16,6 +16,7 @@#endif /* CONFIG_SPARSEMEM */ #ifdef CONFIG_MEMORY_HOTPLUG +extern void resize_hpt_for_hotplug (unsigned long new_mem_size);extern int create_section_mapping (unsigned long start,unsigned long end);extern int remove_section_mapping (unsigned long start,unsigned long end);#ifdef CONFIG_NUMA
arch/powerpc/mm/hash_utils_64.c +29 -0
@@ -748,6 +748,35 @@ static unsigned long __init htab_get_table_size(void) }#ifdef CONFIG_MEMORY_HOTPLUG +void resize_hpt_for_hotplug (unsigned long new_mem_size) +{ +unsigned target_hpt_shift; + +if (!mmu_hash_ops.resize_hpt) +return ; + + target_hpt_shift =htab_shift_for_mem_size (new_mem_size); + +/* +* To avoid lots of HPT resizes if memory size is fluctuating +* across a boundary, we deliberately have some hysterisis +* here: we immediately increase the HPT size if the target +* shift exceeds the current shift, but we won't attempt to +* reduce unless the target shift is at least 2 below the +* current shift +*/ +if ((target_hpt_shift > ppc64_pft_size) + || (target_hpt_shift < (ppc64_pft_size -1 ))) { +int rc; + + rc = mmu_hash_ops.resize_hpt (target_hpt_shift); +if (rc) +printk (KERN_WARNING +"Unable to resize hash page table to target order %d: %d\n" , + target_hpt_shift, rc); + } +} +int create_section_mapping (unsigned long start,unsigned long end) { int rc = htab_bolt_mapping(start, end, __pa(start),
arch/powerpc/mm/mem.c +4 -0
@@ -134,6 +134,8 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)unsigned long nr_pages = size >>PAGE_SHIFT ;int rc; +resize_hpt_for_hotplug (memblock_phys_mem_size ()); + pgdata =NODE_DATA (nid); start = (unsigned long )__va (start);
@@ -174,6 +176,8 @@ int arch_remove_memory(u64 start, u64 size)*/ vm_unmap_aliases (); +resize_hpt_for_hotplug (memblock_phys_mem_size ()); + return ret; }#endif
Signature · 1 line
2.9.3