linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Bernd Schubert <bernd.schubert@fastmail.fm>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: Jingbo Xu <jefflexu@linux.alibaba.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	linux-fsdevel@vger.kernel.org, josef@toxicpanda.com,
	hannes@cmpxchg.org, linux-mm@kvack.org, kernel-team@meta.com
Subject: Re: [PATCH v2 2/2] fuse: remove tmp folio for writebacks and internal rb tree
Date: Wed, 30 Oct 2024 17:21:11 +0100	[thread overview]
Message-ID: <023c4bab-0eb6-45c5-9a42-d8fda0abec02@fastmail.fm> (raw)
In-Reply-To: <CAJnrk1b=ntstDcnjgLsmX+wTyHaiC9SZ7cdSRF2Zbb+0SAG1Zw@mail.gmail.com>



On 10/30/24 17:04, Joanne Koong wrote:
> On Wed, Oct 30, 2024 at 2:32 AM Bernd Schubert
> <bernd.schubert@fastmail.fm> wrote:
>>
>> On 10/28/24 22:58, Joanne Koong wrote:
>>> On Fri, Oct 25, 2024 at 3:40 PM Joanne Koong <joannelkoong@gmail.com> wrote:
>>>>
>>>>> Same here, I need to look some more into the compaction / page
>>>>> migration paths. I'm planning to do this early next week and will
>>>>> report back with what I find.
>>>>>
>>>>
>>>> These are my notes so far:
>>>>
>>>> * We hit the folio_wait_writeback() path when callers call
>>>> migrate_pages() with mode MIGRATE_SYNC
>>>>    ... -> migrate_pages() -> migrate_pages_sync() ->
>>>> migrate_pages_batch() -> migrate_folio_unmap() ->
>>>> folio_wait_writeback()
>>>>
>>>> * These are the places where we call migrate_pages():
>>>> 1) demote_folio_list()
>>>> Can ignore this. It calls migrate_pages() in MIGRATE_ASYNC mode
>>>>
>>>> 2) __damon_pa_migrate_folio_list()
>>>> Can ignore this. It calls migrate_pages() in MIGRATE_ASYNC mode
>>>>
>>>> 3) migrate_misplaced_folio()
>>>> Can ignore this. It calls migrate_pages() in MIGRATE_ASYNC mode
>>>>
>>>> 4) do_move_pages_to_node()
>>>> Can ignore this. This calls migrate_pages() in MIGRATE_SYNC mode but
>>>> this path is only invoked by the move_pages() syscall. It's fine to
>>>> wait on writeback for the move_pages() syscall since the user would
>>>> have to deliberately invoke this on the fuse server for this to apply
>>>> to the server's fuse folios
>>>>
>>>> 5)  migrate_to_node()
>>>> Can ignore this for the same reason as in 4. This path is only invoked
>>>> by the migrate_pages() syscall.
>>>>
>>>> 6) do_mbind()
>>>> Can ignore this for the same reason as 4 and 5. This path is only
>>>> invoked by the mbind() syscall.
>>>>
>>>> 7) soft_offline_in_use_page()
>>>> Can skip soft offlining fuse folios (eg folios with the
>>>> AS_NO_WRITEBACK_WAIT mapping flag set).
>>>> The path for this is soft_offline_page() -> soft_offline_in_use_page()
>>>> -> migrate_pages(). soft_offline_page() only invokes this for in-use
>>>> pages in a well-defined state (see ret value of get_hwpoison_page()).
>>>> My understanding of soft offlining pages is that it's a mitigation
>>>> strategy for handling pages that are experiencing errors but are not
>>>> yet completely unusable, and its main purpose is to prevent future
>>>> issues. It seems fine to skip this for fuse folios.
>>>>
>>>> 8) do_migrate_range()
>>>> 9) compact_zone()
>>>> 10) migrate_longterm_unpinnable_folios()
>>>> 11) __alloc_contig_migrate_range()
>>>>
>>>> 8 to 11 needs more investigation / thinking about. I don't see a good
>>>> way around these tbh. I think we have to operate under the assumption
>>>> that the fuse server running is malicious or benevolently but
>>>> incorrectly written and could possibly never complete writeback. So we
>>>> definitely can't wait on these but it also doesn't seem like we can
>>>> skip waiting on these, especially for the case where the server uses
>>>> spliced pages, nor does it seem like we can just fail these with
>>>> -EBUSY or something.
>>
>> I see some code paths with -EAGAIN in migration. Could you explain why
>> we can't just fail migration for fuse write-back pages?
>>

