Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
systemd
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
steam
systemd
Commits
746f8906
Commit
746f8906
authored
Sep 23, 2010
by
Lennart Poettering
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
readahead: add btrfs defrag support
parent
05115020
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
12 deletions
+44
-12
src/missing.h
src/missing.h
+21
-0
src/readahead-collect.c
src/readahead-collect.c
+23
-12
No files found.
src/missing.h
View file @
746f8906
...
...
@@ -101,4 +101,25 @@ static inline int fanotify_mark(int fanotify_fd, unsigned int flags, uint64_t ma
return
syscall
(
__NR_fanotify_mark
,
fanotify_fd
,
flags
,
mask
,
dfd
,
pathname
);
}
#ifndef BTRFS_IOCTL_MAGIC
#define BTRFS_IOCTL_MAGIC 0x94
#endif
#ifndef BTRFS_PATH_NAME_MAX
#define BTRFS_PATH_NAME_MAX 4087
#endif
struct
btrfs_ioctl_vol_args
{
int64_t
fd
;
char
name
[
BTRFS_PATH_NAME_MAX
+
1
];
};
#ifndef BTRFS_IOC_DEFRAG
#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, struct btrfs_ioctl_vol_args)
#endif
#ifndef BTRFS_SUPER_MAGIC
#define BTRFS_SUPER_MAGIC 0x9123683E
#endif
#endif
src/readahead-collect.c
View file @
746f8906
...
...
@@ -39,6 +39,7 @@
#include <linux/fs.h>
#include <linux/fiemap.h>
#include <sys/ioctl.h>
#include <sys/vfs.h>
#include "missing.h"
#include "util.h"
...
...
@@ -47,15 +48,18 @@
#include "ioprio.h"
#include "readahead-common.h"
/*
fixme:
#define MINCORE_VEC_SIZE (READAHEAD_FILE_SIZE_MAX/PAGE_SIZE)
- BTRFS_IOC_DEFRAG
*/
static
int
btrfs_defrag
(
int
fd
)
{
struct
btrfs_ioctl_vol_args
data
;
#define MINCORE_VEC_SIZE (READAHEAD_FILE_SIZE_MAX/PAGE_SIZE)
zero
(
data
);
data
.
fd
=
fd
;
static
int
pack_file
(
FILE
*
pack
,
const
char
*
fn
)
{
return
ioctl
(
fd
,
BTRFS_IOC_DEFRAG
,
&
data
);
}
static
int
pack_file
(
FILE
*
pack
,
const
char
*
fn
,
bool
on_btrfs
)
{
struct
stat
st
;
void
*
start
=
MAP_FAILED
;
uint8_t
vec
[
MINCORE_VEC_SIZE
];
...
...
@@ -78,6 +82,9 @@ static int pack_file(FILE *pack, const char *fn) {
goto
finish
;
}
if
(
on_btrfs
)
btrfs_defrag
(
fd
);
l
=
PAGE_ALIGN
(
st
.
st_size
);
if
((
start
=
mmap
(
NULL
,
l
,
PROT_READ
,
MAP_SHARED
,
fd
,
0
))
==
MAP_FAILED
)
{
log_warning
(
"mmap(%s) failed: %m"
,
fn
);
...
...
@@ -190,7 +197,8 @@ static int collect(const char *root) {
sigset_t
mask
;
FILE
*
pack
=
NULL
;
char
*
pack_fn_new
=
NULL
,
*
pack_fn
=
NULL
;
bool
on_ssd
;
bool
on_ssd
,
on_btrfs
;
struct
statfs
sfs
;
assert
(
root
);
...
...
@@ -321,6 +329,9 @@ static int collect(const char *root) {
on_ssd
=
fs_on_ssd
(
root
);
log_debug
(
"On SSD: %s"
,
yes_no
(
on_ssd
));
on_btrfs
=
statfs
(
root
,
&
sfs
)
>=
0
&&
sfs
.
f_type
==
BTRFS_SUPER_MAGIC
;
log_debug
(
"On btrfs: %s"
,
yes_no
(
on_btrfs
));
asprintf
(
&
pack_fn
,
"%s/.readahead"
,
root
);
asprintf
(
&
pack_fn_new
,
"%s/.readahead.new"
,
root
);
...
...
@@ -339,13 +350,13 @@ static int collect(const char *root) {
fputs
(
CANONICAL_HOST
"
\n
"
,
pack
);
putc
(
on_ssd
?
'S'
:
'R'
,
pack
);
if
(
on_ssd
)
{
if
(
on_ssd
||
on_btrfs
)
{
/* On SSD
, just write things out in the order
the
*
files where accessed
*/
/* On SSD
or on btrfs, just write things out in
the
*
order the files where accessed.
*/
HASHMAP_FOREACH_KEY
(
q
,
p
,
files
,
i
)
pack_file
(
pack
,
p
);
pack_file
(
pack
,
p
,
on_btrfs
);
}
else
{
struct
item
*
ordered
,
*
j
;
unsigned
k
,
n
;
...
...
@@ -374,7 +385,7 @@ static int collect(const char *root) {
qsort
(
ordered
,
n
,
sizeof
(
struct
item
),
qsort_compare
);
for
(
k
=
0
;
k
<
n
;
k
++
)
pack_file
(
pack
,
ordered
[
k
].
path
);
pack_file
(
pack
,
ordered
[
k
].
path
,
on_btrfs
);
free
(
ordered
);
}
...
...
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