All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Fix THP handling in invalidate_mapping_pages()
@ 2017-06-19 12:47 Jan Kara
  2017-06-19 13:25 ` Kirill A. Shutemov
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2017-06-19 12:47 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, Kirill A. Shutemov, Jan Kara

The condition checking for THP straddling end of invalidated range is
wrong - it checks 'index' against 'end' but 'index' has been already
advanced to point to the end of THP and thus the condition can never be
true. As a result THP straddling 'end' has been fully invalidated. Given
the nature of invalidate_mapping_pages(), this could be only performance
issue. In fact, we are lucky the condition is wrong because if it was
ever true, we'd leave locked page behind.

Fix the condition checking for THP straddling 'end' and also properly
unlock the page. Also update the comment before the condition to explain
why we decide not to invalidate the page as it was not clear to me and I
had to ask Kirill.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 mm/truncate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/mm/truncate.c b/mm/truncate.c
index 6479ed2afc53..2330223841fb 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -530,9 +530,15 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
 			} else if (PageTransHuge(page)) {
 				index += HPAGE_PMD_NR - 1;
 				i += HPAGE_PMD_NR - 1;
-				/* 'end' is in the middle of THP */
-				if (index ==  round_down(end, HPAGE_PMD_NR))
+				/*
+				 * 'end' is in the middle of THP. Don't
+				 * invalidate the page as the part outside of
+				 * 'end' could be still useful.
+				 */
+				if (index > end) {
+					unlock_page(page);
 					continue;
+				}
 			}
 
 			ret = invalidate_inode_page(page);
-- 
2.12.3

--
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] 2+ messages in thread

* Re: [PATCH] mm: Fix THP handling in invalidate_mapping_pages()
  2017-06-19 12:47 [PATCH] mm: Fix THP handling in invalidate_mapping_pages() Jan Kara
@ 2017-06-19 13:25 ` Kirill A. Shutemov
  0 siblings, 0 replies; 2+ messages in thread
From: Kirill A. Shutemov @ 2017-06-19 13:25 UTC (permalink / raw)
  To: Jan Kara; +Cc: Andrew Morton, linux-mm

On Mon, Jun 19, 2017 at 02:47:23PM +0200, Jan Kara wrote:
> The condition checking for THP straddling end of invalidated range is
> wrong - it checks 'index' against 'end' but 'index' has been already
> advanced to point to the end of THP and thus the condition can never be
> true. As a result THP straddling 'end' has been fully invalidated. Given
> the nature of invalidate_mapping_pages(), this could be only performance
> issue. In fact, we are lucky the condition is wrong because if it was
> ever true, we'd leave locked page behind.
> 
> Fix the condition checking for THP straddling 'end' and also properly
> unlock the page. Also update the comment before the condition to explain
> why we decide not to invalidate the page as it was not clear to me and I
> had to ask Kirill.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Thanks a lot for the fix.

-- 
 Kirill A. Shutemov

--
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] 2+ messages in thread

end of thread, other threads:[~2017-06-19 13:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 12:47 [PATCH] mm: Fix THP handling in invalidate_mapping_pages() Jan Kara
2017-06-19 13:25 ` Kirill A. Shutemov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.