]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/madvise.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
13 static cmdinfo_t madvise_cmd
;
20 " advise the page cache about access patterns expected for a mapping\n"
22 " Modifies page cache behavior when operating on the current mapping.\n"
23 " The range arguments are required by some advise commands ([*] below).\n"
24 " With no arguments, the POSIX_MADV_NORMAL advice is implied.\n"
25 " -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n"
26 " -r -- expect random page references (POSIX_MADV_RANDOM)\n"
27 " -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n"
28 " -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n"
30 " NORMAL sets the default readahead setting on the file.\n"
31 " RANDOM sets the readahead setting on the file to zero.\n"
32 " SEQUENTIAL sets double the default readahead setting on the file.\n"
33 " WILLNEED forces the maximum readahead.\n"
42 off64_t offset
, llength
;
45 int advise
= MADV_NORMAL
, c
;
46 size_t blocksize
, sectsize
;
48 while ((c
= getopt(argc
, argv
, "drsw")) != EOF
) {
50 case 'd': /* Don't need these pages */
51 advise
= MADV_DONTNEED
;
53 case 'r': /* Expect random page references */
56 case 's': /* Expect sequential page references */
57 advise
= MADV_SEQUENTIAL
;
59 case 'w': /* Will need these pages */
60 advise
= MADV_WILLNEED
;
63 return command_usage(&madvise_cmd
);
68 offset
= mapping
->offset
;
69 length
= mapping
->length
;
70 } else if (optind
== argc
- 2) {
71 init_cvtnum(&blocksize
, §size
);
72 offset
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
74 printf(_("non-numeric offset argument -- %s\n"),
79 llength
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
81 printf(_("non-numeric length argument -- %s\n"),
84 } else if (llength
> (size_t)llength
) {
85 printf(_("length argument too large -- %lld\n"),
89 length
= (size_t)llength
;
91 return command_usage(&madvise_cmd
);
94 start
= check_mapping_range(mapping
, offset
, length
, 1);
98 if (madvise(start
, length
, advise
) < 0) {
108 madvise_cmd
.name
= "madvise";
109 madvise_cmd
.altname
= "ma";
110 madvise_cmd
.cfunc
= madvise_f
;
111 madvise_cmd
.argmin
= 0;
112 madvise_cmd
.argmax
= -1;
113 madvise_cmd
.flags
= CMD_NOFILE_OK
| CMD_FOREIGN_OK
;
114 madvise_cmd
.args
= _("[-drsw] [off len]");
115 madvise_cmd
.oneline
= _("give advice about use of memory");
116 madvise_cmd
.help
= madvise_help
;
118 add_command(&madvise_cmd
);