Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp262318ybz; Fri, 17 Apr 2020 00:19:43 -0700 (PDT) X-Google-Smtp-Source: APiQypKHWRgpH5xx/5fuFTRIrVrzr9jiRuXPFXzuW/MfdputR6wtXXDgH2CxwIsfW5DutbBFUDMG X-Received: by 2002:aa7:d344:: with SMTP id m4mr1675378edr.297.1587107983591; Fri, 17 Apr 2020 00:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587107983; cv=none; d=google.com; s=arc-20160816; b=wGIvc8KbzaRiqRtyUfAquxHPmSLBt/buJ9SNUeGw38J46QHjQcjnFaEKqtEjoTZ7Wj i1WQ2YzX+qV854K0Bsuj2L4txZ2Fu5eQSbJWnzXsXRdKXmV8OnjpgFDKAXJTofvHGEKZ yUnLZmX9KHAOmDeTyoVQcywB6O44FuVNq2okdExUEHrO2HwoYKx1huyFt+2bpyTU6QWg +dPWPPEC9S9vQENVYRp5VaKP3iu8PZKqZEa1/biBdGGL0XYa+ZQT0yBfkdgS7XezB91I n335EpMXbRG7bPwvBArf+GnGtyJQskkYaD5w8KH4qPNeXgdXlFoldMC3JKRBZ80/TZRR H1Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=TNkukp3ekn8WkmmFVggP7ZqnVBZOWbnrxiI3f/3k2M0=; b=w7eIT2DorUh6UEWy1y4yQBE/vKFYlWbl1WyZpNZEwTGShbAB3ymsx2+assG9tEELJV s6mBYNGikdtImfR5sw36H9quoAj7aidyiZXSULeKOeLXZWQymHak7HolkJheIlD0IlxH jF7h52B1meim2YC3CKTgp5IvlYdZawxh1ScR/H3VDt2uhcpoivyJvu68YmJRXu0vBaAU CuiRM/18dwef+CgY4c9epD6HbVpmJpD5i0Uj/9PdF911T12IZoU1evMW1pPZ7NOK/6kG CcK/CQcLvZWeY6LisQWXmVC3qom8Afo7zKCZCMOXipqZ0axSQlBv7Ild3GSNfifpXCAz ScnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p3si232077edm.574.2020.04.17.00.19.20; Fri, 17 Apr 2020 00:19:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729006AbgDQHRu (ORCPT + 99 others); Fri, 17 Apr 2020 03:17:50 -0400 Received: from m176115.mail.qiye.163.com ([59.111.176.115]:38929 "EHLO m176115.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728808AbgDQHRt (ORCPT ); Fri, 17 Apr 2020 03:17:49 -0400 X-Greylist: delayed 459 seconds by postgrey-1.27 at vger.kernel.org; Fri, 17 Apr 2020 03:17:48 EDT Received: from ubuntu.localdomain (unknown [157.0.31.122]) by m176115.mail.qiye.163.com (Hmail) with ESMTPA id 37C2C665296; Fri, 17 Apr 2020 15:10:06 +0800 (CST) From: Bernard Zhao To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: kernel@vivo.com, Bernard Zhao Subject: [PATCH] kmalloc_index optimization(add kmalloc max size check) Date: Fri, 17 Apr 2020 00:09:35 -0700 Message-Id: <1587107376-111722-1-git-send-email-bernard@vivo.com> X-Mailer: git-send-email 2.7.4 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZT1VJS09CQkJCSUhMS01LTllXWShZQU hPN1dZLVlBSVdZCQ4XHghZQVk1NCk2OjckKS43PlkG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Myo6EQw6ATg4LA4jAxg#CQJD LTcKCz5VSlVKTkNMSktMT0tNT09CVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSUlZV1kIAVlBSUtOQzcG X-HM-Tid: 0a7186f922229373kuws37c2c665296 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kmalloc size should never exceed KMALLOC_MAX_SIZE. kmalloc_index realise if size is exceed KMALLOC_MAX_SIZE, e.g 64M, kmalloc_index just return index 26, but never check with OS`s max kmalloc config KMALLOC_MAX_SIZE. This index`s kmalloc caches maybe not create in function create_kmalloc_caches. We can throw an warninginfo in kmalloc at the beginning, instead of being guaranteed by the buddy alloc behind. Signed-off-by: Bernard Zhao --- include/linux/slab.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/slab.h b/include/linux/slab.h index 6d45488..59b60d2 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -351,6 +351,10 @@ static __always_inline unsigned int kmalloc_index(size_t size) if (!size) return 0; + /* size should never exceed KMALLOC_MAX_SIZE. */ + if (size > KMALLOC_MAX_SIZE) + WARN(1, "size exceed max kmalloc size!\n"); + if (size <= KMALLOC_MIN_SIZE) return KMALLOC_SHIFT_LOW; -- 2.7.4