Open 3DRaven opened 8 years ago
Mounting anything (except the currently created filesystem) is beyond the scope of this project.
Remember: one tool - one job.
There are sufficiently many tools for mounting various filesystems: From the classical /etc/fstab ("mount -a") over the systemd mount-unit nonsense up to specialized and advanced tools like squashmount (the latter is perhaps what you are actually looking for).
Since it appears that you are using Ubuntu or Debian and you are thus damned to systemd, probably the correct way to mount something with aufs (BTW: There is also overlay[fs] and also other alternatives like unionfs-fuse), the "correct" way to configure your aim is probably to create a corresponding systemd mount-unit (or service if you use a more advanced mounting tool), making a dependency on the zram-init service.
But you've added to zram_init ext2 / 4 (in zram-init->):
fsopts='-O^huge_file,sparse_super'
case $fstype in
ext2)
mkfs.ext2 -m0 "$fsopts" ${iratio:+-i "$iratio"} \
${inodes:+-N "$inodes"} "$devnode" >/dev/null \
|| Fatal "mkfs.ext2 $devnode failed"
tune2fs -c0 -i0 -m0 "$devnode" >/dev/null
mount -t ext2 ${opts:+-o "$opts"} -- "$devnode" "$dir" \
|| Fatal "mount $devnode failed";;
ext4)
fsopts=$fsopts',extent,^uninit_bg,dir_nlink,extra_isize,^has_journal'
mkfs.ext4 -m0 "$fsopts" ${iratio:+-i "$iratio"} \
${inodes:+-N "$inodes"} "$devnode" >/dev/null \
|| Fatal "mkfs.ext4 $devnode failed"
tune2fs -c0 -i0 -m0 "$devnode" >/dev/null
! $discard || opts=$opts${opts:+,}'discard'
mount -t ext4 ${opts:+-o "$opts"} -- "$devnode" "$dir" \
|| Fatal "mount $devnode failed";;
Add please aufs block in this place. The rest I do myself including unit to systemd
Please,please,please :)
But you've added to zram_init ext2 / 4: [...]
That's a different story: Some filesystem has to be generated and mounted so that zram can be used. There's some theoretical alternatives to ext2/4 (e.g. xfs, btrfs, zfs), but given the nature of zram this would probably not make a big difference.
Add please aufs block in this place
This would not work: aufs cannot be used instead of ext2/4/xfs/btfs/zfs/... It must be used in addition after creating and mounting that filesystem.
It is like creating some files on the freshly created filesystem: There might be some reasons why one would like to have this for some systems, but it is a task which has nothing to do at all with zram in the first place and therefore should be done by an independent script/unit.
But when the \tmp already mounted, you can not create aufs. Create aufs need immediately after ext4 created in zram, but before mounting. This moment occurs in just zram-init.
Create aufs need immediately after ext4 created in zram, but before mounting.
No. Despite its name, "aufs" is not a file system in the sense that it can access block devices: It can only merge two (or more) already mounted directories. If you want to use aufs to merge two directories into /tmp (one of this being a zram directory), you must have mounted both directories before to a different location. In other words, you should first use zram_init to mount an ext4 directory e.g. to /var/spool/tmp-write and afterwards use aufs to mount /tmp with the option -o br:/var/spool/tmp-write=rw:/your/other/directory=rr
Ok. I try. Thanks.
But! :)
Then need modify zram_tmp.service?
I try create aufs_tmp.service.
[Unit]
Description=Mount /tmp as aufs. Mask tmp.mount if you use this
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
Requires=zram_tmp.service systemd-modules-load.service
[Service]
Type=oneshot
RemainAfterExit=true
# Adapt the maximal size (in MB) and other options like maximal number of
# parallel streams (-s) to your needs.
# Make sure to avoid collision of devices (-d...) with
# zram_swap.service and zram_var_tmp.service and
# that num_devices in modprobe.d/zram.conf contains the maximal used number + 1
ExecStart=/bin/mount -t aufs -o br=/mnt/aufs/zram=rw:/mnt/aufs/rw=rw -o udba=reval none /tmp
ExecStop=/bin/umount /tmp
[Install]
WantedBy=local-fs.target
But in boot log:
aufs_tmp.service - Mount /tmp as aufs. Mask tmp.mount if you use this
Loaded: loaded (/etc/systemd/system/aufs_tmp.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Ср 2016-08-03 23:05:23 MSK; 15min ago
Process: 900 ExecStart=/bin/mount -t aufs -o br=/mnt/aufs/zram=rw:/mnt/aufs/rw=rw -o udba=reval none /tmp (code=exited, status=32)
Main PID: 900 (code=exited, status=32)
авг 03 23:05:23 i3draven-W250ENQ-W270ENQ mount[900]: mount: unknown filesystem type 'aufs'
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
Please help fix this error. if i execute mount in terminal all work fine.
Then need modify zram_tmp.service?
Probably it suffices to generate /etc/systemd/system/zram-tmp.service.d/newdir with the content
[Service]
ExecStart=
ExecStart=/your/modified/execstart/command
Concerning your error: maybe you have to modprobe aufs
. Generate e.g. a corresponding file in /etc/modprobe.d
To mount uses a other type of units. Next, I bring a working unit: cat /etc/systemd/system/zram_tmp.service
[Unit]
Description=Mount /tmp as zram. Mask tmp.mount if you use this
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
[Service]
Type=oneshot
RemainAfterExit=true
# Adapt the maximal size (in MB) and other options like maximal number of
# parallel streams (-s) to your needs.
# Make sure to avoid collision of devices (-d...) with
# zram_swap.service and zram_var_tmp.service and
# that num_devices in modprobe.d/zram.conf contains the maximal used number + 1
ExecStart=/usr/sbin/zram-init -d1 -s2 -alz4 -text4 -ostrictatime -m1777 4096 /mnt/aufs/zram
ExecStop=/usr/sbin/zram-init -d1 0 /mnt/aufs/zram
[Install]
WantedBy=local-fs-pre.target
cat /etc/systemd/system/tmp.mount
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target
Requires=zram_tmp.service systemd-modules-load.service
After=zram_tmp.service systemd-modules-load.service
[Mount]
What=none
Where=/tmp
Type=aufs
Options=br=/mnt/aufs/zram=rw:/mnt/aufs/rw=rw,udba=reval
It is important to specify the name of just such a file. I ask you to add this unit to the project (after finalization).
It is necessary to change the line in tmp.mount:
Options=br=/mnt/aufs/zram=rw:/mnt/aufs/rw=rw,udba=reval,sum
To free space on the / tmp summed from of all layers free space.
Not sure whether this is really what you wanted: With the default policy of aufs, half of your directories in /tmp will go directly to disk, the other to zram. However, it seems that aufs does not support a policy to use one filesystem until a certain size is reached.
In any case, as I said in the beginning, all this has nothing to do with zram in the first place: Some users might e.g. want to have an aufs mount for /tmp even if they do not want to use zram or with zram as a third writable directory, others might want to have it additionally/instead for /tmp (with or without zram), etc. Especially with systemd, it is not possible to write a general-purpose unit which just needs to be configured properly (one of the many conceptual bugs in systemd): This is all simply just general user-local configuration which must done by the user/administrator/distribution and does not belong into a project like zram-init.
I will leave this bug open so that users can see your example.
Ok. Thanks.
Unfortunately aufs does not know how to divide the files. Therefore, if there are two brunch: 1GB (zram) and 5GB (disk). Let's start recording for the first brunch. 2GB file. When the is over free space in the first brunch, you will receive the message "no space left". Although the logic of the file should be split into parts and record continued in the second brunch.
So aufs does not fit for the problem.
But the problem can solve btrfs! Maybe add btrfs in zram-init? :)
btrfs allows you to combine zram and the file on the disk in a single coherent file system.
I have never tried btrfs and have not installed the kernel and userspace tools. If you can produce a patch which works reasonably general (e.g. which just formats and mounts btrfs with user-provided options) and which you have tested, I will merge it.
Ok i try.
I used instead zram-init (it is inconvenient to do such) set of unit files.
/etc/systemd/system/tmp.mount
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target
Requires=btrfs_tmp.service
After=btrfs_tmp.service
[Mount]
What=/dev/loop0
Where=/tmp
Type=btrfs
Options=defaults,compress=lzo,relatime,noatime,nosuid,nodev,noexec,discard
/etc/systemd/system/mnt-tmpfs.mount
[Unit]
Description=Prepare ramdisk for compressed file image witch btrfs
Before=local-fs.target btrfs_tmp.service tmp.mount
After=systemd-modules-load.service
[Mount]
What=tmpfs
Where=/mnt/tmpfs
Type=tmpfs
Options=defaults,noatime,nosuid,nodev,noexec,mode=1777,size=4096M
/etc/systemd/system/btrfs_tmp.service
[Unit]
Description=Prepare btrfs = tmpfs image+disk image
DefaultDependencies=no
Conflicts=umount.target
Before=tmp.mount
Requires=mnt-tmpfs.mount
After=systemd-modules-load.service mnt-tmpfs.mount
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/truncate -s 4G /mnt/tmpfs/image0
ExecStart=/bin/mkfs.btrfs -d single -m single /mnt/tmpfs/image0 /mnt/disk/image0
ExecStart=/sbin/losetup /dev/loop0 /mnt/tmpfs/image0
ExecStart=/sbin/losetup /dev/loop1 /mnt/disk/image0
ExecStart=/bin/btrfs device scan /dev/loop0
ExecStart=/bin/btrfs device scan /dev/loop1
First mounted tmpfs, then in it is created image0 file. The same file (image0) created by me by hand on the disc (use "dd"). Then in these files created btrfs and it is mounted in / tmp
Unfortunately recording on tmpfs image0 and disk image0 occur in the order as want btrfs. With this I still can not do anything. So the data is distributed between the disk and parallel tmpfs. But maybe that's a plus since btrfs is to use the speed optimization
This does not really help you with the btrfs scheduling policy, but some comments. Apparently you do mount on tmpfs, not on zram as you had planned originally.
The purpose of zram-init is actually to support the latter: In your above setting, this means that instead of /etc/systemd/system/mnt-tmpfs.mount you should use some /etc/systemd/system/zram1.service which sets up the device /dev/zram1 (or another device) and creates a btrfs on it (in your case, without mounting it); when the service is stopped, it should free the memory again.
The new release zram-init-3.8 actually supports filesystem creation with btrfs (in addition to ext2 or ext4), and moreover, if you specify the special directory "-", it will actually not mount. Thus, the writing of the unit zram1.service is simplified (an example is given in zram-init-3.8).
btrfs I used because it supports data compression. However, discard + ssd in btrfs probably should return a page in memory when they are freed, but I'm not sure. If used in conjunction with btrfs zram the compression will have to pass in zram. Maybe I'll try. Thank you.
Need to add aufs in zram_init because it will integrate zram + tmp in ram + tmp in disk. Operating procedure:
When zram (/tmp or /var/tmp) full, the data will be written to the disk.