"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/core-madvise.c" (15 Mar 2019, 2551 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "core-madvise.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will 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.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_MADVISE)
   28 static const int madvise_options[] = {
   29 #if defined(MADV_NORMAL)
   30     MADV_NORMAL,
   31 #endif
   32 #if defined(MADV_RANDOM)
   33     MADV_RANDOM,
   34 #endif
   35 #if defined(MADV_SEQUENTIAL)
   36     MADV_SEQUENTIAL,
   37 #endif
   38 #if defined(MADV_WILLNEED)
   39     MADV_WILLNEED,
   40 #endif
   41 /*
   42  *  Don't use DONTNEED as this can zero fill
   43  *  pages that don't have backing store which
   44  *  trips checksum errors when we check that
   45  *  the pages are sane.
   46  *
   47 #if defined(MADV_DONTNEED)
   48     MADV_DONTNEED,
   49 #endif
   50 */
   51 #if defined(MADV_DONTFORK)
   52     MADV_DONTFORK,
   53 #endif
   54 #if defined(MADV_DOFORK)
   55     MADV_DOFORK,
   56 #endif
   57 #if defined(MADV_MERGEABLE)
   58     MADV_MERGEABLE,
   59 #endif
   60 #if defined(MADV_UNMERGEABLE)
   61     MADV_UNMERGEABLE,
   62 #endif
   63 #if defined(MADV_HUGEPAGE)
   64     MADV_HUGEPAGE,
   65 #endif
   66 #if defined(MADV_NOHUGEPAGE)
   67     MADV_NOHUGEPAGE,
   68 #endif
   69 #if defined(MADV_DONTDUMP)
   70     MADV_DONTDUMP,
   71 #endif
   72 #if defined(MADV_DODUMP)
   73     MADV_DODUMP,
   74 #endif
   75 /*
   76  *  Don't use MADV_FREE as this can zero fill
   77  *  pages that don't have backing store which
   78  *  trips checksum errors when we check that
   79  *  the pages are sane.
   80  *
   81 #if defined(MADV_FREE)
   82     MADV_FREE
   83 #endif
   84 */
   85 };
   86 #endif
   87 
   88 /*
   89  * madvise_random()
   90  *  apply random madvise setting to a memory region
   91  */
   92 int madvise_random(void *addr, const size_t length)
   93 {
   94 #if defined(HAVE_MADVISE)
   95     if (g_opt_flags & OPT_FLAGS_MMAP_MADVISE) {
   96         int i = (mwc32() >> 7) % SIZEOF_ARRAY(madvise_options);
   97 
   98         return madvise(addr, length, madvise_options[i]);
   99     }
  100 #else
  101     (void)addr;
  102     (void)length;
  103 #endif
  104     return 0;
  105 }