Linux-f2fs-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Matthew Wilcox <willy@infradead.org>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] Use of FGP_NOFS in f2fs
Date: Mon, 29 Jun 2026 09:39:25 +0800	[thread overview]
Message-ID: <324cc5b6-ebfd-4696-b2f4-33710b771249@kernel.org> (raw)
In-Reply-To: <ca56ceb7-b0a7-41f2-9b26-085e81456794@amlogic.com>

On 6/26/26 17:30, Jiucheng Xu wrote:
> 
> 
> On 6/25/2026 3:17 AM, Matthew Wilcox wrote:
>> [ EXTERNAL EMAIL ]
>>
>> Hi Jiucheng,
>>
>> I am trying to remove FGP_NOFS from the kernel and the last remaining
>> user was added by you last year in commit 2308de27c03d.  I'm trying to
>> understand why.  Did you see an actual problem if you do not use it,
>> or was it theoretical?  The commit message says "to avoid potential
>> deadlock issues", but it's not clear to me whether you know they are
>> there, or only think they are there.
>>
>> I'd really like to understand what the issues are as the normal issues
>> which make calling into the filesystem (holding another folio locked,
>> holding a mutex relied upon by reclaim) don't seem to be present.
>> So if there is something, I'm not sure what it is.
> Hi Matthew,
> 
> The FGP_NOFS flag was suggested by Chao and not adding it might lead to deadlock issues.
> 
> @Chao could you explain this for Matthew?

Hi Matthew, Jiucheng,

IIRC, for normal path from write -> write_begin, it seems fine since there is
no f2fs-specified mutex or other folio lock in the path, but I was worried about
quota path when I suggested to keep GFP_NOFS flag, as the lock race condition
is quite complicated there: f2fs internal lock vs quota system lock vs folio lock...

I searched the commits and found this:

Commit 02117b8ae9c0 ("f2fs: Set GF_NOFS in read_cache_page_gfp while doing
f2fs_quota_read")

In this case, f2fs_quota_read() was calling read_mapping_page(), which allowed
GFP_FS allocations. This triggered the following deadlock:

     Thread 1 (User Open/Write)
     - do_sys_open
      - vfs_open
       - dquot_file_open
        - dquot_initialize
         - dqget
          - dquot_acquire
           : locks &dqopt->dqio_mutex (VFS Quota Mutex)
           - qtree_read_dquot
            - f2fs_quota_read
             - read_mapping_page (GFP_KERNEL / allows GFP_FS)
              - __alloc_pages_nodemask
               - try_to_free_pages (Direct Reclaim)
                - prune_icache_sb
                 - evict
                  - f2fs_evict_inode
                   - dquot_drop
                    - dqput
                     - dquot_commit
                      : tries to lock &dqopt->dqio_mutex again
                      ==> DEADLOCK (waiting for itself)

It may trigger deadlock in f2fs_quota_write() as the same way in f2fs_quota_read()
path? let me know if I'm missing anything.

Are memalloc_nofs_save() and memalloc_nofs_restore() recommended for such case?
any suggestions?

Thanks,


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

  reply	other threads:[~2026-06-29  1:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 19:17 [f2fs-dev] Use of FGP_NOFS in f2fs Matthew Wilcox
2026-06-26  9:30 ` Jiucheng Xu via Linux-f2fs-devel
2026-06-29  1:39   ` Chao Yu via Linux-f2fs-devel [this message]
2026-06-29  3:54     ` Matthew Wilcox
2026-06-29  8:58       ` Jan Kara
2026-06-29 11:10         ` Chao Yu via Linux-f2fs-devel
2026-06-29 11:20       ` Chao Yu via Linux-f2fs-devel

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=324cc5b6-ebfd-4696-b2f4-33710b771249@kernel.org \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=willy@infradead.org \
    /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