linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Avoid always dirtying mapping->flags on O_DIRECT
@ 2014-05-09 21:39 Jens Axboe
  2014-05-12 14:46 ` Jeff Moyer
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2014-05-09 21:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Al Viro, linux-mm

Hi,

In some testing I ran today, 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>

diff --git a/mm/filemap.c b/mm/filemap.c
index 000a220..088358c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -257,9 +257,11 @@ static int filemap_check_errors(struct address_space *mapping)
 {
 	int ret = 0;
 	/* Check for outstanding write errors */
-	if (test_and_clear_bit(AS_ENOSPC, &mapping->flags))
+	if (test_bit(AS_ENOSPC, &mapping->flags) &&
+	    test_and_clear_bit(AS_ENOSPC, &mapping->flags))
 		ret = -ENOSPC;
-	if (test_and_clear_bit(AS_EIO, &mapping->flags))
+	if (test_bit(AS_EIO, &mapping->flags) &&
+	    test_and_clear_bit(AS_EIO, &mapping->flags))
 		ret = -EIO;
 	return ret;
 }


-- 
Jens Axboe

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] Avoid always dirtying mapping->flags on O_DIRECT
  2014-05-09 21:39 [PATCH] Avoid always dirtying mapping->flags on O_DIRECT Jens Axboe
@ 2014-05-12 14:46 ` Jeff Moyer
  2014-05-12 15:08   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Moyer @ 2014-05-12 14:46 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, Andrew Morton, Al Viro, linux-mm

Jens Axboe <axboe@fb.com> writes:

> Hi,
>
> In some testing I ran today, 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.

It might help to use the word cacheline somewhere in here.  ;-) Out of
curiosity, what workload were you running?

Acked-by: Jeff Moyer <jmoyer@redhat.com>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] Avoid always dirtying mapping->flags on O_DIRECT
  2014-05-12 14:46 ` Jeff Moyer
@ 2014-05-12 15:08   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2014-05-12 15:08 UTC (permalink / raw)
  To: Jeff Moyer; +Cc: linux-kernel, Andrew Morton, Al Viro, linux-mm

On 05/12/2014 08:46 AM, Jeff Moyer wrote:
> Jens Axboe <axboe@fb.com> writes:
> 
>> Hi,
>>
>> In some testing I ran today, 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.
> 
> It might help to use the word cacheline somewhere in here.  ;-) Out of

I thought that was self-evident, but yes, I could add that :-)

> curiosity, what workload were you running?

Nothing fancy, just some fio jobs that spread over two nodes.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2014-05-12 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-09 21:39 [PATCH] Avoid always dirtying mapping->flags on O_DIRECT Jens Axboe
2014-05-12 14:46 ` Jeff Moyer
2014-05-12 15:08   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).