Skip to content

Commit 7fcbbaf

Browse files
axboetorvalds
authored andcommitted
mm/filemap.c: avoid always dirtying mapping->flags on O_DIRECT
In some testing I ran today (some fio jobs that spread over two nodes), we end up spending 40% of the time in filemap_check_errors(). That smells fishy. Looking further, this is basically what happens: blkdev_aio_read() generic_file_aio_read() filemap_write_and_wait_range() if (!mapping->nr_pages) filemap_check_errors() and filemap_check_errors() always attempts two test_and_clear_bit() on the mapping flags, thus dirtying it for every single invocation. The patch below tests each of these bits before clearing them, avoiding this issue. In my test case (4-socket box), performance went from 1.7M IOPS to 4.0M IOPS. Signed-off-by: Jens Axboe <axboe@fb.com> Acked-by: Jeff Moyer <jmoyer@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b985194 commit 7fcbbaf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mm/filemap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,11 @@ static int filemap_check_errors(struct address_space *mapping)
257257
{
258258
int ret = 0;
259259
/* Check for outstanding write errors */
260-
if (test_and_clear_bit(AS_ENOSPC, &mapping->flags))
260+
if (test_bit(AS_ENOSPC, &mapping->flags) &&
261+
test_and_clear_bit(AS_ENOSPC, &mapping->flags))
261262
ret = -ENOSPC;
262-
if (test_and_clear_bit(AS_EIO, &mapping->flags))
263+
if (test_bit(AS_EIO, &mapping->flags) &&
264+
test_and_clear_bit(AS_EIO, &mapping->flags))
263265
ret = -EIO;
264266
return ret;
265267
}

0 commit comments

Comments
 (0)