Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp473391ybz; Fri, 17 Apr 2020 04:42:51 -0700 (PDT) X-Google-Smtp-Source: APiQypL1YStjJtQlmKbLABXRSNeyJzsJ8t/ZtoXYq8I2knHNZ1D1Fw64Jo7CUPogzwLc8HWJYWvw X-Received: by 2002:aa7:d0d8:: with SMTP id u24mr2611862edo.138.1587123771424; Fri, 17 Apr 2020 04:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587123771; cv=none; d=google.com; s=arc-20160816; b=EeTrMWpQL35oLbKjmjxhog6BvFP5Jtd8uuy8G7ZUK0cn7Cp7tgqc25dywPMJj/SFyA wMq0iIuRdIqNVE/Ltgp1PTs6FNUOvD3n5UDLNTPCZMxm5gza1G25SWE7yMetKYBKlC8s qWut3AQsOgEcvHGebGem5H2FDTBjYBUttHlCHh1YIiHZsPMOi3S+d+EXnChR3fR7Ue97 UsF0t3g7Neus/f5jvbP1toZCSHybfy3qT+wHYJwLF7x6+9k2UperkpMyNbV4A7hZzNrl xKF+44BdN/KBXwtHiXdnDou6GTHcV8Tzv+1LKzEFHRejLlc22WdKX2XSMd/kPeKtw83h V4bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=kBuWPWQm1wctgOvEVFG4EmTdG+sTyc89IGQTtRi58b8=; b=A7YG8z2AEOVeQ7jw1bmHWyRtREPZ8JqskfS9M6DSsO1p8ZdkKKyoYLc0EtINBsgoxb b3kYVyeAJLT07aU+4F5P2ciSTIBS2AldOpPULS7LbrC6aveRcQhR+Jyt35sdOlMWODqY arStD0bND4VuR7Seewromsb5EQjIi8NIdHN1641YtfzXm4f+tLVxGQMZmBZB3sFXVZ5d yr8sovjqhgVxWbYFVB+VtWB062L467PSLW/XuGXogpzIWQ0I95AxvwXwQfm51OfuaDeO nzYfSjBuHraagFfdngJg6J0jyJFsKI2wWvSswEkRQczqL5bnx/XfJ77ikmcTebbvFEIT A9Rw== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q24si12016239eju.147.2020.04.17.04.42.27; Fri, 17 Apr 2020 04:42:51 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730369AbgDQLjd (ORCPT + 99 others); Fri, 17 Apr 2020 07:39:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41961 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730267AbgDQLjc (ORCPT ); Fri, 17 Apr 2020 07:39:32 -0400 Received: by mail-wr1-f66.google.com with SMTP id g13so639885wrb.8 for ; Fri, 17 Apr 2020 04:39:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kBuWPWQm1wctgOvEVFG4EmTdG+sTyc89IGQTtRi58b8=; b=jb1oJ2M9uFzUMhEkw0PR+OvtgvYISZhGD1yD2w+uIBUxK1Wl6hgxliFTVltevHybi4 1/fymt4+pHJMZQ7WH4EbO0WZ2DRkhfKqAIsxsBtrPQ2tDfEbLzDCb6wPETDYqh8UYGwM 8AChikKiMsjckiHrbbarQhrinjhJKMiwQij59N6AvjN1OuTP/fuat1LyMuHlfBHynp9/ aSX+H6NeeqLl26XPgmVFhX7EcD0v5pXTsL6m146pe3GwFxWpuMlP8eQ88y1Z30gZ9dx+ hWG9A1m3V1oYgHtr3RIfgB+ldoMMq0j8yQAOOusJfqecyX1UB8qE0APENu8xav8pSKRI xuwg== X-Gm-Message-State: AGi0PuadFU7z9WqfnN5j+LO3RS7J10o6VWK943OTItmWlezwSx6rJR0O olIWBRKYkJGnobuPACBInP0= X-Received: by 2002:adf:cd8c:: with SMTP id q12mr3646224wrj.419.1587123570819; Fri, 17 Apr 2020 04:39:30 -0700 (PDT) Received: from localhost (ip-37-188-130-62.eurotel.cz. [37.188.130.62]) by smtp.gmail.com with ESMTPSA id s11sm11371644wrw.71.2020.04.17.04.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2020 04:39:30 -0700 (PDT) Date: Fri, 17 Apr 2020 13:39:28 +0200 From: Michal Hocko To: Bernard Zhao Cc: Christoph Lameter , 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) Message-ID: <20200417113928.GL26707@dhcp22.suse.cz> References: <1587107376-111722-1-git-send-email-bernard@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1587107376-111722-1-git-send-email-bernard@vivo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 17-04-20 00:09:35, 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. I am sorry but I do not follow. What does this patch optimizes? AFAICS, it adds a branch for everybody for something that is highly unlikely usage. Btw. we already do handle those impossible cases. We could argue that BUG() is a bit harsh reaction but a lack of reports suggests this is not a real problem in fact. So what exactly do you want to achieve here? > 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 > -- Michal Hocko SUSE Labs