[meego-commits] 8605: Changes to Trunk:Testing/sreadahead
Auke Kok
no_reply at build.meego.com
Mon Oct 18 22:43:48 UTC 2010
Hi,
I have made the following changes to sreadahead in project Trunk:Testing. Please review and accept ASAP.
Thank You,
Auke Kok
[This message was auto-generated]
---
Request #8605:
submit: home:auke:branches:Trunk:Testing/sreadahead(r2)(cleanup) -> Trunk:Testing/sreadahead
Message:
* Mon Oct 18 2010 Auke Kok <auke-jan.h.kok at intel.com> - 0.11
- Bugfix: tune readahead sizes to reasonable size
- Minor cleanups: fix text messages for ioprio errors.
- Error handling: account for errors processing the pack file at start up.
- Increasing the number of readahead files to 2048.
- Merge __NR_ioprio_set for ARM and PowerPC like in uxlaunch.
State: new 2010-10-18T15:43:47 auke
Comment: None
changes files:
--------------
--- sreadahead.changes
+++ sreadahead.changes
@@ -0,0 +1,7 @@
+* Mon Oct 18 2010 Auke Kok <auke-jan.h.kok at intel.com> - 0.11
+- Bugfix: tune readahead sizes to reasonable size
+- Minor cleanups: fix text messages for ioprio errors.
+- Error handling: account for errors processing the pack file at start up.
+- Increasing the number of readahead files to 2048.
+- Merge __NR_ioprio_set for ARM and PowerPC like in uxlaunch.
+
old:
----
sreadahead-0.10-arm-buildfix.patch
sreadahead-0.10.tar.gz
new:
----
sreadahead-0.11.tar.gz
spec files:
-----------
--- sreadahead.spec
+++ sreadahead.spec
@@ -1,12 +1,11 @@
Name: sreadahead
-Version: 0.10
+Version: 0.11
Release: 1
Summary: Readahead implementation optimized for netbooks
Group: System
License: GPLv2
Source0: sreadahead-%{version}.tar.gz
-Patch0: sreadahead-0.10-arm-buildfix.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Requires(post): /sbin/chkconfig
@@ -17,7 +16,6 @@
%prep
%setup -q
-%patch0 -p1
%build
make %{?_smp_mflags}
other changes:
--------------
++++++ sreadahead-0.10.tar.gz -> sreadahead-0.11.tar.gz
--- Makefile
+++ Makefile
@@ -1,7 +1,7 @@
CFLAGS ?= -Os -march=i686 -g -Wall -W
PROGS = sreadahead-pack sreadahead sreadahead-dump
-VERSION = 0.10
+VERSION = 0.11
all: $(PROGS)
@@ -23,5 +23,3 @@
git tag v$(VERSION)
git archive --format=tar --prefix="sreadahead-$(VERSION)/" v$(VERSION) | \
gzip > sreadahead-$(VERSION).tar.gz
- git push --tags
-
\ No newline at end of file
--- filelist.c
+++ filelist.c
@@ -113,7 +113,7 @@
if (!strncmp(line, "0", 1))
return;
- } else
+ } else
return;
rotating_storage = 1;
@@ -139,7 +139,7 @@
int cur = 0, maxgap;
maxgap = 1024*1024*512;
-
+
for (i = 0; i < count; i++, record++) {
if (i+1 < count) {
int gap;
@@ -153,25 +153,6 @@
return cur;
}
-static void dump_records(struct record *record, int count)
-{
- int i;
- int q;
- q = smallest_gap(record, count);
-
- for (i = 0; i < count; i++, record++) {
- printf("Record %i: Start at %iKb for %iKb", i,
- record->offset/1024, (record->len+1)/1024);
- if (i+1 < count) {
- int gap;
- gap = (record+1)->offset - record->offset - record->len;
- printf("\t gap is %iKb", gap/1024);
- }
- if (q == i) printf("*");
- printf("\n");
- }
-}
-
static int merge_record(struct record *record, int count, int to_merge)
{
record[to_merge].len = record[to_merge+1].offset+record[to_merge+1].len - record[to_merge].offset;
@@ -196,10 +177,10 @@
void *mmapptr;
unsigned char *mincorebuf;
int fd;
- int i, ret;
+ int i;
struct record record[4096];
-
+
int reccount = 0;
int phase;
@@ -217,7 +198,7 @@
if (!file)
return 0;
fd = fileno(file);
-
+
time = ioctl(fd, EXT3_IOC_INODE_JIFFIES);
time += 300000;
@@ -234,10 +215,10 @@
mmapptr = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
-
+
mincorebuf = malloc(statbuf.st_size/4096 + 1);
mincore(mmapptr, statbuf.st_size, mincorebuf);
-
+
if (mincorebuf[0]) {
phase = 1;
start = 0;
@@ -273,15 +254,18 @@
}
free(mincorebuf);
munmap(mmapptr, statbuf.st_size);
-
-
+
+
fclose(file);
-
+
if (reccount && debug)
printf("File %s is %3.1f%% in memory in %i fragments \n", filename, 100.0*there/(there+notthere), reccount);
reccount = reduce_to(record, reccount, 6);
+ if (record[0].len <= 0)
+ return 0;
+
if (reccount>0 && RAcount < 4095) {
memset(&RA[RAcount], 0, sizeof(struct readahead));
strncpy(RA[RAcount].filename, filename, MAX_FNAME_LEN-1);
@@ -338,7 +322,7 @@
return 1;
if (RA[i].block < RA[j].block)
return 0;
-
+
if (RA[i].block == RA[j].block && RA[i].block == 0) {
if (strcmp(RA[i].filename, RA[j].filename) > 0)
return 1;
@@ -375,11 +359,11 @@
static void sort_RA(void)
{
int delta = 1;
-
+
while (delta>0) {
int i;
delta = 0;
- for (i=0; i < RAcount-1; i++)
+ for (i=0; i < RAcount-1; i++)
if (sort_items(i, i+1)) {
struct readahead tmp;
tmp = RA[i+1];
@@ -393,11 +377,11 @@
static void sort_RA_by_time(void)
{
int delta = 1;
-
+
while (delta>0) {
int i;
delta = 0;
- for (i=0; i < RAcount-1; i++)
+ for (i=0; i < RAcount-1; i++)
if (sort_items_by_time(i, i+1)) {
struct readahead tmp;
tmp = RA[i+1];
@@ -410,11 +394,11 @@
static void sort_RA_by_block(void)
{
int delta = 1;
-
+
while (delta>0) {
int i;
delta = 0;
- for (i=0; i < RAcount-1; i++)
+ for (i=0; i < RAcount-1; i++)
if (sort_items_by_block(i, i+1)) {
struct readahead tmp;
tmp = RA[i+1];
@@ -434,7 +418,7 @@
struct btrfs_ioctl_vol_args btrfs;
memset(&btrfs, 0, sizeof(btrfs));
-
+
for (i = 0; i < RAcount; i++) {
file = fopen(RA[i].filename, "r+");
if (!file)
@@ -446,7 +430,7 @@
if (ret < 0 && debug) {
printf("btrfs ioctl failed %i / %i\n", ret, errno);
}
- RA[i].block = first_block(fd);
+ RA[i].block = first_block(fd);
fclose(file);
}
}
@@ -454,9 +438,8 @@
static void mark_adjacent(void)
{
int i;
- int ret;
unsigned long filesize;
-
+
for (i = 0; i < RAcount -1; i++) {
filesize = RA[i].data[0].len + RA[i].data[1].len+
RA[i].data[2].len + RA[i].data[3].len+
@@ -494,11 +477,11 @@
do_metafile(argv[optind]);
if (rotating_storage) {
- sort_RA_by_time();
+ sort_RA_by_time();
system("/bin/mount -o remount,ssd /");
- fill_in_block_data();
- sort_RA_by_block();
- mark_adjacent();
+ fill_in_block_data();
+ sort_RA_by_block();
+ mark_adjacent();
}
sort_RA();
--- readahead.c
+++ readahead.c
@@ -33,6 +33,10 @@
# define __NR_ioprio_set 289
#elif defined(__x86_64__)
# define __NR_ioprio_set 251
+#elif defined(__arm__)
+# define __NR_ioprio_set 314
+#elif defined (__powerpc__)
+# define __NR_ioprio_set 273
#else
# error "Unsupported arch"
#endif
@@ -43,7 +47,11 @@
#define IOPRIO_IDLE_LOWEST (7 | (IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT))
#define IOPRIO_RT_LOWEST (7 | (IOPRIO_CLASS_RT << IOPRIO_CLASS_SHIFT))
-#define MAXR 1024
+/* read_ahead_kb values used during operation, once finished */
+#define RA_STARTUP "16"
+#define RA_NORMAL "128"
+
+#define MAXR 2048
static struct readahead files[MAXR];
static unsigned int total_files = 0;
@@ -51,6 +59,8 @@
static int rotating_storage;
+int ra_err = 0;
+
static void readahead_one(int index)
{
int fd;
@@ -61,6 +71,7 @@
if (fd < 0)
fd = open(files[index].filename, O_RDONLY);
if (fd < 0) {
+ ra_err += 1; /* file is gone, minor error */
fprintf(stderr, "%s: open failed (%s)\n",
files[index].filename, strerror_r(errno, buf, sizeof buf));
return;
@@ -70,6 +81,12 @@
if (files[index].data[i].len)
readahead(fd, files[index].data[i].offset,
files[index].data[i].len);
+ else if (i == 0) {
+ /* corrupt file, disqualify pack */
+ fprintf(stderr, "%s: zero length file\n",
+ files[index].filename);
+ ra_err += 100;
+ }
}
close(fd);
}
@@ -84,7 +101,7 @@
readahead_one(mine);
else
break;
-
+
if (rotating_storage && (mine % 100 == 0))
usleep(100000);
}
@@ -118,7 +135,6 @@
if (strstr(line, "SSD"))
return;
-
}
snprintf(sysf, PATH_MAX, "/sys/block/sda/queue/rotational");
@@ -131,13 +147,38 @@
if (!strncmp(line, "0", 1))
return;
- } else
+ } else
return;
rotating_storage = 1;
}
+static void tune(const char *path, const char *val)
+{
+ FILE *file;
+
+ file = fopen(path, "w");
+ if (!file)
+ return;
+ fprintf(file, "%s", val);
+ fclose(file);
+}
+
+
+static void tune_read_ahead(const char *ra)
+{
+ tune("/sys/block/sda/queue/read_ahead_kb", ra);
+ tune("/sys/block/sdb/queue/read_ahead_kb", ra);
+ tune("/sys/block/sdc/queue/read_ahead_kb", ra);
+ tune("/sys/block/sdd/queue/read_ahead_kb", ra);
+ tune("/sys/block/mmcblk0/read_ahead_kb", ra);
+ tune("/sys/block/mmcblk1/read_ahead_kb", ra);
+ tune("/sys/class/bdi/btrfs-1/read_ahead_kb", ra);
+ tune("/sys/class/bdi/btrfs-2/read_ahead_kb", ra);
+ tune("/sys/class/bdi/btrfs-3/read_ahead_kb", ra);
+ tune("/sys/class/bdi/btrfs-4/read_ahead_kb", ra);
+}
int main(int argc, char **argv)
@@ -146,34 +187,36 @@
FILE *file;
int pid = 0;
pthread_t one;
-
+ int ret = 1;
+
+ tune_read_ahead(RA_STARTUP);
+
check_for_rotation();
file = fopen(name, "r");
if (!file) {
perror(name);
- return 1;
+ goto out;
}
total_files = fread(&files, sizeof(struct readahead), MAXR, file);
if (ferror(file)) {
perror(name);
- return 1;
+ goto out;
}
fclose(file);
if (rotating_storage) {
- if (syscall(__NR_ioprio_set, IOPRIO_WHO_PROCESS, pid,
- IOPRIO_RT_LOWEST) == -1)
- perror("Can not set IO priority to RT class");
+ if (syscall(__NR_ioprio_set, IOPRIO_WHO_PROCESS, pid,
+ IOPRIO_RT_LOWEST) == -1)
+ perror("Can not set IO priority to lowest RT class");
} else {
- if (syscall(__NR_ioprio_set, IOPRIO_WHO_PROCESS, pid,
- IOPRIO_IDLE_LOWEST) == -1)
- perror("Can not set IO priority to RT class");
+ if (syscall(__NR_ioprio_set, IOPRIO_WHO_PROCESS, pid,
+ IOPRIO_IDLE_LOWEST) == -1)
+ perror("Can not set IO priority to lowest IDLE class");
}
-
-
+
/* Try running negative nice */
nice(-5);
@@ -183,5 +226,17 @@
pthread_join(one, NULL);
- return EXIT_SUCCESS;
+ if (ra_err >= 100) {
+ fprintf(stderr, "Error: readahead error limit reached - the /etc/readahead.packed file\n");
+ fprintf(stderr, "appears to be outdated or currupt. It will be removed so that a fresh one\n");
+ fprintf(stderr, "can be autogenerated. Please report this issue if it persists after\n");
+ fprintf(stderr, "several reboots.\n");
+ unlink(name);
+ goto out;
+ }
+
+ ret = 0;
+out:
+ tune_read_ahead(RA_NORMAL);
+ exit (ret);
}
--- readahead.h
+++ readahead.h
@@ -18,4 +18,3 @@
};
#endif
-
--- sreadahead-dump.c
+++ sreadahead-dump.c
@@ -38,11 +38,11 @@
static void sort_RA(void)
{
int delta = 1;
-
+
while (delta>0) {
unsigned int i;
delta = 0;
- for (i = 0; i < total_files - 1; i++)
+ for (i = 0; i < total_files - 1; i++)
if (files[i].data[0].len+files[i].data[1].len+files[i].data[2].len+files[i].data[3].len <
files[i+1].data[0].len+files[i+1].data[1].len+files[i+1].data[2].len+files[i+1].data[3].len ) {
struct readahead tmp;
@@ -86,7 +86,7 @@
total_size += filesize;
printf(" %6liKb [%6liKb]\t%6.3fs\t%lu\t%lu\t%s",
- filesize/1024, total_size / 1024,
+ filesize/1024, total_size / 1024,
files[i].jiffies/1000.0, files[i].block, files[i].block + filesize/4096, files[i].filename);
printf("\n");
}
@@ -94,7 +94,7 @@
printf("\n\n Top size users:\n");
for (i=0; i < 20; i++) {
- printf(" %6iKb %s\n",
+ printf(" %6iKb %s\n",
(files[i].data[0].len+files[i].data[1].len+files[i].data[2].len+files[i].data[3].len)/1024,
files[i].filename);
}
++++++ deleted files:
--- sreadahead-0.10-arm-buildfix.patch
More information about the MeeGo-commits
mailing list