~georgeunix-5/lwan-unofficial/master

« back to all changes in this revision

Viewing changes to src/lib/lwan-readahead.c

  • Committer: Leandro Pereira
  • Date: 2019-02-19 03:26:42 UTC
  • Revision ID: git-v1:e188156997a13a08d6703f77039893cc27e070c7
Don't bother queueing readahead()/madvise() less than a page

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
static int readahead_pipe_fd[2] = {-1, -1};
53
53
static pthread_t readahead_self;
 
54
static long page_size = 4096;
 
55
 
 
56
#if _SC_PAGESIZE > 0
 
57
__attribute__((constructor)) static void get_page_size(void)
 
58
{
 
59
    long ps = sysconf(_SC_PAGESIZE);
 
60
 
 
61
    if (ps >= 0)
 
62
        page_size = ps;
 
63
}
 
64
#endif
54
65
 
55
66
void lwan_readahead_shutdown(void)
56
67
{
74
85
 
75
86
void lwan_readahead_queue(int fd, off_t off, size_t size)
76
87
{
 
88
    if (size < (size_t)page_size)
 
89
        return;
 
90
 
77
91
    struct lwan_readahead_cmd cmd = {
78
92
        .readahead = {.size = size, .fd = fd, .off = off},
79
93
        .cmd = READAHEAD,
85
99
 
86
100
void lwan_madvise_queue(void *addr, size_t length)
87
101
{
 
102
    if (length < (size_t)page_size)
 
103
        return;
 
104
 
88
105
    struct lwan_readahead_cmd cmd = {
89
106
        .madvise = {.addr = addr, .length = length},
90
107
        .cmd = MADVISE,
91
108
    };
92
109
 
93
 
    /* Readahead is just a hint.  Failing to write is not an error. */
 
110
    /* Madvise is just a hint.  Failing to write is not an error. */
94
111
    write(readahead_pipe_fd[1], &cmd, sizeof(cmd));
95
112
}
96
113