# On tuning ext4 for storage nodes

**URL:** <https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073>\
**Category:** Node Operators\
**Tags:** linux, hardware\
**Created:** [July 17, 2022, 1:34pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073 "2022-07-17T13:34:32Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [August 9, 2024, 5:29am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/62 "2024-08-09T05:29:47Z")

</div>

We use an in-memory cache to write to the database, by default it syncs every hour.

---

<div class="post-metadata">

**Author:** ![Zetanova](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/zetanova/32/1137_2.png) [@Zetanova](https://forum.storj.io/u/Zetanova)\
**Post date:** [August 11, 2024, 7:16pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/63 "2024-08-11T19:16:55Z")

</div>

Its not about a in-memory cache by itself.

It’s about that they solution of the sqlite lock contention issue  
produced of the file-walker random IO issue.

It’s basically impossible anymore to run a node on a single HDD  
dedicated or shared with an low IO process.

The solution to add file-system metadata cache in memory or separate dedicated flash storage seams more a workaround then anything else.

What I could extract from the forum, is that a node requires to overcome the file-walker issue around 1GB fs-cache per 1TB data. It makes low HW like raspberry-pi 3,4,5 already not meat this requirement and to run the node as a background task on a server seams on spare/backup drives not feasible.

Then there is the issue with the file directory fragmentation (ext4 and maybe others).  
This could be solved to restructure the storage directory to add files only in the current-week directory and files from previous weeks could only be deleted but none added.

But this would require a file-locator component that would be based on a fast directory (database)

If required, even the current hash-map directory layout could be used in parallel.

I know that simpler is better, but to answer the question of the current inventory  
to make full scan in random mode on the drive makes little sense.

---

<div class="post-metadata">

**Author:** ![JWvdV](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/jwvdv/32/7814_2.png) [@JWvdV](https://forum.storj.io/u/JWvdV)\
**Post date:** [August 11, 2024, 8:00pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/64 "2024-08-11T20:00:07Z")

</div>

> [@Zetanova](#):
>
> I know that simpler is better, but to answer the question of the current inventory  
> to make full scan in random mode on the drive makes little sense.

But that’s is what the badger cache is all about, I thought? Serves the same purpose as a read cache like LVM-hotspotcache or L2ARC.

I mean: aren’t you solving a problem, for which already a solution is in trial mode?

---

<div class="post-metadata">

**Author:** ![Zetanova](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/zetanova/32/1137_2.png) [@Zetanova](https://forum.storj.io/u/Zetanova)\
**Post date:** [August 11, 2024, 8:42pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/65 "2024-08-11T20:42:26Z")

</div>

> [@JWvdV](#):
>
> badger cache

I wrote him this even, the badger cache would resolve the file-walker random IO issue.  
But not the directory fragmentation and stale/ghost data from partially uploaded chunks.

The badger cache would be require to use it as a file-locator, but then it would not be a “cache” anymore. It would then be more a “honey badger”

The main idea is to drop new chunks only in the latest directory example: `storage/2024-32/0/chunkId`  
this would require a lookup in a fast map/index over a file-locator

Benefits of a file-locator in the “honey badger”

- only the latest directory would require a check on restart or node crash.
- on a new week, the previous week directory would be read and delete only and could be garbage collected or maybe differently optimized in the future
- Multiple drives could be used per node, too extend a node or copy “weeks” slowly over
- A flash+hdd mode for new/hot data and an archive hdd’s
- most likely others …

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [August 12, 2024, 5:33am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/66 "2024-08-12T05:33:49Z")

</div>

> [@Zetanova](#):
>
> It’s about that they solution of the sqlite lock contention issue  
> produced of the file-walker random IO issue.

The filewalker will update the database only when it’s finished the scan. So, usually they should not lock a database while working.

> [@Zetanova](#):
>
> The solution to add file-system metadata cache in memory or separate dedicated flash storage seams more a workaround then anything else.

We implemented a different cache with badger, so it is used to cache a metadata and speed up all filewalkers.

> [@Zetanova](#):
>
> What I could extract from the forum, is that a node requires to overcome the file-walker issue around 1GB fs-cache per 1TB data. It makes low HW like raspberry-pi 3,4,5 already not meat this requirement and to run the node as a background task on a server seams on spare/backup drives not feasible.

The badger cache should help a low power devices to survive. However, it requires to disable a lazy mode (because the badger even more sensitive to multiple accesses of different processes).

> [@Zetanova](#):
>
> The main idea is to drop new chunks only in the latest directory example: `storage/2024-32/0/chunkId`  
> this would require a lookup in a fast map/index over a file-locator

> [@Suggestion: add one more subfolder level to blobs folders structure](https://forum.storj.io/t/suggestion-add-one-more-subfolder-level-to-blobs-folders-structure/27266):
>
> Today I wrote about my problem with slow file deletion on ext4 filesystem (mostly for SLC folders): [How do you solve slow file deletion on ext4?](https://forum.storj.io/t/how-do-you-solve-slow-file-deletion-on-ext4/) Right now Storj uses folder structure “/ab/filename.sj1” with 1024 subfolders for every Satellite. During intensive tests SLC sends tens of millions files. I see more than 50mil records in piece\_expiration.db so number of files in each folder can reach 50 000 or even 100 000. And we hope one day Satellites working with customer’s data will surpass the…

and

> [@How do you solve slow file deletion on ext4?](https://forum.storj.io/t/how-do-you-solve-slow-file-deletion-on-ext4/27260/49):
>
> Very often referenced: [Benchmark: Deep directory structure vs. flat directory structure to store millions of files on ext4 | by hartator | Medium](https://medium.com/@hartator/benchmark-deep-directory-structure-vs-flat-directory-structure-to-store-millions-of-files-on-ext4-cac1000ca28)

---

<div class="post-metadata">

**Author:** ![Zetanova](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/zetanova/32/1137_2.png) [@Zetanova](https://forum.storj.io/u/Zetanova)\
**Post date:** [August 13, 2024, 3:22pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/67 "2024-08-13T15:22:48Z")

</div>

> [@Alexey](#):
>
> The badger cache should help a low power devices to survive. However, it requires to disable a lazy mode (because the badger even more sensitive to multiple accesses of different processes).

This problem I don’t understand or better a journal “event-sourcing” would solve it.  
In dotnet I could make in a hand full days, but I am at golang a noob.

Maybe I will implement a tech-demo fork.

I will go currently with the _workaround_ with a new rsp5 the zfs+special device metadata with a 5GB/1TB ratio over a partition on a NVMe

---

<div class="post-metadata">

**Author:** ![Toyoo](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/toyoo/32/1126_2.png) [@Toyoo](https://forum.storj.io/u/Toyoo)\
**Post date:** [August 13, 2024, 9:35pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/68 "2024-08-13T21:35:37Z")

</div>

> [@Zetanova](#):
>
> In dotnet I could make in a hand full days, but I am at golang a noob.

Maybe you can just try writing high-level pseudocode? Might be enough to show the idea.

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [August 14, 2024, 8:16am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/69 "2024-08-14T08:16:13Z")

</div>

There is a limit in the badge cache implementation, which requires an exclusive access. This is also why it’s an experimental feature.

---

<div class="post-metadata">

**Author:** ![Zetanova](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/zetanova/32/1137_2.png) [@Zetanova](https://forum.storj.io/u/Zetanova)\
**Post date:** [October 12, 2024, 7:12am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/70 "2024-10-12T07:12:21Z")

</div>

I forgot to ask, did the disabled sqlite implementation create/open the db-file with the `WAL` feature enabled?

sqlite creates/opens a db file in legacy mode 2001 style with `WAL` disabled. The writes will modify the file-data in place and they will block reads until the transaction finishes.

With `WAL` enabled, regular writes will not block reads on the db file.  
[https://sqlite.org/wal.html](https://sqlite.org/wal.html)

This would be more then the half of my above approach description and most likely this was the issue with the storj-sqlite implementation.

The other optimization/features that a journal offers would only be necessary in high OP scenarios \>50k op/s. where one file upload would generate around `2 + chunks` operations. Don’t really think that even the big nodes have this action, or?

For completion here are the features that would a journal extend beside sqlite-Wal:

- `pass-through` where events do not even gets committed into the journal and instantly get applied/processed. This is feature is near the same as a file upload would store its state in memory and writes to the sqlite db only at the end once.

- Differencing `pub+sync` and `pub+flush` it is related to pub/sub and event-sourcing topic. The producer, in our case the file-upload process, would know best when it needs critical events/data to be persisted `flush` and processed at a later stage (can be minutes later) or when it needs to know that all processed events got fully processed `sync`. As an example for `sync`, a file upload needs to respond to the uploader and to guarantee that a follow up read-file of the uploader would succeed. As an example for `flush`, a delete-fileS would publish multiple events followed by a single `flush`.

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [October 12, 2024, 7:31am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/71 "2024-10-12T07:31:47Z")

</div>

> [@Zetanova](#):
>
> I forgot to ask, did the disabled sqlite implementation create/open the db-file with the `WAL` feature enabled?

Why do you think so?

```auto
$ ls -l /mnt/x/storagenode2/storage/*.db*
-rw-r--r-- 1 root root 75304960 Oct 12 09:59 /mnt/x/storagenode2/storage/bandwidth.db
-rw-r--r-- 1 root root 32768 Oct 12 10:29 /mnt/x/storagenode2/storage/bandwidth.db-shm
-rw-r--r-- 1 root root 4152 Oct 12 10:29 /mnt/x/storagenode2/storage/bandwidth.db-wal

```

I can see a wal files.  
You also may check the code.

---

<div class="post-metadata">

**Author:** ![Zetanova](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/zetanova/32/1137_2.png) [@Zetanova](https://forum.storj.io/u/Zetanova)\
**Post date:** [October 12, 2024, 7:52am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/72 "2024-10-12T07:52:21Z")

</div>

The sqlite of the file catalog got removed from the source and was replaced by the `file-walker` approach with the reason that the sqlite-db is bottle-nacking the file uploads.

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [October 12, 2024, 1:50pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/73 "2024-10-12T13:50:46Z")

</div>

It is not removed, please, check the code.  
SQLite databases are still used.  
However, we implemented a badger cache:

> [@Badger cache: are we ready?](https://forum.storj.io/t/badger-cache-are-we-ready/27323):
>
> We are all on 1.108 now. In our nodes we have a really important improvement disabled by default and ready to launch… badger cache! Can we talk about it? Are you testing it? Is it safe to enable to all nodes? Is it better to wait?

And the ultimate feature of

> [@The whole disk/partition allocation feature](https://forum.storj.io/t/the-whole-disk-partition-allocation-feature/28192):
>
> Hello, If I set the flag for dedicated disk use, will the disk be 100% used? Or will there be enough space left for the DBs? Or should I move the DBs to another disk for safety?

Please, use them!

---

<div class="post-metadata">

**Author:** ![Mitsos](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/mitsos/32/1125_2.png) [@Mitsos](https://forum.storj.io/u/Mitsos)\
**Post date:** [October 12, 2024, 2:02pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/74 "2024-10-12T14:02:53Z")

</div>

> [@Alexey](#):
>
> However, we implemented a badger cache:
> 
> > [@](#):
> >
> > We are all on 1.108 now. In our nodes we have a really important improvement disabled by default and ready to launch… badger cache! Can we talk about it? Are you testing it? Is it safe to enable to all nodes? Is it better to wait?

 ![Screenshot_20241012_165845](https://storj-s3.bcdn.literatehosting.net/original/3X/a/f/af897c318c720896fa4584916041dcbda8b30191.jpeg)

**Here’s me complaining (yet again!) without any single reason, just out of the blue.** 4 months later and we (=baremetal) still don’t have a way to configure where badger is stored.

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [October 12, 2024, 2:21pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/75 "2024-10-12T14:21:40Z")

</div>

Yeees. But if you so concerned, and run the node without docker, you can still reroute it with a symlinks.  
I can help, please post a description of your environment

---

<div class="post-metadata">

**Author:** ![Mitsos](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/mitsos/32/1125_2.png) [@Mitsos](https://forum.storj.io/u/Mitsos)\
**Post date:** [October 12, 2024, 2:25pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/76 "2024-10-12T14:25:52Z")

</div>

Not _that_ concerned, thank you.

---

<div class="post-metadata">

**Author:** ![PieceKeeper](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/piecekeeper/32/1125_2.png) [@PieceKeeper](https://forum.storj.io/u/PieceKeeper)\
**Post date:** [December 23, 2024, 12:07pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/77 "2024-12-23T12:07:37Z")

</div>

> [@Toyoo](#):
>
> -i 65536

Hi @Toyoo, do you think the -i 65536 argument on mke2fs is still a safe value today? I ask because you wrote in another thread ([Recommended GB of RAM / TB stored? - #7 by Toyoo](https://forum.storj.io/t/recommended-gb-of-ram-tb-stored/26823/7)), that the average piece size has gone down alot.

---

<div class="post-metadata">

**Author:** ![Toyoo](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/toyoo/32/1126_2.png) [@Toyoo](https://forum.storj.io/u/Toyoo)\
**Post date:** [December 24, 2024, 11:49pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/78 "2024-12-24T23:49:11Z")

</div>

Looking at the numbers on my nodes I do think it should be good enough for the forseeable future, but I would probably step down any new file systems to ~45000.

With [hashstore](https://forum.storj.io/t/tech-preview-hashtore-backend-for-storage-nodes/28724) on the horizon this number probably matters less now though.

---

<div class="post-metadata">

**Author:** ![alpharabbit](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alpharabbit/32/1129_2.png) [@alpharabbit](https://forum.storj.io/u/alpharabbit)\
**Post date:** [December 25, 2024, 12:10am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/79 "2024-12-25T00:10:38Z")

</div>

The average piece size for all of my nodes is over 200K, so no problem.

---

<div class="post-metadata">

**Author:** ![PieceKeeper](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/piecekeeper/32/1125_2.png) [@PieceKeeper](https://forum.storj.io/u/PieceKeeper)\
**Post date:** [December 25, 2024, 10:05am UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/80 "2024-12-25T10:05:31Z")

</div>

Thanks @Toyoo and @alpharabbit

Merry Christmas everybody 🌲

---

<div class="post-metadata">

**Author:** ![snorkel](https://storj.bcdn.literatehosting.com/letter_avatar/snorkel/32/6_449c533f586939b6e5f246632a46421f.png) [@snorkel](https://forum.storj.io/u/snorkel)\
**Post date:** [December 26, 2024, 9:01pm UTC](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073/81 "2024-12-26T21:01:42Z")

</div>

With the startup-piece-scan now reporting the pieces size and pieces number, it’s easy to calculate the average piece size.  
For my 6TB node, the average piece size is: 203845 bytes.

[Previous page](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073.md?page=3)

[Next page](https://forum.storj.io/t/on-tuning-ext4-for-storage-nodes/19073.md?page=5)
