Function to do end-writeback in bulk

David Howells <[email protected]>
Newsgroups dev.linux.lists.netfs
Organization Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903
Message-ID <[email protected]>
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;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.