Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Gentoo on limited ressources
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
mkrsn
n00b
n00b


Joined: 26 Dec 2020
Posts: 7

PostPosted: Sat Jun 03, 2023 10:26 am    Post subject: Gentoo on limited ressources Reply with quote

Hi all,

I've got 4 tiny Servers (1 vCPU; 512 MiB RAM; 9.7GiB Storage) running Gentoo. Until the last GCC update all was fine (GCC acceptable) so far. Since Gentoo (GCC & Kernel too) is getting bigger and bigger every year I have now problems in compiling GCC on such small Servers. It's currently not possible because of the limited resources.

Some years ago I already put the whole portage tree into a squashfs because of the limited Size. But still, Gentoo is 5GB big (just installed some tools, FRR and telegraf - nothing big, 100MiB logs) - which isn't enough for a swap file & storage for GCC compiling.

- The most obvious thing was to
-- check if there is a gcc-bin package -> unfortunately not (does anyone know why?)
-- building a portage env for GCC and limiting compiling to one process
- I was already thinking about bin-packaging it by myself: that would mean build for each server a own package (they don't have the same CFLAGS)

Unfortunately i don't have an furthers ideas on howto solve this Issue. I even already thought about switching to Artix, but i don't like that idea.

Does anyone here has a Idea of howto solve this problem?


Greetings
Matthias
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 926
Location: Richmond Hill, Canada

PostPosted: Sat Jun 03, 2023 12:35 pm    Post subject: Reply with quote

Can you share what is limiting the build process? 512MB and 9.7G storage should allow you build gcc. however it might take very long time.

Do you use swap?

Are all 4 servers on same network?
Back to top
View user's profile Send private message
mkrsn
n00b
n00b


Joined: 26 Dec 2020
Posts: 7

PostPosted: Sat Jun 03, 2023 1:22 pm    Post subject: Reply with quote

Available Storage is ~4.2GiB - without Swapfile. Thats why the problem depends on the try.

I just need swap when compiling GCC. Otherwise it's removed from the system.

- 2GiB Swap: gcc was killed by OOM
- 2.5GiB Swap: gcc was killed by OOM
- 3GiB Swap: gcc complained about missing storage

The vServers are spreaded around the world (DE, ES, UK, US) but are in a VPN.


While writing this i totally forgot the "root reserved space" from EXT4 - I never freed them, which are ~500 MiB of free storage. Maybe this is now the missing necessary Storage ^^
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 926
Location: Richmond Hill, Canada

PostPosted: Sat Jun 03, 2023 2:19 pm    Post subject: Reply with quote

Since servers spread over long distance so using network storage is not a good option.

is the 4.2G after gcc source code dump? or source code will take further more space?

do you have other linux device(s) in LAN that may have resource(memory or storage) to share?

I heard gcc 13 have something changes will reduce generated sourced to smaller piece so each compile unit will use less resource.

the main constrain is available resource in your use case. so unless there are other nodes that can share resources with the building node, there is not much can be done. I think gcc build have multiple stages so there is chance you can break build processes into multiple steps and do some cleanup in between steps but that require some research on what can be clean up between stages.

if you have nodes on LAN that can share resources memory or storage you can consider use NFS for quick setup, or NBD (network block device) with compress for a little bit more complicated procedures.

Let me know if you need more detail if you think you can use network resources but need more information.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54236
Location: 56N 3W

PostPosted: Sat Jun 03, 2023 6:29 pm    Post subject: Reply with quote

mkrsn,

Do you have any other Gentoo systems?

Build and running Gentoo can be separated. They usually are for weaker embedded systems.
The idea is to build on a powerful system then install the binaries on the target system, like this. The target system need not build anything.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
mkrsn
n00b
n00b


Joined: 26 Dec 2020
Posts: 7

PostPosted: Sat Jun 03, 2023 8:27 pm    Post subject: Reply with quote

@pingtoo,

I already thought about NFS, NBD and co. I think i would swap the Storage Problems with connection Problems because of the long distances. But even if this were not the case, it would still be effort that is not really worth it.

The 4.2GiB is without distfiles, swap and extracted source code.There is also a script which dleans distfiles on a daily base.

In the meantime I've freed the root reserved space and tested it again with 2.5GiB & 3GiB Swap. Both tests were aborted because of missing Storage.

@NeddySeagoon

I also thought about building packages. There are plenty of resources on other Servers. But as I mentioned: It would need to maintain 4 different build chains because of the 4 different CFLAG variations. It's still not worth the effort, then it would be easier to switch all vServers to a different Distro like Artix. I Also thought about building a more generic GCC Version (as like in the stage 3) but i couldn't find an information on that.


@both
I've removed gentoo-sources which brings additional 1.8GiB of storage - which would be a temporary solution (hopefully - compiling still runs) until gcc 13 jumps in.
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 926
Location: Richmond Hill, Canada

PostPosted: Sat Jun 03, 2023 9:10 pm    Post subject: Reply with quote

mkrsn wrote:
I Also thought about building a more generic GCC Version (as like in the stage 3) but i couldn't find an information on that.


In gentoo, there is a tool known as dev-util/catalyst. It can be use to build your own version of stage3/stage1. However it need large storage resource during build process.

Just to give you an idea. I am primary using ARM(aarch64) based systems. my desktop is pi4 with 4GB memory. I also have few other ARM nodes with varies memory size from 512MB to 8GB. my build process invoke on the pi4 that got storage donate from other ARM nodes using NBD on top of ZRAM and I merge those NBD-ZRAM device with LVM. I put the entire build source in to the RAM-LV. My goal of this setup is to avoid writes to SD/SSD. I also use distcc to help compile. (yes, I am aware gcc cannot be distcc-ed)

If you don't have secondary gentoo system readily available, have you consider rent a temporary node, just for the build process? I mean for example get a DigitalOcean's droplet to build gcc. I think it will not cost you more than $10 for the entire gcc build process. Gentoo have ready-made stage3 docker image so it is not difficult to automate the build process.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54236
Location: 56N 3W

PostPosted: Sat Jun 03, 2023 9:43 pm    Post subject: Reply with quote

mkrsn,

Is the ::gentoo repo in squashfs?
The entire repo is 50MB. You throw it away every update. Not rsync.
That compares to my 619M for /var/db/repos/gentoo/ using a filesystem with a 4k block size.

Do you really need 4 different CFLAG variations, or there a lowest common denominator that will run everywhere and still provide the required performance?
What are the 4 settings?

e.g. build gcc once and run it everywhere. The CPUFLAGS it is built with affect the instruction set it will require to run, not the instruction set it can output code for.

The compressed kernel sources can be piped through tar to mksquashfs to get a read only usable to build file that is mounted somewhere to access it.
The kernel cannot be built in the squashfs, as its read only but the kernel build system has an option to put the build products somewhere else. The Makefile says
Code:
...
# Kbuild will save output files in the current working directory.
# This does not need to match to the root of the kernel source tree.
#
# For example, you can do this:
#
#  cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
#
# If you want to save output files in a different location, there are
# two syntaxes to specify it.
#
# 1) O=
# Use "make O=dir/to/store/output/files/"
#
# 2) Set KBUILD_OUTPUT
# Set the environment variable KBUILD_OUTPUT to point to the output directory.
# export KBUILD_OUTPUT=dir/to/store/output/files/; make
#
# The O= assignment takes precedence over the KBUILD_OUTPUT environment
# variable.
...

That clips the kernel sources.

e.g. Installed bt clean
Code:
$ du -d1 -h linux-6.3.4-gentoo/
...
1.5G   linux-6.3.4-gentoo/


As a squashfs with two different compressors.
Code:
$ ls ~/linux-6.3.4* -lh
-rw-r--r-- 1 roy users 213M Jun  3 22:35 /home/roy/linux-6.3.4-gentoo.img.gzip
-rw-r--r-- 1 roy users 182M Jun  3 22:37 /home/roy/linux-6.3.4-gentoo.img.xz

_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
mkrsn
n00b
n00b


Joined: 26 Dec 2020
Posts: 7

PostPosted: Sun Jun 04, 2023 9:40 am    Post subject: Reply with quote

Good Morning,

after removing all kernel sources i had ~3.5GiB of free Storage (with 3GiB Swap file). Even that is not enough resources. The compiling were killed because of missing storage (3.4G /var/tmp/portage/sys-devel/)
The last chance is now to reduce the swapfile a little (to 2.5GiB - praying for not seeing OOM) to have ~4GiB of free storage.

God, I really really hate GCC right now... XD


@pingtoo,

thank you for pointing out catalyst - I'll give it a try.


@NeddySeagoon,

the Portagetree is already in a compressed Squashfs (57MiB).

For GCC i don't need 4 different CFLAG variations. One generic GCC package would be pretty fine - even when compiling is a little slower. But i couldn't find any information on how a generic CFLAG would look like. I yesterday eyeballed a bit into dev-util/catalyst and it looked like I had found here a generic one. I need to test it.

The compressed kernel sources looks really interesting, I'll keep that in mind for other projects - thank you. Unfortunately it won't work here because even without kernel-sources it's not possible to compile GCC 12.2 :/
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54236
Location: 56N 3W

PostPosted: Sun Jun 04, 2023 10:59 am    Post subject: Reply with quote

mkrsn,

Generic for AMD64 is
Code:
CFLAGS="mtune=generic"
with -march unset.
-pipe is a hint to gcc to pass intermediate files in RAM but it will use disk is RAM is scarce.
-O2 is the optimization level.

You will probably see
Code:
CFLAGS="mtune=generic" -O2 -pipe
for generic.

gcc is a big build natively and its built three times for a native build to make sure its 'pure' gcc.

The first build uses any random C++ compiler to build enough of gcc to build itself.
The second build uses the compiler made in the first stage to build enough of gcc to build itself again (its know that the build is using gcc now)
The third stage uses the output of the second stage to build what will be installed on your system.
After its build C++, it compares the output of stage 2 and stage 3. Its an error if the compare fails.
If all is well, it continues building the other targets and completes the install.
The process is called bootstrapping. That's for a native build.

Hold that thought.

What about a gcc building a cross compiler?
The process above would not get very far. Think about using AMD64 to build a gcc for RISC-V.
Thu first build would work, then the AMD64 would try to execute RISC-V instructions. That would end badly.
Instead the bootstrap is skipped and the build goes straight to stage 3
The gcc build system does that.

So ... if it can do it for cross compile, con it be told to skip the bootstrap for native builds too?

-- edit --

From Installing GCC: Configuration
Code:
--disable-bootstrap

    For a native build, the default configuration is to perform a 3-stage bootstrap of the compiler when ‘make’ is invoked, testing that GCC can compile itself correctly. If you want to disable this process, you can configure with --disable-bootstrap.
--enable-bootstrap

    In special cases, you may want to perform a 3-stage build even if the target and host triplets are different. This is possible when the host can run code compiled for the target (e.g. host is i686-linux, target is i486-linux). Starting from GCC 4.2, to do this you have to configure explicitly with --enable-bootstrap.


So passing --disable-bootstrap is required.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2006

PostPosted: Sun Jun 04, 2023 11:44 am    Post subject: Reply with quote

Do you really need 3GB swap? my laptop has CONFIG_ZSWAP_ZPOOL_DEFAULT="z3fold" and CONFIG_ZSWAP_COMPRESSOR_DEFAULT="lzo" backed by 1GB disk. The laptop has 4 GB ram, so zswap default allocation of 20% is 800 MB, tripled to 2.4 GB, so effective memory space is 3.2 + 2.4 = 5.6 GB.

I also have CONFIG_ZRAM=m, CONFIG_ZRAM_DEF_COMP="lzo-rle", with /var/tmp/portage set to zram - you could go further with all /var/tmp set there.
Code:
zramctl
NAME       ALGORITHM DISKSIZE  DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle         1G  592K  9.8K  144K       2 /var/tmp/portage


It's possible to covert the kernel sources to squashfs - there's a command in squashfs-tools-ng for the purpose, though AFAIR it works better if you uncompress the sources and pipe the result to mksquash. Of course, this can be done on any machine. That said, cross-compiling kernels is easy. One way is documented on my wiki page.

A final confusion that probably doesn't help, have you considered clang instead of gcc? Total package is a bit bigger, (~310 MB vas ~280 MB) but I believe it uses less resource in operation.
_________________
Greybeard
Back to top
View user's profile Send private message
mkrsn
n00b
n00b


Joined: 26 Dec 2020
Posts: 7

PostPosted: Mon Jun 05, 2023 11:58 am    Post subject: Reply with quote

I could solve this issue by removing "-pipe" from CFLAGS, setting swapfile to 2GiB (which not worked before removing pipe in any case) and gentoo-sources.

Thanks for all your comments, thoughts and help :)


@NeddySeagoon

thx - i will keep that CFLAG in mind. I pray that gcc 13 will use resources a bit more efficiently than v12 does.


@Goverp

On a system with multiple dedicated CPUs ZRAM & co may work. But on a shared single vCore I'm not sure if this is the way to go. Therefore i try to avoid ZRAM & co here.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54236
Location: 56N 3W

PostPosted: Mon Jun 05, 2023 12:00 pm    Post subject: Reply with quote

mkrsn,

zram swaps CPU time for space.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 1678

PostPosted: Mon Jun 05, 2023 12:01 pm    Post subject: Reply with quote

mkrsn wrote:
I could solve this issue by removing "-pipe" from CFLAGS, setting swapfile to 2GiB (which not worked before removing pipe in any case) and gentoo-sources.

Thanks for all your comments, thoughts and help :)


@NeddySeagoon

thx - i will keep that CFLAG in mind. I pray that gcc 13 will use resources a bit more efficiently than v12 does.


@Goverp

On a system with multiple dedicated CPUs ZRAM & co may work. But on a shared single vCore I'm not sure if this is the way to go. Therefore i try to avoid ZRAM & co here.


You can also try -Wl,--no-keep-memory in LDFLAGS.

With regard to GCC 13: yeah, the change is actually in GCC 14, but we backported it because it's so useful. See https://gitweb.gentoo.org/repo/gentoo.git/commit/sys-devel/gcc?id=aa5725d7e4407bdfa4137cb0518c9d6ffaf5d8ae.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum