From patchwork Wed Sep 4 07:40:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier X-Patchwork-Id: 13789898 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D5E0CA0ED3 for ; Wed, 4 Sep 2024 07:43:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B8B16B029C; Wed, 4 Sep 2024 03:43:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5686E8D0228; Wed, 4 Sep 2024 03:43:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4571A6B0329; Wed, 4 Sep 2024 03:43:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 285A46B029C for ; Wed, 4 Sep 2024 03:43:00 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C36A9A0DBC for ; Wed, 4 Sep 2024 07:42:59 +0000 (UTC) X-FDA: 82526264478.22.9340F8F Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by imf20.hostedemail.com (Postfix) with ESMTP id 516181C000D for ; Wed, 4 Sep 2024 07:42:56 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=oJbTP+xk; spf=pass (imf20.hostedemail.com: domain of xavier_qy@163.com designates 220.197.31.3 as permitted sender) smtp.mailfrom=xavier_qy@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725435683; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=jk8fexfZEn7Heh+nv5LLKvbujnEfLBEC6g0IUs8GINg=; b=TBK5Xri2PbGXBgDb7G8LxgcwLoWM4cvF+63JDykW83YGneSINnXlpM3PYNhFHu6KNdi15h vqjk9+QO5UEg+hX1cBq2E17RtTGV4dOSVmPndxjb1rMaRLhO6bd6b0/N6QSjSX+iZQzbVT zA4OnDnQAXvfVYulSe0MNy01O3NCtJM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725435683; a=rsa-sha256; cv=none; b=gPnslIuOlUI1oS2xf7ugIWMBhmUQffxHqAEt8s0/ws8Skg/aC1Hi7eZVFtW6n/s9RTNOV2 lPAJ4blzum5H6Q8thHyqWaQsM2KWRA3veRfZutwM2m+ZddzRB55YS0RK5TizO3EPLMyfKb K7RhDgfE51eo+DGYvfQyvRnV681i9E4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=oJbTP+xk; spf=pass (imf20.hostedemail.com: domain of xavier_qy@163.com designates 220.197.31.3 as permitted sender) smtp.mailfrom=xavier_qy@163.com; dmarc=pass (policy=none) header.from=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=jk8fe xfZEn7Heh+nv5LLKvbujnEfLBEC6g0IUs8GINg=; b=oJbTP+xkQjBKvRkmR38tp O7d6QnpanQc0Pyao7S+TYSExyx0fLz4bj1J7rhHnDTXww/mQ2m8IQYPkA5xtAwqq DHbOpRUMWv+u7XugnH4i1TXUeLzBwHdodpgV1VpZG1nNhfZ01257Xh1dvgAZhR0J iwxm1//hwvktyJjR+RpwRc= Received: from localhost (unknown [101.132.132.191]) by gzga-smtp-mta-g3-5 (Coremail) with SMTP id _____wCn7y32DthmZiNYLA--.29731S2; Wed, 04 Sep 2024 15:40:39 +0800 (CST) From: Xavier To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xavier Subject: [PATCH v1] mm/slab: Optimize the code logic in find_mergeable() Date: Wed, 4 Sep 2024 15:40:37 +0800 Message-Id: <20240904074037.710692-1-xavier_qy@163.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: _____wCn7y32DthmZiNYLA--.29731S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7GF1UWryxWw4rAr4UCw4Uurg_yoWftrc_Zr 4vvw13CFn7Xr1akFn2vrW5WFW5ua4vvr17W342qF43trW2yr4UZ3ykZFykWFZ5W3yxZrZx Z3yDAry5Wr17GjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRNlksDUUUUU== X-Originating-IP: [101.132.132.191] X-CM-SenderInfo: 50dyxvpubt5qqrwthudrp/1tbiZR05EGXAnsRC8wAEsb X-Rspamd-Queue-Id: 516181C000D X-Stat-Signature: xmfakuza8s5hman5awizwtbbz6r9fady X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725435776-913705 X-HE-Meta: U2FsdGVkX185MspNs5wiFfxXkgMKt6KD+vd2jHWDQ40i6bF4xA91x4J/qzvH+/HWTSXnDhyJ2LaVrbVuDx8UbN1raamuExkHuLSJKBm/NQ1yINpoW4IEEVR/1aG96cQWou/sL0Wc8u/723y6EXHRIhTnYcTSWHZZ91GxZju/Js7XIeIdhHCVuYGRH7Cwcc0Vhn1Q3zjEJyuJt/qvI0aE2EKHDJg8eBG6eiTaZYPwUCvzj/HvDBQjQ9P4Oj/mk/Yoy4Xwi2DwFLY5C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VPdhsYHkmqcG+bESE50Jx5DCN7Z2tgT+gY0rYWni8rTcD3pJDTIKgX7imHWyYW/HATNgPYBtxkjSARRVs+B6qboVxuw7599bSdwyN9MVoxnMoijGhkxUvGv2XwHY7Bo+A8U2O1XujZNPOrGoeK1E0/m+fFGdq5LMAY3+OhYtQP 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: List-Subscribe: List-Unsubscribe: We can first assess the flags, if it's unmergeable, there's no need to calculate the size and align. Signed-off-by: Xavier --- mm/slab_common.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 40b582a014b8..aaf5989f7ffe 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -169,14 +169,15 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, if (ctor) return NULL; - size = ALIGN(size, sizeof(void *)); - align = calculate_alignment(flags, align, size); - size = ALIGN(size, align); flags = kmem_cache_flags(flags, name); if (flags & SLAB_NEVER_MERGE) return NULL; + size = ALIGN(size, sizeof(void *)); + align = calculate_alignment(flags, align, size); + size = ALIGN(size, align); + list_for_each_entry_reverse(s, &slab_caches, list) { if (slab_unmergeable(s)) continue;