mirror of
https://github.com/torvalds/linux.git
synced 2024-11-16 17:12:06 +00:00
0ee931c4e3
GFP_TEMPORARY was introduced by commit e12ba74d8f
("Group short-lived
and reclaimable kernel allocations") along with __GFP_RECLAIMABLE. It's
primary motivation was to allow users to tell that an allocation is
short lived and so the allocator can try to place such allocations close
together and prevent long term fragmentation. As much as this sounds
like a reasonable semantic it becomes much less clear when to use the
highlevel GFP_TEMPORARY allocation flag. How long is temporary? Can the
context holding that memory sleep? Can it take locks? It seems there is
no good answer for those questions.
The current implementation of GFP_TEMPORARY is basically GFP_KERNEL |
__GFP_RECLAIMABLE which in itself is tricky because basically none of
the existing caller provide a way to reclaim the allocated memory. So
this is rather misleading and hard to evaluate for any benefits.
I have checked some random users and none of them has added the flag
with a specific justification. I suspect most of them just copied from
other existing users and others just thought it might be a good idea to
use without any measuring. This suggests that GFP_TEMPORARY just
motivates for cargo cult usage without any reasoning.
I believe that our gfp flags are quite complex already and especially
those with highlevel semantic should be clearly defined to prevent from
confusion and abuse. Therefore I propose dropping GFP_TEMPORARY and
replace all existing users to simply use GFP_KERNEL. Please note that
SLAB users with shrinkers will still get __GFP_RECLAIMABLE heuristic and
so they will be placed properly for memory fragmentation prevention.
I can see reasons we might want some gfp flag to reflect shorterm
allocations but I propose starting from a clear semantic definition and
only then add users with proper justification.
This was been brought up before LSF this year by Matthew [1] and it
turned out that GFP_TEMPORARY really doesn't have a clear semantic. It
seems to be a heuristic without any measured advantage for most (if not
all) its current users. The follow up discussion has revealed that
opinions on what might be temporary allocation differ a lot between
developers. So rather than trying to tweak existing users into a
semantic which they haven't expected I propose to simply remove the flag
and start from scratch if we really need a semantic for short term
allocations.
[1] http://lkml.kernel.org/r/20170118054945.GD18349@bombadil.infradead.org
[akpm@linux-foundation.org: fix typo]
[akpm@linux-foundation.org: coding-style fixes]
[sfr@canb.auug.org.au: drm/i915: fix up]
Link: http://lkml.kernel.org/r/20170816144703.378d4f4d@canb.auug.org.au
Link: http://lkml.kernel.org/r/20170728091904.14627-1-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Mel Gorman <mgorman@suse.de>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Neil Brown <neilb@suse.de>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
246 lines
6.4 KiB
C
246 lines
6.4 KiB
C
/*
|
|
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
*/
|
|
|
|
#include <linux/ptrace.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/kdev_t.h>
|
|
#include <linux/fs_struct.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/file.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/sched/debug.h>
|
|
|
|
#include <asm/arcregs.h>
|
|
#include <asm/irqflags.h>
|
|
|
|
/*
|
|
* Common routine to print scratch regs (r0-r12) or callee regs (r13-r25)
|
|
* -Prints 3 regs per line and a CR.
|
|
* -To continue, callee regs right after scratch, special handling of CR
|
|
*/
|
|
static noinline void print_reg_file(long *reg_rev, int start_num)
|
|
{
|
|
unsigned int i;
|
|
char buf[512];
|
|
int n = 0, len = sizeof(buf);
|
|
|
|
for (i = start_num; i < start_num + 13; i++) {
|
|
n += scnprintf(buf + n, len - n, "r%02u: 0x%08lx\t",
|
|
i, (unsigned long)*reg_rev);
|
|
|
|
if (((i + 1) % 3) == 0)
|
|
n += scnprintf(buf + n, len - n, "\n");
|
|
|
|
/* because pt_regs has regs reversed: r12..r0, r25..r13 */
|
|
if (is_isa_arcv2() && start_num == 0)
|
|
reg_rev++;
|
|
else
|
|
reg_rev--;
|
|
}
|
|
|
|
if (start_num != 0)
|
|
n += scnprintf(buf + n, len - n, "\n\n");
|
|
|
|
/* To continue printing callee regs on same line as scratch regs */
|
|
if (start_num == 0)
|
|
pr_info("%s", buf);
|
|
else
|
|
pr_cont("%s\n", buf);
|
|
}
|
|
|
|
static void show_callee_regs(struct callee_regs *cregs)
|
|
{
|
|
print_reg_file(&(cregs->r13), 13);
|
|
}
|
|
|
|
static void print_task_path_n_nm(struct task_struct *tsk, char *buf)
|
|
{
|
|
char *path_nm = NULL;
|
|
struct mm_struct *mm;
|
|
struct file *exe_file;
|
|
|
|
mm = get_task_mm(tsk);
|
|
if (!mm)
|
|
goto done;
|
|
|
|
exe_file = get_mm_exe_file(mm);
|
|
mmput(mm);
|
|
|
|
if (exe_file) {
|
|
path_nm = file_path(exe_file, buf, 255);
|
|
fput(exe_file);
|
|
}
|
|
|
|
done:
|
|
pr_info("Path: %s\n", !IS_ERR(path_nm) ? path_nm : "?");
|
|
}
|
|
|
|
static void show_faulting_vma(unsigned long address, char *buf)
|
|
{
|
|
struct vm_area_struct *vma;
|
|
struct inode *inode;
|
|
unsigned long ino = 0;
|
|
dev_t dev = 0;
|
|
char *nm = buf;
|
|
struct mm_struct *active_mm = current->active_mm;
|
|
|
|
/* can't use print_vma_addr() yet as it doesn't check for
|
|
* non-inclusive vma
|
|
*/
|
|
down_read(&active_mm->mmap_sem);
|
|
vma = find_vma(active_mm, address);
|
|
|
|
/* check against the find_vma( ) behaviour which returns the next VMA
|
|
* if the container VMA is not found
|
|
*/
|
|
if (vma && (vma->vm_start <= address)) {
|
|
struct file *file = vma->vm_file;
|
|
if (file) {
|
|
nm = file_path(file, buf, PAGE_SIZE - 1);
|
|
inode = file_inode(vma->vm_file);
|
|
dev = inode->i_sb->s_dev;
|
|
ino = inode->i_ino;
|
|
}
|
|
pr_info(" @off 0x%lx in [%s]\n"
|
|
" VMA: 0x%08lx to 0x%08lx\n",
|
|
vma->vm_start < TASK_UNMAPPED_BASE ?
|
|
address : address - vma->vm_start,
|
|
nm, vma->vm_start, vma->vm_end);
|
|
} else
|
|
pr_info(" @No matching VMA found\n");
|
|
|
|
up_read(&active_mm->mmap_sem);
|
|
}
|
|
|
|
static void show_ecr_verbose(struct pt_regs *regs)
|
|
{
|
|
unsigned int vec, cause_code;
|
|
unsigned long address;
|
|
|
|
pr_info("\n[ECR ]: 0x%08lx => ", regs->event);
|
|
|
|
/* For Data fault, this is data address not instruction addr */
|
|
address = current->thread.fault_address;
|
|
|
|
vec = regs->ecr_vec;
|
|
cause_code = regs->ecr_cause;
|
|
|
|
/* For DTLB Miss or ProtV, display the memory involved too */
|
|
if (vec == ECR_V_DTLB_MISS) {
|
|
pr_cont("Invalid %s @ 0x%08lx by insn @ 0x%08lx\n",
|
|
(cause_code == 0x01) ? "Read" :
|
|
((cause_code == 0x02) ? "Write" : "EX"),
|
|
address, regs->ret);
|
|
} else if (vec == ECR_V_ITLB_MISS) {
|
|
pr_cont("Insn could not be fetched\n");
|
|
} else if (vec == ECR_V_MACH_CHK) {
|
|
pr_cont("Machine Check (%s)\n", (cause_code == 0x0) ?
|
|
"Double Fault" : "Other Fatal Err");
|
|
|
|
} else if (vec == ECR_V_PROTV) {
|
|
if (cause_code == ECR_C_PROTV_INST_FETCH)
|
|
pr_cont("Execute from Non-exec Page\n");
|
|
else if (cause_code == ECR_C_PROTV_MISALIG_DATA)
|
|
pr_cont("Misaligned r/w from 0x%08lx\n", address);
|
|
else
|
|
pr_cont("%s access not allowed on page\n",
|
|
(cause_code == 0x01) ? "Read" :
|
|
((cause_code == 0x02) ? "Write" : "EX"));
|
|
} else if (vec == ECR_V_INSN_ERR) {
|
|
pr_cont("Illegal Insn\n");
|
|
#ifdef CONFIG_ISA_ARCV2
|
|
} else if (vec == ECR_V_MEM_ERR) {
|
|
if (cause_code == 0x00)
|
|
pr_cont("Bus Error from Insn Mem\n");
|
|
else if (cause_code == 0x10)
|
|
pr_cont("Bus Error from Data Mem\n");
|
|
else
|
|
pr_cont("Bus Error, check PRM\n");
|
|
#endif
|
|
} else {
|
|
pr_cont("Check Programmer's Manual\n");
|
|
}
|
|
}
|
|
|
|
/************************************************************************
|
|
* API called by rest of kernel
|
|
***********************************************************************/
|
|
|
|
void show_regs(struct pt_regs *regs)
|
|
{
|
|
struct task_struct *tsk = current;
|
|
struct callee_regs *cregs;
|
|
char *buf;
|
|
|
|
buf = (char *)__get_free_page(GFP_KERNEL);
|
|
if (!buf)
|
|
return;
|
|
|
|
print_task_path_n_nm(tsk, buf);
|
|
show_regs_print_info(KERN_INFO);
|
|
|
|
show_ecr_verbose(regs);
|
|
|
|
pr_info("[EFA ]: 0x%08lx\n[BLINK ]: %pS\n[ERET ]: %pS\n",
|
|
current->thread.fault_address,
|
|
(void *)regs->blink, (void *)regs->ret);
|
|
|
|
if (user_mode(regs))
|
|
show_faulting_vma(regs->ret, buf); /* faulting code, not data */
|
|
|
|
pr_info("[STAT32]: 0x%08lx", regs->status32);
|
|
|
|
#define STS_BIT(r, bit) r->status32 & STATUS_##bit##_MASK ? #bit" " : ""
|
|
|
|
#ifdef CONFIG_ISA_ARCOMPACT
|
|
pr_cont(" : %2s%2s%2s%2s%2s%2s%2s\n",
|
|
(regs->status32 & STATUS_U_MASK) ? "U " : "K ",
|
|
STS_BIT(regs, DE), STS_BIT(regs, AE),
|
|
STS_BIT(regs, A2), STS_BIT(regs, A1),
|
|
STS_BIT(regs, E2), STS_BIT(regs, E1));
|
|
#else
|
|
pr_cont(" : %2s%2s%2s%2s\n",
|
|
STS_BIT(regs, IE),
|
|
(regs->status32 & STATUS_U_MASK) ? "U " : "K ",
|
|
STS_BIT(regs, DE), STS_BIT(regs, AE));
|
|
#endif
|
|
pr_info("BTA: 0x%08lx\t SP: 0x%08lx\t FP: 0x%08lx\n",
|
|
regs->bta, regs->sp, regs->fp);
|
|
pr_info("LPS: 0x%08lx\tLPE: 0x%08lx\tLPC: 0x%08lx\n",
|
|
regs->lp_start, regs->lp_end, regs->lp_count);
|
|
|
|
/* print regs->r0 thru regs->r12
|
|
* Sequential printing was generating horrible code
|
|
*/
|
|
print_reg_file(&(regs->r0), 0);
|
|
|
|
/* If Callee regs were saved, display them too */
|
|
cregs = (struct callee_regs *)current->thread.callee_reg;
|
|
if (cregs)
|
|
show_callee_regs(cregs);
|
|
|
|
free_page((unsigned long)buf);
|
|
}
|
|
|
|
void show_kernel_fault_diag(const char *str, struct pt_regs *regs,
|
|
unsigned long address)
|
|
{
|
|
current->thread.fault_address = address;
|
|
|
|
/* Show fault description */
|
|
pr_info("\n%s\n", str);
|
|
|
|
/* Caller and Callee regs */
|
|
show_regs(regs);
|
|
|
|
/* Show stack trace if this Fatality happened in kernel mode */
|
|
if (!user_mode(regs))
|
|
show_stacktrace(current, regs);
|
|
}
|