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-next>] [day] [month] [year] [list]
Date:   Sat, 18 Sep 2021 07:15:51 +0000
From:   Hyeonggon Yoo <42.hyeyoo@...il.com>
To:     42.hyeyoo@...il.com
Cc:     Christoph Lameter <cl@...ux.com>,
        Pekka Enberg <penberg@...nel.org>,
        David Rientjes <rientjes@...gle.com>,
        Joonsoo Kim <iamjoonsoo.kim@....com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Vlastimil Babka <vbabka@...e.cz>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Subject: [RFC PATCH] mm: slub: merge get_freelist into ___slab_alloc

get_freelist was introduced commit 213eeb9fd9d6 ("slub: Extract
get_freelist from __slab_alloc") and its comment says this function
transfers freelist to the per cpu freelist or deactivate page.

But what it actually does is just deactivating page and returning
its freelist. And the code working with variable 'new' is confusing
because it does nothing.

This function have been unmaintained for a long time and is confusing
reader. So simplify it for better readability.

Signed-off-by: Hyeonggon Yoo <42.hyeyoo@...il.com>
---
 mm/slub.c | 46 +++++++++++-----------------------------------
 1 file changed, 11 insertions(+), 35 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 3d2025f7163b..26fe1eb50d88 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2815,40 +2815,6 @@ static inline bool pfmemalloc_match_unsafe(struct page *page, gfp_t gfpflags)
 	return true;
 }
 
-/*
- * Check the page->freelist of a page and either transfer the freelist to the
- * per cpu freelist or deactivate the page.
- *
- * The page is still frozen if the return value is not NULL.
- *
- * If this function returns NULL then the page has been unfrozen.
- */
-static inline void *get_freelist(struct kmem_cache *s, struct page *page)
-{
-	struct page new;
-	unsigned long counters;
-	void *freelist;
-
-	lockdep_assert_held(this_cpu_ptr(&s->cpu_slab->lock));
-
-	do {
-		freelist = page->freelist;
-		counters = page->counters;
-
-		new.counters = counters;
-		VM_BUG_ON(!new.frozen);
-
-		new.inuse = page->objects;
-		new.frozen = freelist != NULL;
-
-	} while (!__cmpxchg_double_slab(s, page,
-		freelist, counters,
-		NULL, new.counters,
-		"get_freelist"));
-
-	return freelist;
-}
-
 /*
  * Slow path. The lockless freelist is empty or we need to perform
  * debugging duties.
@@ -2874,6 +2840,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
 	void *freelist;
 	struct page *page;
 	unsigned long flags;
+	unsigned long counters;
 
 	stat(s, ALLOC_SLOWPATH);
 
@@ -2920,12 +2887,21 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
 		local_unlock_irqrestore(&s->cpu_slab->lock, flags);
 		goto reread_page;
 	}
+
 	freelist = c->freelist;
 	if (freelist)
 		goto load_freelist;
 
-	freelist = get_freelist(s, page);
+	/* deactivate page */
+	do {
+		freelist = page->freelist;
+		counters = page->counters;
+	} while (!__cmpxchg_double_slab(s, page,
+		freelist, counters,
+		NULL, counters,
+		"deactivate_page"));
 
+	/* there was no free objects in that page  */
 	if (!freelist) {
 		c->page = NULL;
 		local_unlock_irqrestore(&s->cpu_slab->lock, flags);
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