Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we increase the amount of RAM from 2 Gb? #311

Open
r3bb1t opened this issue Apr 24, 2024 · 17 comments
Open

How can we increase the amount of RAM from 2 Gb? #311

r3bb1t opened this issue Apr 24, 2024 · 17 comments

Comments

@r3bb1t
Copy link

r3bb1t commented Apr 24, 2024

First of all, thank you very much for this state-of-art emulator. Honestly, it's one of my most admired pieces of software known to me.

I wonder why, since the beginning, we are unable to have more than 2gb of ram? It's too little for year 2024. I, personally want to emulate Windows 10 and do some research by using Bochs.

I both wonder why the RAM limit didn't get bigger and how can community contribute if needed?

@stlintel
Copy link
Contributor

Where the 2GB comes from ?
On the host or on the guest ?
On the host, if you have 64-bit binary you are not limited to 2GB.
On the guest - you also have "memory" setting which allows you to have host and guest memory.
Please elaborate.

@r3bb1t
Copy link
Author

r3bb1t commented Apr 28, 2024

I cloned and built Bochs with the following commands:

git clone --recursive https://github.com/bochs-emu/Bochs
export CC=clang
export CXX=clang++
cd bochs
sh .conf.linux
make j`nproc`

I then launched bochs to set the RAM limits and got the following:

Bochs output
00000000000i[      ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/local/lib/bochs/plugins'
========================================================================
                   Bochs x86 Emulator 2.8.devel
           Built from GitHub snapshot after release 2.8
                Compiled on Apr 28 2024 at 12:45:22
========================================================================
00000000000i[      ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
00000000000i[      ] lt_dlhandle is 0x5a881f71d420
00000000000i[PLUGIN] loaded plugin libbx_speaker.so
00000000000i[      ] lt_dlhandle is 0x5a881f71e500
00000000000i[PLUGIN] loaded plugin libbx_gameport.so
00000000000i[      ] lt_dlhandle is 0x5a881f71ed60
00000000000i[PLUGIN] loaded plugin libbx_extfpuirq.so
00000000000i[      ] lt_dlhandle is 0x5a881f71f500
00000000000i[PLUGIN] loaded plugin libbx_unmapped.so
00000000000i[      ] lt_dlhandle is 0x5a881f71fd10
00000000000i[PLUGIN] loaded plugin libbx_biosdev.so
00000000000i[      ] lt_dlhandle is 0x5a881f720620
00000000000i[PLUGIN] loaded plugin libbx_parallel.so
00000000000i[      ] lt_dlhandle is 0x5a881f7222b0
00000000000i[PLUGIN] loaded plugin libbx_serial.so
00000000000i[      ] reading configuration from .bochsrc
00000000000e[      ] .bochsrc:791: ataX-master/slave CHS set to 0/0/0 - autodetection enabled
00000000000i[      ] lt_dlhandle is 0x5a881f726750
00000000000i[PLUGIN] loaded plugin libbx_textconfig.so
------------------------------
Bochs Configuration: Main Menu
------------------------------

This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate.  Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found.  When you are satisfied with the configuration, go
ahead and start the simulation.

You can also start bochs with the -q option to skip these menus.

1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now

Please choose one: [6] 3
------------------
Bochs Options Menu
------------------
0. Return to previous menu
1. Optional plugin control
2. Logfile options
3. Log options for all devices
4. Log options for individual devices
5. CPU options
6. CPUID options
7. Memory options
8. Clock & CMOS options
9. PCI options
10. Bochs Display & Interface options
11. Keyboard & Mouse options
12. Disk & Boot options
13. Serial / Parallel / USB options
14. Network card options
15. Sound card options
16. Other options
17. User-defined options

Please choose one: [0] 7

--------------
Memory Options
--------------
0. Return to previous menu
1. Standard Options
2. Optional ROM Images
3. Optional RAM Images

Please choose one: [0] 1

----------------
Standard Options
----------------
1. RAM size options
2. BIOS ROM options
3. VGABIOS ROM options

Please choose one: [0] 1

----------------
RAM size options
----------------

Enter memory size (MB): [512] 8192

Enter host memory size (MB): [256] 4096
Your choice (4096) was not an integer between 1 and 2048.

Enter host memory size (MB): [256] 


My Bochs binary is 64 bit.

fuzz@fuzz-pc:~/Desktop/Bochs/bochs$ file bochs
bochs: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ddc9298b7b1ccb01a65f3c28b7dad3d39137b6b5, for GNU/Linux 3.2.0, not stripped

I want to run a windows 10 guest and i want it to see 8gb of ram.

@Vort
Copy link
Contributor

Vort commented Apr 28, 2024

Looks like limit is set here:

Bochs/bochs/config.cc

Lines 864 to 869 in 58f4490

bx_param_num_c *host_ramsize = new bx_param_num_c(ram,
"host",
"Host allocated memory size (megabytes)",
"Amount of host allocated memory in megabytes",
1, 2048,
BX_DEFAULT_MEM_MEGS);

@stlintel
Copy link
Contributor

I want to run a windows 10 guest and i want it to see 8gb of ram

So use host = 2GB and guest as much as you want, even 16GB

@r3bb1t
Copy link
Author

r3bb1t commented Apr 28, 2024

I want to run a windows 10 guest and i want it to see 8gb of ram

So use host = 2GB and guest as much as you want, even 16GB

Okay, it's a bit confusing. I also want to provide the said amount of memory to the VM from host.

@sskras
Copy link
Contributor

sskras commented Apr 28, 2024

@stlintel commented 3 hours ago:

So use host = 2GB and guest as much as you want, even 16GB

Why do a user has the ability to change the memory used by "host" at all, please? I don't get the point.

@stlintel
Copy link
Contributor

Why not ?
if I would like to limit memory consumption by Bochs ?
Remember Bochs started ~20 years ago and not everybody had 2GB and 64-bit systems.

@r3bb1t
Copy link
Author

r3bb1t commented Apr 29, 2024

Alright, but now we need to let the host give more than 2gb of RAM for emulation. Just like with other emulators such as VMware for example.

@sskras
Copy link
Contributor

sskras commented Apr 29, 2024

@r3bb1t, the thing you mean about VMware is being set during the "Enter memory size (MB)" step, I guess.

And the "Enter host memory size (MB)" step defines the amount used for emulation of the guest I/O devices (not to store/emulate the guest RAM).

Have you tried running a guest with 16+2 GiBs and taking a look at the numbers shown by Windows Task Manager or Resource Monitor (Commit, Working Set, Shareable, Private) for your instance of bochs.exe?

@r3bb1t
Copy link
Author

r3bb1t commented Apr 29, 2024

@sskras
I previously tried to run windows on bochs both from windows and Linux hosts (like a year ago) and it was extremely slow. Even the installer's GUI was lagging. And eventually i couldn't install anything and eneded up getting error.

Can you please provide me some .bochsrc config file example for windows? Setting up bochs and especially it's CPU option is very confusing for me.

@sskras
Copy link
Contributor

sskras commented Apr 29, 2024

it was extremely slow. Even the installer's GUI was lagging.

It's because the emulation is pretty slow (and pretty accurate) in comparison with other emulators. With Bochs, it's more about simulation than emulation – that's the reason, I guess.

And eventually i couldn't install anything and eneded up getting error.

That might be a second, different issue.

Can you please provide me some .bochsrc config file example for windows?

Excuse me please, I haven't tried running Windows on it yet. At least you should mention the Windows version.

Setting up bochs and especially it's CPU option is very confusing for me.

CPU configuration might be another, probably the 3rd issue already.

@r3bb1t
Copy link
Author

r3bb1t commented Apr 29, 2024

Excuse me please, I haven't tried running Windows on it yet. At least you should mention the Windows version

My bad, any windows 10 version is fine.

@stlintel
Copy link
Contributor

@r3bb1t, the thing you mean about VMware is being set during the "Enter memory size (MB)" step, I guess.

for emulation of the guest I/O devices (not to store/emulate the guest RAM)

Wrong. Absolutely wrong.

BX_MEM(0)->init_memory(memSize, hostMemSize, memBlockSize);

this is the only place the hostMemSize used for.
And BX_MEM is used... guess for what.

BX_MEM_THIS vector = alloc_vector_aligned(host + BIOSROMSZ + EXROMSIZE + 4096, BX_MEM_VECTOR_ALIGN);

guest RAM

Have you tried running a guest with 16+2 GiBs and taking a look at the numbers shown by Windows Task Manager or Resource Monitor (Commit, Working Set, Shareable, Private) for your instance of bochs.exe?

Why ? These 16G would affect the amount memory Guest sees not the bochs.exe uses.

@sskras
Copy link
Contributor

sskras commented Apr 29, 2024

@r3bb1t, the thing you mean about VMware is being set during the "Enter memory size (MB)" step, I guess.
for emulation of the guest I/O devices (not to store/emulate the guest RAM)

Wrong. Absolutely wrong.

Thank you for fixing my guess, but:

BX_MEM(0)->init_memory(memSize, hostMemSize, memBlockSize);

this is the only place the hostMemSize used for. And BX_MEM is used... guess for what.

BX_MEM_THIS vector = alloc_vector_aligned(host + BIOSROMSZ + EXROMSIZE + 4096, BX_MEM_VECTOR_ALIGN);

guest RAM

... can you explain that for a Bochs user in a simple English, please? :)

For a user it's just hard to guess what does hostMemSize actually do and what is it responsible for. Especially with comparison to memSize.

IOW, we the users see two different parts responsible for memory, but not the whole picture.

Have you tried running a guest with 16+2 GiBs and taking a look at the numbers shown by Windows Task Manager or Resource Monitor (Commit, Working Set, Shareable, Private) for your instance of bochs.exe?

Why ? These 16G would affect the amount memory Guest sees not the bochs.exe uses.

Because of my assumption that if Bochs guest allocates all 16 gigs, the user would see more than 2 gigs (and less than 19 gigs) allocated in the host OS by the emulation process. If @r3bb1t runs the guest really needing 16 gigs, then that would be observable from the host OS too.

@sskras
Copy link
Contributor

sskras commented Apr 29, 2024

PS. OK @stlintel, now reading and trying to decipher a decade old answers from you and @vruppert: https://sourceforge.net/p/bochs/discussion/39592/thread/07aff11d/

OK, this seems to be more up to date:
https://bochs.sourceforge.io/doc/docbook/user/bochsrc.html#BOCHSOPT-MEMORY

guest

Set amount of guest physical memory to emulate. The default is 32MB, the maximum amount limited only by physical address space limitations.

host

Set amount of host memory you want to allocate for guest RAM emulation. It is possible to allocate less memory than you want to emulate in guest system. This will fake guest to see the non-existing memory. Once guest system touches new memory block it will be dynamically taken from the memory pool. You will be warned (by FATAL PANIC) in case guest already used all allocated host memory and wants more.

         Note: Due to limitations in the host OS, Bochs fails to allocate more than 1024MB on most 32-bit systems. In order to overcome this problem, configure and build Bochs with --enable-large-ramfile option.

So I circle back to the original question:

How to run a guest that needs to have its' 16 GiB of RAM allocated successfully on a 64-bit host OS with enough of free memory?

@stlintel
Copy link
Contributor

Just try to change the source code by overcoming limitation at:

Bochs/bochs/config.cc

Lines 864 to 869 in 58f4490

bx_param_num_c *host_ramsize = new bx_param_num_c(ram,
"host",
"Host allocated memory size (megabytes)",
"Amount of host allocated memory in megabytes",
1, 2048,
BX_DEFAULT_MEM_MEGS);

If it doesn't crash for you - we can make it into master.

@stlintel
Copy link
Contributor

Note: Due to limitations in the host OS, Bochs fails to allocate more than 1024MB on most 32-bit systems. In order to >overcome this problem, configure and build Bochs with --enable-large-ramfile option.

BTW, small extension. There is no FATAL PANIC anymore if configured and compiled with --enable-large-ramfile option (which should happen by default as well). With this option Bochs will never run out of memory, it will start managing its own private swap file to manage all the GBs of guest memory inside the host allocated memory.

How to run a guest that needs to have its' 16 GiB of RAM allocated successfully on a 64-bit host OS with enough of free >memory?

Which will give you small increase in run speed, may be 1%-2% because swap file will be located entirely in host RAM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants