All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <yuchao0@huawei.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH 2/2] f2fs: support data compression
Date: Wed, 30 Oct 2019 10:47:14 -0700	[thread overview]
Message-ID: <20191030174714.GA36729@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <20191030165056.GA693@sol.localdomain>

On 10/30, Eric Biggers wrote:
> On Wed, Oct 30, 2019 at 04:43:52PM +0800, Chao Yu wrote:
> > On 2019/10/30 10:55, Eric Biggers wrote:
> > > On Tue, Oct 29, 2019 at 04:33:36PM +0800, Chao Yu wrote:
> > >> On 2019/10/28 6:50, Eric Biggers wrote:
> > >>>> +bool f2fs_is_compressed_page(struct page *page)
> > >>>> +{
> > >>>> +	if (!page_private(page))
> > >>>> +		return false;
> > >>>> +	if (IS_ATOMIC_WRITTEN_PAGE(page) || IS_DUMMY_WRITTEN_PAGE(page))
> > >>>> +		return false;
> > >>>> +	return *((u32 *)page_private(page)) == F2FS_COMPRESSED_PAGE_MAGIC;
> > >>>> +}
> > >>>
> > >>> This code implies that there can be multiple page private structures each of
> > >>> which has a different magic number.  But I only see F2FS_COMPRESSED_PAGE_MAGIC.
> > >>> Where in the code is the other one(s)?
> > >>
> > >> I'm not sure I understood you correctly, did you mean it needs to introduce
> > >> f2fs_is_atomic_written_page() and f2fs_is_dummy_written_page() like
> > >> f2fs_is_compressed_page()?
> > >>
> > > 
> > > No, I'm asking what is the case where the line
> > > 
> > > 	*((u32 *)page_private(page)) == F2FS_COMPRESSED_PAGE_MAGIC
> > > 
> > > returns false?
> > 
> > Should be this?
> > 
> > if (!page_private(page))
> > 	return false;
> > f2fs_bug_on(*((u32 *)page_private(page)) != F2FS_COMPRESSED_PAGE_MAGIC)
> > return true;
> 
> Yes, that makes more sense, unless there are other cases.
> 
> > 
> > > 
> > >>>
> > >>>> +
> > >>>> +static void f2fs_set_compressed_page(struct page *page,
> > >>>> +		struct inode *inode, pgoff_t index, void *data, refcount_t *r)
> > >>>> +{
> > >>>> +	SetPagePrivate(page);
> > >>>> +	set_page_private(page, (unsigned long)data);
> > >>>> +
> > >>>> +	/* i_crypto_info and iv index */
> > >>>> +	page->index = index;
> > >>>> +	page->mapping = inode->i_mapping;
> > >>>> +	if (r)
> > >>>> +		refcount_inc(r);
> > >>>> +}
> > >>>
> > >>> It isn't really appropriate to create fake pagecache pages like this.  Did you
> > >>> consider changing f2fs to use fscrypt_decrypt_block_inplace() instead?
> > >>
> > >> We need to store i_crypto_info and iv index somewhere, in order to pass them to
> > >> fscrypt_decrypt_block_inplace(), where did you suggest to store them?
> > >>
> > > 
> > > The same place where the pages are stored.
> > 
> > Still we need allocate space for those fields, any strong reason to do so?
> > 
> 
> page->mapping set implies that the page is a pagecache page.  Faking it could
> cause problems with code elsewhere.

I've checked it with minchan, and it seems to be fine that filesystem uses
this page internally only, not in pagecache.

> 
> > > 
> > >>>> +
> > >>>> +void f2fs_destroy_compress_ctx(struct compress_ctx *cc)
> > >>>> +{
> > >>>> +	kvfree(cc->rpages);
> > >>>> +}
> > >>>
> > >>> The memory is allocated with kzalloc(), so why is it freed with kvfree() and not
> > >>> just kfree()?
> > >>
> > >> It was allocated by f2fs_*alloc() which will fallback to kvmalloc() once
> > >> kmalloc() failed.
> > > 
> > > This seems to be a bug in f2fs_kmalloc() -- it inappropriately falls back to
> > > kvmalloc().  As per its name, it should only use kmalloc().  f2fs_kvmalloc()
> > > already exists, so it can be used when the fallback is wanted.
> > 
> > We can introduce f2fs_memalloc() to wrap f2fs_kmalloc() and f2fs_kvmalloc() as
> > below:
> > 
> > f2fs_memalloc()
> > {
> > 	mem = f2fs_kmalloc();
> > 	if (mem)
> > 		return mem;
> > 	return f2fs_kvmalloc();
> > }
> > 
> > It can be used in specified place where we really need it, like the place
> > descirbied in 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed") in where
> > we introduced original logic.
> 
> No, just use kvmalloc().  The whole point of kvmalloc() is that it tries
> kmalloc() and then falls back to vmalloc() if it fails.
> 
> - Eric

WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <yuchao0@huawei.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 2/2] f2fs: support data compression
Date: Wed, 30 Oct 2019 10:47:14 -0700	[thread overview]
Message-ID: <20191030174714.GA36729@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <20191030165056.GA693@sol.localdomain>

On 10/30, Eric Biggers wrote:
> On Wed, Oct 30, 2019 at 04:43:52PM +0800, Chao Yu wrote:
> > On 2019/10/30 10:55, Eric Biggers wrote:
> > > On Tue, Oct 29, 2019 at 04:33:36PM +0800, Chao Yu wrote:
> > >> On 2019/10/28 6:50, Eric Biggers wrote:
> > >>>> +bool f2fs_is_compressed_page(struct page *page)
> > >>>> +{
> > >>>> +	if (!page_private(page))
> > >>>> +		return false;
> > >>>> +	if (IS_ATOMIC_WRITTEN_PAGE(page) || IS_DUMMY_WRITTEN_PAGE(page))
> > >>>> +		return false;
> > >>>> +	return *((u32 *)page_private(page)) == F2FS_COMPRESSED_PAGE_MAGIC;
> > >>>> +}
> > >>>
> > >>> This code implies that there can be multiple page private structures each of
> > >>> which has a different magic number.  But I only see F2FS_COMPRESSED_PAGE_MAGIC.
> > >>> Where in the code is the other one(s)?
> > >>
> > >> I'm not sure I understood you correctly, did you mean it needs to introduce
> > >> f2fs_is_atomic_written_page() and f2fs_is_dummy_written_page() like
> > >> f2fs_is_compressed_page()?
> > >>
> > > 
> > > No, I'm asking what is the case where the line
> > > 
> > > 	*((u32 *)page_private(page)) == F2FS_COMPRESSED_PAGE_MAGIC
> > > 
> > > returns false?
> > 
> > Should be this?
> > 
> > if (!page_private(page))
> > 	return false;
> > f2fs_bug_on(*((u32 *)page_private(page)) != F2FS_COMPRESSED_PAGE_MAGIC)
> > return true;
> 
> Yes, that makes more sense, unless there are other cases.
> 
> > 
> > > 
> > >>>
> > >>>> +
> > >>>> +static void f2fs_set_compressed_page(struct page *page,
> > >>>> +		struct inode *inode, pgoff_t index, void *data, refcount_t *r)
> > >>>> +{
> > >>>> +	SetPagePrivate(page);
> > >>>> +	set_page_private(page, (unsigned long)data);
> > >>>> +
> > >>>> +	/* i_crypto_info and iv index */
> > >>>> +	page->index = index;
> > >>>> +	page->mapping = inode->i_mapping;
> > >>>> +	if (r)
> > >>>> +		refcount_inc(r);
> > >>>> +}
> > >>>
> > >>> It isn't really appropriate to create fake pagecache pages like this.  Did you
> > >>> consider changing f2fs to use fscrypt_decrypt_block_inplace() instead?
> > >>
> > >> We need to store i_crypto_info and iv index somewhere, in order to pass them to
> > >> fscrypt_decrypt_block_inplace(), where did you suggest to store them?
> > >>
> > > 
> > > The same place where the pages are stored.
> > 
> > Still we need allocate space for those fields, any strong reason to do so?
> > 
> 
> page->mapping set implies that the page is a pagecache page.  Faking it could
> cause problems with code elsewhere.

I've checked it with minchan, and it seems to be fine that filesystem uses
this page internally only, not in pagecache.

