ecdye / zram-config

A complete zram-config utility for swap, directories, and logs to reduce SD, NAND and eMMC block wear.
MIT License
412 stars 53 forks source link

Add sync option #17

Closed mstormi closed 3 years ago

mstormi commented 5 years ago

Although not recommended syncing without unmounting may be desirable and works in many cases so it should be available as an option.

StuartIanNaylor commented 5 years ago

I am not sure as I did speak to the OverlayFS and they where adamant that a online merge down could take the merge layer out of sync.

I need to do some updates as 4.19 has seen a lib name change from xatrr to attr so the merge requires update. I guess it could be added but would have to make a disclaimer.

GenTarkin commented 4 years ago

I just tried implementing this change on latest commit in my own fork of this repo. The result was the merge script deleted the ./upper directory and hosed the overlayfs upper mount point =(

Heres the snippet from zram-config log showing the action taken by the overlayfs-tools merge script:

mstormi commented 4 years ago

:( Do you still have the log ? Any idea what went wrong ?

GenTarkin commented 4 years ago

:( Do you still have the log ? Any idea what went wrong ?

See the update in my first reply =) ... quoted from the log file, what looks like the culprit. To further clarify, the last line shown in the snippet.

mstormi commented 4 years ago

Hmm so it's the overlayfs-tools who wrongfully want to delete the main (upper) directory ? At least I wouldn't think that's ever meant to be deleted but I'm not the expert. Do you think we can file this as an issue with the overlay tools author/repo ? Could you reproduce or narrow it down somehow?

GenTarkin commented 4 years ago

Well, since they say merge while mounted is officially unsupported ... I doubt we would get any traction. Perhaps this is one of the reasons why =P Ive been pondering developing a file semaphore driven safe "Stop/Start" merge which would not mess w/ any swap entries. (if semaphore exists, skip swap, delete semaphore) The only problem I can see potentially being data written to logs(or other files folders for that matter) while "Stop" merge script is moving items objects from upper to lower. But, I guess even now that can potentially be a problem.

But I do notice another thing thats odd, if I stop service, /dev/zram1 seems to hang around in a limbo state and then when I start the service again(not reboot) ... there are 3 zram devices, 2 populated, the one unpopulated and unmounted is zram1... seems like zram1 is "stuck" ... but I guess everything is still working fine.

GenTarkin commented 4 years ago

I went ahead and logged an issue w/ overlayfs dev/repo. I reread the "info" posted there and the behaviour specified is that the upper should be left "empty" after a merge ... not outright deleted. So yeah, I think this is definitely a bug. In the meantime, perhaps sed or something can be used to post process the .sh file(to remove this line) prior to running it?

GenTarkin commented 4 years ago

Well, I tried the sed approach and while it worked as it intended ... the result is overlayfs did not like it at all. Since doing the successful sync ... while the "upper" dir still remains ... no files written to, ever go there anymore ... in fact I dont know where they are going lol! so yeah, it seems the "copy on write" to previously merged files since overlayfs was mounted, is completely borked when doing this sync approach.

GenTarkin commented 4 years ago

Well, Ive implemented, in my repo, the semaphore based "skip swapfile" approach for stop / start commands. Seems to be good enough for now, This way I can stop/start every half hour using crontab to get lower sync'd safely w/o interrupting swap. Im sure theres a better way to do this, was the easiest I could come up with for now lol!

GenTarkin commented 4 years ago

Well, I guess it doesnt work as well as Id hoped. Because I have it ignoring swap entries, they dont get to devicelist file =( on normal stop / starts. Grr... need to figure out logic to save current swap entry upon a skip swap stop / start

GenTarkin commented 4 years ago

Back to the overlayfs-tools "merge" sync idea.... I wonder if doing a remount command after the merge would restore full overlayfs functionality. Hrm...

mstormi commented 4 years ago

Good idea, but we need to find out why/when the tools misbehave. So they work when unmounted but fail when mounted ? Eventually it's as you say just a bug to remove upper dir that just does not show up because it's unmounted already at that stage.

GenTarkin commented 4 years ago

Sorry for all the updates, but another update on the "merge/sync" approach.... After some experimentation, it seems these are the results:

GenTarkin commented 4 years ago

Good idea, but we need to find out why/when the tools misbehave. So they work when unmounted but fail when mounted ? Eventually it's as you say just a bug to remove upper dir that just does not show up because it's unmounted already at that stage.

I dont think "unmounted vs mounted" state is the tools fault .... I think overlayfs has a problem with the lower changing at all while the filesystem is mounted as such. I've read similar sentiments elsewhere and some saying aufs or similar should be used instead. Although, I DO think the removal of "upper" dir is a bug because its not functioning as technically advertised.

mstormi commented 4 years ago

the only question is how far will logs be rolled back if I power fail the device.(since I have no idea really where these writes are going to

Did you remember or see that old logs - unlike "dir"s - can be rotated to a standard directory ?

GenTarkin commented 4 years ago

the only question is how far will logs be rolled back if I power fail the device.(since I have no idea really where these writes are going to

Did you remember or see that old logs - unlike "dir"s - can be rotated to a standard directory ?

I dont follow what you are asking =/

mstormi commented 4 years ago

If one configures a directory of "log" type, files in there are moved to a normal (non-zram) directory although I don't know the exact mechanism when this happens. "oldlog_dir", last column in /etc/ztab. Maybe that's related to your "disappearing" writes.

GenTarkin commented 4 years ago

If one configures a directory of "log" type, files in there are moved to a normal (non-zram) directory although I don't know the exact mechanism when this happens. "oldlog_dir", last column in /etc/ztab. Maybe that's related to your "disappearing" writes.

Well I check the referenced old_dir in my config and it doesnt seem to have anything relevant to this really. The missing writes definitely arent there, from what I can tell (at least going off file timestamps when comparing /var/log vs /opt/zram/oldlog)

mstormi commented 4 years ago

The missing writes definitely arent there

I had a tail -f running on a logfile on zram and noticed that unmounting caused a whole lot of lines to be appended.

alpe12 commented 4 years ago

So, any way I can periodically sync only one zram folder?