From patchwork Thu Sep 12 02:31:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 11142031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFB6813BD for ; Thu, 12 Sep 2019 02:31:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ABF9A2085B for ; Thu, 12 Sep 2019 02:31:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dxV3cVXE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ABF9A2085B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A208C6B0005; Wed, 11 Sep 2019 22:31:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9D1C96B0006; Wed, 11 Sep 2019 22:31:17 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BC8F6B0007; Wed, 11 Sep 2019 22:31:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id 66A226B0005 for ; Wed, 11 Sep 2019 22:31:17 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id EBDC1180AD802 for ; Thu, 12 Sep 2019 02:31:16 +0000 (UTC) X-FDA: 75924691794.06.smash44_455a440c9de19 X-Spam-Summary: 2,0,0,7f91c2d8b8f51270,d41d8cd98f00b204,38615xqykccgcydlesksskpi.gsqpmryb-qqozego.svk@flex--yuzhao.bounces.google.com,:cl@linux.com:penberg@kernel.org:rientjes@google.com:iamjoonsoo.kim@lge.com:akpm@linux-foundation.org:kirill@shutemov.name:penguin-kernel@i-love.sakura.ne.jp::linux-kernel@vger.kernel.org:yuzhao@google.com,RULES_HIT:41:69:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3867:3868:3870:3871:3874:4385:5007:6261:6653:9969:10004:10400:11026:11473:11658:11914:12048:12294:12296:12297:12533:12555:12895:13069:13161:13229:13311:13357:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:21796:30036:30054:30070,0,RBL:209.85.222.202:@flex--yuzhao.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:n eutral,C X-HE-Tag: smash44_455a440c9de19 X-Filterd-Recvd-Size: 4654 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Sep 2019 02:31:16 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id x77so27355199qka.11 for ; Wed, 11 Sep 2019 19:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UAihQH4uSn5RAg9F05Rz9nBNcH3iynDYf3mYr8rrHrk=; b=dxV3cVXE53/n1Izfi1qmSoph9IuSLiaXaxqFBRHJmANJRLANTHhygEOBautN5vYLCj +srTSW3d5IK4BcpNRAwvJc7b1sGCmbqo6ca3DM5wec1k67X5dq6ufUWRvyVj0oeVTVVb 7LiOgGVm050aCYaOYcAHnzBSOW2a299xVLa5UBWK3S30G4JTPwqaicDk+g6yyesuRzzY +hovsva0uSsVmoJDBjRVV9zsYBPq8mDDGWU1fDALy3MjJLHrakk7TzBhN6l1noAYNu9I nxPa9xNz4PNTaleaS2NseBdMbaj/J8e8biltj53cK7kDMdmL/HYmZaQeH+WuEPVcRYOX kGzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UAihQH4uSn5RAg9F05Rz9nBNcH3iynDYf3mYr8rrHrk=; b=csGHVrc3p4aUXGAzVPybDeYmuLxVOpl4M9JCPpbEDODyQItaNG95JtAT3730y8Rlyr hFmZ2BZKZOR/VM3rJjLw7RIj7ted2FThqGr6JNm26pWGgPXgm62tpARHxcpts4KeqhsI Cgc6fbMPsJ2OU0zYzl0afH6zLBL2rtbGCDDdsYbdxnq3VYCGw/k4iWmCMvzYJi/GzFW2 vcyBtU5/y6z7ouFBNN8FxbL5B3Q9nbzAkd0DFKzC4f5mDccJbYj7ywF5fJnij4qV9M1d 4nLeMvk+zKaIeANcFQJGR+ZC+U/npcb3fe6MTdWMfgnTQnrnGmdmsf0qIoaDAcP9HBQ4 pS8Q== X-Gm-Message-State: APjAAAUeue0WrEIkaQFgKpYSTRDG84RGcybFQzBD6wZb1V+O7phtxIkO 5n8Cr2uF2tqFhTFpJFToFns5lJpY7cQ= X-Google-Smtp-Source: APXvYqw6hIJan2hXsnpnadFHERmC023740UAU4ylmmV8A0Q1zp8plE7D7Ur2LZ+/xNarODD+17QdVSzAroM= X-Received: by 2002:ad4:4485:: with SMTP id m5mr17828114qvt.153.1568255475679; Wed, 11 Sep 2019 19:31:15 -0700 (PDT) Date: Wed, 11 Sep 2019 20:31:09 -0600 In-Reply-To: <20190912023111.219636-1-yuzhao@google.com> Message-Id: <20190912023111.219636-2-yuzhao@google.com> Mime-Version: 1.0 References: <20190912004401.jdemtajrspetk3fh@box> <20190912023111.219636-1-yuzhao@google.com> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog Subject: [PATCH v2 2/4] mm: clean up validate_slab() From: Yu Zhao To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , "Kirill A . Shutemov" , Tetsuo Handa Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao 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: The function doesn't need to return any value, and the check can be done in one pass. There is a behavior change: before the patch, we stop at the first invalid free object; after the patch, we stop at the first invalid object, free or in use. This shouldn't matter because the original behavior isn't intended anyway. Signed-off-by: Yu Zhao --- mm/slub.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 62053ceb4464..7b7e1ee264ef 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4386,31 +4386,26 @@ static int count_total(struct page *page) #endif #ifdef CONFIG_SLUB_DEBUG -static int validate_slab(struct kmem_cache *s, struct page *page, +static void validate_slab(struct kmem_cache *s, struct page *page, unsigned long *map) { void *p; void *addr = page_address(page); - if (!check_slab(s, page) || - !on_freelist(s, page, NULL)) - return 0; + if (!check_slab(s, page) || !on_freelist(s, page, NULL)) + return; /* Now we know that a valid freelist exists */ bitmap_zero(map, page->objects); get_map(s, page, map); for_each_object(p, s, addr, page->objects) { - if (test_bit(slab_index(p, s, addr), map)) - if (!check_object(s, page, p, SLUB_RED_INACTIVE)) - return 0; - } + u8 val = test_bit(slab_index(p, s, addr), map) ? + SLUB_RED_INACTIVE : SLUB_RED_ACTIVE; - for_each_object(p, s, addr, page->objects) - if (!test_bit(slab_index(p, s, addr), map)) - if (!check_object(s, page, p, SLUB_RED_ACTIVE)) - return 0; - return 1; + if (!check_object(s, page, p, val)) + break; + } } static void validate_slab_slab(struct kmem_cache *s, struct page *page,