From: Andrew Morton <andrewm@uow.edu.au>
To: lkml <linux-kernel@vger.kernel.org>
Subject: [patch] truncate_inode_pages
Date: Sun, 10 Jun 2001 01:51:47 +1000 [thread overview]
Message-ID: <3B224613.440AE25C@uow.edu.au> (raw)
The ftruncate() in this program:
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
int clean = 64 * 1024 * 1024;
int dirty = 64 * 1024 * 1024;
main()
{
int fd = open("foo", O_RDWR|O_TRUNC|O_CREAT, 0666);
void *mem;
ftruncate(fd, clean + dirty);
mem = mmap(0, clean + dirty, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
memset(mem, 0, clean + dirty);
msync(mem, clean, MS_SYNC);
ftruncate(fd, clean);
}
takes 45 seconds CPU time due to the O(clean * dirty) algorithm in
truncate_inode_pages(). The machine is locked up for the duration.
The patch reduces this to 20 milliseconds via an O(clean + dirty)
algorithm.
--- linux-2.4.5/mm/filemap.c Mon May 28 13:31:49 2001
+++ linux-akpm/mm/filemap.c Sun Jun 10 01:27:09 2001
@@ -273,15 +273,24 @@
{
unsigned long start = (lstart + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
unsigned partial = lstart & (PAGE_CACHE_SIZE - 1);
+ int complete;
-repeat:
spin_lock(&pagecache_lock);
- if (truncate_list_pages(&mapping->clean_pages, start, &partial))
- goto repeat;
- if (truncate_list_pages(&mapping->dirty_pages, start, &partial))
- goto repeat;
- if (truncate_list_pages(&mapping->locked_pages, start, &partial))
- goto repeat;
+ do {
+ complete = 1;
+ while (truncate_list_pages(&mapping->clean_pages, start, &partial)) {
+ spin_lock(&pagecache_lock);
+ complete = 0;
+ }
+ while (truncate_list_pages(&mapping->dirty_pages, start, &partial)) {
+ spin_lock(&pagecache_lock);
+ complete = 0;
+ }
+ while (truncate_list_pages(&mapping->locked_pages, start, &partial)) {
+ spin_lock(&pagecache_lock);
+ complete = 0;
+ }
+ } while (!complete);
spin_unlock(&pagecache_lock);
}
next reply other threads:[~2001-06-09 15:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-09 15:51 Andrew Morton [this message]
2001-06-09 17:40 ` [patch] truncate_inode_pages Alexander Viro
2001-06-09 22:53 ` Daniel Phillips
2001-06-10 1:31 ` Andrew Morton
2001-06-10 16:40 ` Daniel Phillips
2001-06-11 12:45 ` Andrew Morton
2001-06-11 13:13 ` Daniel Phillips
2001-06-11 13:28 ` Andrew Morton
2001-06-11 2:22 Dieter Nützel
[not found] ` <200106112252.AAA19615@mail.bonn-fries.net>
[not found] ` <01061214324600.00879@starship>
2001-06-12 16:32 ` Dieter Nützel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3B224613.440AE25C@uow.edu.au \
--to=andrewm@uow.edu.au \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).