Re: [PATCH v3 1/3] iomap: resched ioend completion when in non-atomic context
From: "Darrick J. Wong" <djwong@kernel.org>
Date: 2021-05-20 21:59:00
Also in:
linux-fsdevel
On Tue, May 18, 2021 at 07:38:01AM -0400, Brian Foster wrote:
On Mon, May 17, 2021 at 06:54:34PM +0100, Matthew Wilcox wrote:quoted
On Mon, May 17, 2021 at 01:17:20PM -0400, Brian Foster wrote:quoted
@@ -1084,9 +1084,12 @@ iomap_finish_ioend(struct iomap_ioend *ioend, int error) next = bio->bi_private; /* walk each page on bio, ending page IO on them */ - bio_for_each_segment_all(bv, bio, iter_all) + bio_for_each_segment_all(bv, bio, iter_all) { iomap_finish_page_writeback(inode, bv->bv_page, error, bv->bv_len); + if (!atomic) + cond_resched(); + }I don't know that it makes sense to check after _every_ page. I might go for every segment. Some users check after every thousand pages.The handful of examples I come across on a brief scan (including the other iomap usage) have a similar pattern as used here. I don't doubt there are others, but I think I'd prefer to have more reasoning behind adding more code than might be necessary (i.e. do we expect additional overhead to be measurable here?). As it is, the intent isn't so much to check on every page as much as this just happens to be the common point of the function to cover both long bio chains and single vector bios with large numbers of pages.
It's been a while since I waded through the macro hell to find out what cond_resched actually does, but iirc it can do some fairly heavyweight things (disable preemption, call the scheduler, rcu stuff) which is why we're supposed to be a little judicious about amortizing each call over a few thousand pages. --D
Brian