dm: use hugetlb by default

use hugetlb to set vm memory by default.

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
This commit is contained in:
Li, Fei1 2018-06-29 10:54:16 +08:00 committed by lijinxia
parent 136d5c30fb
commit 652e37e908
6 changed files with 27 additions and 46 deletions

View File

@ -72,7 +72,6 @@ char *guest_uuid_str;
char *vsbl_file_name;
uint8_t trusty_enabled;
bool stdio_in_use;
bool hugetlb;
static int guest_vmexit_on_hlt, guest_vmexit_on_pause;
static int virtio_msix = 1;
@ -145,7 +144,6 @@ usage(int code)
" -U: uuid\n"
" -w: ignore unimplemented MSRs\n"
" -W: force virtio to use single-vector MSI\n"
" -T: use hugetlb for memory allocation\n"
" -x: local apic is in x2APIC mode\n"
" -Y: disable MPtable generation\n"
" -k: kernel image path\n"
@ -649,14 +647,13 @@ main(int argc, char *argv[])
mptgen = 1;
memflags = 0;
quit_vm_loop = 0;
hugetlb = 0;
if (signal(SIGHUP, sig_handler_term) == SIG_ERR)
fprintf(stderr, "cannot register handler for SIGHUP\n");
if (signal(SIGINT, sig_handler_term) == SIG_ERR)
fprintf(stderr, "cannot register handler for SIGINT\n");
optstr = "abehuwxACHIPSTWYvk:r:B:p:g:c:s:m:l:U:G:i:";
optstr = "abehuwxACHIPSWYvk:r:B:p:g:c:s:m:l:U:G:i:";
while ((c = getopt_long(argc, argv, optstr, long_options,
&option_idx)) != -1) {
switch (c) {
@ -740,10 +737,6 @@ main(int argc, char *argv[])
case 'W':
virtio_msix = 0;
break;
case 'T':
if (check_hugetlb_support())
hugetlb = 1;
break;
case 'x':
x2apic_mode = 1;
break;
@ -807,6 +800,11 @@ main(int argc, char *argv[])
if (argc != 1)
usage(1);
if (!check_hugetlb_support()) {
fprintf(stderr, "check_hugetlb_support failed\n");
exit(1);
}
vmname = argv[0];
for (;;) {

View File

@ -385,8 +385,7 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms)
objsize = ctx->lowmem;
}
if (hugetlb)
return hugetlb_setup_memory(ctx);
return hugetlb_setup_memory(ctx);
/*
* Stake out a contiguous region covering the guest physical memory
@ -431,10 +430,8 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms)
void
vm_unsetup_memory(struct vmctx *ctx)
{
if (hugetlb) {
hugetlb_unsetup_memory(ctx);
return;
}
hugetlb_unsetup_memory(ctx);
return;
if (ctx->lowmem > 0)
munmap(ctx->mmap_lowmem, ctx->lowmem);

View File

@ -159,6 +159,4 @@ int vm_reset_ptdev_intx_info(struct vmctx *ctx, int virt_pin, bool pic_pin);
int vm_create_vcpu(struct vmctx *ctx, uint16_t vcpu_id);
int vm_get_cpu_state(struct vmctx *ctx, void *state_buf);
extern bool hugetlb;
#endif /* _VMMAPI_H_ */

View File

@ -107,7 +107,7 @@ else
fi
acrn-dm -T -A -m $mem_size -c $2$boot_GVT_option"$GVT_args" -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
acrn-dm -A -m $mem_size -c $2$boot_GVT_option"$GVT_args" -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
-s 5,virtio-console,@pty:pty_port \
-s 6,virtio-hyper_dmabuf \
-s 8,wdt-i6300esb \
@ -274,7 +274,7 @@ else
GVT_args=''
fi
acrn-dm -T -A -m $mem_size -c $2$boot_GVT_option"$GVT_args" -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
acrn-dm -A -m $mem_size -c $2$boot_GVT_option"$GVT_args" -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
-l com1,stdio \
-s 9,virtio-net,$tap \
-s 3,virtio-blk$boot_dev_flag,/data/$5/$5.img \

View File

@ -19,7 +19,7 @@ mem_size=1000M
# make sure there is enough 2M hugepages in the pool
echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
acrn-dm -T -A -m $mem_size -c $2 -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
acrn-dm -A -m $mem_size -c $2 -s 0:0,hostbridge -s 1:0,lpc -l com1,stdio \
-s 2,pci-gvt -G "$3" \
-s 5,virtio-console,@pty:pty_port \
-s 6,virtio-hyper_dmabuf \

View File

@ -330,38 +330,26 @@ Set up Reference UOS
Device Manager memory allocation mechanism
==========================================
There are two Device Manager memory allocation mechanisms available:
The ACRN Device Manager (DM) virtual memory allocation uses the HugeTLB mechanism.
(You can read more about `HugeTLB in the linux kernel <https://linuxgazette.net/155/krishnakumar.html>`_
for more information about how this mechanism works.)
- Contiguous Memory Allocator (CMA), and
- Huge Page Tables (HugeTLB). HugeTLB is the default.
For hugeTLB to work, you'll need to reserve huge pages:
To choose CMA, do the following:
- For a (large) 1GB huge page reservation, add ``hugepagesz=1G hugepages=reserved_pg_num``
(for example, ``hugepagesz=1G hugepages=4``) to the SOS cmdline in
``acrn.conf`` (for EFI)
1) Add ``cma=reserved_mem_size@recommend_memory_offset-0``, (for example
``cma=2560M@0x100000000-0``) to the SOS cmdline in ``acrn.conf``
- For a (smaller) 2MB huge page reservation, after the SOS starts up, run the
command::
2) Start ``acrn-dm`` *without* the ``-T`` option
echo reserved_pg_num > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
To support HugeTLB, do the following:
1) Do huge page reservation
- For 1G huge page reservation, add ``hugepagesz=1G hugepages=reserved_pg_num``
(for example, ``hugepagesz=1G hugepages=4``) to the SOS cmdline in
``acrn.conf`` (for EFI)
- For 2M huge page reservation, after the SOS starts up, run the
command::
echo reserved_pg_num > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
.. note::
You can use 2M reserving method to do reservation for 1G page size, but it
may fail. For an EFI platform, you may skip 1G page reservation
by using a 2M page, but make sure your huge page reservation size is
large enough for your usage.
2) Start ``acrn-dm`` *with* the ``-T`` option.
.. note::
You can use 2M reserving method to do reservation for 1G page size, but it
may fail. For an EFI platform, you may skip 1G page reservation
by using a 2M page, but make sure your huge page reservation size is
large enough for your usage.
Build ACRN from Source
**********************