Hi Joanne,

thanks a lot for your quick reply (especially as my reviews come in very 
late).

> 
> My understanding (and please correct me here Shakeel if I'm wrong) is
> that this could block system optimizations, especially since if an
> unprivileged malicious fuse server never replies to the writeback
> request, then this completely stalls progress. In the best case
> scenario, -EAGAIN could be used because the server might just be slow
> in serving the writeback, but I think we need to also account for
> servers that never complete the writeback. For
> __alloc_contig_migrate_range() for example, my understanding is that
> this is used to migrate pages so that there are more physically
> contiguous ranges of memory freed up. If fuse writeback blocks that,
> then that hurts system health overall.

Hmm, I wonder what is worse - tmp page copies or missing compaction.
Especially if we expect a low range of in-writeback pages/folios. 
One could argue that an evil user might spawn many fuse server
processes to work around the default low fuse write-back limits, but
does that make any difference with tmp pages? And these cannot be
compacted either?

And with timeouts that would be so far totally uncritical, I
think.


You also mentioned 

> especially for the case where the server uses spliced pages

could you provide more details for that? 



> 
>>>>
>>>
>>> I'm still not seeing a good way around this.
>>>
>>> What about this then? We add a new fuse sysctl called something like
>>> "/proc/sys/fs/fuse/writeback_optimization_timeout" where if the sys
>>> admin sets this, then it opts into optimizing writeback to be as fast
>>> as possible (eg skipping the page copies) and if the server doesn't
>>> fulfill the writeback by the set timeout value, then the connection is
>>> aborted.
>>>
>>> Alternatively, we could also repurpose
>>> /proc/sys/fs/fuse/max_request_timeout from the request timeout
>>> patchset [1] but I like the additional flexibility and explicitness
>>> having the "writeback_optimization_timeout" sysctl gives.
>>>
>>> Any thoughts on this?
>>
>>
>> I'm a bit worried that we might lock up the system until time out is
>> reached - not ideal. Especially as timeouts are in minutes now. But
>> even a slightly stuttering video system not be great. I think we
>> should give users/admin the choice then, if they prefer slow page
>> copies or fast, but possibly shortly unresponsive system.
>>
> I was thinking the /proc/sys/fs/fuse/writeback_optimization_timeout
> would be in seconds, where the sys admin would probably set something
> more reasonable like 5 seconds or so.
> If this syctl value is set, then servers who want writebacks to be
> fast can opt into it at mount time (and by doing so agree that they
> will service writeback requests by the timeout or their connection
> will be aborted).


I think your current patch set has it in minutes? (Should be easy
enough to change that.) Though I'm more worried about the impact
of _frequent_ timeout scanning through the different fuse lists 
on performance, than about missing compaction for folios that are
currently in write-back.


Thanks,
Bernd


  reply	other threads:[~2024-10-30 16:21 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 18:22 [PATCH v2 0/2] fuse: remove extra page copies in writeback Joanne Koong
2024-10-14 18:22 ` [PATCH v2 1/2] mm: skip reclaiming folios in writeback contexts that may trigger deadlock Joanne Koong
2024-10-14 18:38   ` Shakeel Butt
2024-10-14 21:04     ` Joanne Koong
2024-10-14 23:57       ` Shakeel Butt
2024-10-15 16:59         ` Joanne Koong
2024-10-14 18:22 ` [PATCH v2 2/2] fuse: remove tmp folio for writebacks and internal rb tree Joanne Koong
2024-10-15 10:01   ` Miklos Szeredi
2024-10-15 17:06     ` Joanne Koong
2024-10-15 19:17       ` Shakeel Butt
2024-10-16  9:44         ` Jingbo Xu
2024-10-16  9:57           ` Miklos Szeredi
2024-10-16  9:51         ` Miklos Szeredi
2024-10-16 17:52           ` Shakeel Butt
2024-10-16 18:37             ` Miklos Szeredi
2024-10-16 21:27               ` Shakeel Butt
2024-10-17 13:31                 ` Miklos Szeredi
2024-10-18  5:31                   ` Shakeel Butt
2024-10-21 10:15                     ` Miklos Szeredi
2024-10-21 17:01                       ` Shakeel Butt
2024-10-22 15:03                         ` Miklos Szeredi
2024-10-21 21:05                       ` Joanne Koong
2024-10-24 16:54                         ` Joanne Koong
2024-10-25  1:38                           ` Jingbo Xu
2024-10-25 15:32                             ` Miklos Szeredi
2024-10-25 17:36                             ` Joanne Koong
2024-10-25 18:02                               ` Miklos Szeredi
2024-10-25 18:19                                 ` Joanne Koong
2024-10-28  2:02                                   ` Jingbo Xu
2024-10-25 18:47                               ` Joanne Koong
2024-10-28  2:28                                 ` Jingbo Xu
2024-10-28 21:57                                   ` Joanne Koong
2024-10-25 22:40                               ` Joanne Koong
2024-10-28 21:58                                 ` Joanne Koong
2024-10-30  9:32                                   ` Bernd Schubert
2024-10-30 16:04                                     ` Joanne Koong
2024-10-30 16:21                                       ` Bernd Schubert [this message]
2024-10-30 17:02                                         ` Joanne Koong
2024-10-30 17:27                                           ` Bernd Schubert
2024-10-30 17:35                                             ` Joanne Koong
2024-10-30 21:56                                               ` Shakeel Butt
2024-10-30 22:17                                                 ` Bernd Schubert
2024-10-30 22:51                                                   ` Joanne Koong
2024-10-31  0:30                                                     ` Shakeel Butt
2024-10-31 19:06                                                       ` Joanne Koong
2024-10-31 20:06                                                         ` Shakeel Butt
2024-10-31 21:52                                                           ` Joanne Koong
2024-10-31 22:38                                                             ` Shakeel Butt
2024-11-06 23:37                                                               ` Joanne Koong
2024-11-06 23:56                                                                 ` Shakeel Butt
2024-11-01 11:44                                                             ` Jingbo Xu
2024-11-01 20:54                                                               ` Joanne Koong
2024-11-04  8:09                                                                 ` Jingbo Xu
2024-10-29 22:04                   ` Bernd Schubert
2024-10-16  9:56     ` Jingbo Xu
2024-10-16 10:00       ` Miklos Szeredi
2024-10-18  1:30     ` Joanne Koong
2024-10-18  5:57       ` Shakeel Butt
2024-10-18 19:57         ` Joanne Koong
2024-10-18 20:46           ` Shakeel Butt
2024-10-21  9:32       ` Miklos Szeredi
2024-10-18  9:24   ` Jingbo Xu
2024-10-18 20:29     ` Joanne Koong

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=023c4bab-0eb6-45c5-9a42-d8fda0abec02@fastmail.fm \
    --to=bernd.schubert@fastmail.fm \
    --cc=hannes@cmpxchg.org \
    --cc=jefflexu@linux.alibaba.com \
    --cc=joannelkoong@gmail.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@meta.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=shakeel.butt@linux.dev \
    /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