// memory/vm related tapset // Copyright (C) 2005, 2006 IBM Corp. // Copyright (C) 2006 Intel Corporation. // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General // Public License (GPL); either version 2, or (at your option) any // later version. // // This family of probe points is used to probe memory-related events. // %{ #include %} global VM_FAULT_OOM=0, VM_FAULT_SIGBUS=1, VM_FAULT_MINOR=2, VM_FAULT_MAJOR=3 global VM_FAULT_NOPAGE=4, VM_FAULT_LOCKED=5, VM_FAULT_ERROR=6 /** * sfunction vm_fault_contains - Test return value for page fault reason * @value: The fault_type returned by vm.page_fault.return * @test: The type of fault to test for (VM_FAULT_OOM or similar) */ function vm_fault_contains:long (value:long, test:long) %{ int res; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) switch (THIS->test){ case 0: res = THIS->value == VM_FAULT_OOM; break; case 1: res = THIS->value == VM_FAULT_SIGBUS; break; case 2: res = THIS->value == VM_FAULT_MINOR; break; case 3: res = THIS->value == VM_FAULT_MAJOR; break; default: res = 0; break; } #else switch (THIS->test){ case 0: res = THIS->value & VM_FAULT_OOM; break; case 1: res = THIS->value & VM_FAULT_SIGBUS; break; case 2: /* VM_FAULT_MINOR infered by that flags off */ res = !((VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_MAJOR) & THIS->value); break; case 3: res = THIS->value & VM_FAULT_MAJOR; break; case 4: res = THIS->value & VM_FAULT_NOPAGE; break; case 5: res = THIS->value & VM_FAULT_LOCKED; break; case 6: res = THIS->value & VM_FAULT_ERROR; break; default: res = 0; } #endif THIS->__retvalue = (res != 0); return; %} /** * probe vm.pagefault - Records that a page fault occurred. * @address: The address of the faulting memory access; i.e. the address that caused the page fault. * @write_access: Indicates whether this was a write or read access; 1 indicates a write, * while 0 indicates a read. * * Context: The process which triggered the fault */ probe vm.pagefault = kernel.function("__handle_mm_fault@mm/memory.c") ?, kernel.function("handle_mm_fault@mm/memory.c") ? { write_access = $write_access address = $address } /** * probe vm.pagefault.return - Indicates what type of fault occurred. * @fault_type: Returns either * 0 (VM_FAULT_OOM) for out of memory faults, * 2 (VM_FAULT_MINOR) for minor faults, 3 (VM_FAULT_MAJOR) for * major faults, or 1 (VM_FAULT_SIGBUS) if the fault was neither OOM, minor fault, * nor major fault. */ probe vm.pagefault.return = kernel.function("__handle_mm_fault@mm/memory.c").return ?, kernel.function("handle_mm_fault@mm/memory.c").return ? { fault_type = $return } /** * sfunction addr_to_node - Returns which node a given address belongs to within a NUMA system. * @addr: The address of the faulting memory access. * */ function addr_to_node:long(addr:long) %{ /* pure */ int nid; int pfn = __pa(THIS->addr) >> PAGE_SHIFT; for_each_online_node(nid) if ( NODE_DATA(nid)->node_start_pfn <= pfn && pfn < (NODE_DATA(nid)->node_start_pfn + NODE_DATA(nid)->node_spanned_pages) ) { THIS->__retvalue = nid; break; } %} // Return whether a page to be copied is a zero page. function _IS_ZERO_PAGE:long(from:long, vaddr:long) %{ /* pure */ THIS->__retvalue = (THIS->from == (long) ZERO_PAGE(THIS->vaddr)); %} /** * probe vm.write_shared - Attempts at writing to a shared page. * @address: The address of the shared write. * * Context: * The context is the process attempting the write. * * Fires when a process attempts to write to a shared page. * If a copy is necessary, this will be followed by a * vm.write_shared_copy. */ probe vm.write_shared = kernel.function("do_wp_page") { address = $address } /** * probe vm.write_shared_copy - Page copy for shared page write. * @address: The address of the shared write. * @zero: Boolean indicating whether it is a zero page * (can do a clear instead of a copy). * * Context: * The process attempting the write. * * Fires when a write to a shared page requires a page copy. This is * always preceded by a vm.shared_write. */ probe vm.write_shared_copy = kernel.function("copy_cow_page")? { address = $address zero = _IS_ZERO_PAGE($from, address); } /** * probe vm.mmap - Fires when an mmap is requested. * @address: The requested address * @length: The length of the memory segment * * Context: * The process calling mmap. */ probe vm.mmap = kernel.function("do_mmap"), kernel.function("do_mmap2")? { address = $addr length = $len } /** * probe vm.munmap - Fires when an munmap is requested. * @address: The requested address * @length: The length of the memory segment * * Context: * The process calling munmap. */ probe vm.munmap = kernel.function("do_munmap") { address = $start length = $len } /** * probe vm.brk - Fires when a brk is requested (i.e. the heap will be resized). * @address: The requested address * @length: The length of the memory segment * * Context: * The process calling brk. */ probe vm.brk = kernel.function("do_brk") { address = $addr length = $len } /** * probe vm.oom_kill - Fires when a thread is selected for termination by the OOM killer. * @task: The task being killed * * Context: * The process that tried to consume excessive memory, and thus * triggered the OOM. (is this correct?) */ probe vm.oom_kill = kernel.function("__oom_kill_task") { task = $p } ref='#n52'>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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
/*
 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms 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.  See the
 * GNU General Public License for more details.
 *
 * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "xfs.h"
#include "xfs_fs.h"
#include "xfs_types.h"
#include "xfs_log.h"
#include "xfs_inum.h"
#include "xfs_trans.h"
#include "xfs_sb.h"
#include "xfs_ag.h"
#include "xfs_dir2.h"
#include "xfs_dmapi.h"
#include "xfs_mount.h"
#include "xfs_da_btree.h"
#include "xfs_bmap_btree.h"
#include "xfs_dir2_sf.h"
#include "xfs_attr_sf.h"
#include "xfs_dinode.h"
#include "xfs_inode.h"
#include "xfs_inode_item.h"
#include "xfs_bmap.h"
#include "xfs_error.h"
#include "xfs_quota.h"
#include "xfs_utils.h"
#include "xfs_trans_space.h"
#include "xfs_vnodeops.h"


/*
 * Given an array of up to 4 inode pointers, unlock the pointed to inodes.
 * If there are fewer than 4 entries in the array, the empty entries will
 * be at the end and will have NULL pointers in them.
 */
