From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AB23E6F086 for ; Fri, 1 Nov 2024 20:54:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F029A8D0002; Fri, 1 Nov 2024 16:54:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8C148D0001; Fri, 1 Nov 2024 16:54:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D062E8D0002; Fri, 1 Nov 2024 16:54:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AE25A8D0001 for ; Fri, 1 Nov 2024 16:54:25 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C7296140FCD for ; Fri, 1 Nov 2024 20:54:24 +0000 (UTC) X-FDA: 82738728366.10.4089C7A Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) by imf27.hostedemail.com (Postfix) with ESMTP id D608240003 for ; Fri, 1 Nov 2024 20:53:53 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=h5TbQvsX; spf=pass (imf27.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.222.50 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730494417; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=72rrXdFo0l5ehALIIAXsZqz06DGl5q6wJrjEh4jxrE4=; b=M2jUxtvUfBCiT53BJipun9FdQ8zS1pFGX+voE2cYkWj/j6mi0PYSbqIr9aUTmi9B2O8SKR IgidIVkFQu0HvmA7XWPQaM+0YZ9K8/6iOTDwR+x1+greXpTHD/uZ8tBKvHMVd9scNdz64K vcijkCtbXJZFxJCXRZFLr5sdOx1FQOo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730494417; a=rsa-sha256; cv=none; b=uOS5KeZfbHh5n0h2F7SaPytsp+xJjQ3ZtpfxDNIm67B/e8YwhJmJ9b6ksmCX85QrFtKl9s Ethfc+/+XqLVipD473Wa9A8RX1TO75wPHCWOauFehl/7zV9HaXWUkg6vWkSF6iCDP+N0h2 64BqSenw2ChJdo/Bs8oFbtPA1CWhBcQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=h5TbQvsX; spf=pass (imf27.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.222.50 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-84fb533bb9bso461413241.3 for ; Fri, 01 Nov 2024 13:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730494462; x=1731099262; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=72rrXdFo0l5ehALIIAXsZqz06DGl5q6wJrjEh4jxrE4=; b=h5TbQvsXIGNITddUj2o+1kvj/nucEU+ZVqi+JMGKOXC/5NfFmoARoJG5FzfGx1eP6F vCAEWFnAu/trKAtQms7P4GqgBQYGF91SzoAUeCRBrscrXgK+gSiGp08NGf479MwY9bgL 8x2S9WMlkxaaFsxdZOnsdZ4aEF52+YnjX2tXjdKmlJJ68qYGIOLl9dUFeu0B8/rjt/3A XsTxBI8txnMS1jX4vylOoFn035vf1DtQveD1J89baXRHvta/RMwzvGo0BnYae2Qb+DZs sngZ5yJltmP5GtfOM6whimk7en/jJEPE0q9tHgw7ZOF8erKSAZ16StXpR1UyGPliGOJc aZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730494462; x=1731099262; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=72rrXdFo0l5ehALIIAXsZqz06DGl5q6wJrjEh4jxrE4=; b=WHCCs11BqHq0GI9mI8rHtPTvvDAeilN86eWHe2vJcA4gc9bhGND3NRZ1RpOAjteQ9I yNmZAvyFWn8JL5+i5p4m8AgoB2GRbSIOF8WsB9DrIHwWa+h4qul5gvRTPHCrBdFBL2+E FL/JyixXBHAaC5oCJodo5HqiqYxnMnLdh7s/XSD1FLirrJzi8VlgeOAJ/FCb6it63OkQ sTcA5cWtHYnqAkn7ZZ/1/cO7I42TgkT+sKfz+LqsdIEm67EXAU58uFodgsEp9HwoUncl eCON6PKrWVlDzeX3KAUEFscJej4tP9U6sNBkkP8ZEgeXDe/FAtFFKkySG1YLH0yK/dpa Anlg== X-Forwarded-Encrypted: i=1; AJvYcCWlbM6sQ/pQs9AoV6WlwKNZ1vb2GtfCzGexRxCc0uuC2txNBEBIc0oEWqUqCrSAz/+3ppCrLvg0Cw==@kvack.org X-Gm-Message-State: AOJu0Yyp4ZT3r8obQvKh4I+DPw/EwXqE40WLNBrsCRG5VWG/mYGxywHl MlvLKb02GHMrXcxOb9xde5CLbzP01Dne3bz2RVcvzoAXd7zpS8X0glZPqCIocBo+DcoNjdsQr1e qA8LBbxw4xz/PBTl8TgVJzED4Pxg= X-Google-Smtp-Source: AGHT+IGuZG6Zps+QEUgjuCFxK13wB0hEARewUS++teG0zGNgGa68js4bh98mD2veSaeWbGmEogOQwRhqfD0Ttz81phk= X-Received: by 2002:a05:6102:390b:b0:4a3:e644:54dd with SMTP id ada2fe7eead31-4a8cfb4d9e4mr24241735137.12.1730494462040; Fri, 01 Nov 2024 13:54:22 -0700 (PDT) MIME-Version: 1.0 References: <023c4bab-0eb6-45c5-9a42-d8fda0abec02@fastmail.fm> <4hwdxhdxgjyxgxutzggny4isnb45jxtump7j7tzzv6paaqg2lr@55sguz7y4hu7> <43aeed1a-0572-4bcc-8c06-49522459f7d2@linux.alibaba.com> In-Reply-To: <43aeed1a-0572-4bcc-8c06-49522459f7d2@linux.alibaba.com> From: Joanne Koong Date: Fri, 1 Nov 2024 13:54:10 -0700 Message-ID: Subject: Re: [PATCH v2 2/2] fuse: remove tmp folio for writebacks and internal rb tree To: Jingbo Xu Cc: Shakeel Butt , Bernd Schubert , Miklos Szeredi , linux-fsdevel@vger.kernel.org, josef@toxicpanda.com, hannes@cmpxchg.org, linux-mm@kvack.org, kernel-team@meta.com, Vlastimil Babka Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 3imi8icerirk9sfwn66fhhstkbn9oup3 X-Rspam-User: X-Rspamd-Queue-Id: D608240003 X-Rspamd-Server: rspam02 X-HE-Tag: 1730494433-81364 X-HE-Meta: U2FsdGVkX1/rsYi8hGEIlhB+wHSotO5+8yLwar21tyfU0re77N7rZ1s0MenUiC5BOkWXUU0beoNmv4mpnuA4tq/71SvdD5nQMlmLzvlRqrRx+ULcUOFmmhzYIRaSKmzmv39j+XstUHXDn1meKDVN6HiEaFQYTwBde/rZvc0jA9DvgC0BtS5Xdhq9RrNi1KrXZUmBy7vKux+kZ2fTIJY48ihKATebziJNWAfBDE/SANsQxRQ44MqXfvqY+C7lS/kPTEFGT/PxFEjBsvZ0xlvCgR/EgI58cxTysUx/VBvYgoaEPAVwXO+BfNHFFMxsliNEaCpdZ+TC7aaIxGkPHnDtg71jIArltnIXtC/3eBHxPJ/KypprXjomSIs+YYKXG8N1jfjiUlrefzLQViUbveSw5poZ+ldu5MKO4qFJdhwxEnkWByvmPJVWu5oBwgEdAKR0HNbdnHocSYwplpFGGPerv4OI/JjZ4Xaj1sHTShLx8UhKF2UFP0PSo8Up/g6N+xvtMA445geu7paoyjet0bUirAr20dmTgpkU7g/5cWes9DQEtc9pviV1JFHzBwa1FgRZ1KwhEC6qcbQs5lB3+Hdb1D9GOsHbgavbglnaRQrPDwsKSnVL/lB/MSPQCtBgLTfbPHYw6REdVZHpPmTchPZRtqoCzhYwFDlFuN43oocLs4LTO7kdW/Rss2+7nn/gUyrygGJB3DT91N6lMP4WOtlv1HQDOUEk/l/cvbKuyDoeynNSbbp/H5rZ2lXX7vZLvghjDxwwaFj/7bkVNLnZnxh3CDZ26kSBK26BT+rncQbR4fR2+RpkM2s1t7rkIJ+dG0IwvG3HMQSSUUDGA6xqJbpv5CIeqIcZWZlr7uAvCtLGF44PcGpczdM5gHhJfIuytJOTUct07+IwbPdMeO3xxCiLjhpcn14KF+i2Dszb802u5qTwe1a367i6jXl1S8BQvUyxQbisUBdWgLJcghSWXAf rZAObcQe hnITWcus5P5qZ8/VlTwW1KqnhLuUkQL6sEk/pcuoLEIpRmwX3SzS+OKsAhaVZTW34yDToYcD2iSChVDRK7HFNKabskLy3i6ZffTHrdDLf2v8lL3OKEg+43x8vXydBptTUFxNkAHOdImb6bo/GohBorzIwqg3zVFYPaOP0UIhHIs+QiYRrq7f81sOj7jls4QRp3M9I3nbTzojW8QTEcIAUENOkhP0aTv4my7DFLycQVCsVttVhSiu5bU5zmVW3PWD8V7RQRrS4qxt7jhtaNzGD8Kl1WwilkgsDOYKLDqvXpaz79ZiBhxoT9FUstJNmfWFdW0jp18fGMfN7UITLet316Op9SQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Nov 1, 2024 at 4:44=E2=80=AFAM Jingbo Xu wrote: > > Hi Joanne, > > Thanks for keeping pushing this forward. > > On 11/1/24 5:52 AM, Joanne Koong wrote: > > On Thu, Oct 31, 2024 at 1:06=E2=80=AFPM Shakeel Butt wrote: > >> > >> On Thu, Oct 31, 2024 at 12:06:49PM GMT, Joanne Koong wrote: > >>> On Wed, Oct 30, 2024 at 5:30=E2=80=AFPM Shakeel Butt wrote: > >> [...] > >>>> > >>>> Memory pool is a bit confusing term here. Most probably you are aski= ng > >>>> about the migrate type of the page block from which tmp page is > >>>> allocated from. In a normal system, tmp page would be allocated from= page > >>>> block with MIGRATE_UNMOVABLE migrate type while the page cache page,= it > >>>> depends on what gfp flag was used for its allocation. What does fuse= fs > >>>> use? GFP_HIGHUSER_MOVABLE or something else? Under low memory situat= ion > >>>> allocations can get mixed up with different migrate types. > >>>> > >>> > >>> I believe it's GFP_HIGHUSER_MOVABLE for the page cache pages since > >>> fuse doesn't set any additional gfp masks on the inode mapping. > >>> > >>> Could we just allocate the fuse writeback pages with GFP_HIGHUSER > >>> instead of GFP_HIGHUSER_MOVABLE? That would be in fuse_write_begin() > >>> where we pass in the gfp mask to __filemap_get_folio(). I think this > >>> would give us the same behavior memory-wise as what the tmp pages > >>> currently do, > >> > >> I don't think it would be the same behavior. From what I understand th= e > >> liftime of the tmp page is from the start of the writeback till the ac= k > >> from the fuse server that writeback is done. While the lifetime of the > >> page of the page cache can be arbitrarily large. We should just make i= t > >> unmovable for its lifetime. I think it is fine to make the page > >> unmovable during the writeback. We should not try to optimize for the > >> bad or buggy behavior of fuse server. > >> > >> Regarding the avoidance of wait on writeback for fuse folios, I think = we > >> can handle the migration similar to how you are handling reclaim and i= n > >> addition we can add a WARN() in folio_wait_writeback() if the kernel e= ver > >> sees a fuse folio in that function. > > > > Awesome, this is what I'm planning to do in v3 to address migration the= n: > > > > 1) in migrate_folio_unmap(), only call "folio_wait_writeback(src);" if > > src->mapping does not have the AS_NO_WRITEBACK_WAIT bit set on it (eg > > fuse folios will have that AS_NO_WRITEBACK_WAIT bit set) > > I think it's generally okay to skip FUSE pages under writeback when the > sync migrate_pages() is called in low memory context, which only tries > to migrate as many pages as possible (i.e. best effort). > > While more caution may be needed when the sync migrate_pages() is called > with an implicit hint that the migration can not fail. For example, > > ``` > offline_pages > while { > scan_movable_pages > do_migrate_range > } > ``` > > If the malicious server never completes the writeback IO, no progress > will be made in the above while loop, and I'm afraid it will be a dead > loop then. > Thanks for taking a look and sharing your thoughts. I agree. I think for this offline_pages() path, we need to handle this "TODO: fatal migration failures should bail out". For v3 I'm thinking of handling this by having some number of retries where we try do_migrate_range() but if it still doesn't succeed, to skip those pages and move onto the next. > > > > > 2) in the fuse filesystem's implementation of the > > mapping->a_ops->migrate_folio callback, return -EAGAIN if the folio is > > under writeback. > > Is there any possibility that a_ops->migrate_folio() may be called with > the folio under writeback? > > - for most pages without AS_NO_WRITEBACK_WAIT, a_ops->migrate_folio() > will be called only when Page_writeback is cleared; > - for AS_NO_WRITEBACK_WAIT pages, they are skipped if they are under > writeback > For AS_NO_WRITEBACK_WAIT_PAGES, if we skip waiting on them if they are under writeback, I think the a_ops->migrate_folio() will still get called (by migrate_pages_batch() -> migrate_folio_move() -> move_to_new_folio()). Looking at migrate_folio_unmap() some more though, I don't think we can just skip the wait call like we can for the sync(2) case. I think we need to error out here instead since after the wait call, migrate_folio_unmap() will replace the folio's page table mappings (try_to_migrate()). If we error out here, then there's no hitting a_ops->migrate_folio() when the folio is under writeback. Thanks, Joanne > -- > Thanks, > Jingbo