Received: by 10.213.65.68 with SMTP id h4csp26659imn; Fri, 6 Apr 2018 14:50:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/cqPkkBGT2AWtriRyXqlNKjZZTin2BQHoHKZAjqcJVlZtsBQiNA9Mg1wBKzKBR7C/vE12j X-Received: by 2002:a17:902:8c84:: with SMTP id t4-v6mr28800605plo.357.1523051453544; Fri, 06 Apr 2018 14:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523051453; cv=none; d=google.com; s=arc-20160816; b=SlgWdwEPdMLP5j2KkzkFJwHRfFrL6BrHGJhatCv9SFlQpjbfb9/BjEqRB3VaZXHr3k Nay4VH8JfH+ziqPcsgUWHK+9IfbZK1csUxE0ItUUqXxwhSQ6AQhSV0COG9fuNLdU6ara WGqX4gqLUKlUNe7OPooSwMx2FYjTO/iXbse67KINLB0+cmFSnWvrbRFWMkqMwuN37Pqe GUUstxcV5c1gdyoCa2YxyziEYBvbTJLLSAu5l8wVNPAdzoKz001BnKulXQhpe6tFy/WL ymOdIpvs87NI/0FpWEU/7QVNAUWERaKD+KIuohmyLKkIXetAcDJ+D9gYxU1Nc33CHFOI fqCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:reply-to:dkim-signature :arc-authentication-results; bh=qT9EVksZwYdip5xH8AfNX5L3AmmzHaz6lPYlLod7sB8=; b=kVvDRp0Q9rlMMLQqTZW22V7HOrfAZX/9Az2A3EV4nOfXx5r/sZL7scW2WS6bYvNi3J 3Nz7gM6z5981b2rSeImZUe/hvMZRInNXmAMJd3xjPQIldKOFftPcuZYob6WmQRLspgU2 009rsmlNAc0cEpEP6DCHChjScC3xZi4gLLX69n1qAnShsVpo6bnZcpNQPOLVz1getjSo tID+P9rlv/Dak9/Im2o/PlwGLvwFToJQlMqGsJtAzc3bTPpSy6pr5eAZYAy5D7W8WbOx MSrTgcHqWDB0FyEIhMF6/XqyNHRnuUSEW2rd56YepYGe8BCgV0CukwgnTJVFeNf5CDa8 b6Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OUDQrAHY; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10si7648990pgc.400.2018.04.06.14.50.14; Fri, 06 Apr 2018 14:50:53 -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=@gmail.com header.s=20161025 header.b=OUDQrAHY; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751869AbeDFVr1 (ORCPT + 99 others); Fri, 6 Apr 2018 17:47:27 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:37872 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751417AbeDFVr0 (ORCPT ); Fri, 6 Apr 2018 17:47:26 -0400 Received: by mail-oi0-f66.google.com with SMTP id f63-v6so2394256oic.4 for ; Fri, 06 Apr 2018 14:47:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=qT9EVksZwYdip5xH8AfNX5L3AmmzHaz6lPYlLod7sB8=; b=OUDQrAHYrrv+jd40Ws6Q0+T4wy7/tUt8rXC0I0mxqMRiTfXjf6EOigC7nI35pGvTHL p+Rca4+QLh835PYxLBEvjAmqW4PTx/nuohNzNgtNw0MR88JacKJxhF5ZKXmOm63KCunw YD+7la6L4m843lXzCMD8oOgtwlURuQIElvSDaUelVPcpqHgIuE1C+UKBmq+S8azV6Mgi GoY/oqapFtVrXeVmUviZnoE6JBS5ly1WwuxOfK4hmt8S5aY1K7IPirsi9lrTqg+nxfyR hgSJNKgtZMN54zFfUkYeHu7/ulbKYGMLYnXXzr8DqoXClFHStav20shZyCqcmG3Ea8ZZ qUyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=qT9EVksZwYdip5xH8AfNX5L3AmmzHaz6lPYlLod7sB8=; b=ND2d0mubNgQvBoYheWQ4xFpYEPPQn72SRyDnWOfB45gyYsZwrs2gsyW3SA1bonjWi9 AHZndsrK5ysaet4lETYlrifyYWyNUxN1rw5GAKpHy9ZKzKY/Qrl1dKTBVxL4qhpbEbqe AySh7b2wg0905bo5FA6iCkYPKxEiVEU9RrMmTntZhJ298d4gUzEf6F6DGAzLwy6QhB9M SHM7gD/RLtK7YykCLYWc9DsQ2s/IA9exsGp9yg+Bflp/RUIdZDOqMBLITjpDlQ/sdD+/ HaFMkUbwyJSSzjeK5mKh1rVEumBq4JbjKU64oCiAdY80OI+HqB9XPBp/3srm0KuIuIYh ZUDg== X-Gm-Message-State: AElRT7HNJeVQ90SCBWS1tQ9X72/7GpXbQgDcVsrIWMYzFXYutXbEFcWV UgkF3fJVV52wbbqBnFQ4yrdhD8c= X-Received: by 2002:aca:3191:: with SMTP id x139-v6mr15319550oix.283.1523051245636; Fri, 06 Apr 2018 14:47:25 -0700 (PDT) Received: from [192.168.27.3] ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id e15-v6sm6155171oic.18.2018.04.06.14.47.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Apr 2018 14:47:24 -0700 (PDT) Reply-To: minyard@acm.org Subject: Re: [PATCH ipmi/kcs_bmc v1] ipmi: kcs_bmc: optimize the data buffers allocation To: Haiyue Wang , minyard@acm.org, openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <1521116452-4993-1-git-send-email-haiyue.wang@linux.intel.com> From: Corey Minyard Message-ID: Date: Fri, 6 Apr 2018 16:47:23 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1521116452-4993-1-git-send-email-haiyue.wang@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/15/2018 07:20 AM, Haiyue Wang wrote: > Allocate a continuous memory block for the three KCS data buffers with > related index assignment. I'm finally getting to this. Is there a reason you want to do this?  In general, it's better to not try to outsmart your base system.  Depending on the memory allocator, in this case, you might actually use more memory.  You probably won't use any less. In the original case, you allocate three 1000 byte buffers, resulting in 3 1024 byte slab allocated. In the changed case, you will allocate a 3000 byte buffer, resulting in a single 4096 byte slab allocation, wasting 1024 more bytes of memory. -corey > Signed-off-by: Haiyue Wang > --- > drivers/char/ipmi/kcs_bmc.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c > index fbfc05e..dc19c0d 100644 > --- a/drivers/char/ipmi/kcs_bmc.c > +++ b/drivers/char/ipmi/kcs_bmc.c > @@ -435,6 +435,7 @@ static const struct file_operations kcs_bmc_fops = { > struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel) > { > struct kcs_bmc *kcs_bmc; > + void *buf; > > kcs_bmc = devm_kzalloc(dev, sizeof(*kcs_bmc) + sizeof_priv, GFP_KERNEL); > if (!kcs_bmc) > @@ -448,11 +449,12 @@ struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel) > mutex_init(&kcs_bmc->mutex); > init_waitqueue_head(&kcs_bmc->queue); > > - kcs_bmc->data_in = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL); > - kcs_bmc->data_out = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL); > - kcs_bmc->kbuffer = devm_kmalloc(dev, KCS_MSG_BUFSIZ, GFP_KERNEL); > - if (!kcs_bmc->data_in || !kcs_bmc->data_out || !kcs_bmc->kbuffer) > + buf = devm_kmalloc_array(dev, 3, KCS_MSG_BUFSIZ, GFP_KERNEL); > + if (!buf) > return NULL; > + kcs_bmc->data_in = buf; > + kcs_bmc->data_out = buf + KCS_MSG_BUFSIZ; > + kcs_bmc->kbuffer = buf + KCS_MSG_BUFSIZ * 2; > > kcs_bmc->miscdev.minor = MISC_DYNAMIC_MINOR; > kcs_bmc->miscdev.name = dev_name(dev);