From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: torvalds@linux-foundation.org
Cc: arnd@arndb.de, jakobkoschel@gmail.com,
linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
keescook@chromium.org, jannh@google.com,
linux-kbuild@vger.kernel.org, linux-mm@kvack.org,
netdev@vger.kernel.org, Xiaomeng Tong <xiam0nd.tong@gmail.com>
Subject: [PATCH 4/6] mm: remove iterator use outside the loop
Date: Tue, 1 Mar 2022 15:58:37 +0800 [thread overview]
Message-ID: <20220301075839.4156-5-xiam0nd.tong@gmail.com> (raw)
In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com>
Demonstrations for:
- list_for_each_entry_inside
- list_for_each_entry_reverse_inside
- list_for_each_entry_safe_inside
- list_for_each_entry_from_inside
- list_for_each_entry_continue_reverse_inside
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
mm/list_lru.c | 10 ++++++----
mm/slab_common.c | 7 ++-----
mm/vmalloc.c | 6 +++---
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 0cd5e89ca..d8aab53a7 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -493,20 +493,22 @@ static void memcg_cancel_update_list_lru(struct list_lru *lru,
int memcg_update_all_list_lrus(int new_size)
{
int ret = 0;
- struct list_lru *lru;
+ struct list_lru *ll = NULL;
int old_size = memcg_nr_cache_ids;
mutex_lock(&list_lrus_mutex);
- list_for_each_entry(lru, &memcg_list_lrus, list) {
+ list_for_each_entry_inside(lru, struct list_lru, &memcg_list_lrus, list) {
ret = memcg_update_list_lru(lru, old_size, new_size);
- if (ret)
+ if (ret) {
+ ll = lru;
goto fail;
+ }
}
out:
mutex_unlock(&list_lrus_mutex);
return ret;
fail:
- list_for_each_entry_continue_reverse(lru, &memcg_list_lrus, list)
+ list_for_each_entry_continue_reverse_inside(lru, ll, &memcg_list_lrus, list)
memcg_cancel_update_list_lru(lru, old_size, new_size);
goto out;
}
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 23f2ab071..68a25d385 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -186,8 +186,6 @@ int slab_unmergeable(struct kmem_cache *s)
struct kmem_cache *find_mergeable(unsigned int size, unsigned int align,
slab_flags_t flags, const char *name, void (*ctor)(void *))
{
- struct kmem_cache *s;
-
if (slab_nomerge)
return NULL;
@@ -202,7 +200,7 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align,
if (flags & SLAB_NEVER_MERGE)
return NULL;
- list_for_each_entry_reverse(s, &slab_caches, list) {
+ list_for_each_entry_reverse_inside(s, struct kmem_cache, &slab_caches, list) {
if (slab_unmergeable(s))
continue;
@@ -419,7 +417,6 @@ EXPORT_SYMBOL(kmem_cache_create);
static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)
{
LIST_HEAD(to_destroy);
- struct kmem_cache *s, *s2;
/*
* On destruction, SLAB_TYPESAFE_BY_RCU kmem_caches are put on the
@@ -439,7 +436,7 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)
rcu_barrier();
- list_for_each_entry_safe(s, s2, &to_destroy, list) {
+ list_for_each_entry_safe_inside(s, s2, struct kmem_cache, &to_destroy, list) {
debugfs_slab_release(s);
kfence_shutdown_cache(s);
#ifdef SLAB_SUPPORTS_SYSFS
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 4165304d3..65a9f1db7 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3417,14 +3417,14 @@ long vread(char *buf, char *addr, unsigned long count)
if ((unsigned long)addr + count <= va->va_start)
goto finished;
- list_for_each_entry_from(va, &vmap_area_list, list) {
+ list_for_each_entry_from_inside(iter, va, &vmap_area_list, list) {
if (!count)
break;
- if (!va->vm)
+ if (!iter->vm)
continue;
- vm = va->vm;
+ vm = iter->vm;
vaddr = (char *) vm->addr;
if (addr >= vaddr + get_vm_area_size(vm))
continue;
--
2.17.1
next prev parent reply other threads:[~2022-03-01 7:59 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 7:58 [PATCH 0/6] list_for_each_entry*: make iterator invisiable " Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 1/6] Kbuild: compile kernel with gnu11 std Xiaomeng Tong
2022-03-01 17:59 ` kernel test robot
2022-03-01 20:16 ` Linus Torvalds
2022-03-01 20:54 ` Arnd Bergmann
2022-03-01 21:04 ` Linus Torvalds
2022-03-01 21:15 ` Linus Torvalds
2022-03-01 21:43 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Xiaomeng Tong
2022-03-02 2:52 ` kernel test robot
2022-03-02 13:02 ` James Bottomley
2022-03-03 3:31 ` Xiaomeng Tong
2022-03-06 14:33 ` James Bottomley
2022-03-03 20:02 ` Linus Torvalds
2022-03-04 2:51 ` Xiaomeng Tong
2022-03-05 21:09 ` Linus Torvalds
2022-03-06 0:35 ` Linus Torvalds
2022-03-06 12:19 ` Jakob Koschel
2022-03-06 18:57 ` Linus Torvalds
2022-03-06 14:06 ` Xiaomeng Tong
2022-03-10 23:54 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable Michał Mirosław
2022-03-11 0:46 ` Linus Torvalds
2022-03-12 10:24 ` Michał Mirosław
2022-03-12 21:43 ` Linus Torvalds
2022-03-11 7:15 ` [RFC PATCH] list: test: Add a test for list_traverse David Gow
2022-03-11 14:27 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Daniel Thompson
2022-03-11 18:41 ` Linus Torvalds
2022-03-16 15:45 ` Daniel Thompson
2022-03-01 7:58 ` [PATCH 3/6] kernel: remove iterator use " Xiaomeng Tong
2022-03-01 10:41 ` Greg KH
2022-03-01 11:34 ` Xiaomeng Tong
2022-03-01 11:48 ` Xiaomeng Tong
2022-03-01 7:58 ` Xiaomeng Tong [this message]
2022-03-01 12:19 ` [PATCH 4/6] mm: " Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 5/6] net/core: " Xiaomeng Tong
2022-03-01 12:23 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 6/6] drivers/dma: " Xiaomeng Tong
2022-03-01 12:25 ` Xiaomeng Tong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220301075839.4156-5-xiam0nd.tong@gmail.com \
--to=xiam0nd.tong@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=jakobkoschel@gmail.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox