Re: [PATCH v5 2/4] mm: Introduce mem_cgroup_swapin_uncharge_swap_nr() helper for large folios swap-in

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 26, 2024 at 2:47 AM Barry Song <21cnbao@xxxxxxxxx> wrote:
>
> From: Barry Song <v-songbaohua@xxxxxxxx>
>
> With large folios swap-in, we might need to uncharge multiple entries
> all together, it is better to introduce a helper for that.
>
> Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx>
> ---
>  include/linux/memcontrol.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 1b79760af685..55958cbce61b 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -684,6 +684,14 @@ int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm,
>                                   gfp_t gfp, swp_entry_t entry);
>  void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry);
>
> +static inline void mem_cgroup_swapin_uncharge_swap_nr(swp_entry_t entry, int nr)
> +{
> +       int i;
> +
> +       for (i = 0; i < nr; i++, entry.val++)
> +               mem_cgroup_swapin_uncharge_swap(entry);

mem_cgroup_swapin_uncharge_swap() calls mem_cgroup_uncharge_swap()
which already takes in nr_pages, but we currently only pass 1. Would
it be better if we just make mem_cgroup_swapin_uncharge_swap() take in
nr_pages as well and pass it along to mem_cgroup_uncharge_swap(),
instead of calling it in a loop?

This would batch the page counter, stats updates, and refcount updates
in mem_cgroup_uncharge_swap(). You may be able to observe a bit of a
performance gain with this.

> +}
> +
>  void __mem_cgroup_uncharge(struct folio *folio);
>
>  /**
> @@ -1185,6 +1193,10 @@ static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry)
>  {
>  }
>
> +static inline void mem_cgroup_swapin_uncharge_swap_nr(swp_entry_t entry, int nr)
> +{
> +}
> +
>  static inline void mem_cgroup_uncharge(struct folio *folio)
>  {
>  }
> --
> 2.34.1
>





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux