Register for the iXsystems Community to get an ad-free experience

ZFS tweak for first-fit versus best-fit

Western Digital Drives - The Preferred Drives of FreeNAS and TrueNAS CORE
Status
Not open for further replies.

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
So as has been mentioned a lot on the forums, once you hit 80% full on a zpool then the allocation algorithm changes to first available instead of best fit. Since I'm slowly heading towards that number and a zpool with 20% free still equates to over 6TB for me I figured there should be a way to change the crossover to 90% or something a little more limiting. I was just thinking that 20% on a zpool of my size is quite a bit of wasted space that would be forced to use "best-fit". So I found: http://blogs.everycity.co.uk/alasda...ly-slowly-when-free-disk-usage-goes-above-80/ and it says to use
echo "set zfs:metaslab_df_free_pct=4" >> /etc/system
Now that webpage says it is for Opensolaris 10 only. I wasn't sure if the same tweak applies to FreeBSD's implementation of ZFS. More Googling lead me to find http://fxr.watson.org/fxr/trackident?i=metaslab_df_free_pct which makes me think it does exist so I then went about trying to verify that "4" is the correct value. So I clicked on the FreeBSD link at the last link and for comments it says:

The minimum free space, in percent, which must be available in a space map to continue allocations in a first-fit fashion. Once the space_map's free space drops below this level we dynamically switch to using best-fit allocations.

Now, since the default is 4 and with that explanation it really makes me think that zpools actually use the best fit until 96% full. This is somewhat contradictory from what is told on the forums, so I found this interesting. Additionally I found this, which has a change to FreeBSD head: (not sure which version exactly, but it is dated 2010)
-int metaslab_df_free_pct = 30;
+int metaslab_df_free_pct = 4;

So here it looks like the "crossover" from first-fit to best-fit changed from 30% free to 4%. Of course, this only creates more questions because we're still not at the fabled 80% mark.

Anyone else come to the same conclusion or know anything else regarding this? I was just hoping to find the tunable parameter to change when the algorithm changes, but it has brought with it new questions.

All I'm really trying to figure out is if this variable is correct for FreeNAS and what the value actually is normally. Any ideas how I can validate this?
 

jgreco

Resident Grinch
Moderator
Joined
May 29, 2011
Messages
16,544
What you're looking at there is the metaslab free space threshold. ZFS creates many regions on a virtual device, they're called metaslabs and they each have a space map. FreeBSD has used 4 for quite some time I believe. Regardless of the actual allocation strategy, as your disks fill, the ability of the system to find contiguous and convenient storage blocks will begin to deteriorate, and as it does so, the system will begin to perform poorly, especially for writes, but also reading bits that were written under the stressy conditions as well.

UTSL. :smile:
 
Status
Not open for further replies.
Top