> 
> > > 
> > >>>> +
> > >>>> +void f2fs_destroy_compress_ctx(struct compress_ctx *cc)
> > >>>> +{
> > >>>> +	kvfree(cc->rpages);
> > >>>> +}
> > >>>
> > >>> The memory is allocated with kzalloc(), so why is it freed with kvfree() and not
> > >>> just kfree()?
> > >>
> > >> It was allocated by f2fs_*alloc() which will fallback to kvmalloc() once
> > >> kmalloc() failed.
> > > 
> > > This seems to be a bug in f2fs_kmalloc() -- it inappropriately falls back to
> > > kvmalloc().  As per its name, it should only use kmalloc().  f2fs_kvmalloc()
> > > already exists, so it can be used when the fallback is wanted.
> > 
> > We can introduce f2fs_memalloc() to wrap f2fs_kmalloc() and f2fs_kvmalloc() as
> > below:
> > 
> > f2fs_memalloc()
> > {
> > 	mem = f2fs_kmalloc();
> > 	if (mem)
> > 		return mem;
> > 	return f2fs_kvmalloc();
> > }
> > 
> > It can be used in specified place where we really need it, like the place
> > descirbied in 5222595d093e ("f2fs: use kvmalloc, if kmalloc is failed") in where
> > we introduced original logic.
> 
> No, just use kvmalloc().  The whole point of kvmalloc() is that it tries
> kmalloc() and then falls back to vmalloc() if it fails.
> 
> - Eric


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  parent reply	other threads:[~2019-10-30 17:47 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 17:16 [PATCH 1/2] f2fs: support aligned pinned file Jaegeuk Kim
2019-10-22 17:16 ` [f2fs-dev] " Jaegeuk Kim
2019-10-22 17:16 ` [PATCH 2/2] f2fs: support data compression Jaegeuk Kim
2019-10-22 17:16   ` [f2fs-dev] " Jaegeuk Kim
2019-10-22 17:53   ` Ju Hyung Park
2019-10-24  9:10     ` Chao Yu
2019-10-23  5:24   ` Eric Biggers
2019-10-23  5:24     ` [f2fs-dev] " Eric Biggers
2019-10-23 17:28     ` Jaegeuk Kim
2019-10-23 17:28       ` [f2fs-dev] " Jaegeuk Kim
2019-10-25  9:07     ` Chao Yu
2019-10-25  9:07       ` Chao Yu
2019-10-27 22:50   ` Eric Biggers
2019-10-27 22:50     ` [f2fs-dev] " Eric Biggers
2019-10-28  2:33     ` Chao Yu
2019-10-28  2:33       ` Chao Yu
2019-10-29  8:33     ` Chao Yu
2019-10-29  8:33       ` Chao Yu
2019-10-30  2:55       ` Eric Biggers
2019-10-30  2:55         ` [f2fs-dev] " Eric Biggers
2019-10-30  8:43         ` Chao Yu
2019-10-30  8:43           ` [f2fs-dev] " Chao Yu
2019-10-30 16:50           ` Eric Biggers
2019-10-30 16:50             ` [f2fs-dev] " Eric Biggers
2019-10-30 17:22             ` Gao Xiang
2019-10-30 17:22               ` Gao Xiang via Linux-f2fs-devel
2019-10-30 17:47             ` Jaegeuk Kim [this message]
2019-10-30 17:47               ` Jaegeuk Kim
2019-10-31  2:16             ` Chao Yu
2019-10-31  2:16               ` [f2fs-dev] " Chao Yu
2019-10-31 15:35               ` Jaegeuk Kim
2019-10-31 15:35                 ` [f2fs-dev] " Jaegeuk Kim
2019-11-01 10:02                 ` Chao Yu
2019-11-01 10:02                   ` [f2fs-dev] " Chao Yu
2019-10-30 17:02           ` Eric Biggers
2019-10-30 17:02             ` [f2fs-dev] " Eric Biggers
2019-10-31  2:21             ` Chao Yu
2019-10-31  2:21               ` [f2fs-dev] " Chao Yu
2019-11-13 13:10             ` Chao Yu
2019-11-13 13:10               ` [f2fs-dev] " Chao Yu
2019-11-18 16:11               ` Jaegeuk Kim
2019-11-18 16:11                 ` [f2fs-dev] " Jaegeuk Kim
2019-11-18 20:58                 ` Jaegeuk Kim
2019-11-18 20:58                   ` [f2fs-dev] " Jaegeuk Kim
2019-11-25 17:42                   ` Jaegeuk Kim
2019-11-25 17:42                     ` Jaegeuk Kim
2019-12-11  1:27                     ` Jaegeuk Kim
2019-12-11  1:27                       ` Jaegeuk Kim
2019-12-12 15:07                       ` Chao Yu
2019-12-12 15:07                         ` Chao Yu
2019-10-24  8:21 ` [f2fs-dev] [PATCH 1/2] f2fs: support aligned pinned file Chao Yu
2019-10-24  8:21   ` Chao Yu
2019-10-25 18:18   ` Jaegeuk Kim
2019-10-25 18:18     ` Jaegeuk Kim
2019-10-26  1:31     ` Chao Yu
2019-10-26  1:31       ` Chao Yu
2019-10-30 16:09       ` Jaegeuk Kim
2019-10-30 16:09         ` Jaegeuk Kim
2019-10-31  2:27         ` Chao Yu
2019-10-31  2:27           ` Chao Yu
2019-10-31 15:29           ` Jaegeuk Kim
2019-10-31 15:29             ` Jaegeuk Kim
2019-11-05  3:39             ` Chao Yu
2019-11-05  3:39               ` Chao Yu
2019-11-07 19:14 ` [PATCH 1/2 v2] " Jaegeuk Kim
2019-11-07 19:14   ` [f2fs-dev] " Jaegeuk Kim

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=20191030174714.GA36729@jaegeuk-macbookpro.roam.corp.google.com \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.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.