]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/madvise.c
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs/command.h"
21 #include "xfs/input.h"
26 static cmdinfo_t madvise_cmd
;
33 " advise the page cache about access patterns expected for a mapping\n"
35 " Modifies page cache behavior when operating on the current mapping.\n"
36 " The range arguments are required by some advise commands ([*] below).\n"
37 " With no arguments, the POSIX_MADV_NORMAL advice is implied.\n"
38 " -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n"
39 " -r -- expect random page references (POSIX_MADV_RANDOM)\n"
40 " -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n"
41 " -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n"
43 " NORMAL sets the default readahead setting on the file.\n"
44 " RANDOM sets the readahead setting on the file to zero.\n"
45 " SEQUENTIAL sets double the default readahead setting on the file.\n"
46 " WILLNEED forces the maximum readahead.\n"
55 off64_t offset
, llength
;
58 int advise
= MADV_NORMAL
, c
;
59 size_t blocksize
, sectsize
;
61 while ((c
= getopt(argc
, argv
, "drsw")) != EOF
) {
63 case 'd': /* Don't need these pages */
64 advise
= MADV_DONTNEED
;
66 case 'r': /* Expect random page references */
69 case 's': /* Expect sequential page references */
70 advise
= MADV_SEQUENTIAL
;
72 case 'w': /* Will need these pages */
73 advise
= MADV_WILLNEED
;
76 return command_usage(&madvise_cmd
);
81 offset
= mapping
->offset
;
82 length
= mapping
->length
;
83 } else if (optind
== argc
- 2) {
84 init_cvtnum(&blocksize
, §size
);
85 offset
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
87 printf(_("non-numeric offset argument -- %s\n"),
92 llength
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
94 printf(_("non-numeric length argument -- %s\n"),
97 } else if (llength
> (size_t)llength
) {
98 printf(_("length argument too large -- %lld\n"),
102 length
= (size_t)llength
;
104 return command_usage(&madvise_cmd
);
107 start
= check_mapping_range(mapping
, offset
, length
, 1);
111 if (madvise(start
, length
, advise
) < 0) {
121 madvise_cmd
.name
= "madvise";
122 madvise_cmd
.altname
= "ma";
123 madvise_cmd
.cfunc
= madvise_f
;
124 madvise_cmd
.argmin
= 0;
125 madvise_cmd
.argmax
= -1;
126 madvise_cmd
.flags
= CMD_NOFILE_OK
| CMD_FOREIGN_OK
;
127 madvise_cmd
.args
= _("[-drsw] [off len]");
128 madvise_cmd
.oneline
= _("give advice about use of memory");
129 madvise_cmd
.help
= madvise_help
;
131 add_command(&madvise_cmd
);