linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RESEND] [PATCH] mm: Do not discard partial pages with POSIX_FADV_DONTNEED
@ 2016-06-03  1:25 green
  0 siblings, 0 replies; only message in thread
From: green @ 2016-06-03  1:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: <linux-kernel@vger.kernel.org> Mailing List, linux-mm, Oleg Drokin

From: Oleg Drokin <green@linuxhacker.ru>

I noticed that if the logic in fadvise64_64 syscall is incorrect
for partial pages. While first page of the region is correctly skipped
if it is partial, the last page of the region is mistakenly discarded.
This leads to problems for applications that read data in
non-page-aligned chunks discarding already processed data between
the reads.

Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
---
A somewhat misguided application that does something like
write(XX bytes (non-page-alligned)); drop the data it just wrote; repeat
gets a significant penalty in performance as the result.

 mm/fadvise.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mm/fadvise.c b/mm/fadvise.c
index b8024fa..6c707bf 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -126,6 +126,17 @@ SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice)
 		 */
 		start_index = (offset+(PAGE_SIZE-1)) >> PAGE_SHIFT;
 		end_index = (endbyte >> PAGE_SHIFT);
+		if ((endbyte & ~PAGE_MASK) != ~PAGE_MASK) {
+			/* First page is tricky as 0 - 1 = -1, but pgoff_t
+			 * is unsigned, so the end_index >= start_index
+			 * check below would be true and we'll discard the whole
+			 * file cache which is not what was asked.
+			 */
+			if (end_index == 0)
+				break;
+
+			end_index--;
+		}
 
 		if (end_index >= start_index) {
 			unsigned long count = invalidate_mapping_pages(mapping,
-- 
2.1.0

--
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] only message in thread

only message in thread, other threads:[~2016-06-03  1:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03  1:25 [RESEND] [PATCH] mm: Do not discard partial pages with POSIX_FADV_DONTNEED green

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).