linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Austin S. Hemmelgarn" <ahferroin7@gmail.com>
To: Dave <davestechshop@gmail.com>,
	Linux fs Btrfs <linux-btrfs@vger.kernel.org>
Cc: Peter Grandi <pg@btfs.list.sabi.co.uk>
Subject: Re: defragmenting best practice?
Date: Thu, 2 Nov 2017 07:17:19 -0400	[thread overview]
Message-ID: <11db29b3-e421-2b0b-68d5-fb6c233d0767@gmail.com> (raw)
In-Reply-To: <CAH=dxU6bhi=xwugt+nynU5BSnvBzZ5L=C5nxPt39v14YwhcNCA@mail.gmail.com>

On 2017-11-01 20:09, Dave wrote:
> On Wed, Nov 1, 2017 at 1:48 PM, Peter Grandi <pg@btfs.list.sabi.co.uk> wrote:
>>> When defragmenting individual files on a BTRFS filesystem with
>>> COW, I assume reflinks between that file and all snapshots are
>>> broken. So if there are 30 snapshots on that volume, that one
>>> file will suddenly take up 30 times more space... [ ... ]
>>
>> Defragmentation works by effectively making a copy of the file
>> contents (simplistic view), so the end result is one copy with
>> 29 reflinked contents, and one copy with defragmented contents.
> 
> The clarification is much appreciated.
> 
>>> Can you also give an example of using find, as you suggested
>>> above? [ ... ]
>>
>> Well, one way is to use 'find' as a filtering replacement for
>> 'defrag' option '-r', as in for example:
>>
>>    find "$HOME" -xdev '(' -name '*.sqlite' -o -name '*.mk4' ')' \
>>      -type f  -print0 | xargs -0 btrfs fi defrag
>>
>> Another one is to find the most fragmented files first or all
>> files of at least 1M with with at least say 100 fragments as in:
>>
>>    find "$HOME" -xdev -type f -size +1M -print0 | xargs -0 filefrag \
>>      | perl -n -e 'print "$1\0" if (m/(.*): ([0-9]+) extents/ && $1 > 100)' \
>>      | xargs -0 btrfs fi defrag
>>
>> But there are many 'find' web pages and that is not quite a
>> Btrfs related topic.
> 
> Your examples were perfect. I have experience using find in similar
> ways. I can take it from there. :-)
> 
>>> Background: I'm not sure why our Firefox performance is so terrible
>>
>> As I always say, "performance" is not the same as "speed", and
>> probably your Firefox "performance" is sort of OKish even if the
>> "speed" is terrile, and neither is likely related to the profile
>> or the cache being on Btrfs.
> 
> Here's what happened. Two years ago I installed Kubuntu (with Firefox)
> on two desktop computers. One machine performed fine. Like you said,
> "sort of OKish" and that's what we expect with the current state of
> Linux. The other machine was substantially worse. We ran side-by-side
> real-world tests on these two machines for months.
> 
> Initially I did a lot of testing, troubleshooting and reconfiguration
> trying to get the second machine to perform as well as the first. I
> never had success. At first I thought it was related to the GPU (or
> driver). Then I thought it was because the first machine used the z170
> chipset and the second was X99 based. But that wasn't it. I have never
> solved the problem and I have been coming back to it periodically
> these last two years. In that time I have tried different distros from
> opensuse to Arch, and a lot of different hardware.
> 
> Furthermore, my new machines have the same performance problem. The
> most interesting example is a high end machine with 256 GB of RAM. It
> showed substantially worse desktop application performance than any
> other computer here. All are running the exact same version of Firefox
> with the exact same add-ons. (The installations are carbon copies of
> each other.)
> 
> What originally caught my attention was earlier information in this thread:
> 
> Am Wed, 20 Sep 2017 07:46:52 -0400
> schrieb "Austin S. Hemmelgarn" <ahferroin7@gmail.com>:
> 
>>>       Fragmentation: Files with a lot of random writes can become
>>> heavily fragmented (10000+ extents) causing excessive multi-second
>>> spikes of CPU load on systems with an SSD or large amount a RAM. On
>>> desktops this primarily affects application databases (including
>>> Firefox). Workarounds include manually defragmenting your home
>>> directory using btrfs fi defragment. Auto-defragment (mount option
>>> autodefrag) should solve this problem.
>>>
>>> Upon reading that I am wondering if fragmentation in the Firefox
>>> profile is part of my issue. That's one thing I never tested
>>> previously. (BTW, this system has 256 GB of RAM and 20 cores.)
>> Almost certainly.  Most modern web browsers are brain-dead and insist
>> on using SQLite databases (or traditional DB files) for everything,
>> including the cache, and the usage for the cache in particular kills
>> performance when fragmentation is an issue.
> 
> It turns out the the first machine (which performed well enough) was
> the last one which was installed using LVM + EXT4. The second machine
> (the one with the original performance problem) and all subsequent
> machines have used BTRFS.
> 
> And the worst performing machine was the one with the most RAM and a
> fast NVMe drive and top of the line hardware.
Somewhat nonsensically, I'll bet that NVMe is a contributing factor in 
this particular case.  NVMe has particularly bad performance with the 
old block IO schedulers (though it is NVMe, so it should still be better 
than a SATA or SAS SSD), and the new blk-mq framework just got 
scheduling support in 4.12, and only got reasonably good scheduling 
options in 4.13.  I doubt it's the entirety of the issue, but it's 
probably part of it.
> 
> While Firefox and Linux in general have their performance "issues",
> that's not relevant here. I'm comparing the same distros, same Firefox
> versions, same Firefox add-ons, etc. I eventually tested many hardware
> configurations: different CPU's, motherboards, GPU's, SSD's, RAM, etc.
> The only remaining difference I can find is that the computer with
> acceptable performance uses LVM + EXT4 while all the others use BTRFS.
> 
> With all the great feedback I have gotten here, I'm now ready to
> retest this after implementing all the BTRFS-related suggestions I
> have received. Maybe that will solve the problem or maybe this mystery
> will continue...
Hmm, if you're only using SSD's, that may partially explain things.  I 
don't remember if it was mentioned earlier in this thread, but you might 
try adding 'nossd' to the mount options.  The 'ssd' mount option (which 
gets set automatically if the device reports as non-rotational) impacts 
how the block allocator works, and that can have a pretty insane impact 
on performance.  Additionally, independently from that, try toggling the 
'discard' mount option.  If you have it enabled, disable it, if you have 
it disabled, enable it.  Inline discards can be very expensive on some 
hardware, especially older SSD's, and discards happen pretty frequently 
in a COW filesystem.

  reply	other threads:[~2017-11-02 11:17 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31  7:05 btrfs filesystem defragment -r -- does it affect subvolumes? Ulli Horlacher
2017-09-12 16:28 ` defragmenting best practice? Ulli Horlacher
2017-09-12 17:27   ` Austin S. Hemmelgarn
2017-09-14  7:54     ` Duncan
2017-09-14 12:28       ` Austin S. Hemmelgarn
2017-09-14 11:38   ` Kai Krakow
2017-09-14 13:31     ` Tomasz Kłoczko
2017-09-14 15:24       ` Kai Krakow
2017-09-14 15:47         ` Kai Krakow
2017-09-14 17:48         ` Tomasz Kłoczko
2017-09-14 18:53           ` Austin S. Hemmelgarn
2017-09-15  2:26             ` Tomasz Kłoczko
2017-09-15 12:23               ` Austin S. Hemmelgarn
2017-09-14 20:17           ` Kai Krakow
2017-09-15 10:54           ` Michał Sokołowski
2017-09-15 11:13             ` Peter Grandi
2017-09-15 13:07             ` Tomasz Kłoczko
2017-09-15 14:11               ` Michał Sokołowski
2017-09-15 16:35                 ` Peter Grandi
2017-09-15 17:08                 ` Kai Krakow
2017-09-15 19:10                   ` Tomasz Kłoczko
2017-09-20  6:38                     ` Dave
2017-09-20 11:46                       ` Austin S. Hemmelgarn
2017-09-21 20:10                         ` Kai Krakow
2017-09-21 23:30                           ` Dave
2017-09-21 23:58                           ` Kai Krakow
2017-09-22 11:22                           ` Austin S. Hemmelgarn
2017-09-22 20:29                             ` Marc Joliet
2017-09-21 11:09                       ` Duncan
2017-10-31 21:47                         ` Dave
2017-10-31 23:06                           ` Peter Grandi
2017-11-01  0:37                             ` Dave
2017-11-01 12:21                               ` Austin S. Hemmelgarn
2017-11-02  1:39                                 ` Dave
2017-11-02 11:07                                   ` Austin S. Hemmelgarn
2017-11-03  2:59                                     ` Dave
2017-11-03  7:12                                       ` Kai Krakow
2017-11-03  5:58                                   ` Marat Khalili
2017-11-03  7:19                                     ` Kai Krakow
2017-11-01 17:48                               ` Peter Grandi
2017-11-02  0:09                                 ` Dave
2017-11-02 11:17                                   ` Austin S. Hemmelgarn [this message]
2017-11-02 18:09                                     ` Dave
2017-11-02 18:37                                       ` Austin S. Hemmelgarn
2017-11-02  0:43                                 ` Peter Grandi
2017-11-02 21:16                               ` Kai Krakow
2017-11-03  2:47                                 ` Dave
2017-11-03  7:26                                   ` Kai Krakow
2017-11-03 11:30                                     ` Austin S. Hemmelgarn
     [not found]                             ` <CAH=dxU47-52-asM5vJ_-qOpEpjZczHw7vQzgi1-TeKm58++zBQ@mail.gmail.com>
2017-12-11  5:18                               ` Dave
2017-12-11  6:10                                 ` Timofey Titovets
2017-11-01  7:43                           ` Sean Greenslade
2017-11-01 13:31                           ` Duncan
2017-11-01 23:36                             ` Dave
2017-09-21 19:28                       ` Sean Greenslade
2017-09-20  7:34                     ` Dmitry Kudriavtsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11db29b3-e421-2b0b-68d5-fb6c233d0767@gmail.com \
    --to=ahferroin7@gmail.com \
    --cc=davestechshop@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=pg@btfs.list.sabi.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).