Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2071714ybe; Sat, 14 Sep 2019 07:22:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwanTv6cdTP0KDe1fX9P4QMp7fOILiCdbthRarvSuFNa1i/ojR/mNhx8KrjTv2HxBFLYWOp X-Received: by 2002:a50:8a9d:: with SMTP id j29mr54287087edj.283.1568470934078; Sat, 14 Sep 2019 07:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568470934; cv=none; d=google.com; s=arc-20160816; b=Yy3+tzhxzfu+f0Ap6DHIxT8fp7cN4lXJ0lcGJ3lZ2rRd+PXI/yLW/ACj+2I9bN5crB UhnUNc+CfUyxvIq9ZiH4QbhccQsVblIWg7PWVb7PXxMWURpkd2zZjWxKo5BvlCPRH/TT 5LIntJ/Sb5Mcde5IV6io97tBJOFHd9u0b7LevicKl5SsthLUEJJxWZLnWNcs82StHmyj kxg2oDqHGwB9ZrgeYA9j8ReIuisONfJtlPvftUcoIabmLb9UKhfny4D0UxmBzx6OViyf oIqqobeZgDdgJzeRsEQrs4vXZPoDHPxxkQtv2inThuW3MhQXe6KbV55RqjP+s802wkSe Giyg== 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=lp1ovS/BiJIimm2KkXbVRdqzH3DGx1lv+fcqWa50ZBQ=; b=hYzIpQk2ULXZRSQkqlMzKjIVNvch3hpoSn3LCfNAjotOM789nb3OKKTxg0cjnz48vO rlcpi5fvoYzdmaU422qSs6mF/R3aFY6eY9kCH9MDufYSLu3S1i5z9XIOCmeqAcwU6E5r 8NyByLVAxZYTQmLZiW6BrFBjjH+LGDnt4ngI2dyevbxTVIbn1On8uv+NCr5com2O005Y M1VO1fX/Qm0PN2ookSTeZc99LThXoBHp9ntiNdNhC+Xu0FScQSKnLXQFXla4zPILZNlF +xhR1MfMosiBVOVDe0sS07Rzh7L70zjMpe4r+0JgwUXRv+6OvIClbE/P+irK2XieZnAJ O4FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Rt4uWEX1; 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 q18si7978510ejp.226.2019.09.14.07.21.50; Sat, 14 Sep 2019 07:22:14 -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=Rt4uWEX1; 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 S2390761AbfINAIA (ORCPT + 99 others); Fri, 13 Sep 2019 20:08:00 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:44751 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388667AbfINAIA (ORCPT ); Fri, 13 Sep 2019 20:08:00 -0400 Received: by mail-qk1-f201.google.com with SMTP id x77so34831857qka.11 for ; Fri, 13 Sep 2019 17:07:58 -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=lp1ovS/BiJIimm2KkXbVRdqzH3DGx1lv+fcqWa50ZBQ=; b=Rt4uWEX1WC7qsSkLnMn+ja/K/Z3LuRUh6r6DRsPyhmXDfrHb/YriCW9u2abhjk3VxE bxtxaY2Tp7jiu+zQxe96ddm2u+q4E64QCoBM3NhEhMdMZ55Jr7T3N+faJlXo8PveLQp8 kgcQNWh4O+jcf95NBm8xdqd/NVgkWSn4vxVpwIEqVHINNAMIScoyEFUs+9THwDEPC9D0 C7h35JMQcp+Xb8IXk1bDu2CcML0EFrI+65MLL8ju5FQTuReB/suY9v5BcpjwMdq+iahb 5A5DXIbsceoB3nj8e8SXZqwdXH/d57EzYDAYurm8Ataj6pN05YrcFH624rF1ek2xNINK u9Tw== 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=lp1ovS/BiJIimm2KkXbVRdqzH3DGx1lv+fcqWa50ZBQ=; b=F+Hk7ek0yeH3AhOftqURgiogp0xf/upYuGVgY5arL7l5s3HbvCkoIOrqYd+z5N1UWZ D0thg45He2Un4PyJMeC4q7XODS4ZWVsvhAmZbDPr/LvWQYNKiZu3D+yCfVfHqUmvULcz QorN+3myuORdYnxLA6M6tfSKUem5e5P+dmSA5I2ikmL/xh2z4rL/XpLJBeAv8BZjKN0Z kKYZgVhU+7nxbrFYziBg7hXL+FvA9LLCxS4CTzX4MBO8v+Dke+DycBDmo+TDEjuWepso YmEHhZkFnpc0QEu03exKTivieQdQa6GEsd3W5um0aD2zyHEN4R+Q/aXjf7KxRB/GdT8z FDRA== X-Gm-Message-State: APjAAAVZDe86jFPoRI91K1F0HOrXFUtm+6Ojl6gl83k6qjXrp1ISX/zy z4XdyG47C91N8ul0Qlv8Hd6py0FZHWQ= X-Received: by 2002:a0c:f8ce:: with SMTP id h14mr22188070qvo.2.1568419677790; Fri, 13 Sep 2019 17:07:57 -0700 (PDT) Date: Fri, 13 Sep 2019 18:07:42 -0600 In-Reply-To: <20190912023111.219636-1-yuzhao@google.com> Message-Id: <20190914000743.182739-1-yuzhao@google.com> Mime-Version: 1.0 References: <20190912023111.219636-1-yuzhao@google.com> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog Subject: [PATCH v3 1/2] 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 8834563cdb4b..445ef8b2aec0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4384,31 +4384,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.237.gc6a4ce50a0-goog