From patchwork Mon Oct 4 13:46:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12534239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2C4EC433F5 for ; Mon, 4 Oct 2021 14:52:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6403C61175 for ; Mon, 4 Oct 2021 14:52:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6403C61175 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D60DD94004E; Mon, 4 Oct 2021 10:52:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D10E694000B; Mon, 4 Oct 2021 10:52:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD96394004E; Mon, 4 Oct 2021 10:52:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id AA90994000B for ; Mon, 4 Oct 2021 10:52:17 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 701792DEBE for ; Mon, 4 Oct 2021 14:52:17 +0000 (UTC) X-FDA: 78659045514.02.CD3FE36 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 297431000A80 for ; Mon, 4 Oct 2021 14:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=RWRCIWW/YKFbWLDMrwFgdy3wJdFZ6F9Jn8ZHDko0M80=; b=PK/62uzhX4XLdTtLoWAd3VJNJu e1oHl7ScZ1fNgWOJa/sWw7tdBwSPT8L2lnlNqhWfGROtmm+wm43zKfnIPjcxkFK0fl6S6yB1Ct5PF aFZFv31dS1x+ZjFd8U5acJ/Yyoz1Vpp6JgmzLWR0yVIUBaeJd2r5yZT1IE/egG771oEFj90jsghWd ePUU2qr05hWflneR1T/IRlvfSSWrpcphvSPYhpgnbo9zXsBhkevJQJBNn4HaoJ8qnfHD2ZYigkWji kzl8/LLAnop24Y9P9DbjrXs5p8L9pPlYA4rvTMf5V9iPQkQSrWCjui3PzFG+UaeOnpxK7wLbOT45v kFDGe5uw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXPHg-00H1Yp-MS; Mon, 04 Oct 2021 14:50:04 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 50/62] mm/slub: Convert slab_lock() and slab_unlock() to struct slab Date: Mon, 4 Oct 2021 14:46:38 +0100 Message-Id: <20211004134650.4031813-51-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211004134650.4031813-1-willy@infradead.org> References: <20211004134650.4031813-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 297431000A80 X-Stat-Signature: p6nh8niup43wncapruo33r91mtokqsnr Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="PK/62uzh"; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1633359137-910333 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Improve type safety to the point where we can get rid of the assertions that this is not a tail page. Remove a lot of calls to slab_page(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/slub.c | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 86d06f6aa743..5cf305b2b8da 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -48,7 +48,7 @@ * 1. slab_mutex (Global Mutex) * 2. node->list_lock (Spinlock) * 3. kmem_cache->cpu_slab->lock (Local lock) - * 4. slab_lock(page) (Only on some arches or for debugging) + * 4. slab_lock() (Only on some arches or for debugging) * 5. object_map_lock (Only for debugging) * * slab_mutex @@ -64,10 +64,10 @@ * * The slab_lock is only used for debugging and on arches that do not * have the ability to do a cmpxchg_double. It only protects: - * A. page->freelist -> List of object free in a page - * B. page->inuse -> Number of objects in use - * C. page->objects -> Number of objects in page - * D. page->frozen -> frozen state + * A. slab->freelist -> List of object free in a page + * B. slab->inuse -> Number of objects in use + * C. slab->objects -> Number of objects in page + * D. slab->frozen -> frozen state * * Frozen slabs * @@ -417,28 +417,26 @@ static inline unsigned int oo_objects(struct kmem_cache_order_objects x) /* * Per slab locking using the pagelock */ -static __always_inline void __slab_lock(struct page *page) +static __always_inline void __slab_lock(struct slab *slab) { - VM_BUG_ON_PAGE(PageTail(page), page); - bit_spin_lock(PG_locked, &page->flags); + bit_spin_lock(PG_locked, &slab->flags); } -static __always_inline void __slab_unlock(struct page *page) +static __always_inline void __slab_unlock(struct slab *slab) { - VM_BUG_ON_PAGE(PageTail(page), page); - __bit_spin_unlock(PG_locked, &page->flags); + __bit_spin_unlock(PG_locked, &slab->flags); } -static __always_inline void slab_lock(struct page *page, unsigned long *flags) +static __always_inline void slab_lock(struct slab *slab, unsigned long *flags) { if (IS_ENABLED(CONFIG_PREEMPT_RT)) local_irq_save(*flags); - __slab_lock(page); + __slab_lock(slab); } -static __always_inline void slab_unlock(struct page *page, unsigned long *flags) +static __always_inline void slab_unlock(struct slab *slab, unsigned long *flags) { - __slab_unlock(page); + __slab_unlock(slab); if (IS_ENABLED(CONFIG_PREEMPT_RT)) local_irq_restore(*flags); } @@ -468,15 +466,15 @@ static inline bool __cmpxchg_double_slab(struct kmem_cache *s, struct slab *slab /* init to 0 to prevent spurious warnings */ unsigned long flags = 0; - slab_lock(slab_page(slab), &flags); + slab_lock(slab, &flags); if (slab->freelist == freelist_old && slab->counters == counters_old) { slab->freelist = freelist_new; slab->counters = counters_new; - slab_unlock(slab_page(slab), &flags); + slab_unlock(slab, &flags); return true; } - slab_unlock(slab_page(slab), &flags); + slab_unlock(slab, &flags); } cpu_relax(); @@ -507,16 +505,16 @@ static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct slab *slab, unsigned long flags; local_irq_save(flags); - __slab_lock(slab_page(slab)); + __slab_lock(slab); if (slab->freelist == freelist_old && slab->counters == counters_old) { slab->freelist = freelist_new; slab->counters = counters_new; - __slab_unlock(slab_page(slab)); + __slab_unlock(slab); local_irq_restore(flags); return true; } - __slab_unlock(slab_page(slab)); + __slab_unlock(slab); local_irq_restore(flags); } @@ -1353,7 +1351,7 @@ static noinline int free_debug_processing( int ret = 0; spin_lock_irqsave(&n->list_lock, flags); - slab_lock(slab_page(slab), &flags2); + slab_lock(slab, &flags2); if (s->flags & SLAB_CONSISTENCY_CHECKS) { if (!check_slab(s, slab)) @@ -1386,7 +1384,7 @@ static noinline int free_debug_processing( slab_err(s, slab, "Bulk freelist count(%d) invalid(%d)\n", bulk_cnt, cnt); - slab_unlock(slab_page(slab), &flags2); + slab_unlock(slab, &flags2); spin_unlock_irqrestore(&n->list_lock, flags); if (!ret) slab_fix(s, "Object at 0x%p not freed", object); @@ -4214,7 +4212,7 @@ static void list_slab_objects(struct kmem_cache *s, struct slab *slab, void *p; slab_err(s, slab, text, s->name); - slab_lock(slab_page(slab), &flags); + slab_lock(slab, &flags); map = get_map(s, slab); for_each_object(p, s, addr, slab->objects) { @@ -4225,7 +4223,7 @@ static void list_slab_objects(struct kmem_cache *s, struct slab *slab, } } put_map(map); - slab_unlock(slab_page(slab), &flags); + slab_unlock(slab, &flags); #endif } @@ -4958,7 +4956,7 @@ static void validate_slab(struct kmem_cache *s, struct slab *slab, void *addr = slab_address(slab); unsigned long flags; - slab_lock(slab_page(slab), &flags); + slab_lock(slab, &flags); if (!check_slab(s, slab) || !on_freelist(s, slab, NULL)) goto unlock; @@ -4973,7 +4971,7 @@ static void validate_slab(struct kmem_cache *s, struct slab *slab, break; } unlock: - slab_unlock(slab_page(slab), &flags); + slab_unlock(slab, &flags); } static int validate_slab_node(struct kmem_cache *s,