* [uml-devel] madvise(DONTNEED) on tmpfs pages instead of /dev/anon
@ 2005-08-10 19:36 Blaisorblade
2005-08-12 16:38 ` [uml-devel] " Jeff Dike
0 siblings, 1 reply; 5+ messages in thread
From: Blaisorblade @ 2005-08-10 19:36 UTC (permalink / raw)
To: Jeff Dike, Rik van Riel; +Cc: user-mode-linux-devel
UML would need to free file-backed pages anonymously mapped from the host
memory. In all relevant cases, those pages are file-backed from tmpfs (or
ramfs, but that can also be excluded)
About this, I was thinking back to what Rik said in Ottawa at the OLS. He said
"just use madvise(DONTNEED) on it", but I remarked that the pages were
file-backed.
Actually, however, since backing store for tmpfs is just pagecache/swapcache
memory,
I have the doubt that madvise(DONTNEED) already does what we need, and if not
that it might be easily fixed (since zap_page_range->unmap_vmas ->
unmap_page_range accept a range of pages to be flushed - that was a recent
change from Hugh Dickins).
For UML, the patch to use this support should be trivial (given in
pseudocode):
+//remember virt, is an address in the (guest) kernel page range
int physmem_remove_mapping(void *virt)
{
struct phys_desc *desc;
virt = (void *) ((unsigned long) virt & PAGE_MASK);
desc = find_phys_mapping(virt);
- if(desc == NULL)
- return(0);
+ if(desc == NULL) {
+ madvise(virt, PAGE_SIZE, MADV_DONTNEED);
+ return 0;
+ }
remove_mapping(desc);
return(1);
}
--
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade
___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [uml-devel] Re: madvise(DONTNEED) on tmpfs pages instead of /dev/anon
2005-08-10 19:36 [uml-devel] madvise(DONTNEED) on tmpfs pages instead of /dev/anon Blaisorblade
@ 2005-08-12 16:38 ` Jeff Dike
2005-08-12 17:00 ` Blaisorblade
0 siblings, 1 reply; 5+ messages in thread
From: Jeff Dike @ 2005-08-12 16:38 UTC (permalink / raw)
To: Blaisorblade; +Cc: Rik van Riel, user-mode-linux-devel
On Wed, Aug 10, 2005 at 09:36:43PM +0200, Blaisorblade wrote:
> About this, I was thinking back to what Rik said in Ottawa at the OLS. He said
> "just use madvise(DONTNEED) on it", but I remarked that the pages were
> file-backed.
> Actually, however, since backing store for tmpfs is just pagecache/swapcache
> memory,
They are still file-backed, just the underlying filesystem is often tmpfs.
> I have the doubt that madvise(DONTNEED) already does what we need, and if not
> that it might be easily fixed (since zap_page_range->unmap_vmas ->
> unmap_page_range accept a range of pages to be flushed - that was a recent
> change from Hugh Dickins).
The man page is silent about whether the pages are synced to their
backing store, and in any case, tmpfs hsa no real backing store.
The desired behavior is that such pages are dropped as though they
were clean, even if they are dirty. It goes against the grain of a
filesystem to drop dirty pages on the floor.
Looking at the code, the comment above madvise_dontneed is promising:
/*
* Application no longer needs these pages. If the pages are dirty,
* it's OK to just throw them away. The app will be more careful about
* data it wants to keep. Be sure to free swap resources too.
which sounds like exactly what we need.
And in zap_pte_range, I don't see any checking of PageDirty, so it
looks like this works.
Jeff
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [uml-devel] Re: madvise(DONTNEED) on tmpfs pages instead of /dev/anon
2005-08-12 16:38 ` [uml-devel] " Jeff Dike
@ 2005-08-12 17:00 ` Blaisorblade
2005-08-22 20:24 ` Jeff Dike
0 siblings, 1 reply; 5+ messages in thread
From: Blaisorblade @ 2005-08-12 17:00 UTC (permalink / raw)
To: Jeff Dike; +Cc: Rik van Riel, user-mode-linux-devel
On Friday 12 August 2005 18:38, Jeff Dike wrote:
> On Wed, Aug 10, 2005 at 09:36:43PM +0200, Blaisorblade wrote:
> > About this, I was thinking back to what Rik said in Ottawa at the OLS. He
> > said "just use madvise(DONTNEED) on it", but I remarked that the pages
> > were file-backed.
> > Actually, however, since backing store for tmpfs is just
> > pagecache/swapcache memory,
> They are still file-backed, just the underlying filesystem is often tmpfs.
Yes, but for the VM, there is nothing else than pagecache and swapcache and
swap entries. Since that call will drop them, on normal files backing store
will remain, on tmpfs everything will vanish!
Hope you'll implement this soon, if it works.
> > I have the doubt that madvise(DONTNEED) already does what we need, and if
> > not that it might be easily fixed (since zap_page_range->unmap_vmas ->
> > unmap_page_range accept a range of pages to be flushed - that was a
> > recent change from Hugh Dickins).
> The man page is silent about whether the pages are synced to their
> backing store, and in any case, tmpfs hsa no real backing store.
> The desired behavior is that such pages are dropped as though they
> were clean, even if they are dirty. It goes against the grain of a
> filesystem to drop dirty pages on the floor.
Yes, I remember.
> Looking at the code, the comment above madvise_dontneed is promising:
> /*
> * Application no longer needs these pages. If the pages are dirty,
> * it's OK to just throw them away. The app will be more careful about
> * data it wants to keep. Be sure to free swap resources too.
> which sounds like exactly what we need.
> And in zap_pte_range, I don't see any checking of PageDirty, so it
> looks like this works.
Exactly as mentioned in the comment. Well, working on remap_file_pages was
very instructive for me (I'm going to send the first version of the revised
patches)!
--
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade
___________________________________
Yahoo! Messenger: chiamate gratuite in tutto il mondo
http://it.beta.messenger.yahoo.com
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [uml-devel] Re: madvise(DONTNEED) on tmpfs pages instead of /dev/anon
2005-08-12 17:00 ` Blaisorblade
@ 2005-08-22 20:24 ` Jeff Dike
2005-08-26 15:06 ` Blaisorblade
0 siblings, 1 reply; 5+ messages in thread
From: Jeff Dike @ 2005-08-22 20:24 UTC (permalink / raw)
To: Blaisorblade; +Cc: Rik van Riel, user-mode-linux-devel
On Fri, Aug 12, 2005 at 07:00:26PM +0200, Blaisorblade wrote:
> Yes, but for the VM, there is nothing else than pagecache and swapcache and
> swap entries. Since that call will drop them, on normal files backing store
> will remain, on tmpfs everything will vanish!
>
> Hope you'll implement this soon, if it works.
There was a small omission in my quick analysis, which you alluded to above.
It's removed from the address space, but preserved in the page cache.
Run the test below to see this.
With a tmpfs /tmp, MADV_DONTNEED preserves the data.
Jeff
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/mman.h>
#include <asm/page.h>
int main(int argc, char **argv)
{
int fd, i;
unsigned char *addr, c = 0xff;
fd = open("/tmp/test", O_RDWR | O_CREAT);
if(fd < 0){
perror("Opening /tmp/test");
exit(1);
}
for(i = 0; i < PAGE_SIZE; i++)
write(fd, &c, 1);
close(fd);
fd = open("/tmp/test", O_RDWR);
if(fd < 0){
perror("Opening /tmp/test for mmap");
exit(1);
}
addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE,
fd, 0);
if(addr == MAP_FAILED){
perror("mmapping test file 1");
exit(1);
}
for(i = 0; i < PAGE_SIZE; i++){
if(addr[i] != 0xff){
printf("First mmap - bytes not == 0xff\n");
exit(1);
}
}
if(madvise(addr, PAGE_SIZE, MADV_DONTNEED) < 0){
perror("MADV_DONTNEED");
exit(1);
}
munmap(addr, PAGE_SIZE);
addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE,
fd, 0);
if(addr == MAP_FAILED){
perror("mmapping test file 2");
exit(1);
}
for(i = 0; i < PAGE_SIZE; i++){
if(addr[i] != 0xff){
printf("Second mmap - bytes not == 0xff\n");
exit(1);
}
}
printf("Data was preserved across MADV_DONTNEED\n");
}
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [uml-devel] Re: madvise(DONTNEED) on tmpfs pages instead of /dev/anon
2005-08-22 20:24 ` Jeff Dike
@ 2005-08-26 15:06 ` Blaisorblade
0 siblings, 0 replies; 5+ messages in thread
From: Blaisorblade @ 2005-08-26 15:06 UTC (permalink / raw)
To: Jeff Dike; +Cc: Rik van Riel, user-mode-linux-devel
On Monday 22 August 2005 22:24, Jeff Dike wrote:
> On Fri, Aug 12, 2005 at 07:00:26PM +0200, Blaisorblade wrote:
> > Yes, but for the VM, there is nothing else than pagecache and swapcache
> > and swap entries. Since that call will drop them, on normal files backing
> > store will remain, on tmpfs everything will vanish!
> > Hope you'll implement this soon, if it works.
> There was a small omission in my quick analysis, which you alluded to
> above.
> It's removed from the address space, but preserved in the page cache.
Yes, yesterday I realized this point. The pagecache has one additional
reference, which is only deleted after try_to_unmap() (the rmap function to
detach a page from page tables) succeeds (grep try_to_unmap mm/*.c to find
the caller).
In fact, the madvise() comment only talks about anonymous memory.
Rik, is there any hope to extend madvise() to cater for this?
> Run the test below to see this.
--
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade
___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-08-26 15:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-10 19:36 [uml-devel] madvise(DONTNEED) on tmpfs pages instead of /dev/anon Blaisorblade
2005-08-12 16:38 ` [uml-devel] " Jeff Dike
2005-08-12 17:00 ` Blaisorblade
2005-08-22 20:24 ` Jeff Dike
2005-08-26 15:06 ` Blaisorblade
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.