From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751348AbcFCB0G (ORCPT ); Thu, 2 Jun 2016 21:26:06 -0400 Received: from linuxhacker.ru ([217.76.32.60]:38118 "EHLO fiona.linuxhacker.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751241AbcFCB0C (ORCPT ); Thu, 2 Jun 2016 21:26:02 -0400 From: green@linuxhacker.ru To: Andrew Morton Cc: " Mailing List" , linux-mm@kvack.org, Oleg Drokin Subject: [RESEND] [PATCH] mm: Do not discard partial pages with POSIX_FADV_DONTNEED Date: Thu, 2 Jun 2016 21:25:40 -0400 Message-Id: <1464917140-1506698-1-git-send-email-green@linuxhacker.ru> X-Mailer: git-send-email 2.1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleg Drokin 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 --- 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