From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE3C6C2D0EF for ; Fri, 17 Apr 2020 15:59:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B8A572078E for ; Fri, 17 Apr 2020 15:59:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8A572078E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 568378E0031; Fri, 17 Apr 2020 11:59:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 517AB8E0023; Fri, 17 Apr 2020 11:59:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 454E98E0031; Fri, 17 Apr 2020 11:59:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id 2C7F98E0023 for ; Fri, 17 Apr 2020 11:59:02 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E36C44FF4 for ; Fri, 17 Apr 2020 15:59:01 +0000 (UTC) X-FDA: 76717805682.24.rod81_149dc7bc9cc52 X-HE-Tag: rod81_149dc7bc9cc52 X-Filterd-Recvd-Size: 2146 Received: from gentwo.org (gentwo.org [3.19.106.255]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 17 Apr 2020 15:59:01 +0000 (UTC) Received: by gentwo.org (Postfix, from userid 1002) id D03D83F9C5; Fri, 17 Apr 2020 15:59:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTP id CF7753E91E; Fri, 17 Apr 2020 15:59:00 +0000 (UTC) Date: Fri, 17 Apr 2020 15:59:00 +0000 (UTC) From: Christopher Lameter X-X-Sender: cl@www.lameter.com To: Bernard Zhao cc: Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel@vivo.com Subject: Re: [PATCH] kmalloc_index optimization(add kmalloc max size check) In-Reply-To: <1587107376-111722-1-git-send-email-bernard@vivo.com> Message-ID: References: <1587107376-111722-1-git-send-email-bernard@vivo.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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: On Fri, 17 Apr 2020, Bernard Zhao wrote: > 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. kmalloc_index(0 already bugs if the allocation is more than 64M ... if (size <= 64 * 1024 * 1024) return 26; BUG(); You could modify that to check for KMALLOC_MAX_SIZE with some more conditionals but then kmalloc_index) is written so that the compiler gets constant folding right. If you have a patch like that then please verify that all c compilers in use perform correct constant folding and do not add unnecessary code.