Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1656564ybe; Wed, 11 Sep 2019 19:33:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk2+tDAsxH+E3l7M5H+l3PCGGyiwaQnHB1z0SJaBgFCLog7QitbFwlnCLi5XbPEwF6FIiu X-Received: by 2002:a17:906:b808:: with SMTP id dv8mr23029233ejb.119.1568255632560; Wed, 11 Sep 2019 19:33:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568255632; cv=none; d=google.com; s=arc-20160816; b=pvkFkRArGWEqTK08BhhZ/72M0nr0k4PZXLa5ZCZetTHhQjFaoxv8l7P5rlHxC1/0bY f09/l9CN8ciHV1wGFJyopXtxFhM4xdydRFQb9QXa9kqB/cSSSgRBZztGkJ/p0J8acexh ebjmwi6UUq0rgQymBmqeSMCqCSaYpxfxermcOjKBY5WxIbRul7vLAs400lKIEQcgx7Rw wzrfovgF0cNjDySd5k3tSIwXrY0i1Zk2zF0oKdCL7K5qaCCfLTwQbH3OSHwPDlsMPIcg MLdrlOkEfwJ/VYrcRnEV/9luxZqwVXNbLkJqo037hLMdGiCEm0G+E/AvorD1oFS3SHZx GyNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=UAihQH4uSn5RAg9F05Rz9nBNcH3iynDYf3mYr8rrHrk=; b=EYCIwHSryN3zSnHMaNXhL4xs1bDsZxMisvdr8W2CjxsWrfImerTpmsBfNle44hBJEj qMGYevB/pWej/MRK+a/CwtLXJS/opj+RcfYFOy0Z9Mf8hyOx81L/bFAx97rTstty1LSL Laqg77y68lr8FFmcigw+E8ZYhsgAYA5vxDdvyT1kCV4moUuWWFEeFLsI3+d4Xrg6LnD0 ZqosHmvoMPW1wxVARg8RHXgCWjCdK249x/+0XcdJhMmRHULP7Jm8AHDsPgMiGQIvrXDf Uc7BV5Hj5IiF1DRwJMSOZ5V7YTVefBH1g7vDWd4u2uCqidA8+qkfYG66Le57+LIhSNmB zi6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dxV3cVXE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l15si12060008ejc.100.2019.09.11.19.33.14; Wed, 11 Sep 2019 19:33:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dxV3cVXE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728993AbfILCbR (ORCPT + 99 others); Wed, 11 Sep 2019 22:31:17 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:57252 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727477AbfILCbR (ORCPT ); Wed, 11 Sep 2019 22:31:17 -0400 Received: by mail-qt1-f202.google.com with SMTP id m6so25946152qtk.23 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=h3qIBPAQVjsfroIZf+sh1DvWeiJveiq5S+P45nmRRdnoFUMyFNQ8Ecz1TwRy8mpfRh OV37ux+0qv8Lw8/NlJ8VhscyuyeZOOcnd6uBcBBABRu/HE5BdrqRSX3OPPtfruZ7Q0Zg 9X/K5q5jOCEz2KHEs3+WieZ1YvrX5bMlorxwih7/KgZI0OIdhN9KeuSEOIQjqYQEG6jM KlKBt6wp1l3DGulrIFcqxo0/wH7i/vKhRKJh8/A8w0RqYAYGl525mSK1oCSyDShPvu92 cAz7GQEAVKKtCUolC14LIEnPUwfYs15ti0rJPYoYg+k8cV6D2daiI2tlYYQWKCVR/rXZ Jqwg== X-Gm-Message-State: APjAAAWqppyANHSUQA/2RVfFaBCKZAeodNhI0q90OSnVZAiZfsRa0NLK 8xlK5NuxNjoXXgas03ybWDDSJpvI7q0= 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.23.0.162.g0b9fbb3734-goog