Re: [RFC MM 3/4] add mm version number

Minchan Kim
2009-11-13T15:27:50Z

Hi, Kame.

On Fri, Nov 13, 2009 at 4:40 PM, KAMEZAWA Hiroyuki
<kamezawa.hiroyu@jp.fujitsu.com> wrote:
>
> Add logical timestamp to mm_struct, which is incremented always
> mmap_sem(write) is got and released. By this, it works like seqlock's
> counter and indicates mm_struct is modified or not.
>
> And this adds vma_cache to each thread. Each thread remember the last
> faulted vma and grab reference count. Correctness of cache is checked by
> mm->generation timestamp. (mm struct's vma cache is not very good
> if mm is shared, I think)
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
>  arch/x86/mm/fault.c       |   18 ++++++++++++++++--
>  fs/exec.c                 |    4 ++++
>  include/linux/init_task.h |    1 +
>  include/linux/mm_types.h  |   11 ++++++++++-
>  include/linux/sched.h     |    4 ++++
>  kernel/exit.c             |    3 +++
>  kernel/fork.c             |    5 ++++-
>  7 files changed, 42 insertions(+), 4 deletions(-)
>
> Index: mmotm-2.6.32-Nov2/include/linux/mm_types.h
> ===================================================================
> --- mmotm-2.6.32-Nov2.orig/include/linux/mm_types.h
> +++ mmotm-2.6.32-Nov2/include/linux/mm_types.h
> @@ -216,6 +216,7 @@ struct mm_struct {
>        atomic_t mm_users;                      /* How many users with user space? */
>        atomic_t mm_count;                      /* How many references to "struct mm_struct" (users count as 1) */
>        int map_count;                          /* number of VMAs */
> +       unsigned int generation;                /* logical timestamp of last modification */
>        struct rw_semaphore sem;
>        spinlock_t page_table_lock;             /* Protects page tables and some counters */
>
> @@ -308,16 +309,21 @@ static inline int mm_reader_trylock(stru
>  static inline void mm_writer_lock(struct mm_struct *mm)
>  {
>        down_write(&mm->sem);
> +       mm->generation++;
>  }
>
>  static inline void mm_writer_unlock(struct mm_struct *mm)
>  {
> +       mm->generation++;
>        up_write(&mm->sem);
>  }
>
>  static inline int mm_writer_trylock(struct mm_struct *mm)
>  {
> -       return down_write_trylock(&mm->sem);
> +       int ret = down_write_trylock(&mm->sem);
> +       if (!ret)

It seems your typo.
if (ret) ?

> +               mm->generation++;
> +       return ret;
>  }

--
Kind regards,
Minchan Kim