* Re: [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE
@ 2020-10-07 2:49 linmiaohe
0 siblings, 0 replies; 4+ messages in thread
From: linmiaohe @ 2020-10-07 2:49 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel
Friendly ping.
> We could use helper memset to fill the swap_map with SWAP_HAS_CACHE instead of a direct loop here to simplify the code. Also we can remove the local variable i and map this way.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
> mm/swapfile.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c index 8feaab31a3a9..b0b629b24e3a 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -975,8 +975,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot) {
> unsigned long idx;
> struct swap_cluster_info *ci;
> - unsigned long offset, i;
> - unsigned char *map;
> + unsigned long offset;
>
> /*
> * Should not even be attempting cluster allocations when huge @@ -996,9 +995,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
> alloc_cluster(si, idx);
> cluster_set_count_flag(ci, SWAPFILE_CLUSTER, CLUSTER_FLAG_HUGE);
>
> - map = si->swap_map + offset;
> - for (i = 0; i < SWAPFILE_CLUSTER; i++)
> - map[i] = SWAP_HAS_CACHE;
> + memset(si->swap_map + offset, SWAP_HAS_CACHE, SWAPFILE_CLUSTER);
> unlock_cluster(ci);
> swap_range_alloc(si, offset, SWAPFILE_CLUSTER);
> *slot = swp_entry(si->type, offset);
> --
> 2.19.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE
@ 2020-10-26 3:03 linmiaohe
0 siblings, 0 replies; 4+ messages in thread
From: linmiaohe @ 2020-10-26 3:03 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm, linux-kernel, Hugh Dickins
Andrew Morton <akpm@linux-foundation.org> wrote:
> On Mon, 21 Sep 2020 08:22:24 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:
>
>> We could use helper memset to fill the swap_map with SWAP_HAS_CACHE
>> instead of a direct loop here to simplify the code. Also we can remove
>> the local variable i and map this way.
>> *slot = swp_entry(si->type, offset);
>
>I suppose so. But it does assume that the ->swapmap array has the type char. If we ever change that, breakage will ensue.
>
The origin code already assumes that the ->swap_map array has the type char. So, this change is ok. ;)
And if we change the type of ->swap_map, each place uses the swap_map should be fixed accordingly.;(
Many thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE
2020-09-21 12:22 Miaohe Lin
@ 2020-10-26 0:14 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2020-10-26 0:14 UTC (permalink / raw)
To: Miaohe Lin; +Cc: linux-mm, linux-kernel, Hugh Dickins
On Mon, 21 Sep 2020 08:22:24 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:
> We could use helper memset to fill the swap_map with SWAP_HAS_CACHE instead
> of a direct loop here to simplify the code. Also we can remove the local
> variable i and map this way.
>
> ...
>
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -975,8 +975,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
> {
> unsigned long idx;
> struct swap_cluster_info *ci;
> - unsigned long offset, i;
> - unsigned char *map;
> + unsigned long offset;
>
> /*
> * Should not even be attempting cluster allocations when huge
> @@ -996,9 +995,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
> alloc_cluster(si, idx);
> cluster_set_count_flag(ci, SWAPFILE_CLUSTER, CLUSTER_FLAG_HUGE);
>
> - map = si->swap_map + offset;
> - for (i = 0; i < SWAPFILE_CLUSTER; i++)
> - map[i] = SWAP_HAS_CACHE;
> + memset(si->swap_map + offset, SWAP_HAS_CACHE, SWAPFILE_CLUSTER);
> unlock_cluster(ci);
> swap_range_alloc(si, offset, SWAPFILE_CLUSTER);
> *slot = swp_entry(si->type, offset);
I suppose so. But it does assume that the ->swapmap array has the type
char. If we ever change that, breakage will ensue.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE
@ 2020-09-21 12:22 Miaohe Lin
2020-10-26 0:14 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Miaohe Lin @ 2020-09-21 12:22 UTC (permalink / raw)
To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe
We could use helper memset to fill the swap_map with SWAP_HAS_CACHE instead
of a direct loop here to simplify the code. Also we can remove the local
variable i and map this way.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/swapfile.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 8feaab31a3a9..b0b629b24e3a 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -975,8 +975,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
{
unsigned long idx;
struct swap_cluster_info *ci;
- unsigned long offset, i;
- unsigned char *map;
+ unsigned long offset;
/*
* Should not even be attempting cluster allocations when huge
@@ -996,9 +995,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
alloc_cluster(si, idx);
cluster_set_count_flag(ci, SWAPFILE_CLUSTER, CLUSTER_FLAG_HUGE);
- map = si->swap_map + offset;
- for (i = 0; i < SWAPFILE_CLUSTER; i++)
- map[i] = SWAP_HAS_CACHE;
+ memset(si->swap_map + offset, SWAP_HAS_CACHE, SWAPFILE_CLUSTER);
unlock_cluster(ci);
swap_range_alloc(si, offset, SWAPFILE_CLUSTER);
*slot = swp_entry(si->type, offset);
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-26 3:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 2:49 [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE linmiaohe
-- strict thread matches above, loose matches on Subject: below --
2020-10-26 3:03 linmiaohe
2020-09-21 12:22 Miaohe Lin
2020-10-26 0:14 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).