Received: by 10.192.165.156 with SMTP id m28csp786659imm; Fri, 13 Apr 2018 07:50:41 -0700 (PDT) X-Google-Smtp-Source: AIpwx48f8rv9sJ27cI6HwL7ThcWCJECY7YaNQ0C8Haq3Da0vXFIwKUi67OlAlrRYumgU1wgk/XJ9 X-Received: by 10.98.160.92 with SMTP id r89mr11661893pfe.235.1523631041770; Fri, 13 Apr 2018 07:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523631041; cv=none; d=google.com; s=arc-20160816; b=KTkCfzFwZEWWUPx5ieSrEbM3/p5MU54EKXhtT9xs/DxDgsB1LxdX51PWA2aerGJLTi lT1B3hnIcxrn7jYbonxHcFgZ3K8mbLBC8QX/5ZQzRvzrCQNKWmlrC77nRtuF8csKf1fi RBfROAJqokQ0umIfqfGEfzX1qlUnaGOi4FF1NyuNilJwWTKtdDyrCBZq+DGA74hCJ1X6 xGURverR/NF4tuh1T2/LdC8DGA8S8dtkLJsOsD2DcfNLY6jUkqSxWh5XFXTYvcxgzSrn rq+93hD4KwS7RRbbutis26LxaHQMns12o8FZSKcwci6khHHqMTUHRqCBLVWV6fyjoj2l mWvA== 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=bLzhJhkE8H64iTerd1+091Yk0lvB8RcJ2RGJEsPAmus=; b=Ay9AC/yFgQMtgxy09PrP1yOYlaYiUxVjCwjMp94jaxzSYIRPbPBecDNDUrRPz9WEIl J+1SfDPcNY6fxRdOAFR+Z0AHGT/TsrTcxB56NCG4r15/Z2Uk5v/BQIpRLXntHB4FCqlG hYWuZBIlCkVRW6L5nATXqADUC9GyOvuFikBl4MD4qm8DwlhlmmuyyPjr84ThBo5dE8a6 UJkNNYeK7F8TlNsv8+guUhQ7VwtDuIPfONO54fmgtncP+jnxU2m3aYDCx4I5ENAeiLlV VoZ93fn1ybt0aJVc0cZrb3NNEP8ZYDUVMO1uZfIM6eHwKVPJ7AZKSAv1OqnJxYKwf+Qu 88Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b03Db571; 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 s198si4106295pgc.151.2018.04.13.07.50.27; Fri, 13 Apr 2018 07:50:41 -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=b03Db571; 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 S1754226AbeDMNuH (ORCPT + 99 others); Fri, 13 Apr 2018 09:50:07 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:32771 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754133AbeDMNuF (ORCPT ); Fri, 13 Apr 2018 09:50:05 -0400 Received: by mail-oi0-f65.google.com with SMTP id 126-v6so8409141oig.0 for ; Fri, 13 Apr 2018 06:50:05 -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=bLzhJhkE8H64iTerd1+091Yk0lvB8RcJ2RGJEsPAmus=; b=b03Db571ICYMUPuX0rvXLNDuB341qKN5unS/sZhDPOf7Wvg4/UmqLXL7dy7dEM/0FL oZAlzWQ3ZWZfB2LeDib8xAxy2/fHFxJwqtu05Gcl5E529i//LlUvclP3Iruc/kzkdsPy EfyCsMUr0t/m8Lx3U3sccs08afZH7b/8RbhLdrxAj3XBYzXLkWHkmPhkQQm2nJv5Z9qd 45zw2PAIsZzWyjSpkxqWDfd8Qv1aVCTefbcm02F1Fz606yx+upZve8ZMCbUGL2fklD7m stlZ0YHMgqHC0xA5Tbq0bPP4MaJY+lyUjjoOG2Btw5gZRd1hmF2FvFZMmGqsbQPh5HNg hHAA== 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=bLzhJhkE8H64iTerd1+091Yk0lvB8RcJ2RGJEsPAmus=; b=BqOHJFn7Por1WupAY7TZU4mN1gGTu2du4M2oNlhwzOCci0yhafTsIO4KTUMtvtxgT0 oHSNJJe2IGbAe7NzyaBr/fJgfi4DNimcBY8qRgSrpyGGl9uUjf4wNPjlnCwYF4aKPFPa b/S2uXd74tKetTLmd8FTYYB9aiYMdT0S4toM4Nl+b4D6Ch9m7pZ2wLEFGjX1+K0U4DAF QX+CCXgWwFzjYsXBZdXXvlIr44Fr224PNRoIoNx8b31ws+17TTqvG6JToTw6Gr79E7QT myWDPk/4C286T8il+hcmAWJ3e0eLG0oU501KGAZRpicrH0UKexs/qFZhOiGs+c5Iculf hQ/w== X-Gm-Message-State: ALQs6tBXuOGUarmmhfuplNVlfP7wv+T6C7kQtOjjOo7/la6Q1+teyU4K /mYcyLZJ4Ztl59r4kIpHpTAhPKg= X-Received: by 2002:aca:490b:: with SMTP id w11-v6mr8680589oia.301.1523627404673; Fri, 13 Apr 2018 06:50:04 -0700 (PDT) Received: from [192.168.27.3] ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id r12-v6sm5205101otr.27.2018.04.13.06.50.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 06:50:03 -0700 (PDT) Reply-To: minyard@acm.org Subject: Re: [PATCH ipmi/kcs_bmc v1] ipmi: kcs_bmc: optimize the data buffers allocation To: "Wang, Haiyue" , 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> <1710edd4-277b-1d2e-5885-a070751ddd2a@linux.intel.com> From: Corey Minyard Message-ID: <1483ac91-5f41-e299-6c74-3dd31aa95ad6@gmail.com> Date: Fri, 13 Apr 2018 08:50:02 -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: <1710edd4-277b-1d2e-5885-a070751ddd2a@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 04/07/2018 02:54 AM, Wang, Haiyue wrote: > Hi Corey, > > Since IPMI 2.0 just defined minimum, no maximum: > > ---- > > KCS/SMIC Input : Required: 40 bytes IPMI Message, minimum > > KCS/SMIC Output : Required: 38 bytes IPMI Message, minimum > Yes, though there are practical maximums that are much smaller than 1000 bytes. > ---- > > We can enlarge the block size for avoiding waste, and make our driver > > support most worst message size case. And I think this patch make > checking > > simple (from 3 to 1), and the code clean, this is the biggest reason I > want to > > change. The TLB is just memory management study from book, no data to > > support access improvement. :) I would argue that the way it is now expresses the intent of the code better than one allocation split into three parts.  Expressing your intent is more important than the number of checks and a minuscule performance improvement.  For me it makes the code easier to understand.  If you had a tool that checked for out-of-bounds memory access, then a single allocation might not find an overrun between the parts.  Smaller allocations tend to result in less memory fragmentation. My preference is to leave it as it is.  However, it's not that important, and if you really want this patch, I can include it. Thanks, -corey > > BR, > > Haiyue > > > On 2018-04-07 10:37, Wang, Haiyue wrote: >> >> >> On 2018-04-07 05:47, Corey Minyard wrote: >>> 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. >>> >> I got this idea from another code review, but that patch allocates 30 >> more >> the same size memory block, reducing the devm_kmalloc call will be >> better. >> For KCS only have 3, may be the key point is memory waste. >> >>> 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. >>> >> As the kcs has memory copy between in/out/kbuffer, put them in the same >> page will be better ? Such as the same TLB ? (Well, I just got this >> from book, >> no real experience of memory accessing performance. And also, I was told >> that using space to save the time. :-)). >> >> Just my stupid thinking. I'm OK to drop this patch if it doesn't help >> with >> performance, or something else. >> >> BR. >> Haiyue >> >>> -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); >>> >>> >> >