Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

zram-init swap setup for /var/tmp/portage

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
OpiateSkittles
n00b
n00b
Posts: 16
Joined: Sat Dec 26, 2020 3:08 am

zram-init swap setup for /var/tmp/portage

  • Quote

Post by OpiateSkittles » Thu Dec 31, 2020 4:54 pm

hey everyone,

recently posted about using tmpfs for /var/tmp/portage and ended up taking the advice of someone who said to set up zram instead. this is mainly because i only have 8GB physical memory, and i felt the compression would benefit me. i have it set up and working now, but i have a couple of questions about the swap part of it and i'm hoping someone could help me figure it out.

pertinent info: i have 8GB physical RAM, as i said before, and also an 8GB swap partition. I mainly only have swap as a "just in case" type thing, and the 8GB is something that isn't an issue with space so, while i do have a dedicated partition, i have swappiness set to 10.

here is my my zram-init config file:

Code: Select all

# load zram kernel module on start?
load_on_start=yes

# unload zram kernel module on stop?
unload_on_stop=yes

# Number of devices.
# This value is also passed to the kernel module on modprobe.
num_devices=2

# swap - 500M (or a fourth of available memory if uncommenting)
type0=swap
flag0= # The default "16383" is fine for us
size0=8192
#size0=`LC_ALL=C free -m | awk '/^Mem:/{print int($2/4)}'`
mlim0= # no hard memory limit
back0= # no backup device
icmp0= # no incompressible page writing to backup device
idle0= # no idle page writing to backup device
wlim0= # no writeback_limit for idle page writing for backup device
notr0= # keep the default on linux-3.15 or newer
maxs0=2 # maximum number of parallel processes for this device
algo0=zstd # zstd (since linux-4.18), lz4 (since linux-3.15), or lzo.
           # Size: zstd (best) > lzo > lz4. Speed: lz4 (best) > zstd > lzo
labl0=zram_swap # the label name
uuid0="6344e2ab-3787-4e0d-9d56-f6216d1f94d1"
args0= # we could e.g. have set args0="-L 'zram_swap'" instead of using labl0

# /tmp - 2G
# If you use this, you should put zram-init into the boot runlevel,
# and services using /tmp should be in the default runlevel and/or have
# rc_need=zram-init in their /etc/conf.d/... file
type1=/var/tmp/portage
flag1=ext4
size1=6144
mlim1= # no hard memory limit
back1= # no backup device
icmp1= # no incompressible page writing to backup device
idle1= # no idle page writing to backup device
wlim1= # no writeback_limit for idle page writing for backup device
blck1=4096 # the default blocksize of 4096
irat1= # bytes/inode ratio
inod1= # inode number
opts1="noatime,nosuid,nodev" # e.g. "relatime" or "noatime" are also reasonable choic>
mode1=1777
owgr1= # No reason to change the default "root:root"
notr1= # keep the default on linux-3.15 or newer
maxs1=2
algo1=zstd
now, here are my questions/issues. for the most part, everything is working. service is at boot runlevel and everything works fine as far as compiling in zram. however, the swap part is throwing me off. i have uuid0 set to my swap partition to force it to use my existing swap partition. but what throws me off is that, in my system monitor, it now says i have 16GB of swap (on an 8GB partition). is something wrong with my config or is there just some sort of wonkiness with how the system sees it?

also, i haven't yet built a very large package with this configuration, but is there anything else i need to set to make sure the swap is recognized as available space? what i mean is, the physical zram is 6GB, and mounted as /var/tmp/portage. is there anything i should be doing differently in my swap config to make sure that portage sees the 8GB of swap as available space for /var/tmp/portage as well?

as always, any and all input is very much appreciated. have a wonderful new year everyone.

-sebastian
Top
Ladon
n00b
n00b
Posts: 1
Joined: Thu Jan 28, 2021 5:19 pm

  • Quote

Post by Ladon » Thu Jan 28, 2021 6:12 pm

  • uuid0: I think this sets a new UUID to the device. It does not use an existing partition.
  • mlim#: This is actually the real limit to the RAM used. But it is set (in v10.9) in bytes!
  • size#: This can be even 3x mlim#. This means you expect the data to be compressed to 33% their initial size. I think it's safe to make it even larger.
