[6ccf55]: testcases / kernel / mem / ksm / ksm03.c Maximize Restore History

Download this file

ksm03.c    123 lines (114 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Kernel Samepage Merging (KSM) for Memory Resource Controller
*
* Basic tests were to start several programs with same and different
* memory contents and ensure only to merge the ones with the same
* contents. When changed the content of one of merged pages in a
* process and to the mode "unmerging", it should discard all merged
* pages there. Also tested it is possible to disable KSM. There are
* also command-line options to specify the memory allocation size, and
* number of processes have same memory contents so it is possible to
* test more advanced things like KSM + OOM etc.
*
* Prerequisites:
*
* 1) ksm and ksmtuned daemons need to be disabled. Otherwise, it could
* distrub the testing as they also change some ksm tunables depends
* on current workloads.
*
* The test steps are:
* - Check ksm feature and backup current run setting.
* - Change run setting to 1 - merging.
* - 3 memory allocation programs have the memory contents that 2 of
* them are all 'a' and one is all 'b'.
* - Check ksm statistics and verify the content.
* - 1 program changes the memory content from all 'a' to all 'b'.
* - Check ksm statistics and verify the content.
* - All programs change the memory content to all 'd'.
* - Check ksm statistics and verify the content.
* - Change one page of a process.
* - Check ksm statistics and verify the content.
* - Change run setting to 2 - unmerging.
* - Check ksm statistics and verify the content.
* - Change run setting to 0 - stop.
*
* Copyright (C) 2010 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Further, this software is distributed without any warranty that it
* is free of the rightful claim of any third person regarding
* infringement or the like. Any license provided herein, whether
* implied or otherwise, applies only to this software file. Patent
* licenses, if any, provided herein do not apply to combinations of
* this program with other software, or any other product whatsoever.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include "test.h"
#include "usctest.h"
#include "../include/mem.h"
char *TCID = "ksm03";
int TST_TOTAL = 1;
option_t ksm_options[] = {
{ "n:", &opt_num, &opt_numstr},
{ "s:", &opt_size, &opt_sizestr},
{ "u:", &opt_unit, &opt_unitstr},
{ NULL, NULL, NULL}
};
int main(int argc, char *argv[])
{
int lc;
char *msg;
int size = 128, num = 3, unit = 1;
msg = parse_opts(argc, argv, ksm_options, ksm_usage);
if (msg != NULL)
tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
check_ksm_options(&size, &num, &unit);
write_memcg();
create_same_memory(size, num, unit);
}
cleanup();
tst_exit();
}
void setup(void)
{
tst_require_root(NULL);
if (tst_kvercmp(2, 6, 32) < 0)
tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
if (access(PATH_KSM, F_OK) == -1)
tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
tst_sig(FORK, DEF_HANDLER, NULL);
TEST_PAUSE;
}
void cleanup(void)
{
umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
TEST_CLEANUP;
}