Skip to contentSkip to conversation

fadvise invalidating range fix

PATCH WU Fengguang 1 participant 2 messages Mar 9, 2004 – Mar 10, 2004 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 14 lines · Andrew Morton
Quoted 7 lines · WU Fengguang

- When 'offset' and/or 'offset+len' do no align to page boundary, we must decide whether to abandon the partial page at the beginning/end of the range. My patch assumes that the application is scanning forward,
which is the most common case.
So 'end_index' is set to the page just before the ending partial page.

If you're going to preserve the partial page at end' (which seems reasonable) then you should also preserve the partial page at start', don't you agree?

Review

Quoted 2 lines
(quoted diff) +1 -1
-	start_index = offset >> PAGE_CACHE_SHIFT;
+	start_index = (offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;

In fact, it depends on the access pattern.
I would expect the normal usage of fadvise to be:

	for() {
		read() and consume() data in [offset, offset+LEN);
		fadvise(fd, offset, LEN, POSIX_FADV_DONTNEED);
		offset += LEN; /*scanning forward*/
	}

In this case, the partial page at `start' should be freed. Certainly there may be other patterns.

I wonder the best solution in kernel is to code in favor of the normal case, and the best(safe and portable) practice in usermode code is to always align 'offset' and 'offset+len' to page boundaries.
And some comment in the manual page of posix_fadvise is recommended.

#3 lore raw
In reply to a message not in the archive
Quoted 19 lines · Andrew Morton
Quoted 10 lines · WU Fengguang

- When 'offset' and/or 'offset+len' do no align to page boundary, we must
decide whether to abandon the partial page at the beginning/end of the range.
My patch assumes that the application is scanning forward, which is the most common case.
So 'end_index' is set to the page just before the ending partial page.

If you're going to preserve the partial page at end' (which seems reasonable) then you should also preserve the partial page at start', don't
you agree?

(quoted diff) +1 -1
-     start_index = offset >> PAGE_CACHE_SHIFT;
+     start_index = (offset + PAGE_CACHE_SIZE - 1) >>
Quoted 2 lines

PAGE_CACHE_SHIFT;

I gave it a rethink today, and yes, we should preserve the starting partial page as well. Doing so helps reducing unnecessary disk I/O for any access pattern, and the kernel will behave more consistent and robust.

The only negative effect is, some useless pages are left to be freed at some later time by the page replacement routines, and the cost of which is acceptable.

regards, Wu Fengguang