From: Matthew Wilcox <willy@infradead.org>
To: David Howells <dhowells@redhat.com>
Cc: Paulo Alcantara <pc@manguebit.org>, netfs@lists.linux.dev
Subject: Re: Function to do end-writeback in bulk
Date: Mon, 24 Aug 2026 16:25:41 +0100 [thread overview]
Message-ID: <aoxidVrUtl3F0QUi@casper.infradead.org> (raw)
In-Reply-To: <761202.1787584160@warthog.procyon.org.uk>
On Mon, Aug 24, 2026 at 04:09:20PM +0100, David Howells wrote:
> Can you take a look at the function below? This is what I've come up with for
> the moment for a basic bulk end-writeback (and I'll need something similar for
> bulk unlock). At the moment, it returns true/false depending on whether it
> made progress, but I'm thinking that it might be better if it returns the
> remaining size of any folio that partially overlaps the end position and so
> didn't get unlocked. This would could allow me to set a minimum amount to
> accrue before I call it again. Whether progress was made can also be
> determined by comparing @from before and after.
>
> Thanks,
> David
> ---
> /**
> * folio_end_writeback_range - End writeback for the folios within the range
> * @mapping: The pagecache to modify
> * @from: Pointer to the starting position (updated)
> * @to: The end position (exclusive)
> * @cleaner_func: Function to clean up the folios in the range
> * @cleaner_priv: Private data for the cleaner func
I hate this API. I much prefer the _iter() style:
struct end_writeback_ctrl {
struct xa_state xas;
uoff_t fend;
};
struct folio *end_writeback_iter(struct address_space *mapping,
uoff_t from, uoff_t to,
struct end_writeback_ctrl *ctrl, struct folio *folio)
{
if (!folio) {
ctrl->xas = __XA_STATE(&mapping->i_pages, from / PAGE_SIZE,
0, 0);
folio = xas_find(&ctrl->xas, to / PAGE_SIZE);
} else {
retry:
folio_end_writeback(folio);
folio = xas_next_entry(&ctrl->xas, to / PAGE_SIZE);
}
if (xas_retry(&xas, folio))
goto retry;
ctrl->fend = folio_next_pos(folio);
if (ctrl->fend > to)
folio = NULL;
return folio;
}
(you can embed the rcu_read_lock() / unlock in here too, but probably
better to do it in the caller)
> * Unlock folios that are entirely within in the given range, where @from is
> * included in the range, but @to is excluded from the range.
> *
> * Return: True if at least one folio got cleaned, false otherwise. @from will
> * be updated to point past the last folio cleaned.
> */
> static inline
> bool folio_end_writeback_range(struct address_space *mapping,
> uoff_t *from, uoff_t to,
> void (*cleaner_func)(struct folio *folio,
> void *cleaner_priv),
> void *cleaner_priv)
> {
> struct folio *folio;
> XA_STATE(xas, &mapping->i_pages, *from / PAGE_SIZE);
> bool cleaned = false;
>
> rcu_read_lock();
> xas_for_each(&xas, folio, (to - 1) / PAGE_SIZE) {
> uoff_t fend;
>
> if (xas_retry(&xas, folio))
> continue;
>
> fend = folio_next_pos(folio);
> if (fend > to)
> break;
>
> cleaner_func(folio, cleaner_priv);
> folio_end_writeback(folio);
> *from = fend;
> cleaned = true;
> }
> rcu_read_unlock();
> return cleaned;
> }
>
next prev parent reply other threads:[~2026-08-24 15:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 15:09 Function to do end-writeback in bulk David Howells
2026-08-24 15:25 ` Matthew Wilcox [this message]
2026-08-24 15:47 ` David Howells
2026-08-24 16:16 ` Matthew Wilcox
2026-08-24 19:14 ` David Howells
2026-08-24 19:27 ` Matthew Wilcox
2026-09-01 7:17 ` David Howells
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=aoxidVrUtl3F0QUi@casper.infradead.org \
--to=willy@infradead.org \
--cc=dhowells@redhat.com \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.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 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.