Skip to content

Commit

Permalink
aufs3.16 mmap patch
Browse files Browse the repository at this point in the history
  • Loading branch information
sfjro authored and ppisa committed Aug 24, 2014
1 parent 6a730ac commit e8fa52e
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 26 deletions.
2 changes: 1 addition & 1 deletion fs/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
* Update file times before taking page lock. We may end up failing the
* fault so this update may be superfluous but who really cares...
*/
file_update_time(vma->vm_file);
vma_file_update_time(vma);

ret = __block_page_mkwrite(vma, vmf, get_block);
sb_end_pagefault(sb);
Expand Down
5 changes: 4 additions & 1 deletion fs/proc/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
file = region->vm_file;

if (file) {
struct inode *inode = file_inode(region->vm_file);
struct inode *inode;

file = vmr_pr_or_file(region);
inode = file_inode(file);
dev = inode->i_sb->s_dev;
ino = inode->i_ino;
}
Expand Down
7 changes: 5 additions & 2 deletions fs/proc/task_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
const char *name = NULL;

if (file) {
struct inode *inode = file_inode(vma->vm_file);
struct inode *inode;

file = vma_pr_or_file(vma);
inode = file_inode(file);
dev = inode->i_sb->s_dev;
ino = inode->i_ino;
pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
Expand Down Expand Up @@ -1390,7 +1393,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
struct vm_area_struct *vma = v;
struct numa_maps *md = &numa_priv->md;
struct file *file = vma->vm_file;
struct file *file = vma_pr_or_file(vma);
struct task_struct *task = proc_priv->task;
struct mm_struct *mm = vma->vm_mm;
struct mm_walk walk = {};
Expand Down
5 changes: 4 additions & 1 deletion fs/proc/task_nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
file = vma->vm_file;

if (file) {
struct inode *inode = file_inode(vma->vm_file);
struct inode *inode;

file = vma_pr_or_file(file);
inode = file_inode(file);
dev = inode->i_sb->s_dev;
ino = inode->i_ino;
pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
Expand Down
22 changes: 22 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
}
#endif

#ifdef CONFIG_MMU
extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
int);
extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
extern void vma_do_fput(struct vm_area_struct *, const char[], int);

#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
__LINE__)
#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
__LINE__)
#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
#else
extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
extern void vmr_do_fput(struct vm_region *, const char[], int);

#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
__LINE__)
#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
#endif /* CONFIG_MMU */

extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
void *buf, int len, int write);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/mm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ struct vm_region {
unsigned long vm_top; /* region allocated to here */
unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
struct file *vm_file; /* the backing file or NULL */
struct file *vm_prfile; /* the virtual backing file or NULL */

int vm_usage; /* region usage count (access under nommu_region_sem) */
bool vm_icache_flushed : 1; /* true if the icache has been flushed for
Expand Down Expand Up @@ -300,6 +301,7 @@ struct vm_area_struct {
unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
units, *not* PAGE_CACHE_SIZE */
struct file * vm_file; /* File we map to (can be NULL). */
struct file *vm_prfile; /* shadow of vm_file */
void * vm_private_data; /* was vm_pte (shared mem) */

#ifndef CONFIG_MMU
Expand Down
2 changes: 1 addition & 1 deletion kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
struct inode *inode = file_inode(file);
struct address_space *mapping = file->f_mapping;

get_file(file);
vma_get_file(tmp);
if (tmp->vm_flags & VM_DENYWRITE)
atomic_dec(&inode->i_writecount);
mutex_lock(&mapping->i_mmap_mutex);
Expand Down
2 changes: 1 addition & 1 deletion mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
mm_init.o mmu_context.o percpu.o slab_common.o \
compaction.o balloon_compaction.o vmacache.o \
interval_tree.o list_lru.o workingset.o \
iov_iter.o $(mmu-y)
iov_iter.o prfile.o $(mmu-y)

obj-y += init-mm.o

Expand Down
2 changes: 1 addition & 1 deletion mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
int ret = VM_FAULT_LOCKED;

sb_start_pagefault(inode->i_sb);
file_update_time(vma->vm_file);
vma_file_update_time(vma);
lock_page(page);
if (page->mapping != inode->i_mapping) {
unlock_page(page);
Expand Down
16 changes: 14 additions & 2 deletions mm/fremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,28 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
*/
if (mapping_cap_account_dirty(mapping)) {
unsigned long addr;
struct file *file = get_file(vma->vm_file);
struct file *file = vma->vm_file,
*prfile = vma->vm_prfile;

/* mmap_region may free vma; grab the info now */
vm_flags = vma->vm_flags;

vma_get_file(vma);
addr = mmap_region(file, start, size, vm_flags, pgoff);
fput(file);
vma_fput(vma);
if (IS_ERR_VALUE(addr)) {
err = addr;
} else {
BUG_ON(addr != start);
if (prfile) {
struct vm_area_struct *new_vma;

new_vma = find_vma(mm, addr);
if (!new_vma->vm_prfile)
new_vma->vm_prfile = prfile;
if (new_vma != vma)
get_file(prfile);
}
err = 0;
}
goto out_freed;
Expand Down
4 changes: 2 additions & 2 deletions mm/madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ static long madvise_remove(struct vm_area_struct *vma,
* vma's reference to the file) can go away as soon as we drop
* mmap_sem.
*/
get_file(f);
vma_get_file(vma);
up_read(&current->mm->mmap_sem);
error = do_fallocate(f,
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
offset, end - start);
fput(f);
vma_fput(vma);
down_read(&current->mm->mmap_sem);
return error;
}
Expand Down
2 changes: 1 addition & 1 deletion mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
set_page_dirty_balance(dirty_page);
/* file_update_time outside page_lock */
if (vma->vm_file)
file_update_time(vma->vm_file);
vma_file_update_time(vma);
}
put_page(dirty_page);
if (page_mkwrite) {
Expand Down
12 changes: 6 additions & 6 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
if (vma->vm_ops && vma->vm_ops->close)
vma->vm_ops->close(vma);
if (vma->vm_file)
fput(vma->vm_file);
vma_fput(vma);
mpol_put(vma_policy(vma));
kmem_cache_free(vm_area_cachep, vma);
return next;
Expand Down Expand Up @@ -863,7 +863,7 @@ again: remove_next = 1 + (end > next->vm_end);
if (remove_next) {
if (file) {
uprobe_munmap(next, next->vm_start, next->vm_end);
fput(file);
vma_fput(vma);
}
if (next->anon_vma)
anon_vma_merge(vma, next);
Expand Down Expand Up @@ -1643,8 +1643,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
unmap_and_free_vma:
if (vm_flags & VM_DENYWRITE)
allow_write_access(file);
vma_fput(vma);
vma->vm_file = NULL;
fput(file);

/* Undo any partial mapping done by a device driver. */
unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
Expand Down Expand Up @@ -2434,7 +2434,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
goto out_free_mpol;

if (new->vm_file)
get_file(new->vm_file);
vma_get_file(new);

if (new->vm_ops && new->vm_ops->open)
new->vm_ops->open(new);
Expand All @@ -2453,7 +2453,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
if (new->vm_ops && new->vm_ops->close)
new->vm_ops->close(new);
if (new->vm_file)
fput(new->vm_file);
vma_fput(new);
unlink_anon_vmas(new);
out_free_mpol:
mpol_put(vma_policy(new));
Expand Down Expand Up @@ -2842,7 +2842,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
if (anon_vma_clone(new_vma, vma))
goto out_free_mempol;
if (new_vma->vm_file)
get_file(new_vma->vm_file);
vma_get_file(new_vma);
if (new_vma->vm_ops && new_vma->vm_ops->open)
new_vma->vm_ops->open(new_vma);
vma_link(mm, new_vma, prev, rb_link, rb_parent);
Expand Down
4 changes: 2 additions & 2 deletions mm/msync.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
start = vma->vm_end;
if ((flags & MS_SYNC) && file &&
(vma->vm_flags & VM_SHARED)) {
get_file(file);
vma_get_file(vma);
up_read(&mm->mmap_sem);
if (vma->vm_flags & VM_NONLINEAR)
error = vfs_fsync(file, 1);
else
error = vfs_fsync_range(file, fstart, fend, 1);
fput(file);
vma_fput(vma);
if (error || start >= end)
goto out;
down_read(&mm->mmap_sem);
Expand Down
10 changes: 5 additions & 5 deletions mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ static void __put_nommu_region(struct vm_region *region)
up_write(&nommu_region_sem);

if (region->vm_file)
fput(region->vm_file);
vmr_fput(region);

/* IO memory and memory shared directly out of the pagecache
* from ramfs/tmpfs mustn't be released here */
Expand Down Expand Up @@ -823,7 +823,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
if (vma->vm_ops && vma->vm_ops->close)
vma->vm_ops->close(vma);
if (vma->vm_file)
fput(vma->vm_file);
vma_fput(vma);
put_nommu_region(vma->vm_region);
kmem_cache_free(vm_area_cachep, vma);
}
Expand Down Expand Up @@ -1385,7 +1385,7 @@ unsigned long do_mmap_pgoff(struct file *file,
goto error_just_free;
}
}
fput(region->vm_file);
vmr_fput(region);
kmem_cache_free(vm_region_jar, region);
region = pregion;
result = start;
Expand Down Expand Up @@ -1461,10 +1461,10 @@ unsigned long do_mmap_pgoff(struct file *file,
up_write(&nommu_region_sem);
error:
if (region->vm_file)
fput(region->vm_file);
vmr_fput(region);
kmem_cache_free(vm_region_jar, region);
if (vma->vm_file)
fput(vma->vm_file);
vma_fput(vma);
kmem_cache_free(vm_area_cachep, vma);
kleave(" = %d", ret);
return ret;
Expand Down
86 changes: 86 additions & 0 deletions mm/prfile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Mainly for aufs which mmap(2) diffrent file and wants to print different path
* in /proc/PID/maps.
* Call these functions via macros defined in linux/mm.h.
*
* See Documentation/filesystems/aufs/design/06mmap.txt
*
* Copyright (c) 2014 Junjro R. Okajima
* Copyright (c) 2014 Ian Campbell
*/

#include <linux/mm.h>
#include <linux/file.h>
#include <linux/fs.h>

/* #define PRFILE_TRACE */
static inline void prfile_trace(struct file *f, struct file *pr,
const char func[], int line, const char func2[])
{
#ifdef PRFILE_TRACE
if (pr)
pr_info("%s:%d: %s, %p\n", func, line, func2,
f ? (char *)f->f_dentry->d_name.name : "(null)");
#endif
}

#ifdef CONFIG_MMU
void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
int line)
{
struct file *f = vma->vm_file, *pr = vma->vm_prfile;

prfile_trace(f, pr, func, line, __func__);
file_update_time(f);
if (f && pr)
file_update_time(pr);
}

struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
int line)
{
struct file *f = vma->vm_file, *pr = vma->vm_prfile;

prfile_trace(f, pr, func, line, __func__);
return (f && pr) ? pr : f;
}

void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
{
struct file *f = vma->vm_file, *pr = vma->vm_prfile;

prfile_trace(f, pr, func, line, __func__);
get_file(f);
if (f && pr)
get_file(pr);
}

void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
{
struct file *f = vma->vm_file, *pr = vma->vm_prfile;

prfile_trace(f, pr, func, line, __func__);
fput(f);
if (f && pr)
fput(pr);
}
#else
struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
int line)
{
struct file *f = region->vm_file, *pr = region->vm_prfile;

prfile_trace(f, pr, func, line, __func__);
return (f && pr) ? pr : f;
}

void vmr_do_fput(struct vm_region *region, const char func[], int line)
{
struct file *f = region->vm_file, *pr = region->vm_prfile;

prfile_trace(f, pr, func, line, __func__);
fput(f);
if (f && pr)
fput(pr);
}
#endif /* CONFIG_MMU */

0 comments on commit e8fa52e

Please sign in to comment.