Re: [RESEND RFC PATCH v2 1/1] mm/vmalloc.c: simplify /proc/vmallocinfo implementation

From: Michal Hocko
Date: Wed Oct 12 2016 - 05:25:31 EST


On Wed 12-10-16 16:23:01, zijun_hu wrote:
> From: zijun_hu <zijun_hu@xxxxxxx>
>
> many seq_file helpers exist for simplifying implementation of virtual files
> especially, for /proc nodes. however, the helpers for iteration over
> list_head are available but aren't adopted to implement /proc/vmallocinfo
> currently.
>
> simplify /proc/vmallocinfo implementation by existing seq_file helpers

the simplification is nice and code duplication removal useful

> Signed-off-by: zijun_hu <zijun_hu@xxxxxxx>

Acked-by: Michal Hocko <mhocko@xxxxxxxx>

Thanks!

> ---
> Changes in v2:
> - the redundant type cast is removed as advised by rientjes@xxxxxxxxxx
> - commit messages are updated
>
> mm/vmalloc.c | 27 +++++----------------------
> 1 file changed, 5 insertions(+), 22 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index f2481cb4e6b2..e73948afac70 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2574,32 +2574,13 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
> static void *s_start(struct seq_file *m, loff_t *pos)
> __acquires(&vmap_area_lock)
> {
> - loff_t n = *pos;
> - struct vmap_area *va;
> -
> spin_lock(&vmap_area_lock);
> - va = list_first_entry(&vmap_area_list, typeof(*va), list);
> - while (n > 0 && &va->list != &vmap_area_list) {
> - n--;
> - va = list_next_entry(va, list);
> - }
> - if (!n && &va->list != &vmap_area_list)
> - return va;
> -
> - return NULL;
> -
> + return seq_list_start(&vmap_area_list, *pos);
> }
>
> static void *s_next(struct seq_file *m, void *p, loff_t *pos)
> {
> - struct vmap_area *va = p, *next;
> -
> - ++*pos;
> - next = list_next_entry(va, list);
> - if (&next->list != &vmap_area_list)
> - return next;
> -
> - return NULL;
> + return seq_list_next(p, &vmap_area_list, pos);
> }
>
> static void s_stop(struct seq_file *m, void *p)
> @@ -2634,9 +2615,11 @@ static void show_numa_info(struct seq_file *m, struct vm_struct *v)
>
> static int s_show(struct seq_file *m, void *p)
> {
> - struct vmap_area *va = p;
> + struct vmap_area *va;
> struct vm_struct *v;
>
> + va = list_entry(p, struct vmap_area, list);
> +
> /*
> * s_show can encounter race with remove_vm_area, !VM_VM_AREA on
> * behalf of vmap area is being tear down or vm_map_ram allocation.
> --
> 1.9.1
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@xxxxxxxxxx For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>

--
Michal Hocko
SUSE Labs