Skip to contentSkip to conversation

Improve documentation of FADV_DONTNEED behaviour

PATCH In review Mel Gorman 2 participants 5 messages Dec 3, 2014 – Dec 30, 2014

Subsystems (2)
lore
Share & tools
lore

Mel Gorman

author
#0 lore raw

cover Improve documentation of FADV_DONTNEED behaviour

Partial page discard requests are ignored and the documentation on why this is correct behaviour sucks. A readahead patch looked like a "regression" to a random IO storage benchmark because posix_fadvise() was used incorrectly to force IO requests to go to disk. In reality, the benchmark sucked but it was non-obvious why. Patch 1 updates the kernel comment in case someone "fixes" either readahead or fadvise for inappropriate reasons. Patch 2 updates the relevant man page on the rough off chance that application developers do not read kernel source comments.

Signature · 7 lines
2.1.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#1 lore raw

PATCH 1/2 mm: fadvise: Document the fadvise(FADV_DONTNEED) behaviour for partial pages

A random seek IO benchmark appeared to regress because of a change to readahead but the real problem was the benchmark. To ensure the IO request accesssed disk, it used fadvise(FADV_DONTNEED) on a block boundary (512K) but the hint is ignored by the kernel. This is correct but not necessarily obvious behaviour. As much as I dislike comment patches, the explanation for this behaviour predates current git history. Clarify why it behaves like this in case someone "fixes" fadvise or readahead for the wrong reasons.

---
 mm/fadvise.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/fadvise.c +5 -1
index 3bcfd81d..c908c72 100644
@@ -117,7 +117,11 @@ SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice)
 			__filemap_fdatawrite_range(mapping, offset, endbyte,
 						   WB_SYNC_NONE);
 
-		/* First and last FULL page! */
+		/*
+		 * First and last FULL page! Partial pages are deliberately
+		 * preserved on the expectation that it is better to preserve
+		 * needed memory than to discard unneeded memory.
+		 */
 		start_index = (offset+(PAGE_CACHE_SIZE-1)) >> PAGE_CACHE_SHIFT;
 		end_index = (endbyte >> PAGE_CACHE_SHIFT);
 
Signature · 7 lines
2.1.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#2 lore raw

PATCH 2/2 posix_fadvise.2: Document the behaviour of partial page discard requests

In reply to Mel Gorman

It is not obvious from the interface that partial page discard requests are ignored. It should be spelled out.

---
 man2/posix_fadvise.2 | 5 +++++
 1 file changed, 5 insertions(+)
man2/posix_fadvise.2 +5 -0
index 25d0c50..07313a9 100644
@@ -144,6 +144,11 @@ A program may periodically request the kernel to free cached data
 that has already been used, so that more useful cached pages are not
 discarded instead.
 
+Requests to discard partial pages are ignored. It is preferable to preserve
+needed data than discard unneeded data. If the application requires that
+data be considered for discarding then \fIoffset\fP and \fIlen\fP must be
+page-aligned.
+
 Pages that have not yet been written out will be unaffected, so if the
 application wishes to guarantee that pages will be released, it should
 call

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

#3 lore raw

Re: [PATCH 2/2] posix_fadvise.2: Document the behaviour of partial page discard requests

Quoted 2 lines · Mel Gorman

It is not obvious from the interface that partial page discard requests are ignored. It should be spelled out.

Thanks, Mel. Applied.

Cheers,

Michael

Quoted 22 lines
---
 man2/posix_fadvise.2 | 5 +++++
 1 file changed, 5 insertions(+)
man2/posix_fadvise.2 +5 -0
index 25d0c50..07313a9 100644
@@ -144,6 +144,11 @@ A program may periodically request the kernel to free cached data
 that has already been used, so that more useful cached pages are not
 discarded instead.
 
+Requests to discard partial pages are ignored. It is preferable to preserve
+needed data than discard unneeded data. If the application requires that
+data be considered for discarding then \fIoffset\fP and \fIlen\fP must be
+page-aligned.
+
 Pages that have not yet been written out will be unaffected, so if the
 application wishes to guarantee that pages will be released, it should
 call
Signature · 9 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
In reply to Mel Gorman
Quoted 8 lines · Mel Gorman

Partial page discard requests are ignored and the documentation on why this is correct behaviour sucks. A readahead patch looked like a "regression" to a random IO storage benchmark because posix_fadvise() was used incorrectly to force IO requests to go to disk. In reality, the benchmark sucked but it was non-obvious why. Patch 1 updates the kernel comment in case someone "fixes" either readahead or fadvise for inappropriate reasons. Patch 2 updates the relevant man page on the rough off chance that application developers do not read kernel source comments.

It feels like that last sentence should have made LWN quote of the week :-/.

Signature · 9 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

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