lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YN8D2JcxcBDxSucE@dhcp22.suse.cz>
Date:   Fri, 2 Jul 2021 14:17:28 +0200
From:   Michal Hocko <mhocko@...e.com>
To:     Ohhoon Kwon <ohoono.kwon@...sung.com>
Cc:     david@...hat.com, akpm@...ux-foundation.org, bhe@...hat.com,
        rppt@...ux.ibm.com, ohkwon1043@...il.com, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] mm: sparse: pass section_nr to find_memory_block

On Fri 02-07-21 18:41:31, Ohhoon Kwon wrote:
> With CONFIG_SPARSEMEM_EXTREME enabled, __section_nr() which converts
> mem_section to section_nr could be costly since it iterates all
> section roots to check if the given mem_section is in its range.
> 
> On the other hand, __nr_to_section() which converts section_nr to
> mem_section can be done in O(1).
> 
> Let's pass section_nr instead of mem_section ptr to
> find_memory_block() in order to reduce needless iterations.

Yeah, it seems like the only existing user (maybe there used to be more
in the past - haven't checked) is just doing pointless translation to
comply with the API that doesn't fit it. Just to undo all that work
in find_memory_block 

Nice cleanup and potentially even a performance improvement!
 
> Signed-off-by: Ohhoon Kwon <ohoono.kwon@...sung.com>

Acked-by: Michal Hocko <mhocko@...e.com>

> ---
>  arch/powerpc/platforms/pseries/hotplug-memory.c | 4 +---
>  drivers/base/memory.c                           | 4 ++--
>  include/linux/memory.h                          | 2 +-
>  3 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> index 8377f1f7c78e..905790092e0e 100644
> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> @@ -211,13 +211,11 @@ static int update_lmb_associativity_index(struct drmem_lmb *lmb)
>  static struct memory_block *lmb_to_memblock(struct drmem_lmb *lmb)
>  {
>  	unsigned long section_nr;
> -	struct mem_section *mem_sect;
>  	struct memory_block *mem_block;
>  
>  	section_nr = pfn_to_section_nr(PFN_DOWN(lmb->base_addr));
> -	mem_sect = __nr_to_section(section_nr);
>  
> -	mem_block = find_memory_block(mem_sect);
> +	mem_block = find_memory_block(section_nr);
>  	return mem_block;
>  }
>  
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index d5ffaab3cb61..e31598955cc4 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -578,9 +578,9 @@ static struct memory_block *find_memory_block_by_id(unsigned long block_id)
>  /*
>   * Called under device_hotplug_lock.
>   */
> -struct memory_block *find_memory_block(struct mem_section *section)
> +struct memory_block *find_memory_block(unsigned long section_nr)
>  {
> -	unsigned long block_id = memory_block_id(__section_nr(section));
> +	unsigned long block_id = memory_block_id(section_nr);
>  
>  	return find_memory_block_by_id(block_id);
>  }
> diff --git a/include/linux/memory.h b/include/linux/memory.h
> index 97e92e8b556a..d9a0b61cd432 100644
> --- a/include/linux/memory.h
> +++ b/include/linux/memory.h
> @@ -90,7 +90,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size,
>  void remove_memory_block_devices(unsigned long start, unsigned long size);
>  extern void memory_dev_init(void);
>  extern int memory_notify(unsigned long val, void *v);
> -extern struct memory_block *find_memory_block(struct mem_section *);
> +extern struct memory_block *find_memory_block(unsigned long section_nr);
>  typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *);
>  extern int walk_memory_blocks(unsigned long start, unsigned long size,
>  			      void *arg, walk_memory_blocks_func_t func);
> -- 
> 2.17.1

-- 
Michal Hocko
SUSE Labs

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