All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/7] btrfs: Preallocate chunks in cow_file_range_async
Date: Thu, 28 Mar 2019 15:11:18 +0100	[thread overview]
Message-ID: <20190328141118.GI29086@twin.jikos.cz> (raw)
In-Reply-To: <04687d49-6642-54bf-1a8f-18f6b54465a0@suse.com>

On Thu, Mar 28, 2019 at 02:49:30PM +0200, Nikolay Borisov wrote:
> 
> 
> On 27.03.19 г. 19:23 ч., David Sterba wrote:
> > On Tue, Mar 12, 2019 at 05:20:24PM +0200, Nikolay Borisov wrote:
> >> @@ -1190,45 +1201,71 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
> >>  				unsigned int write_flags)
> >>  {
> >>  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
> >> -	struct async_cow *async_cow;
> >> +	struct async_cow *ctx;
> >> +	struct async_chunk *async_chunk;
> >>  	unsigned long nr_pages;
> >>  	u64 cur_end;
> >> +	u64 num_chunks = DIV_ROUND_UP(end - start, SZ_512K);
> >> +	int i;
> >> +	bool should_compress;
> >>  
> >>  	clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED,
> >>  			 1, 0, NULL);
> >> -	while (start < end) {
> >> -		async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
> >> -		BUG_ON(!async_cow); /* -ENOMEM */
> >> +
> >> +	if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS &&
> >> +	    !btrfs_test_opt(fs_info, FORCE_COMPRESS)) {
> >> +		num_chunks = 1;
> >> +		should_compress = false;
> >> +	} else {
> >> +		should_compress = true;
> >> +	}
> >> +
> >> +	ctx = kmalloc(struct_size(ctx, chunks, num_chunks), GFP_NOFS);
> > 
> > This leads to OOM due to high order allocation. And this is worse than
> > the previous state, where there are many small allocation that could
> > potentially fail (but most likely will not due to GFP_NOSF and size <
> > PAGE_SIZE).
> > 
> > So this needs to be reworked to avoid the costly allocations or reverted
> > to the previous state.
> 
> Right, makes sense. In order to have a simplified submission logic I
> think to rework the allocation to have a loop that allocates a single
> item for every chunk or alternatively switch to using kvmalloc? I think
> the fact that vmalloced memory might not be contiguous is not critical
> for the metadata structures in this case?

kvmalloc would work here, though there is some overhead involved
compared to bare kmalloc (the mappings). As the call happens on writeout
path, I'd be cautious about unnecessary overhead.

If looping over the range works, then we can allocate the largest size
that does not require kvmalloc (PAGE_ALLOC_COSTLY_ORDER) and then reuse
it for each iteration.

  parent reply	other threads:[~2019-03-28 14:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-12 15:20 [PATCH v4 0/7] Compress path cleanups Nikolay Borisov
2019-03-12 15:20 ` [PATCH 1/7] btrfs: Preallocate chunks in cow_file_range_async Nikolay Borisov
2019-03-12 15:35   ` Johannes Thumshirn
2019-03-27 17:23   ` David Sterba
2019-03-28 12:49     ` Nikolay Borisov
2019-03-28 12:52       ` Nikolay Borisov
2019-03-28 14:11       ` David Sterba [this message]
2019-03-28 15:10         ` Nikolay Borisov
2019-03-28 15:45           ` David Sterba
2019-03-12 15:20 ` [PATCH 2/7] btrfs: Rename async_cow to async_chunk Nikolay Borisov
2019-03-12 15:34   ` Johannes Thumshirn
2019-03-12 15:20 ` [PATCH 3/7] btrfs: Remove fs_info from struct async_chunk Nikolay Borisov
2019-03-12 15:20 ` [PATCH 4/7] btrfs: Make compress_file_range take only " Nikolay Borisov
2019-03-12 15:20 ` [PATCH 5/7] btrfs: Replace clear_extent_bit with unlock_extent Nikolay Borisov
2019-03-12 15:27   ` Johannes Thumshirn
2019-03-12 15:20 ` [PATCH 6/7] btrfs: Set iotree only once in submit_compressed_extents Nikolay Borisov
2019-03-12 15:30   ` Johannes Thumshirn
2019-03-12 15:20 ` [PATCH 7/7] btrfs: Factor out common extent locking code " Nikolay Borisov
2019-03-12 15:31   ` Johannes Thumshirn
2019-03-13 15:36 ` [PATCH v4 0/7] Compress path cleanups David Sterba

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=20190328141118.GI29086@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.