From patchwork Thu Jul 26 18:53:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 10546321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD7DA112E for ; Thu, 26 Jul 2018 18:54:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EEBB28910 for ; Thu, 26 Jul 2018 18:54:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9268C2BC29; Thu, 26 Jul 2018 18:54:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FBFC28910 for ; Thu, 26 Jul 2018 18:54:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC4AC6B0006; Thu, 26 Jul 2018 14:54:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B25566B0007; Thu, 26 Jul 2018 14:54:03 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99F096B0008; Thu, 26 Jul 2018 14:54:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by kanga.kvack.org (Postfix) with ESMTP id 6C8AD6B0006 for ; Thu, 26 Jul 2018 14:54:03 -0400 (EDT) Received: by mail-qk0-f197.google.com with SMTP id i8-v6so2123460qke.7 for ; Thu, 26 Jul 2018 11:54:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:subject :to:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=ca69DtF7vtiZ184VBWhLpLOHGgdNRqUrKWlPZG+Q+7A=; b=dDcUseN6UaQG6C6nEG+gR2cbJ0d0P+55NcDmshdLHG6Y632g+x0P2IE0NQmxna6uen 5yUkzyn8FZXKx9A+6V0MuGoLnTPVskxzZ72A6ktdby52KcD/lxoZ1m3QidGUxPmFLmCt UbaI0fVsKTUhm4tv7Nkw+5wx30RVTIdgpsCMFLyGWBpqLorvvVjgwLAOEO8lGajDgD5C Fr5uUSQTbMNP6fZ9p13D+GU/9dHW4W1pfFgWvAp1tRGZWPX1n6EUfsL5Ytac72Qv0dHv I6G2N71MeWc+9GSgOMt58PyI6Wf8/xTh+cvpCgIF/6f+kLxu348UQ6qgu1uDaXafcvXH hmOA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of btv1==745586be884==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==745586be884==tonyb@cybernetics.com" X-Gm-Message-State: AOUpUlEyShD/GFzepV6pWi7i5K/347njhn0CzyPeaWassaqz0ADcAfmh qt4ZDVh7RHWJz6MuCHYMCjGC0oC7mh9DT5DrozTjIeZz1GahSr3cpUQn6XfUW0UmxTQryIygPQS pkj6hEb7jAfM6XdCOFanUskw1z15X8c/zLPwN5Pk4o1oGqX59+Ob7oiqCqwAR0LzmfA== X-Received: by 2002:a37:c8e:: with SMTP id 136-v6mr2924218qkm.197.1532631243230; Thu, 26 Jul 2018 11:54:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpekt5/NX8puSRRkQaikIjP6LJ9HJE+oSQugX4BZCY/r+lu6KZJw7s3zLmdhNDDb6OEZTI34 X-Received: by 2002:a37:c8e:: with SMTP id 136-v6mr2924166qkm.197.1532631242204; Thu, 26 Jul 2018 11:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532631242; cv=none; d=google.com; s=arc-20160816; b=c4mnJ+jJSjrbPE3sI2r6VuQLihbzVxA1pgJ4o8C6ugdkR2+aq3weD+6Pa1R3toWTqx /lMNXNexArxSU9E/MMG3wOnz8NXLlqJ3BFqtDgfBpWpGVZrzkk6UPabRcN3BC8SJLWjj CFW/gr3vZQOzCJr9GjXm3TDpMK1YwGVilhUv9ATnp9RCJ+/nUoGaL+DVJ2bSyy587S/Y FgKXRh1bE1z/20kxBo6tcSuoLKI5+TQjyF7ve8I0VZ3SPVZSwjJa8yp7JYhmve3XBums U3ep4ize4n3cloJ6tB9jtqM5Sx6I81YsuURVSlmuZ46k/uMTbNwiw1CUymHRCDBltaI7 3nKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-language:content-transfer-encoding:mime-version:user-agent :date:message-id:to:subject:from:arc-authentication-results; bh=ca69DtF7vtiZ184VBWhLpLOHGgdNRqUrKWlPZG+Q+7A=; b=hIn4uGVIUaqh3RhMYLNq9jgs/x69lVqByiPi4awNX8+M4QR/FXcRg/cJKhUzY4MQa9 dW0S55vBzJFXybQTBeGrQxfKLkY7ksrlCHAEoHoHhFMZ4VCMrzXrL6fTks0J37R3jf1/ R8fS5QjuQBTNCRXw3PgblijTpnwxQbv0Tqi0M3JUop3aha55ony28u6mUrrAY/nnhhml NVjr7tf9+OYHG0ccJyDVLnR5UxngPHWLgAcfkvJAtQq5RxnWs8UL6NXbpemNNzwzQQcg mLBa/4zhJxyptEVhmyM1G4sdz8OM2l5AN/wuuHOZP5ADCJciTJklRf6pkuAZf+HN7RVZ bdyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of btv1==745586be884==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==745586be884==tonyb@cybernetics.com" Received: from mail.cybernetics.com (mail.cybernetics.com. [173.71.130.66]) by mx.google.com with ESMTPS id o39-v6si290697qtf.75.2018.07.26.11.54.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 11:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of btv1==745586be884==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) client-ip=173.71.130.66; Authentication-Results: mx.google.com; spf=pass (google.com: domain of btv1==745586be884==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==745586be884==tonyb@cybernetics.com" X-ASG-Debug-ID: 1532631226-0fb3b01fb33a2730001-v9ZeMO Received: from cybernetics.com ([10.157.1.126]) by mail.cybernetics.com with ESMTP id 2SIaIMvBxFGlPltX (version=SSLv3 cipher=DES-CBC3-SHA bits=112 verify=NO); Thu, 26 Jul 2018 14:53:46 -0400 (EDT) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-ASG-Whitelist: Client Received: from [10.157.2.224] (account tonyb HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 5.1.14) with ESMTPSA id 8303999; Thu, 26 Jul 2018 14:53:46 -0400 From: Tony Battersby Subject: [PATCH 0/3] mpt3sas and dmapool scalability To: Christoph Hellwig , Marek Szyprowski , Matthew Wilcox , Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , iommu@lists.linux-foundation.org, linux-mm@kvack.org, linux-scsi , MPT-FusionLinux.pdl@broadcom.com X-ASG-Orig-Subj: [PATCH 0/3] mpt3sas and dmapool scalability Message-ID: <73ec1f52-d758-05df-fb6a-41d269e910d0@cybernetics.com> Date: Thu, 26 Jul 2018 14:53:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Language: en-US X-Barracuda-Connect: UNKNOWN[10.157.1.126] X-Barracuda-Start-Time: 1532631226 X-Barracuda-Encrypted: DES-CBC3-SHA X-Barracuda-URL: https://10.157.1.122:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 3181 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-BRTS-Status: 1 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: X-Virus-Scanned: ClamAV using ClamSMTP drivers/scsi/mpt3sas is running into a scalability problem with the kernel's DMA pool implementation. With a LSI/Broadcom SAS 9300-8i 12Gb/s HBA and max_sgl_entries=256, during modprobe, mpt3sas does the equivalent of: chain_dma_pool = dma_pool_create(size = 128); for (i = 0; i < 373959; i++) { dma_addr[i] = dma_pool_alloc(chain_dma_pool); } And at rmmod, system shutdown, or system reboot, mpt3sas does the equivalent of: for (i = 0; i < 373959; i++) { dma_pool_free(chain_dma_pool, dma_addr[i]); } dma_pool_destroy(chain_dma_pool); With this usage, both dma_pool_alloc() and dma_pool_free() exhibit O(n^2) complexity, although dma_pool_free() is much worse due to implementation details. On my system, the dma_pool_free() loop above takes about 9 seconds to run. Note that the problem was even worse before commit 74522a92bbf0 ("scsi: mpt3sas: Optimize I/O memory consumption in driver."), where the dma_pool_free() loop could take ~30 seconds because the iteration count was bigger. mpt3sas also has some other DMA pools, but chain_dma_pool is the only one with so many allocations: cat /sys/devices/pci0000:80/0000:80:07.0/0000:85:00.0/pools (manually cleaned up column alignment) poolinfo - 0.1 reply_post_free_array pool 1 21 192 1 reply_free pool 1 1 41728 1 reply pool 1 1 1335296 1 sense pool 1 1 970272 1 chain pool 373959 386048 128 12064 reply_post_free pool 12 12 166528 12 The first two patches in this series improve the scalability of the DMA pool implementation, which significantly reduces the running time of the DMA alloc/free loops. The third patch modifies mpt3sas to replace chain_dma_pool with direct calls to dma_alloc_coherent() and dma_free_coherent(). This eliminates the allocation of up to 12,064 "struct dma_page" per ioc (the exact number depends on the HBA's can_queue and sg_tablesize) and reduces overhead even further. The mpt3sas patch is independent of the dmapool patches; it can be used with or without them. If either the dmapool patches or the mpt3sas patch is applied, then "modprobe mpt3sas", "rmmod mpt3sas", and system shutdown/reboot with mpt3sas loaded are significantly faster. Here are some benchmarks (of DMA alloc/free only, not the entire modprobe/rmmod): dma_pool_create() + dma_pool_alloc() loop, size = 128, count = 373959 original: 350 ms ( 1x) dmapool patches: 18 ms (19x) mpt3sas patch: 7 ms (51x) dma_pool_free() loop + dma_pool_destroy(), size = 128, count = 373959 original: 8901 ms ( 1x) dmapool patches: 19 ms ( 477x) mpt3sas patch: 2 ms (4245x) Considering that LSI/Broadcom offer an out-of-tree vendor driver that works across multiple kernel versions that won't get the dmapool patches, it may be worth it for them to patch mpt3sas to avoid the problem on older kernels. The downside is that the code is a bit more complicated. So I leave it to their judgement whether they think it is worth it to apply the mpt3sas patch.