From: akpm@linux-foundation.org Subject: [merged] readahead-fix-sequential-read-cache-miss-detection.patch removed from -mm tree Date: Wed, 13 Nov 2013 12:39:14 -0800 Message-ID: <5283e372.Fg38DNJsJpXwYGgI%akpm@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:42773 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751449Ab3KMUjP (ORCPT ); Wed, 13 Nov 2013 15:39:15 -0500 Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: mm-commits@vger.kernel.org, pierre.tardy@intel.com, fengguang.wu@intel.com, david.a.cohen@linux.intel.com, damien.ramonda@intel.com Subject: [merged] readahead-fix-sequential-read-cache-miss-detection.patch removed from -mm tree To: damien.ramonda@intel.com,david.a.cohen@linux.intel.com,fengguang.wu@intel.com,pierre.tardy@intel.com,mm-commits@vger.kernel.org From: akpm@linux-foundation.org Date: Wed, 13 Nov 2013 12:39:14 -0800 The patch titled Subject: readahead: fix sequential read cache miss detection has been removed from the -mm tree. Its filename was readahead-fix-sequential-read-cache-miss-detection.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Damien Ramonda Subject: readahead: fix sequential read cache miss detection The kernel's readahead algorithm sometimes interprets random read accesses as sequential and triggers unnecessary data prefecthing from storage device (impacting random read average latency). In order to identify sequential cache read misses, the readahead algorithm intends to check whether offset - previous offset == 1 (trivial sequential reads) or offset - previous offset == 0 (sequential reads not aligned on page boundary): if (offset - (ra->prev_pos >> PAGE_CACHE_SHIFT) <= 1UL) The current offset is stored in the "offset" variable of type "pgoff_t" (unsigned long), while previous offset is stored in "ra->prev_pos" of type "loff_t" (long long). Therefore, operands of the if statement are implicitly converted to type long long. Consequently, when previous offset > current offset (which happens on random pattern), the if condition is true and access is wrongly interpeted as sequential. An unnecessary data prefetching is triggered, impacting the average random read latency. Storing the previous offset value in a "pgoff_t" variable (unsigned long) fixes the sequential read detection logic. Signed-off-by: Damien Ramonda Reviewed-by: Fengguang Wu Acked-by: Pierre Tardy Acked-by: David Cohen Signed-off-by: Andrew Morton --- mm/readahead.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff -puN mm/readahead.c~readahead-fix-sequential-read-cache-miss-detection mm/readahead.c --- a/mm/readahead.c~readahead-fix-sequential-read-cache-miss-detection +++ a/mm/readahead.c @@ -401,6 +401,7 @@ ondemand_readahead(struct address_space unsigned long req_size) { unsigned long max = max_sane_readahead(ra->ra_pages); + pgoff_t prev_offset; /* * start of file @@ -452,8 +453,11 @@ ondemand_readahead(struct address_space /* * sequential cache miss + * trivial case: (offset - prev_offset) == 1 + * unaligned reads: (offset - prev_offset) == 0 */ - if (offset - (ra->prev_pos >> PAGE_CACHE_SHIFT) <= 1UL) + prev_offset = (unsigned long long)ra->prev_pos >> PAGE_CACHE_SHIFT; + if (offset - prev_offset <= 1UL) goto initial_readahead; /* _ Patches currently in -mm which might be from damien.ramonda@intel.com are origin.patch