Skip to content

Commit

Permalink
dm: use hugetlb by default
Browse files Browse the repository at this point in the history
use hugetlb to set vm memory by default.

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
  • Loading branch information
lifeix authored and lijinxia committed Jun 29, 2018
1 parent 136d5c3 commit 652e37e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 46 deletions.
14 changes: 6 additions & 8 deletions devicemodel/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 (;;) {
Expand Down
9 changes: 3 additions & 6 deletions devicemodel/core/vmmapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions devicemodel/include/vmmapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
4 changes: 2 additions & 2 deletions devicemodel/samples/apl-mrb/launch_uos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion devicemodel/samples/nuc/launch_uos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
42 changes: 15 additions & 27 deletions doc/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
**********************
Expand Down

0 comments on commit 652e37e

Please sign in to comment.