From patchwork Mon Oct 4 13:46:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12534179 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 AE2EFC433F5 for ; Mon, 4 Oct 2021 14:40:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4159061373 for ; Mon, 4 Oct 2021 14:40:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4159061373 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 D22D9940044; Mon, 4 Oct 2021 10:40:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD2DC94000B; Mon, 4 Oct 2021 10:40:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC246940044; Mon, 4 Oct 2021 10:40:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id ADEEF94000B for ; Mon, 4 Oct 2021 10:40:37 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6261A182A6CB5 for ; Mon, 4 Oct 2021 14:40:37 +0000 (UTC) X-FDA: 78659016114.20.C719800 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 11E66700864A for ; Mon, 4 Oct 2021 14:40:36 +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=mqDGptlt0kDY2UoM0GUV9bKnRVRX2WNfLX46D22kcB0=; b=USTEUPsDBbmob6TJb6XGCOuYcr H8jmiqFtS4INYqtJpojIZWr8fayv8hMmv+7csW4XewuCHwiG6zNkdVJ74Y+In7hUnWself3bFpf9O SC7eNMZ0LAuWrWf4Xd2yvyaRKPAPyCQ8WG7hN+2BVyQLOAw0+S4SS56hwnmasDd4BOQ4OIP8hOd7X BMU5Q5TjKfZjyMP+t91N65oZA+pTZJoH4GS+IgcmAdgCei9MNVYNNb835MsDCY2hkr3HqbiVn8MqZ r7aLfr0BjtkA0a2zv4JPRqmTN2bsUuV9X+SmVasiOA3VQ2O1+wxe0w0V3+RydvaWAEwcrGubAB+zD TKpKL6/g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXP7n-00H0rV-SD; Mon, 04 Oct 2021 14:39:37 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 40/62] mm/slub: Convert on_freelist() to struct slab Date: Mon, 4 Oct 2021 14:46:28 +0100 Message-Id: <20211004134650.4031813-41-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: rspam02 X-Rspamd-Queue-Id: 11E66700864A X-Stat-Signature: yxbtn7u9q1p7sx5zzr59zh9m3daycsz1 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=USTEUPsD; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1633358436-175158 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: Improves type safety as well as pushing down calls to slab_page(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/slub.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index fd11ca47bce8..10db0ce7fe2a 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1111,29 +1111,29 @@ static int check_slab(struct kmem_cache *s, struct page *page) } /* - * Determine if a certain object on a page is on the freelist. Must hold the + * Determine if a certain object in a slab is on the freelist. Must hold the * slab lock to guarantee that the chains are in a consistent state. */ -static int on_freelist(struct kmem_cache *s, struct page *page, void *search) +static int on_freelist(struct kmem_cache *s, struct slab *slab, void *search) { int nr = 0; void *fp; void *object = NULL; int max_objects; - fp = page->freelist; - while (fp && nr <= page->objects) { + fp = slab->freelist; + while (fp && nr <= slab->objects) { if (fp == search) return 1; - if (!check_valid_pointer(s, page, fp)) { + if (!check_valid_pointer(s, slab_page(slab), fp)) { if (object) { - object_err(s, page, object, + object_err(s, slab_page(slab), object, "Freechain corrupt"); set_freepointer(s, object, NULL); } else { - slab_err(s, page, "Freepointer corrupt"); - page->freelist = NULL; - page->inuse = page->objects; + slab_err(s, slab_page(slab), "Freepointer corrupt"); + slab->freelist = NULL; + slab->inuse = slab->objects; slab_fix(s, "Freelist cleared"); return 0; } @@ -1144,20 +1144,20 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search) nr++; } - max_objects = order_objects(compound_order(page), s->size); + max_objects = order_objects(slab_order(slab), s->size); if (max_objects > MAX_OBJS_PER_PAGE) max_objects = MAX_OBJS_PER_PAGE; - if (page->objects != max_objects) { - slab_err(s, page, "Wrong number of objects. Found %d but should be %d", - page->objects, max_objects); - page->objects = max_objects; + if (slab->objects != max_objects) { + slab_err(s, slab_page(slab), "Wrong number of objects. Found %d but should be %d", + slab->objects, max_objects); + slab->objects = max_objects; slab_fix(s, "Number of objects adjusted"); } - if (page->inuse != page->objects - nr) { - slab_err(s, page, "Wrong object count. Counter is %d but counted were %d", - page->inuse, page->objects - nr); - page->inuse = page->objects - nr; + if (slab->inuse != slab->objects - nr) { + slab_err(s, slab_page(slab), "Wrong object count. Counter is %d but counted were %d", + slab->inuse, slab->objects - nr); + slab->inuse = slab->objects - nr; slab_fix(s, "Object count adjusted"); } return search == NULL; @@ -1315,7 +1315,7 @@ static inline int free_consistency_checks(struct kmem_cache *s, return 0; } - if (on_freelist(s, slab_page(slab), object)) { + if (on_freelist(s, slab, object)) { object_err(s, slab_page(slab), object, "Object already free"); return 0; } @@ -4959,7 +4959,7 @@ static void validate_slab(struct kmem_cache *s, struct slab *slab, slab_lock(slab_page(slab), &flags); - if (!check_slab(s, slab_page(slab)) || !on_freelist(s, slab_page(slab), NULL)) + if (!check_slab(s, slab_page(slab)) || !on_freelist(s, slab, NULL)) goto unlock; /* Now we know that a valid freelist exists */