From 04f6b195f9fae5a6ad25f5df3a49492111881969 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:04:46 +0300 Subject: [PATCH 01/10] dump(posix.fsync-pitfalls): update --- site/dump/posix/fsync-pitfalls.md | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 site/dump/posix/fsync-pitfalls.md diff --git a/site/dump/posix/fsync-pitfalls.md b/site/dump/posix/fsync-pitfalls.md new file mode 100644 index 0000000..7b30f59 --- /dev/null +++ b/site/dump/posix/fsync-pitfalls.md @@ -0,0 +1,86 @@ +--- +title: "`fsync(2)` Pitfalls" +date: 2025-07-11 +--- + +# `fsync` Pitfalls + +This is a non-comprehensive list of the pitfalls of the `fsync` syscall. + +
+Linux `man 2 fsync` + +> `fsync()` transfers ("flushes") all modified in-core data of (i.e., modified +> buffer cache pages for) the file referred to by the file descriptor fd to the +> disk device (or other permanent storage device) so that all changed +> information can be retrieved even if the system crashes or is rebooted. This +> includes writing through or flushing a disk cache if present. The call blocks +> until the device reports that the transfer has completed. +> +> As well as flushing the file data, `fsync()` also flushes the metadata +> information associated with the file (see inode(7)). +> +> Calling `fsync()` does not necessarily ensure that the entry in the directory +> containing the file has also reached disk. For that an explicit `fsync()` on a +> file descriptor for the directory is also needed. +> +> `fdatasync()` is similar to `fsync()`, but does not flush modified metadata +> unless that metadata is needed in order to allow a subsequent data retrieval +> to be correctly handled. For example, changes to st_atime or st_mtime +> (respectively, time of last access and time of last modification; see +> inode(7)) do not require flushing because they are not necessary for a +> subsequent data read to be handled correctly. On the other hand, a change to +> the file size (st_size, as made by say ftruncate(2)), would require a metadata +> flush. +> +> The aim of `fdatasync()` is to reduce disk activity for applications that do +> not require all metadata to be synchronized with the disk. + +
+ +I will expand this list as I have more questions about all the questionable +filesystems used and created by operating system enthusiasts. + +--- + +## `fsync` does not ensure that a `fsync`'d file is visible in its parent directory + +From the manpage: + +> Calling `fsync()` does not necessarily ensure that the entry in the directory +> containing the file has also reached disk. For that an explicit `fsync()` on a +> file descriptor for the directory is also needed. + +This means that that you cannot rely on a file being in the directory after +`fsync`ing the file itself. You have to `fsync` the directory too. + +Speaking about `fsync`ing a directory: + +--- + +## `fsync` on a directory does not ensure children are `fsync`'d + +From the manpage: + +> Calling `fsync()` does not necessarily ensure that the entry in the directory +> containing the file has also reached disk. For that an explicit `fsync()` on a +> file descriptor for the directory is also needed. + +The assumption that `fsync` a directory will fsync the files themselves is also +wrong. You can imagine a directory as a file containing a list of children, and +the list is just pointers to inodes. So `fsync`ing a directory will just write +the list of pointers to disk. + +--- + +## More reading on `fsync` + +- [(danluu) Fsyncgate: Errors on `fsync` are unrecoverable](https://danluu.com/fsyncgate/) +- [(puzpuzpuz) The secret life of `fsync`](https://puzpuzpuz.dev/the-secret-life-of-fsync) +- [(stackoverflow) Difference between `syncfs` (Linux only) and `fsync` (POSIX)](https://stackoverflow.com/questions/48171855/what-is-the-difference-between-fsync-and-syncfs) + (TL;DR: `syncfs` is "pretty please" fsync and doesn't block until the + operation is done) +- [(LWN) Feathersticth: Killing `fsync` softly](https://lwn.net/Articles/354861/) +- [(stackoverflow) Your Program ---~~`fflush`~~---> Your OS ---~~`fsync`~~---> Your Disk](https://stackoverflow.com/questions/2340610/difference-between-fflush-and-fsync) +- [(despairlabs) `fsync()` after `open()` is an elaborate no-op](https://despairlabs.com/blog/posts/2025-03-13-fsync-after-open-is-an-elaborate-no-op/) +- [(Postgres Wiki) `fsync` errors](https://wiki.postgresql.org/wiki/Fsync_Errors) From 51db068f5fb2e30d9c810942fd0fc6a52bd799c0 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:08:28 +0300 Subject: [PATCH 02/10] dump(posix.fsync-pitfalls): update --- site/dump/posix/fsync-pitfalls.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/site/dump/posix/fsync-pitfalls.md b/site/dump/posix/fsync-pitfalls.md index 7b30f59..0ecf2aa 100644 --- a/site/dump/posix/fsync-pitfalls.md +++ b/site/dump/posix/fsync-pitfalls.md @@ -41,8 +41,6 @@ This is a non-comprehensive list of the pitfalls of the `fsync` syscall. I will expand this list as I have more questions about all the questionable filesystems used and created by operating system enthusiasts. ---- - ## `fsync` does not ensure that a `fsync`'d file is visible in its parent directory From the manpage: @@ -56,8 +54,6 @@ This means that that you cannot rely on a file being in the directory after Speaking about `fsync`ing a directory: ---- - ## `fsync` on a directory does not ensure children are `fsync`'d From the manpage: From 985bf7e36f0c3f31621e4044489c2da2c41322c5 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:08:37 +0300 Subject: [PATCH 03/10] dump(posix.fsync-pitfalls): update --- site/dump/posix/fsync-pitfalls.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/site/dump/posix/fsync-pitfalls.md b/site/dump/posix/fsync-pitfalls.md index 0ecf2aa..8498ddb 100644 --- a/site/dump/posix/fsync-pitfalls.md +++ b/site/dump/posix/fsync-pitfalls.md @@ -67,8 +67,6 @@ wrong. You can imagine a directory as a file containing a list of children, and the list is just pointers to inodes. So `fsync`ing a directory will just write the list of pointers to disk. ---- - ## More reading on `fsync` - [(danluu) Fsyncgate: Errors on `fsync` are unrecoverable](https://danluu.com/fsyncgate/) From 07e9881fe77e6dcf593e272e096ea6ddb0d93399 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:10:47 +0300 Subject: [PATCH 04/10] dump(posix.fsync-pitfalls): update --- site/dump/posix/fsync-pitfalls.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/dump/posix/fsync-pitfalls.md b/site/dump/posix/fsync-pitfalls.md index 8498ddb..8ba5e98 100644 --- a/site/dump/posix/fsync-pitfalls.md +++ b/site/dump/posix/fsync-pitfalls.md @@ -8,7 +8,11 @@ date: 2025-07-11 This is a non-comprehensive list of the pitfalls of the `fsync` syscall.
-Linux `man 2 fsync` + + +Linux `man 2 fsync` + + > `fsync()` transfers ("flushes") all modified in-core data of (i.e., modified > buffer cache pages for) the file referred to by the file descriptor fd to the From 6f112dd0cdbe5620cdabee93e02cf3a9c33c5136 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:31:22 +0300 Subject: [PATCH 05/10] css: comment out broken styles for now --- site/assets/css/default.css | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/site/assets/css/default.css b/site/assets/css/default.css index d8085bd..b4f4391 100644 --- a/site/assets/css/default.css +++ b/site/assets/css/default.css @@ -199,7 +199,8 @@ body { @apply wrap-anywhere; } - &:not(:has(> code:only-child), :has(> img)) { + /* See next FIXME */ + &:not(/* :has(> code:only-child), */ :has(> img)) { @apply px-1; &:not(.font-mono) { @@ -211,9 +212,10 @@ body { @apply inline wrap-anywhere text-[red] dark:text-[yellow] border-2 border-[transparent] border-dashed; - &:has(> code:only-child) { - @apply border-dotted; - } + /* FIXME: :only-child still triggers when there is sibling raw content: foo bar: this is an only child */ + /* &:has(> code:only-child) { */ + /* @apply border-dotted; */ + /* } */ &:hover { @apply border-[red] dark:border-[yellow]; @@ -258,10 +260,11 @@ body { code:not(pre > code) { @apply border-1 border-dotted px-2 py-0.5 border-black dark:border-white; - a:is(:hover, :active) /* TODO: :only-child selector doesn't have effect. */ - &:not(:where(h1, h2, h3, h4, h5, h6) code):only-child { - @apply border-transparent; - } + /* See previous FIXME */ + /* a:is(:hover, :active) */ + /* &:not(:where(h1, h2, h3, h4, h5, h6) code):only-child { */ + /* @apply border-transparent; */ + /* } */ } pre code, pre code * { From ad7e1a12c196472097baac393f2672ca46f70d91 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:41:49 +0300 Subject: [PATCH 06/10] css: style details --- site/assets/css/default.css | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/site/assets/css/default.css b/site/assets/css/default.css index b4f4391..9c341df 100644 --- a/site/assets/css/default.css +++ b/site/assets/css/default.css @@ -311,8 +311,16 @@ body { } blockquote { - @apply border-1 p-2 bg-[#eee] shadow-[4px_4px_#444] dark:border-white - dark:bg-[#111] dark:shadow-[4px_4px_#bbb]; + @apply border-1 border-black dark:border-white p-2 bg-[#eee] + shadow-[4px_4px_#444] dark:bg-[#111] dark:shadow-[4px_4px_#bbb]; + } + + details { + & > summary { + @apply inline-block border-4 border-double border-[red] + hover:border-[maroon] dark:border-[yellow] dark:hover:border-[goldenrod] + p-4 cursor-pointer; + } } .callout { From a765c5fadc6083f339b0237ebd8d54d739baedcd Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:41:49 +0300 Subject: [PATCH 07/10] dump(posix.fsync-pitfalls): update --- site/dump/posix/fsync-pitfalls.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/dump/posix/fsync-pitfalls.md b/site/dump/posix/fsync-pitfalls.md index 8ba5e98..16bf9ee 100644 --- a/site/dump/posix/fsync-pitfalls.md +++ b/site/dump/posix/fsync-pitfalls.md @@ -71,9 +71,10 @@ wrong. You can imagine a directory as a file containing a list of children, and the list is just pointers to inodes. So `fsync`ing a directory will just write the list of pointers to disk. -## More reading on `fsync` +## More reading on `fsync` and other things related to files - [(danluu) Fsyncgate: Errors on `fsync` are unrecoverable](https://danluu.com/fsyncgate/) +- [(danluu) Files are hard](https://danluu.com/file-consistency/) - [(puzpuzpuz) The secret life of `fsync`](https://puzpuzpuz.dev/the-secret-life-of-fsync) - [(stackoverflow) Difference between `syncfs` (Linux only) and `fsync` (POSIX)](https://stackoverflow.com/questions/48171855/what-is-the-difference-between-fsync-and-syncfs) (TL;DR: `syncfs` is "pretty please" fsync and doesn't block until the From 1116a3d79787a815fd8aec80fd33827e6464c3f7 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 11 Jul 2025 23:43:49 +0300 Subject: [PATCH 08/10] dump(posix.fsync-pitfalls): update --- site/dump/posix/fsync-pitfalls.md | 1 + 1 file changed, 1 insertion(+) diff --git a/site/dump/posix/fsync-pitfalls.md b/site/dump/posix/fsync-pitfalls.md index 16bf9ee..548ccf2 100644 --- a/site/dump/posix/fsync-pitfalls.md +++ b/site/dump/posix/fsync-pitfalls.md @@ -79,6 +79,7 @@ the list of pointers to disk. - [(stackoverflow) Difference between `syncfs` (Linux only) and `fsync` (POSIX)](https://stackoverflow.com/questions/48171855/what-is-the-difference-between-fsync-and-syncfs) (TL;DR: `syncfs` is "pretty please" fsync and doesn't block until the operation is done) +- [(transactional.blog) Userland Disk I/O](https://transactional.blog/how-to-learn/disk-io) - [(LWN) Feathersticth: Killing `fsync` softly](https://lwn.net/Articles/354861/) - [(stackoverflow) Your Program ---~~`fflush`~~---> Your OS ---~~`fsync`~~---> Your Disk](https://stackoverflow.com/questions/2340610/difference-between-fflush-and-fsync) - [(despairlabs) `fsync()` after `open()` is an elaborate no-op](https://despairlabs.com/blog/posts/2025-03-13-fsync-after-open-is-an-elaborate-no-op/) From a52b2f60017cfdc4cfdcdba6105eb1254e7ef6b5 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 12 Jul 2025 00:53:06 +0300 Subject: [PATCH 09/10] blog.why-cores: fix typo --- site/blog/2025-06-05-why-cores.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/blog/2025-06-05-why-cores.md b/site/blog/2025-06-05-why-cores.md index 7ad61b9..3bec659 100644 --- a/site/blog/2025-06-05-why-cores.md +++ b/site/blog/2025-06-05-why-cores.md @@ -262,7 +262,7 @@ than others. The process determines how faulty a CPU is and sorts them into higher tier CPUs exist. The likelihood of faulty silicon also increases with the smaller the -architecture size gets (the Apple M4 is 4m, which is crazy), so this method of +architecture size gets (the Apple M4 is 4nm, which is crazy), so this method of recycling worse chips is becoming much more valuable by the day. So, in summary the 32 core CPU I was testing this on was most likely just the 64 From 03d1ef80aba226f2a5678b005c88c7374d2d2a2f Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 12 Jul 2025 00:54:10 +0300 Subject: [PATCH 10/10] treewide: fix typos --- site/blog/2025-06-20-intro-cab.md | 14 +++++++------- site/dump/web/hsts.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/site/blog/2025-06-20-intro-cab.md b/site/blog/2025-06-20-intro-cab.md index 7cf81f5..8242b60 100644 --- a/site/blog/2025-06-20-intro-cab.md +++ b/site/blog/2025-06-20-intro-cab.md @@ -55,7 +55,7 @@ Let's start from the top: Cab doesn't have "declarations", or "pattern matching". This is a _literal_ -comparision operation. Exactly the same as the `==` operator in most languages. +comparison operation. Exactly the same as the `==` operator in most languages. But then, how do we even declare anything in the local scope? How do we address values by name, instead of inlining them all? @@ -67,7 +67,7 @@ In Cab, you can create a binding value with the `@` syntax. So here, `@Any` is a binding value. And the way you use bindings (aka, binds) in Cab is simple: You compare them -using the comparision operator, `=` or `!=`. +using the comparison operator, `=` or `!=`. A bind is equal to _any_ value, literally anything! So, `@foo = 123` is always true. @@ -95,7 +95,7 @@ In order to prevent things from going out of control, Cab limits when binds can bind the value they are compared to to their local scope. The rule that governs this is: A bind, when compared to a value, will bind that -value to the scope the bind was declared in _if the comparision operation is +value to the scope the bind was declared in _if the comparison operation is within that scope_. So, we don't actually get `_` bound to `@Any` because the `=` is outside the @@ -137,7 +137,7 @@ Trailing commas are nice! -I've already explained how comparisions & binds work in Cab, so I'll skip the +I've already explained how comparisons & binds work in Cab, so I'll skip the `@symbol =` part. The way lambdas work in Cab is as follows: ` => `. @@ -146,8 +146,8 @@ The `=>` is an infix operator, yet again. And the `` can be _any expression_. When a lambda is called, the `` is compared with the argument in a new -scope. If they are not "equal", aka when the comparision evaluates to `false`, -an exception is thrown. +scope. If they are not "equal", aka when the comparison evaluates to `false`, an +exception is thrown. But when it is `true`, the `` is evaluated and returned. @@ -172,7 +172,7 @@ What is `String`? It's a value that is equal to all strings. No, not exactly a "type"! This is why Cab doesn't exactly have "typing", as everything is a value. This makes `@name & String` a value that is equal to any string, and when -compared to a string value, will bind it to the scope & have the comparision +compared to a string value, will bind it to the scope & have the comparison expression evaluate to `true`. ## The body diff --git a/site/dump/web/hsts.md b/site/dump/web/hsts.md index 711eb5d..e5b02d8 100644 --- a/site/dump/web/hsts.md +++ b/site/dump/web/hsts.md @@ -21,5 +21,5 @@ able to recall the HSTS header, and let you connect insecurely. > Do not do this if you value your browsing history of that site. It literally > says "Forget This Site", act accordingly. -These instrucitons are Firefox and Firefox-based browser specific, but the +These instructions are Firefox and Firefox-based browser specific, but the process is same on other browsers.