STATIC void
xfs_rename_unlock4(
	xfs_inode_t	**i_tab,
	uint		lock_mode)
{
	int	i;

	xfs_iunlock(i_tab[0], lock_mode);
	for (i = 1; i < 4; i++) {
		if (i_tab[i] == NULL)
			break;

		/*
		 * Watch out for duplicate entries in the table.
		 */
		if (i_tab[i] != i_tab[i-1])
			xfs_iunlock(i_tab[i], lock_mode);
	}
}

/*
 * Enter all inodes for a rename transaction into a sorted array.
 */
STATIC void
xfs_sort_for_rename(
	xfs_inode_t	*dp1,	/* in: old (source) directory inode */
	xfs_inode_t	*dp2,	/* in: new (target) directory inode */
	xfs_inode_t	*ip1,	/* in: inode of old entry */
	xfs_inode_t	*ip2,	/* in: inode of new entry, if it
				   already exists, NULL otherwise. */
	xfs_inode_t	**i_tab,/* out: array of inode returned, sorted */
	int		*num_inodes)  /* out: number of inodes in array */
{
	xfs_inode_t		*temp;
	int			i, j;

	/*
	 * i_tab contains a list of pointers to inodes.  We initialize
	 * the table here & we'll sort it.  We will then use it to
	 * order the acquisition of the inode locks.
	 *
	 * Note that the table may contain duplicates.  e.g., dp1 == dp2.
	 */
	i_tab[0] = dp1;
	i_tab[1] = dp2;
	i_tab[2] = ip1;
	if (ip2) {
		*num_inodes = 4;
		i_tab[3] = ip2;
	} else {
		*num_inodes = 3;
		i_tab[3] = NULL;
	}

	/*
	 * Sort the elements via bubble sort.  (Remember, there are at
	 * most 4 elements to sort, so this is adequate.)
	 */
	for (i = 0; i < *num_inodes; i++) {
		for (j = 1; j < *num_inodes; j++) {
			if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) {
				temp = i_tab[j];
				i_tab[j] = i_tab[j-1];
				i_tab[j-1] = temp;