Linux network filesystem support library
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: dhowells@redhat.com, Paulo Alcantara <pc@manguebit.org>,
	netfs@lists.linux.dev
Subject: Function to do end-writeback in bulk
Date: Mon, 24 Aug 2026 16:09:20 +0100	[thread overview]
Message-ID: <761202.1787584160@warthog.procyon.org.uk> (raw)

Hi Willy,

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
 *
 * 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;
}


             reply	other threads:[~2026-08-24 15:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 15:09 David Howells [this message]
2026-08-24 15:25 ` Function to do end-writeback in bulk Matthew Wilcox
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=761202.1787584160@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=netfs@lists.linux.dev \
    --cc=pc@manguebit.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