提交 12fe32e4 编写于 作者: L Linus Torvalds

Merge branch 'kmemtrace-for-linus' of...

Merge branch 'kmemtrace-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'kmemtrace-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  kmemtrace: trace kfree() calls with NULL or zero-length objects
  kmemtrace: small cleanups
  kmemtrace: restore original tracing data binary format, improve ABI
  kmemtrace: kmemtrace_alloc() must fill type_id
  kmemtrace: use tracepoints
  kmemtrace, rcu: don't include unnecessary headers, allow kmemtrace w/ tracepoints
  kmemtrace, rcu: fix rcupreempt.c data structure dependencies
  kmemtrace, rcu: fix rcu_tree_trace.c data structure dependencies
  kmemtrace, rcu: fix linux/rcutree.h and linux/rcuclassic.h dependencies
  kmemtrace, mm: fix slab.h dependency problem in mm/failslab.c
  kmemtrace, kbuild: fix slab.h dependency problem in lib/decompress_unlzma.c
  kmemtrace, kbuild: fix slab.h dependency problem in lib/decompress_bunzip2.c
  kmemtrace, kbuild: fix slab.h dependency problem in lib/decompress_inflate.c
  kmemtrace, squashfs: fix slab.h dependency problem in squasfs
  kmemtrace, befs: fix slab.h dependency problem
  kmemtrace, security: fix linux/key.h header file dependencies
  kmemtrace, fs: fix linux/fdtable.h header file dependencies
  kmemtrace, fs: uninline simple_transaction_set()
  kmemtrace, fs, security: move alloc_secdata() and free_secdata() to linux/security.h
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/slab.h>
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
...@@ -575,6 +575,21 @@ ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos, ...@@ -575,6 +575,21 @@ ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
* possibly a read which collects the result - which is stored in a * possibly a read which collects the result - which is stored in a
* file-local buffer. * file-local buffer.
*/ */
void simple_transaction_set(struct file *file, size_t n)
{
struct simple_transaction_argresp *ar = file->private_data;
BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
/*
* The barrier ensures that ar->size will really remain zero until
* ar->data is ready for reading.
*/
smp_mb();
ar->size = n;
}
char *simple_transaction_get(struct file *file, const char __user *buf, size_t size) char *simple_transaction_get(struct file *file, const char __user *buf, size_t size)
{ {
struct simple_transaction_argresp *ar; struct simple_transaction_argresp *ar;
...@@ -820,6 +835,7 @@ EXPORT_SYMBOL(simple_sync_file); ...@@ -820,6 +835,7 @@ EXPORT_SYMBOL(simple_sync_file);
EXPORT_SYMBOL(simple_unlink); EXPORT_SYMBOL(simple_unlink);
EXPORT_SYMBOL(simple_read_from_buffer); EXPORT_SYMBOL(simple_read_from_buffer);
EXPORT_SYMBOL(memory_read_from_buffer); EXPORT_SYMBOL(memory_read_from_buffer);
EXPORT_SYMBOL(simple_transaction_set);
EXPORT_SYMBOL(simple_transaction_get); EXPORT_SYMBOL(simple_transaction_get);
EXPORT_SYMBOL(simple_transaction_read); EXPORT_SYMBOL(simple_transaction_read);
EXPORT_SYMBOL(simple_transaction_release); EXPORT_SYMBOL(simple_transaction_release);
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/dcache.h> #include <linux/dcache.h>
#include <linux/exportfs.h> #include <linux/exportfs.h>
#include <linux/zlib.h> #include <linux/zlib.h>
#include <linux/slab.h>
#include "squashfs_fs.h" #include "squashfs_fs.h"
#include "squashfs_fs_sb.h" #include "squashfs_fs_sb.h"
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
#ifndef __LINUX_FDTABLE_H #ifndef __LINUX_FDTABLE_H
#define __LINUX_FDTABLE_H #define __LINUX_FDTABLE_H
#include <asm/atomic.h>
#include <linux/posix_types.h> #include <linux/posix_types.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/init.h>
#include <asm/atomic.h>
/* /*
* The default fd array needs to be at least BITS_PER_LONG, * The default fd array needs to be at least BITS_PER_LONG,
......
...@@ -2341,19 +2341,7 @@ ssize_t simple_transaction_read(struct file *file, char __user *buf, ...@@ -2341,19 +2341,7 @@ ssize_t simple_transaction_read(struct file *file, char __user *buf,
size_t size, loff_t *pos); size_t size, loff_t *pos);
int simple_transaction_release(struct inode *inode, struct file *file); int simple_transaction_release(struct inode *inode, struct file *file);
static inline void simple_transaction_set(struct file *file, size_t n) void simple_transaction_set(struct file *file, size_t n);
{
struct simple_transaction_argresp *ar = file->private_data;
BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
/*
* The barrier ensures that ar->size will really remain zero until
* ar->data is ready for reading.
*/
smp_mb();
ar->size = n;
}
/* /*
* simple attribute files * simple attribute files
...@@ -2400,27 +2388,6 @@ ssize_t simple_attr_read(struct file *file, char __user *buf, ...@@ -2400,27 +2388,6 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
ssize_t simple_attr_write(struct file *file, const char __user *buf, ssize_t simple_attr_write(struct file *file, const char __user *buf,
size_t len, loff_t *ppos); size_t len, loff_t *ppos);
#ifdef CONFIG_SECURITY
static inline char *alloc_secdata(void)
{
return (char *)get_zeroed_page(GFP_KERNEL);
}
static inline void free_secdata(void *secdata)
{
free_page((unsigned long)secdata);
}
#else
static inline char *alloc_secdata(void)
{
return (char *)1;
}
static inline void free_secdata(void *secdata)
{ }
#endif /* CONFIG_SECURITY */
struct ctl_table; struct ctl_table;
int proc_nr_files(struct ctl_table *table, int write, struct file *filp, int proc_nr_files(struct ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos); void __user *buffer, size_t *lenp, loff_t *ppos);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/sysctl.h> #include <linux/sysctl.h>
#include <linux/rwsem.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#ifdef __KERNEL__ #ifdef __KERNEL__
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/threads.h> #include <linux/threads.h>
#include <linux/percpu.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/seqlock.h> #include <linux/seqlock.h>
...@@ -108,25 +107,14 @@ struct rcu_data { ...@@ -108,25 +107,14 @@ struct rcu_data {
struct rcu_head barrier; struct rcu_head barrier;
}; };
DECLARE_PER_CPU(struct rcu_data, rcu_data);
DECLARE_PER_CPU(struct rcu_data, rcu_bh_data);
/* /*
* Increment the quiescent state counter. * Increment the quiescent state counter.
* The counter is a bit degenerated: We do not need to know * The counter is a bit degenerated: We do not need to know
* how many quiescent states passed, just if there was at least * how many quiescent states passed, just if there was at least
* one since the start of the grace period. Thus just a flag. * one since the start of the grace period. Thus just a flag.
*/ */
static inline void rcu_qsctr_inc(int cpu) extern void rcu_qsctr_inc(int cpu);
{ extern void rcu_bh_qsctr_inc(int cpu);
struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
rdp->passed_quiesc = 1;
}
static inline void rcu_bh_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
rdp->passed_quiesc = 1;
}
extern int rcu_pending(int cpu); extern int rcu_pending(int cpu);
extern int rcu_needs_cpu(int cpu); extern int rcu_needs_cpu(int cpu);
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/threads.h> #include <linux/threads.h>
#include <linux/percpu.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/seqlock.h> #include <linux/seqlock.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
......
...@@ -36,34 +36,19 @@ ...@@ -36,34 +36,19 @@
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/threads.h> #include <linux/threads.h>
#include <linux/percpu.h> #include <linux/smp.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/seqlock.h> #include <linux/seqlock.h>
struct rcu_dyntick_sched { extern void rcu_qsctr_inc(int cpu);
int dynticks; static inline void rcu_bh_qsctr_inc(int cpu) { }
int dynticks_snap;
int sched_qs;
int sched_qs_snap;
int sched_dynticks_snap;
};
DECLARE_PER_CPU(struct rcu_dyntick_sched, rcu_dyntick_sched);
static inline void rcu_qsctr_inc(int cpu)
{
struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu);
rdssp->sched_qs++;
}
#define rcu_bh_qsctr_inc(cpu)
/* /*
* Someone might want to pass call_rcu_bh as a function pointer. * Someone might want to pass call_rcu_bh as a function pointer.
* So this needs to just be a rename and not a macro function. * So this needs to just be a rename and not a macro function.
* (no parentheses) * (no parentheses)
*/ */
#define call_rcu_bh call_rcu #define call_rcu_bh call_rcu
/** /**
* call_rcu_sched - Queue RCU callback for invocation after sched grace period. * call_rcu_sched - Queue RCU callback for invocation after sched grace period.
...@@ -117,30 +102,12 @@ extern struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu); ...@@ -117,30 +102,12 @@ extern struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu);
struct softirq_action; struct softirq_action;
#ifdef CONFIG_NO_HZ #ifdef CONFIG_NO_HZ
extern void rcu_enter_nohz(void);
static inline void rcu_enter_nohz(void) extern void rcu_exit_nohz(void);
{ #else
static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1); # define rcu_enter_nohz() do { } while (0)
# define rcu_exit_nohz() do { } while (0)
smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ #endif
__get_cpu_var(rcu_dyntick_sched).dynticks++;
WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs);
}
static inline void rcu_exit_nohz(void)
{
static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
__get_cpu_var(rcu_dyntick_sched).dynticks++;
smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1),
&rs);
}
#else /* CONFIG_NO_HZ */
#define rcu_enter_nohz() do { } while (0)
#define rcu_exit_nohz() do { } while (0)
#endif /* CONFIG_NO_HZ */
/* /*
* A context switch is a grace period for rcupreempt synchronize_rcu() * A context switch is a grace period for rcupreempt synchronize_rcu()
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/threads.h> #include <linux/threads.h>
#include <linux/percpu.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/seqlock.h> #include <linux/seqlock.h>
...@@ -236,30 +235,8 @@ struct rcu_state { ...@@ -236,30 +235,8 @@ struct rcu_state {
#endif /* #ifdef CONFIG_NO_HZ */ #endif /* #ifdef CONFIG_NO_HZ */
}; };
extern struct rcu_state rcu_state; extern void rcu_qsctr_inc(int cpu);
DECLARE_PER_CPU(struct rcu_data, rcu_data); extern void rcu_bh_qsctr_inc(int cpu);
extern struct rcu_state rcu_bh_state;
DECLARE_PER_CPU(struct rcu_data, rcu_bh_data);
/*
* Increment the quiescent state counter.
* The counter is a bit degenerated: We do not need to know
* how many quiescent states passed, just if there was at least
* one since the start of the grace period. Thus just a flag.
*/
static inline void rcu_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
rdp->passed_quiesc = 1;
rdp->passed_quiesc_completed = rdp->completed;
}
static inline void rcu_bh_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
rdp->passed_quiesc = 1;
rdp->passed_quiesc_completed = rdp->completed;
}
extern int rcu_pending(int cpu); extern int rcu_pending(int cpu);
extern int rcu_needs_cpu(int cpu); extern int rcu_needs_cpu(int cpu);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/key.h> #include <linux/key.h>
#include <linux/xfrm.h> #include <linux/xfrm.h>
#include <linux/gfp.h>
#include <net/flow.h> #include <net/flow.h>
/* Maximum number of letters for an LSM name string */ /* Maximum number of letters for an LSM name string */
...@@ -2953,5 +2954,28 @@ static inline void securityfs_remove(struct dentry *dentry) ...@@ -2953,5 +2954,28 @@ static inline void securityfs_remove(struct dentry *dentry)
#endif #endif
#ifdef CONFIG_SECURITY
static inline char *alloc_secdata(void)
{
return (char *)get_zeroed_page(GFP_KERNEL);
}
static inline void free_secdata(void *secdata)
{
free_page((unsigned long)secdata);
}
#else
static inline char *alloc_secdata(void)
{
return (char *)1;
}
static inline void free_secdata(void *secdata)
{ }
#endif /* CONFIG_SECURITY */
#endif /* ! __LINUX_SECURITY_H */ #endif /* ! __LINUX_SECURITY_H */
...@@ -73,8 +73,8 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags) ...@@ -73,8 +73,8 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
ret = kmem_cache_alloc_notrace(cachep, flags); ret = kmem_cache_alloc_notrace(cachep, flags);
kmemtrace_mark_alloc(KMEMTRACE_TYPE_KMALLOC, _THIS_IP_, ret, trace_kmalloc(_THIS_IP_, ret,
size, slab_buffer_size(cachep), flags); size, slab_buffer_size(cachep), flags);
return ret; return ret;
} }
...@@ -128,9 +128,9 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) ...@@ -128,9 +128,9 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
ret = kmem_cache_alloc_node_notrace(cachep, flags, node); ret = kmem_cache_alloc_node_notrace(cachep, flags, node);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, _THIS_IP_, trace_kmalloc_node(_THIS_IP_, ret,
ret, size, slab_buffer_size(cachep), size, slab_buffer_size(cachep),
flags, node); flags, node);
return ret; return ret;
} }
......
...@@ -233,8 +233,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags) ...@@ -233,8 +233,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
unsigned int order = get_order(size); unsigned int order = get_order(size);
void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order); void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
kmemtrace_mark_alloc(KMEMTRACE_TYPE_KMALLOC, _THIS_IP_, ret, trace_kmalloc(_THIS_IP_, ret, size, PAGE_SIZE << order, flags);
size, PAGE_SIZE << order, flags);
return ret; return ret;
} }
...@@ -255,9 +254,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags) ...@@ -255,9 +254,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
ret = kmem_cache_alloc_notrace(s, flags); ret = kmem_cache_alloc_notrace(s, flags);
kmemtrace_mark_alloc(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc(_THIS_IP_, ret, size, s->size, flags);
_THIS_IP_, ret,
size, s->size, flags);
return ret; return ret;
} }
...@@ -296,9 +293,8 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) ...@@ -296,9 +293,8 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
ret = kmem_cache_alloc_node_notrace(s, flags, node); ret = kmem_cache_alloc_node_notrace(s, flags, node);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc_node(_THIS_IP_, ret,
_THIS_IP_, ret, size, s->size, flags, node);
size, s->size, flags, node);
return ret; return ret;
} }
......
...@@ -9,65 +9,53 @@ ...@@ -9,65 +9,53 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/tracepoint.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/marker.h>
enum kmemtrace_type_id {
KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */
KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */
KMEMTRACE_TYPE_PAGES, /* __get_free_pages() and friends. */
};
#ifdef CONFIG_KMEMTRACE #ifdef CONFIG_KMEMTRACE
extern void kmemtrace_init(void); extern void kmemtrace_init(void);
#else
extern void kmemtrace_mark_alloc_node(enum kmemtrace_type_id type_id,
unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags,
int node);
extern void kmemtrace_mark_free(enum kmemtrace_type_id type_id,
unsigned long call_site,
const void *ptr);
#else /* CONFIG_KMEMTRACE */
static inline void kmemtrace_init(void) static inline void kmemtrace_init(void)
{ {
} }
#endif
static inline void kmemtrace_mark_alloc_node(enum kmemtrace_type_id type_id,
unsigned long call_site, DECLARE_TRACE(kmalloc,
const void *ptr, TP_PROTO(unsigned long call_site,
size_t bytes_req, const void *ptr,
size_t bytes_alloc, size_t bytes_req,
gfp_t gfp_flags, size_t bytes_alloc,
int node) gfp_t gfp_flags),
{ TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags));
} DECLARE_TRACE(kmem_cache_alloc,
TP_PROTO(unsigned long call_site,
static inline void kmemtrace_mark_free(enum kmemtrace_type_id type_id, const void *ptr,
unsigned long call_site, size_t bytes_req,
const void *ptr) size_t bytes_alloc,
{ gfp_t gfp_flags),
} TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags));
DECLARE_TRACE(kmalloc_node,
#endif /* CONFIG_KMEMTRACE */ TP_PROTO(unsigned long call_site,
const void *ptr,
static inline void kmemtrace_mark_alloc(enum kmemtrace_type_id type_id, size_t bytes_req,
unsigned long call_site, size_t bytes_alloc,
const void *ptr, gfp_t gfp_flags,
size_t bytes_req, int node),
size_t bytes_alloc, TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node));
gfp_t gfp_flags) DECLARE_TRACE(kmem_cache_alloc_node,
{ TP_PROTO(unsigned long call_site,
kmemtrace_mark_alloc_node(type_id, call_site, ptr, const void *ptr,
bytes_req, bytes_alloc, gfp_flags, -1); size_t bytes_req,
} size_t bytes_alloc,
gfp_t gfp_flags,
int node),
TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node));
DECLARE_TRACE(kfree,
TP_PROTO(unsigned long call_site, const void *ptr),
TP_ARGS(call_site, ptr));
DECLARE_TRACE(kmem_cache_free,
TP_PROTO(unsigned long call_site, const void *ptr),
TP_ARGS(call_site, ptr));
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
...@@ -65,6 +65,7 @@ static struct rcu_ctrlblk rcu_ctrlblk = { ...@@ -65,6 +65,7 @@ static struct rcu_ctrlblk rcu_ctrlblk = {
.lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock), .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock),
.cpumask = CPU_BITS_NONE, .cpumask = CPU_BITS_NONE,
}; };
static struct rcu_ctrlblk rcu_bh_ctrlblk = { static struct rcu_ctrlblk rcu_bh_ctrlblk = {
.cur = -300, .cur = -300,
.completed = -300, .completed = -300,
...@@ -73,8 +74,26 @@ static struct rcu_ctrlblk rcu_bh_ctrlblk = { ...@@ -73,8 +74,26 @@ static struct rcu_ctrlblk rcu_bh_ctrlblk = {
.cpumask = CPU_BITS_NONE, .cpumask = CPU_BITS_NONE,
}; };
DEFINE_PER_CPU(struct rcu_data, rcu_data) = { 0L }; static DEFINE_PER_CPU(struct rcu_data, rcu_data);
DEFINE_PER_CPU(struct rcu_data, rcu_bh_data) = { 0L }; static DEFINE_PER_CPU(struct rcu_data, rcu_bh_data);
/*
* Increment the quiescent state counter.
* The counter is a bit degenerated: We do not need to know
* how many quiescent states passed, just if there was at least
* one since the start of the grace period. Thus just a flag.
*/
void rcu_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
rdp->passed_quiesc = 1;
}
void rcu_bh_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
rdp->passed_quiesc = 1;
}
static int blimit = 10; static int blimit = 10;
static int qhimark = 10000; static int qhimark = 10000;
......
...@@ -147,7 +147,51 @@ struct rcu_ctrlblk { ...@@ -147,7 +147,51 @@ struct rcu_ctrlblk {
wait_queue_head_t sched_wq; /* Place for rcu_sched to sleep. */ wait_queue_head_t sched_wq; /* Place for rcu_sched to sleep. */
}; };
struct rcu_dyntick_sched {
int dynticks;
int dynticks_snap;
int sched_qs;
int sched_qs_snap;
int sched_dynticks_snap;
};
static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_dyntick_sched, rcu_dyntick_sched) = {
.dynticks = 1,
};
void rcu_qsctr_inc(int cpu)
{
struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu);
rdssp->sched_qs++;
}
#ifdef CONFIG_NO_HZ
void rcu_enter_nohz(void)
{
static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
__get_cpu_var(rcu_dyntick_sched).dynticks++;
WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs);
}
void rcu_exit_nohz(void)
{
static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
__get_cpu_var(rcu_dyntick_sched).dynticks++;
smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1),
&rs);
}
#endif /* CONFIG_NO_HZ */
static DEFINE_PER_CPU(struct rcu_data, rcu_data); static DEFINE_PER_CPU(struct rcu_data, rcu_data);
static struct rcu_ctrlblk rcu_ctrlblk = { static struct rcu_ctrlblk rcu_ctrlblk = {
.fliplock = __SPIN_LOCK_UNLOCKED(rcu_ctrlblk.fliplock), .fliplock = __SPIN_LOCK_UNLOCKED(rcu_ctrlblk.fliplock),
.completed = 0, .completed = 0,
...@@ -427,10 +471,6 @@ static void __rcu_advance_callbacks(struct rcu_data *rdp) ...@@ -427,10 +471,6 @@ static void __rcu_advance_callbacks(struct rcu_data *rdp)
} }
} }
DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_dyntick_sched, rcu_dyntick_sched) = {
.dynticks = 1,
};
#ifdef CONFIG_NO_HZ #ifdef CONFIG_NO_HZ
static DEFINE_PER_CPU(int, rcu_update_flag); static DEFINE_PER_CPU(int, rcu_update_flag);
......
...@@ -78,6 +78,26 @@ DEFINE_PER_CPU(struct rcu_data, rcu_data); ...@@ -78,6 +78,26 @@ DEFINE_PER_CPU(struct rcu_data, rcu_data);
struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state);
DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); DEFINE_PER_CPU(struct rcu_data, rcu_bh_data);
/*
* Increment the quiescent state counter.
* The counter is a bit degenerated: We do not need to know
* how many quiescent states passed, just if there was at least
* one since the start of the grace period. Thus just a flag.
*/
void rcu_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
rdp->passed_quiesc = 1;
rdp->passed_quiesc_completed = rdp->completed;
}
void rcu_bh_qsctr_inc(int cpu)
{
struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
rdp->passed_quiesc = 1;
rdp->passed_quiesc_completed = rdp->completed;
}
#ifdef CONFIG_NO_HZ #ifdef CONFIG_NO_HZ
DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
.dynticks_nesting = 1, .dynticks_nesting = 1,
......
/*
* RCU implementation internal declarations:
*/
extern struct rcu_state rcu_state;
DECLARE_PER_CPU(struct rcu_data, rcu_data);
extern struct rcu_state rcu_bh_state;
DECLARE_PER_CPU(struct rcu_data, rcu_bh_data);
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include "rcutree.h"
static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
{ {
if (!rdp->beenonline) if (!rdp->beenonline)
......
...@@ -6,14 +6,16 @@ ...@@ -6,14 +6,16 @@
* Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com> * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
*/ */
#include <linux/dcache.h> #include <linux/tracepoint.h>
#include <linux/seq_file.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/dcache.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/seq_file.h>
#include <trace/kmemtrace.h> #include <trace/kmemtrace.h>
#include "trace.h"
#include "trace_output.h" #include "trace_output.h"
#include "trace.h"
/* Select an alternative, minimalistic output than the original one */ /* Select an alternative, minimalistic output than the original one */
#define TRACE_KMEM_OPT_MINIMAL 0x1 #define TRACE_KMEM_OPT_MINIMAL 0x1
...@@ -25,14 +27,156 @@ static struct tracer_opt kmem_opts[] = { ...@@ -25,14 +27,156 @@ static struct tracer_opt kmem_opts[] = {
}; };
static struct tracer_flags kmem_tracer_flags = { static struct tracer_flags kmem_tracer_flags = {
.val = 0, .val = 0,
.opts = kmem_opts .opts = kmem_opts
}; };
static bool kmem_tracing_enabled __read_mostly;
static struct trace_array *kmemtrace_array; static struct trace_array *kmemtrace_array;
/* Trace allocations */
static inline void kmemtrace_alloc(enum kmemtrace_type_id type_id,
unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags,
int node)
{
struct trace_array *tr = kmemtrace_array;
struct kmemtrace_alloc_entry *entry;
struct ring_buffer_event *event;
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
if (!event)
return;
entry = ring_buffer_event_data(event);
tracing_generic_entry_update(&entry->ent, 0, 0);
entry->ent.type = TRACE_KMEM_ALLOC;
entry->type_id = type_id;
entry->call_site = call_site;
entry->ptr = ptr;
entry->bytes_req = bytes_req;
entry->bytes_alloc = bytes_alloc;
entry->gfp_flags = gfp_flags;
entry->node = node;
ring_buffer_unlock_commit(tr->buffer, event);
trace_wake_up();
}
static inline void kmemtrace_free(enum kmemtrace_type_id type_id,
unsigned long call_site,
const void *ptr)
{
struct trace_array *tr = kmemtrace_array;
struct kmemtrace_free_entry *entry;
struct ring_buffer_event *event;
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
if (!event)
return;
entry = ring_buffer_event_data(event);
tracing_generic_entry_update(&entry->ent, 0, 0);
entry->ent.type = TRACE_KMEM_FREE;
entry->type_id = type_id;
entry->call_site = call_site;
entry->ptr = ptr;
ring_buffer_unlock_commit(tr->buffer, event);
trace_wake_up();
}
static void kmemtrace_kmalloc(unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags)
{
kmemtrace_alloc(KMEMTRACE_TYPE_KMALLOC, call_site, ptr,
bytes_req, bytes_alloc, gfp_flags, -1);
}
static void kmemtrace_kmem_cache_alloc(unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags)
{
kmemtrace_alloc(KMEMTRACE_TYPE_CACHE, call_site, ptr,
bytes_req, bytes_alloc, gfp_flags, -1);
}
static void kmemtrace_kmalloc_node(unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags,
int node)
{
kmemtrace_alloc(KMEMTRACE_TYPE_KMALLOC, call_site, ptr,
bytes_req, bytes_alloc, gfp_flags, node);
}
static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags,
int node)
{
kmemtrace_alloc(KMEMTRACE_TYPE_CACHE, call_site, ptr,
bytes_req, bytes_alloc, gfp_flags, node);
}
static void kmemtrace_kfree(unsigned long call_site, const void *ptr)
{
kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr);
}
static void kmemtrace_kmem_cache_free(unsigned long call_site, const void *ptr)
{
kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr);
}
static int kmemtrace_start_probes(void)
{
int err;
err = register_trace_kmalloc(kmemtrace_kmalloc);
if (err)
return err;
err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc);
if (err)
return err;
err = register_trace_kmalloc_node(kmemtrace_kmalloc_node);
if (err)
return err;
err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node);
if (err)
return err;
err = register_trace_kfree(kmemtrace_kfree);
if (err)
return err;
err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free);
return err;
}
static void kmemtrace_stop_probes(void)
{
unregister_trace_kmalloc(kmemtrace_kmalloc);
unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc);
unregister_trace_kmalloc_node(kmemtrace_kmalloc_node);
unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node);
unregister_trace_kfree(kmemtrace_kfree);
unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free);
}
static int kmem_trace_init(struct trace_array *tr) static int kmem_trace_init(struct trace_array *tr)
{ {
int cpu; int cpu;
...@@ -41,14 +185,14 @@ static int kmem_trace_init(struct trace_array *tr) ...@@ -41,14 +185,14 @@ static int kmem_trace_init(struct trace_array *tr)
for_each_cpu_mask(cpu, cpu_possible_map) for_each_cpu_mask(cpu, cpu_possible_map)
tracing_reset(tr, cpu); tracing_reset(tr, cpu);
kmem_tracing_enabled = true; kmemtrace_start_probes();
return 0; return 0;
} }
static void kmem_trace_reset(struct trace_array *tr) static void kmem_trace_reset(struct trace_array *tr)
{ {
kmem_tracing_enabled = false; kmemtrace_stop_probes();
} }
static void kmemtrace_headers(struct seq_file *s) static void kmemtrace_headers(struct seq_file *s)
...@@ -66,47 +210,84 @@ static void kmemtrace_headers(struct seq_file *s) ...@@ -66,47 +210,84 @@ static void kmemtrace_headers(struct seq_file *s)
} }
/* /*
* The two following functions give the original output from kmemtrace, * The following functions give the original output from kmemtrace,
* or something close to....perhaps they need some missing things * plus the origin CPU, since reordering occurs in-kernel now.
*/ */
#define KMEMTRACE_USER_ALLOC 0
#define KMEMTRACE_USER_FREE 1
struct kmemtrace_user_event {
u8 event_id;
u8 type_id;
u16 event_size;
u32 cpu;
u64 timestamp;
unsigned long call_site;
unsigned long ptr;
};
struct kmemtrace_user_event_alloc {
size_t bytes_req;
size_t bytes_alloc;
unsigned gfp_flags;
int node;
};
static enum print_line_t static enum print_line_t
kmemtrace_print_alloc_original(struct trace_iterator *iter, kmemtrace_print_alloc_user(struct trace_iterator *iter,
struct kmemtrace_alloc_entry *entry) struct kmemtrace_alloc_entry *entry)
{ {
struct kmemtrace_user_event_alloc *ev_alloc;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
int ret; struct kmemtrace_user_event *ev;
ev = trace_seq_reserve(s, sizeof(*ev));
if (!ev)
return TRACE_TYPE_PARTIAL_LINE;
/* Taken from the old linux/kmemtrace.h */ ev->event_id = KMEMTRACE_USER_ALLOC;
ret = trace_seq_printf(s, "type_id %d call_site %lu ptr %lu " ev->type_id = entry->type_id;
"bytes_req %lu bytes_alloc %lu gfp_flags %lu node %d\n", ev->event_size = sizeof(*ev) + sizeof(*ev_alloc);
entry->type_id, entry->call_site, (unsigned long) entry->ptr, ev->cpu = iter->cpu;
(unsigned long) entry->bytes_req, (unsigned long) entry->bytes_alloc, ev->timestamp = iter->ts;
(unsigned long) entry->gfp_flags, entry->node); ev->call_site = entry->call_site;
ev->ptr = (unsigned long)entry->ptr;
if (!ret) ev_alloc = trace_seq_reserve(s, sizeof(*ev_alloc));
if (!ev_alloc)
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
ev_alloc->bytes_req = entry->bytes_req;
ev_alloc->bytes_alloc = entry->bytes_alloc;
ev_alloc->gfp_flags = entry->gfp_flags;
ev_alloc->node = entry->node;
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static enum print_line_t static enum print_line_t
kmemtrace_print_free_original(struct trace_iterator *iter, kmemtrace_print_free_user(struct trace_iterator *iter,
struct kmemtrace_free_entry *entry) struct kmemtrace_free_entry *entry)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
int ret; struct kmemtrace_user_event *ev;
/* Taken from the old linux/kmemtrace.h */ ev = trace_seq_reserve(s, sizeof(*ev));
ret = trace_seq_printf(s, "type_id %d call_site %lu ptr %lu\n", if (!ev)
entry->type_id, entry->call_site, (unsigned long) entry->ptr);
if (!ret)
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
ev->event_id = KMEMTRACE_USER_FREE;
ev->type_id = entry->type_id;
ev->event_size = sizeof(*ev);
ev->cpu = iter->cpu;
ev->timestamp = iter->ts;
ev->call_site = entry->call_site;
ev->ptr = (unsigned long)entry->ptr;
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
/* The two other following provide a more minimalistic output */ /* The two other following provide a more minimalistic output */
static enum print_line_t static enum print_line_t
kmemtrace_print_alloc_compress(struct trace_iterator *iter, kmemtrace_print_alloc_compress(struct trace_iterator *iter,
...@@ -178,7 +359,7 @@ kmemtrace_print_alloc_compress(struct trace_iterator *iter, ...@@ -178,7 +359,7 @@ kmemtrace_print_alloc_compress(struct trace_iterator *iter,
static enum print_line_t static enum print_line_t
kmemtrace_print_free_compress(struct trace_iterator *iter, kmemtrace_print_free_compress(struct trace_iterator *iter,
struct kmemtrace_free_entry *entry) struct kmemtrace_free_entry *entry)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
int ret; int ret;
...@@ -239,20 +420,22 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter) ...@@ -239,20 +420,22 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
switch (entry->type) { switch (entry->type) {
case TRACE_KMEM_ALLOC: { case TRACE_KMEM_ALLOC: {
struct kmemtrace_alloc_entry *field; struct kmemtrace_alloc_entry *field;
trace_assign_type(field, entry); trace_assign_type(field, entry);
if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL) if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)
return kmemtrace_print_alloc_compress(iter, field); return kmemtrace_print_alloc_compress(iter, field);
else else
return kmemtrace_print_alloc_original(iter, field); return kmemtrace_print_alloc_user(iter, field);
} }
case TRACE_KMEM_FREE: { case TRACE_KMEM_FREE: {
struct kmemtrace_free_entry *field; struct kmemtrace_free_entry *field;
trace_assign_type(field, entry); trace_assign_type(field, entry);
if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL) if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)
return kmemtrace_print_free_compress(iter, field); return kmemtrace_print_free_compress(iter, field);
else else
return kmemtrace_print_free_original(iter, field); return kmemtrace_print_free_user(iter, field);
} }
default: default:
...@@ -260,70 +443,13 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter) ...@@ -260,70 +443,13 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
} }
} }
/* Trace allocations */
void kmemtrace_mark_alloc_node(enum kmemtrace_type_id type_id,
unsigned long call_site,
const void *ptr,
size_t bytes_req,
size_t bytes_alloc,
gfp_t gfp_flags,
int node)
{
struct ring_buffer_event *event;
struct kmemtrace_alloc_entry *entry;
struct trace_array *tr = kmemtrace_array;
if (!kmem_tracing_enabled)
return;
event = trace_buffer_lock_reserve(tr, TRACE_KMEM_ALLOC,
sizeof(*entry), 0, 0);
if (!event)
return;
entry = ring_buffer_event_data(event);
entry->call_site = call_site;
entry->ptr = ptr;
entry->bytes_req = bytes_req;
entry->bytes_alloc = bytes_alloc;
entry->gfp_flags = gfp_flags;
entry->node = node;
trace_buffer_unlock_commit(tr, event, 0, 0);
}
EXPORT_SYMBOL(kmemtrace_mark_alloc_node);
void kmemtrace_mark_free(enum kmemtrace_type_id type_id,
unsigned long call_site,
const void *ptr)
{
struct ring_buffer_event *event;
struct kmemtrace_free_entry *entry;
struct trace_array *tr = kmemtrace_array;
if (!kmem_tracing_enabled)
return;
event = trace_buffer_lock_reserve(tr, TRACE_KMEM_FREE,
sizeof(*entry), 0, 0);
if (!event)
return;
entry = ring_buffer_event_data(event);
entry->type_id = type_id;
entry->call_site = call_site;
entry->ptr = ptr;
trace_buffer_unlock_commit(tr, event, 0, 0);
}
EXPORT_SYMBOL(kmemtrace_mark_free);
static struct tracer kmem_tracer __read_mostly = { static struct tracer kmem_tracer __read_mostly = {
.name = "kmemtrace", .name = "kmemtrace",
.init = kmem_trace_init, .init = kmem_trace_init,
.reset = kmem_trace_reset, .reset = kmem_trace_reset,
.print_line = kmemtrace_print_line, .print_line = kmemtrace_print_line,
.print_header = kmemtrace_headers, .print_header = kmemtrace_headers,
.flags = &kmem_tracer_flags .flags = &kmem_tracer_flags
}; };
void kmemtrace_init(void) void kmemtrace_init(void)
...@@ -335,5 +461,4 @@ static int __init init_kmem_tracer(void) ...@@ -335,5 +461,4 @@ static int __init init_kmem_tracer(void)
{ {
return register_tracer(&kmem_tracer); return register_tracer(&kmem_tracer);
} }
device_initcall(init_kmem_tracer); device_initcall(init_kmem_tracer);
...@@ -182,6 +182,12 @@ struct trace_power { ...@@ -182,6 +182,12 @@ struct trace_power {
struct power_trace state_data; struct power_trace state_data;
}; };
enum kmemtrace_type_id {
KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */
KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */
KMEMTRACE_TYPE_PAGES, /* __get_free_pages() and friends. */
};
struct kmemtrace_alloc_entry { struct kmemtrace_alloc_entry {
struct trace_entry ent; struct trace_entry ent;
enum kmemtrace_type_id type_id; enum kmemtrace_type_id type_id;
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#endif /* !STATIC */ #endif /* !STATIC */
#include <linux/decompress/mm.h> #include <linux/decompress/mm.h>
#include <linux/slab.h>
#ifndef INT_MAX #ifndef INT_MAX
#define INT_MAX 0x7fffffff #define INT_MAX 0x7fffffff
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#endif /* STATIC */ #endif /* STATIC */
#include <linux/decompress/mm.h> #include <linux/decompress/mm.h>
#include <linux/slab.h>
#define INBUF_LEN (16*1024) #define INBUF_LEN (16*1024)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#endif /* STATIC */ #endif /* STATIC */
#include <linux/decompress/mm.h> #include <linux/decompress/mm.h>
#include <linux/slab.h>
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b))
......
#include <linux/fault-inject.h> #include <linux/fault-inject.h>
#include <linux/gfp.h>
static struct { static struct {
struct fault_attr attr; struct fault_attr attr;
......
...@@ -3565,8 +3565,8 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) ...@@ -3565,8 +3565,8 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
{ {
void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0)); void *ret = __cache_alloc(cachep, flags, __builtin_return_address(0));
kmemtrace_mark_alloc(KMEMTRACE_TYPE_CACHE, _RET_IP_, ret, trace_kmem_cache_alloc(_RET_IP_, ret,
obj_size(cachep), cachep->buffer_size, flags); obj_size(cachep), cachep->buffer_size, flags);
return ret; return ret;
} }
...@@ -3627,9 +3627,9 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) ...@@ -3627,9 +3627,9 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid)
void *ret = __cache_alloc_node(cachep, flags, nodeid, void *ret = __cache_alloc_node(cachep, flags, nodeid,
__builtin_return_address(0)); __builtin_return_address(0));
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_CACHE, _RET_IP_, ret, trace_kmem_cache_alloc_node(_RET_IP_, ret,
obj_size(cachep), cachep->buffer_size, obj_size(cachep), cachep->buffer_size,
flags, nodeid); flags, nodeid);
return ret; return ret;
} }
...@@ -3657,9 +3657,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller) ...@@ -3657,9 +3657,8 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)
return cachep; return cachep;
ret = kmem_cache_alloc_node_notrace(cachep, flags, node); ret = kmem_cache_alloc_node_notrace(cachep, flags, node);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc_node((unsigned long) caller, ret,
(unsigned long) caller, ret, size, cachep->buffer_size, flags, node);
size, cachep->buffer_size, flags, node);
return ret; return ret;
} }
...@@ -3709,9 +3708,8 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, ...@@ -3709,9 +3708,8 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags,
return cachep; return cachep;
ret = __cache_alloc(cachep, flags, caller); ret = __cache_alloc(cachep, flags, caller);
kmemtrace_mark_alloc(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc((unsigned long) caller, ret,
(unsigned long) caller, ret, size, cachep->buffer_size, flags);
size, cachep->buffer_size, flags);
return ret; return ret;
} }
...@@ -3757,7 +3755,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp) ...@@ -3757,7 +3755,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
__cache_free(cachep, objp); __cache_free(cachep, objp);
local_irq_restore(flags); local_irq_restore(flags);
kmemtrace_mark_free(KMEMTRACE_TYPE_CACHE, _RET_IP_, objp); trace_kmem_cache_free(_RET_IP_, objp);
} }
EXPORT_SYMBOL(kmem_cache_free); EXPORT_SYMBOL(kmem_cache_free);
...@@ -3775,6 +3773,8 @@ void kfree(const void *objp) ...@@ -3775,6 +3773,8 @@ void kfree(const void *objp)
struct kmem_cache *c; struct kmem_cache *c;
unsigned long flags; unsigned long flags;
trace_kfree(_RET_IP_, objp);
if (unlikely(ZERO_OR_NULL_PTR(objp))) if (unlikely(ZERO_OR_NULL_PTR(objp)))
return; return;
local_irq_save(flags); local_irq_save(flags);
...@@ -3784,8 +3784,6 @@ void kfree(const void *objp) ...@@ -3784,8 +3784,6 @@ void kfree(const void *objp)
debug_check_no_obj_freed(objp, obj_size(c)); debug_check_no_obj_freed(objp, obj_size(c));
__cache_free(c, (void *)objp); __cache_free(c, (void *)objp);
local_irq_restore(flags); local_irq_restore(flags);
kmemtrace_mark_free(KMEMTRACE_TYPE_KMALLOC, _RET_IP_, objp);
} }
EXPORT_SYMBOL(kfree); EXPORT_SYMBOL(kfree);
......
...@@ -490,9 +490,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node) ...@@ -490,9 +490,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
*m = size; *m = size;
ret = (void *)m + align; ret = (void *)m + align;
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc_node(_RET_IP_, ret,
_RET_IP_, ret, size, size + align, gfp, node);
size, size + align, gfp, node);
} else { } else {
unsigned int order = get_order(size); unsigned int order = get_order(size);
...@@ -503,9 +502,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node) ...@@ -503,9 +502,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
page->private = size; page->private = size;
} }
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc_node(_RET_IP_, ret,
_RET_IP_, ret, size, PAGE_SIZE << order, gfp, node);
size, PAGE_SIZE << order, gfp, node);
} }
return ret; return ret;
...@@ -516,6 +514,8 @@ void kfree(const void *block) ...@@ -516,6 +514,8 @@ void kfree(const void *block)
{ {
struct slob_page *sp; struct slob_page *sp;
trace_kfree(_RET_IP_, block);
if (unlikely(ZERO_OR_NULL_PTR(block))) if (unlikely(ZERO_OR_NULL_PTR(block)))
return; return;
...@@ -526,8 +526,6 @@ void kfree(const void *block) ...@@ -526,8 +526,6 @@ void kfree(const void *block)
slob_free(m, *m + align); slob_free(m, *m + align);
} else } else
put_page(&sp->page); put_page(&sp->page);
kmemtrace_mark_free(KMEMTRACE_TYPE_KMALLOC, _RET_IP_, block);
} }
EXPORT_SYMBOL(kfree); EXPORT_SYMBOL(kfree);
...@@ -599,16 +597,14 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node) ...@@ -599,16 +597,14 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
if (c->size < PAGE_SIZE) { if (c->size < PAGE_SIZE) {
b = slob_alloc(c->size, flags, c->align, node); b = slob_alloc(c->size, flags, c->align, node);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_CACHE, trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
_RET_IP_, b, c->size, SLOB_UNITS(c->size) * SLOB_UNIT,
SLOB_UNITS(c->size) * SLOB_UNIT, flags, node);
flags, node);
} else { } else {
b = slob_new_pages(flags, get_order(c->size), node); b = slob_new_pages(flags, get_order(c->size), node);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_CACHE, trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
_RET_IP_, b, c->size, PAGE_SIZE << get_order(c->size),
PAGE_SIZE << get_order(c->size), flags, node);
flags, node);
} }
if (c->ctor) if (c->ctor)
...@@ -646,7 +642,7 @@ void kmem_cache_free(struct kmem_cache *c, void *b) ...@@ -646,7 +642,7 @@ void kmem_cache_free(struct kmem_cache *c, void *b)
__kmem_cache_free(b, c->size); __kmem_cache_free(b, c->size);
} }
kmemtrace_mark_free(KMEMTRACE_TYPE_CACHE, _RET_IP_, b); trace_kmem_cache_free(_RET_IP_, b);
} }
EXPORT_SYMBOL(kmem_cache_free); EXPORT_SYMBOL(kmem_cache_free);
......
...@@ -1621,8 +1621,7 @@ void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags) ...@@ -1621,8 +1621,7 @@ void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags)
{ {
void *ret = slab_alloc(s, gfpflags, -1, _RET_IP_); void *ret = slab_alloc(s, gfpflags, -1, _RET_IP_);
kmemtrace_mark_alloc(KMEMTRACE_TYPE_CACHE, _RET_IP_, ret, trace_kmem_cache_alloc(_RET_IP_, ret, s->objsize, s->size, gfpflags);
s->objsize, s->size, gfpflags);
return ret; return ret;
} }
...@@ -1641,8 +1640,8 @@ void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node) ...@@ -1641,8 +1640,8 @@ void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node)
{ {
void *ret = slab_alloc(s, gfpflags, node, _RET_IP_); void *ret = slab_alloc(s, gfpflags, node, _RET_IP_);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_CACHE, _RET_IP_, ret, trace_kmem_cache_alloc_node(_RET_IP_, ret,
s->objsize, s->size, gfpflags, node); s->objsize, s->size, gfpflags, node);
return ret; return ret;
} }
...@@ -1767,7 +1766,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x) ...@@ -1767,7 +1766,7 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
slab_free(s, page, x, _RET_IP_); slab_free(s, page, x, _RET_IP_);
kmemtrace_mark_free(KMEMTRACE_TYPE_CACHE, _RET_IP_, x); trace_kmem_cache_free(_RET_IP_, x);
} }
EXPORT_SYMBOL(kmem_cache_free); EXPORT_SYMBOL(kmem_cache_free);
...@@ -2702,8 +2701,7 @@ void *__kmalloc(size_t size, gfp_t flags) ...@@ -2702,8 +2701,7 @@ void *__kmalloc(size_t size, gfp_t flags)
ret = slab_alloc(s, flags, -1, _RET_IP_); ret = slab_alloc(s, flags, -1, _RET_IP_);
kmemtrace_mark_alloc(KMEMTRACE_TYPE_KMALLOC, _RET_IP_, ret, trace_kmalloc(_RET_IP_, ret, size, s->size, flags);
size, s->size, flags);
return ret; return ret;
} }
...@@ -2729,10 +2727,9 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) ...@@ -2729,10 +2727,9 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
if (unlikely(size > SLUB_MAX_SIZE)) { if (unlikely(size > SLUB_MAX_SIZE)) {
ret = kmalloc_large_node(size, flags, node); ret = kmalloc_large_node(size, flags, node);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, trace_kmalloc_node(_RET_IP_, ret,
_RET_IP_, ret, size, PAGE_SIZE << get_order(size),
size, PAGE_SIZE << get_order(size), flags, node);
flags, node);
return ret; return ret;
} }
...@@ -2744,8 +2741,7 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) ...@@ -2744,8 +2741,7 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
ret = slab_alloc(s, flags, node, _RET_IP_); ret = slab_alloc(s, flags, node, _RET_IP_);
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, _RET_IP_, ret, trace_kmalloc_node(_RET_IP_, ret, size, s->size, flags, node);
size, s->size, flags, node);
return ret; return ret;
} }
...@@ -2796,6 +2792,8 @@ void kfree(const void *x) ...@@ -2796,6 +2792,8 @@ void kfree(const void *x)
struct page *page; struct page *page;
void *object = (void *)x; void *object = (void *)x;
trace_kfree(_RET_IP_, x);
if (unlikely(ZERO_OR_NULL_PTR(x))) if (unlikely(ZERO_OR_NULL_PTR(x)))
return; return;
...@@ -2806,8 +2804,6 @@ void kfree(const void *x) ...@@ -2806,8 +2804,6 @@ void kfree(const void *x)
return; return;
} }
slab_free(page->slab, page, object, _RET_IP_); slab_free(page->slab, page, object, _RET_IP_);
kmemtrace_mark_free(KMEMTRACE_TYPE_KMALLOC, _RET_IP_, x);
} }
EXPORT_SYMBOL(kfree); EXPORT_SYMBOL(kfree);
...@@ -3290,8 +3286,7 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller) ...@@ -3290,8 +3286,7 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
ret = slab_alloc(s, gfpflags, -1, caller); ret = slab_alloc(s, gfpflags, -1, caller);
/* Honor the call site pointer we recieved. */ /* Honor the call site pointer we recieved. */
kmemtrace_mark_alloc(KMEMTRACE_TYPE_KMALLOC, caller, ret, size, trace_kmalloc(caller, ret, size, s->size, gfpflags);
s->size, gfpflags);
return ret; return ret;
} }
...@@ -3313,8 +3308,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags, ...@@ -3313,8 +3308,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
ret = slab_alloc(s, gfpflags, node, caller); ret = slab_alloc(s, gfpflags, node, caller);
/* Honor the call site pointer we recieved. */ /* Honor the call site pointer we recieved. */
kmemtrace_mark_alloc_node(KMEMTRACE_TYPE_KMALLOC, caller, ret, trace_kmalloc_node(caller, ret, size, s->size, gfpflags, node);
size, s->size, gfpflags, node);
return ret; return ret;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/tracepoint.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
/** /**
...@@ -236,3 +237,18 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start, ...@@ -236,3 +237,18 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start,
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(get_user_pages_fast); EXPORT_SYMBOL_GPL(get_user_pages_fast);
/* Tracepoints definitions. */
DEFINE_TRACE(kmalloc);
DEFINE_TRACE(kmem_cache_alloc);
DEFINE_TRACE(kmalloc_node);
DEFINE_TRACE(kmem_cache_alloc_node);
DEFINE_TRACE(kfree);
DEFINE_TRACE(kmem_cache_free);
EXPORT_TRACEPOINT_SYMBOL(kmalloc);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
EXPORT_TRACEPOINT_SYMBOL(kmalloc_node);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node);
EXPORT_TRACEPOINT_SYMBOL(kfree);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册