On another note,
  • zswap is a kernel module that compresses data when they enter the swap.
/etc/conf.d/zram-init:

Code: Select all

load_on_start=yes
unload_on_stop=no
num_devices=2

############################################################################
#                                                                          #
#                                   /tmp                                   #
#                                                                          #
############################################################################

type0=/tmp
size0=18432
mlim0=8589934592
maxs0=2
algo0=lzo-rle	# https://linuxreviews.org/Comparison_of_Compression_Algorithms - #
flag0=ext2
labl0="/tmp,/var/tmp/portage"
opts0="noatime,nodev,nosuid"
mode0=1777

############################################################################
#                                                                          #
#                                    RAM                                   #
#                                                                          #
############################################################################

# swap - 3072M
# info : https://askubuntu.com/questions/471912/zram-vs-zswap-vs-zcache-ultimate-guide-when-to-use-which-one
type1=swap
# Swap priority (pri).
# -
flag1=100
size1=$((3*3*1024))	# Virtual size (Spyros).
		# -
		# ^So normally disksize < mem_limit makes almost no sense, disksize==mem_limit in most cases 
		# guarantees any write would succeed, and disksize > mem_limit means we expect a certain amount 
		# of compression, and if we`d not satisfy it - we won`t be able to complete a write and IO op 
		# would err. Src : https://www.quora.com/What-does-disksize-in-zram-means.
		# -
mlim1=$((3*1024**3))	# Actual size (Spyros).
		# -
maxs1=1		# maximum number of parallel processes for this device
# checked with 4.9.148 ( $ stress-ng --class memory --vm 3 -v --vm-bytes 16G )
algo1=lzo-rle
labl1=ZRAM
  • Example zswap kernel boot options:

Code: Select all

zswap.enabled=1
So, each zram_swap will be added to the rest of the hdd_swaps and appear as one in $top. You can, however, inspect the sizes of /tmp and zram_swap with $zramctl --output-all.
Top
Buffoon
Veteran
Veteran
User avatar
Posts: 1369
Joined: Wed Jun 17, 2015 2:22 pm
Location: EU or US

  • Quote

Post by Buffoon » Thu Jan 28, 2021 6:20 pm

Regarding swap use. Don't. Better reduce the number of make instances if your box goes swapping. You will build faster with lower -j setting than using higher -j and suffering swapping. You can set MAKEOPTS per package if you wish.
Top
PlatinumTrinity
Tux's lil' helper
Tux's lil' helper
Posts: 100
Joined: Tue Mar 10, 2020 8:22 am

  • Quote

Post by PlatinumTrinity » Sun Jan 31, 2021 2:43 am

Buffoon wrote:Regarding swap use. Don't. Better reduce the number of make instances if your box goes swapping. You will build faster with lower -j setting than using higher -j and suffering swapping. You can set MAKEOPTS per package if you wish.
This is what I do. Reduced MAKKEOPTS from -j8 to -j6. Prevents larger packages from hitting swap (mainly just firefox, chrome, and sometimes rust). I also use zram but instead of using it for /tmp/portage I use it like a swap device. So on my machine when it first needs swap it just starts compressing things in RAM and putting them into zram. I have swap on the HDD as well (same amount as my RAM) but I am thinking about removing it. I never need it with the zram swap and mainly have it just in case to prevent hard locking.

I do it this way so I'm not using the CPU to compress RAM unless absolutely needed. I'm at 30 days uptime right now with 482M sitting in zram and 11.1G of RAM used out of 16G available. The longer you keep a machine powered on the more RAM it will use. That's not a concern and normal. I also have swappiness set to something really low like 1. I use a lower MAKEOPTS so the CPU has free resources for running the DE and compressing stuff in RAM. When I ran -j8 I would sometimes get a locked situation for up to a minute. Now it barely stutters at all.

I rarely get a stutter for half a second when it starts hitting the zram swap device but it's stable and never locks up anymore. Is there any point of changing my config to work like the one in the OP? By the way if you have a good graphics card in your machine you can use its RAM for this purpose as well if you need a bit extra. I haven't ever tried it but my friend uses a config like that to get a bit of extra space.
Top
Post Reply

4 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic