Skip to content

Commit 802fb3a

Browse files
committed
Merge branch 'bytedance-readahead-rawlog'
2 parents e4343d3 + 1c45948 commit 802fb3a

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)