Linux network filesystem support library
 help / color / mirror / Atom feed
* Function to do end-writeback in bulk
@ 2026-08-24 15:09 David Howells
  2026-08-24 15:25 ` Matthew Wilcox
  0 siblings, 1 reply; 7+ messages in thread
From: David Howells @ 2026-08-24 15:09 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: dhowells, Paulo Alcantara, netfs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-01  7:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-24 15:09 Function to do end-writeback in bulk David Howells
2026-08-24 15:25 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox