Skip to content

Commit a34e347

Browse files
committed
Readahead rawlog to make -b operation faster
1, use posix_fadvise POSIX_FADV_SEQUENTIAL to double kernel readahead buffer. 2, HDD typically has a 100~200 IOPS, atop needs to read raw records more fastly under low IOPS. So use pread syscall to load a large area(default every 4M) in page-cache. Test env: set disk iops as 200 for a virtual machine(KVM). virsh blkdeviotune stretch sdb --write-iops-sec 200 --read-iops-sec 200 --live Test cases: 1, test upstream atop without any page cache ~# vmtouch -e /var/log/atop/atop_20190916 ~# time /root/atop-upstream -r /var/log/atop/atop_20190916 -b 18:00 real 0m54.639s user 0m0.094s sys 0m0.321s 2, test upstream atop with full page cache ~# vmtouch -t /var/log/atop/atop_20190916 ~# time /root/atop-upstream -r /var/log/atop/atop_20190916 -b 18:00 real 0m1.266s user 0m0.004s sys 0m0.021s 3, test new atop without any page cache ~# vmtouch -e /var/log/atop/atop_20190916 ~# time /root/atop-new -r /var/log/atop/atop_20190916 -b 18:00 real 0m3.818s user 0m0.023s sys 0m0.170s case 1 & case 2: speed of reading rawlog effects atop performance a lot. case 1 & case 3: readahead makes performance better. Signed-off-by: zhenwei pi <[email protected]>
1 parent a802f1a commit a34e347

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

rawlog.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
** etcetera .....
7070
*/
7171
#define MYMAGIC (unsigned int) 0xfeedbeef
72+
#define READAHEADOFF 22
73+
#define READAHEADSIZE (1 << READAHEADOFF)
7274

7375
struct rawheader {
7476
unsigned int magic;
@@ -514,6 +516,10 @@ rawread(void)
514516
}
515517
}
516518

519+
/* make the kernel readahead more effective, */
520+
if (isregular)
521+
posix_fadvise(rawfd, 0, 0, POSIX_FADV_SEQUENTIAL);
522+
517523
/*
518524
** read the raw header and verify the magic
519525
*/
@@ -644,8 +650,22 @@ rawread(void)
644650

645651
if (isregular)
646652
{
647-
lseek(rawfd, rr.scomplen+rr.pcomplen,
648-
SEEK_CUR);
653+
static off_t curr_pos = -1;
654+
off_t next_pos;
655+
656+
lastcmd = 1;
657+
next_pos = lseek(rawfd, rr.scomplen+rr.pcomplen, SEEK_CUR);
658+
if ((curr_pos >> READAHEADOFF) != (next_pos >> READAHEADOFF))
659+
{
660+
/* just read READAHEADSIZE bytes into page cache */
661+
char *buf = malloc(READAHEADSIZE);
662+
ptrverify(buf, "Malloc failed for readahead");
663+
pread(rawfd, buf, READAHEADSIZE,
664+
next_pos & ~(READAHEADSIZE - 1));
665+
free(buf);
666+
}
667+
curr_pos = next_pos;
668+
continue;
649669
}
650670
else // named pipe not seekable
651671
{

0 commit comments

Comments
 (0)