[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: Tumblr_l_87039169290545.jpg (492 KB, 1446x2048)
492 KB JPG
previous: >>108622965

#define __NR_sync                    162
#define __NR_syncfs 306

https://man7.org/linux/man-pages/man2/sync.2.html

tl;dr:
write dirty memory

useful if you expect you might soon perform a hard reboot. maybe in some other circumstances, too. filesystems are weird
not much to say about this one. it does one thing and does it well

relevant resources:
man man

man syscalls

https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
>>
>>108631610
The 3POSIX man says
>The writing, although scheduled, is not necessarily complete upon return from sync()
Then how do you know when it completes and was successful?
>>
>>108631650
on posix, you don't
linux blocks
>>
>syncfs(int fd)
It's like they never learnt their lessons.
>>
I hate this little fucker like you wouldn't believe
If I were less lazy I'd create a custom kernel where this is a no-op for my machines behind a UPS, but even then I'm not sure if libc does some fuckery in there or even if compilers are aware of the system call and "optimize" around it
>>
>>108634087
lol, what's so bad about it?
>>
>>108634123
tanks performance for a scenario that has never ever ever ever happened to me (PC crash or power loss)
similar to meltdown mitigations for me, i always disable them
>>
>>108631610
>filesystems are weird
I've been looking into internals of Linux file systems and they are some of the most unreadable event-driven shit I've ever seen.
>there are like 7 different functions for reading a folio (which is the newer version of the page struct)
>you have to go from dentry to inode to address_space to folio to void* just to get to the actual file data
>there are 2 completely different ways of doing direct I/O for some reason
>half of all file systems don't even do the work in *_operations structs' callbacks and launch a kernel thread to run all the operations instead
>the writepages callback in address_space_operations can distinguish between a sync(2) and periodic writeback but it's impossible for it to know if it was triggered by memory pressure
>red hat introduced yet another layer of structs with function pointers in the form of iomap

>>108634087
>>108634163
Try setting vm.dirty_writeback_centisecs = 6000 and vm.laptop_mode = 15 (or however many seconds) + LD_PRELOADing libeatmydata on login. It won't help you with static binaries though.
>>
snippet that atomically writes a file to disk (or overrides existing)
int atomic_write_file_with_tmp(const char* path, const char* tmp_path, const uint8_t* data, size_t size)
{
int fd = open(tmp_path, O_CREAT|O_WRONLY|O_TRUNC | O_EXCL | O_CLOEXEC, 0666);
if (fd < 0) {
return -1;
}
size_t i = 0;
while (i < size) {
ssize_t rc = write(fd, data + i, size - i);
if (rc < 0) {
if (errno == EINTR) {
continue;
}
close(fd);
return -1;
}
i += rc;
}
if (fsync(fd) < 0) {
close(fd);
return -1;
}
close(fd);

if (rename(tmp_path, path) < 0) {
return -1;
}

return 0;
}

tmp file needs to be on same partition to be atomically moves. ideally in same directory, and with random unique name. alternatively linux and other OSs can create anonymous file, so no collisions.
doesn't deal with parent directory creation.
>>
>>108631610
I hate that a sync command has no progress info, it just fucking blocks the terminal
>inb4 just cat that one /sys file bro
Could you remember the filepath without chatgpt?
>>
>>108636494
How much shit are you syncing to need a progress bar?
>>
>>108636524
>a colleague asked to put some datasets on flash drive
>~100Gb uploaded in 3 seconds
>sus.jpg
>do the safe eject thing
>it does nothing
>run sync
>it just blocks the terminal
>"hey anon when it's finished? I have a meeting in 2 minutes"
No fucking clue because linux is an unusable piece of garbage
>>
>>108636551
Oh, you're right. Forgot about that. If it's a single file you can try copying it via dd if=... of=... bs=4M oflag=direct status=progress



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.