Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nocache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Danil Mikhailov
nocache
Commits
9461083e
Commit
9461083e
authored
Apr 23, 2013
by
Julius Plenz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement "-n <n>" flag for repeated posix_fadvise()
parent
113adf08
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
16 deletions
+39
-16
cachedel.c
cachedel.c
+17
-8
fcntl_helpers.c
fcntl_helpers.c
+5
-5
fcntl_helpers.h
fcntl_helpers.h
+1
-1
nocache
nocache
+5
-0
nocache.c
nocache.c
+11
-2
No files found.
cachedel.c
View file @
9461083e
...
...
@@ -4,6 +4,7 @@
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
exiterr
(
const
char
*
s
)
{
...
...
@@ -13,32 +14,40 @@ int exiterr(const char *s)
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
,
n
=
1
;
int
fd
;
char
*
fn
;
struct
stat
st
;
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"usage: %s <file> "
"-- call fadvise(DONTNEED) on file"
,
argv
[
0
]);
if
(
argc
==
4
&&
!
strcmp
(
"-n"
,
argv
[
1
]))
{
n
=
atoi
(
argv
[
2
]);
fn
=
argv
[
3
];
}
else
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"usage: %s [-n <n>] <file> "
"-- call fadvise(DONTNEED) <n> times on file"
,
argv
[
0
]);
exit
(
1
);
}
else
{
fn
=
argv
[
1
];
}
fd
=
open
(
argv
[
1
]
,
O_RDONLY
);
fd
=
open
(
fn
,
O_RDONLY
);
if
(
fd
==
-
1
)
exiterr
(
"open"
);
if
(
fstat
(
fd
,
&
st
)
==
-
1
)
exiterr
(
"fstat"
);
if
(
!
S_ISREG
(
st
.
st_mode
))
{
fprintf
(
stderr
,
"%s: S_ISREG: not a regular file"
,
argv
[
1
]
);
fprintf
(
stderr
,
"%s: S_ISREG: not a regular file"
,
fn
);
return
EXIT_FAILURE
;
}
if
(
st
.
st_size
==
0
)
{
fprintf
(
stderr
,
"%s: file size is 0!
\n
"
,
argv
[
1
]
);
fprintf
(
stderr
,
"%s: file size is 0!
\n
"
,
fn
);
return
EXIT_FAILURE
;
}
if
(
posix_fadvise
(
fd
,
0
,
0
,
POSIX_FADV_DONTNEED
)
==
-
1
)
exiterr
(
"posix_fadvise"
);
for
(
i
=
0
;
i
<
n
;
i
++
)
if
(
posix_fadvise
(
fd
,
0
,
0
,
POSIX_FADV_DONTNEED
)
==
-
1
)
exiterr
(
"posix_fadvise"
);
return
EXIT_SUCCESS
;
}
fcntl_helpers.c
View file @
9461083e
...
...
@@ -5,12 +5,12 @@
/* Since open() and close() are re-defined in nocache.c, it's not
* possible to include <fcntl.h> there. So we do it here. */
int
fadv_dontneed
(
int
fd
,
off_t
offset
,
off_t
len
)
int
fadv_dontneed
(
int
fd
,
off_t
offset
,
off_t
len
,
int
n
)
{
#ifdef DOUBLEFADVISE
posix_fadvise
(
fd
,
offset
,
len
,
POSIX_FADV_DONTNEED
);
#endif
return
posix_fadvise
(
fd
,
offset
,
len
,
POSIX_FADV_DONTNEED
)
;
int
i
,
ret
;
for
(
i
=
0
;
i
<
n
;
i
++
)
ret
=
posix_fadvise
(
fd
,
offset
,
len
,
POSIX_FADV_DONTNEED
);
return
ret
;
}
int
fadv_noreuse
(
int
fd
,
off_t
offset
,
off_t
len
)
...
...
fcntl_helpers.h
View file @
9461083e
#ifndef _FCNTL_HELPERS_H
#define _FCNTL_HELPERS_H
extern
int
fadv_dontneed
(
int
fd
,
off_t
offset
,
off_t
len
);
extern
int
fadv_dontneed
(
int
fd
,
off_t
offset
,
off_t
len
,
int
n
);
extern
int
fadv_noreuse
(
int
fd
,
off_t
offset
,
off_t
len
);
extern
int
valid_fd
(
int
fd
);
extern
void
sync_if_writable
(
int
fd
);
...
...
nocache
View file @
9461083e
...
...
@@ -8,4 +8,9 @@ else
export
LD_PRELOAD
=
"
$libnocache
"
fi
if
[
"
$1
"
=
"-n"
]
;
then
export
NOCACHE_NR_FADVISE
=
"
$2
"
shift
2
fi
exec
"
$@
"
nocache.c
View file @
9461083e
...
...
@@ -60,9 +60,13 @@ static struct fadv_info fds[_MAX_FDS];
static
size_t
PAGESIZE
;
static
pthread_mutex_t
lock
;
/* protects access to fds[] */
static
char
*
env_nr_fadvise
=
"NOCACHE_NR_FADVISE"
;
static
int
nr_fadvise
;
static
void
init
(
void
)
{
int
i
;
char
*
s
;
char
*
error
;
_original_open
=
(
int
(
*
)(
const
char
*
,
int
,
mode_t
))
...
...
@@ -82,6 +86,11 @@ static void init(void)
exit
(
EXIT_FAILURE
);
}
if
((
s
=
getenv
(
env_nr_fadvise
))
!=
NULL
)
nr_fadvise
=
atoi
(
s
);
if
(
nr_fadvise
<=
0
)
nr_fadvise
=
1
;
PAGESIZE
=
getpagesize
();
for
(
i
=
0
;
i
<
_MAX_FDS
;
i
++
)
fds
[
i
].
fd
=
-
1
;
...
...
@@ -295,14 +304,14 @@ static void free_unclaimed_pages(int fd)
while
(
j
<
fds
[
i
].
nr_pages
)
{
if
(
fds
[
i
].
info
[
j
]
&
1
)
{
if
(
start
<
j
)
fadv_dontneed
(
fd
,
start
*
PAGESIZE
,
(
j
-
start
)
*
PAGESIZE
);
fadv_dontneed
(
fd
,
start
*
PAGESIZE
,
(
j
-
start
)
*
PAGESIZE
,
nr_fadvise
);
start
=
j
+
1
;
}
j
++
;
}
/* forget written contents that go beyond previous file size */
fadv_dontneed
(
fd
,
start
<
j
?
start
*
PAGESIZE
:
fds
[
i
].
size
,
0
);
fadv_dontneed
(
fd
,
start
<
j
?
start
*
PAGESIZE
:
fds
[
i
].
size
,
0
,
nr_fadvise
);
free
(
fds
[
i
].
info
);
fds
[
i
].
fd
=
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment