From: Andi Kleen <andi@firstfloor.org>
To: linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] scsi: Remove some false sharing in Scsi_Host / Scsi_Device
Date: Fri, 11 Jul 2014 13:25:10 -0700 [thread overview]
Message-ID: <1405110310-3555-1-git-send-email-andi@firstfloor.org> (raw)
From: Andi Kleen <ak@linux.intel.com>
These data structures are accessed by different CPUs and have some
fields which are mostly read only and others which are frequently
written. Separate some common ones into separate cache line
to minimize false sharing while submitting a command.
This allows scsi_dispatch_cmd to do more work with shared clean
cache lines.
- Move the cmd_serial_number to the end before the host data
- Separate write common fields from read mostly fields in
the scsi device
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
include/scsi/scsi_device.h | 4 ++++
include/scsi/scsi_host.h | 15 ++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 5853c91..2064d47 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -98,6 +98,10 @@ struct scsi_device {
unsigned long last_queue_ramp_up; /* last queue ramp up time */
+ /* Mostly read fields below. Move to own cache line to avoid false
+ * sharing */
+ char align1 __attribute__((aligned(SMP_CACHE_BYTES)));
+
unsigned int id, lun, channel;
unsigned int manufacturer; /* Manufacturer of device, for using
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 94844fc..a9371b9 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -654,11 +654,7 @@ struct Scsi_Host {
short unsigned int sg_prot_tablesize;
short unsigned int max_sectors;
unsigned long dma_boundary;
- /*
- * Used to assign serial numbers to the cmds.
- * Protected by the host lock.
- */
- unsigned long cmd_serial_number;
+
unsigned active_mode:2;
unsigned unchecked_isa_dma:1;
@@ -761,6 +757,15 @@ struct Scsi_Host {
struct device *dma_dev;
/*
+ * Used to assign serial numbers to the cmds.
+ * Protected by the host lock.
+ * Hot cache line, keep separate from read only fields.
+ */
+ unsigned long cmd_serial_number
+ __attribute__((aligned(SMP_CACHE_BYTES)));
+ char pad[SMP_CACHE_BYTES - sizeof(unsigned long)];
+
+ /*
* We should ensure that this is aligned, both for better performance
* and also because some compilers (m68k) don't automatically force
* alignment to a long boundary.
--
1.9.3
next reply other threads:[~2014-07-11 20:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 20:25 Andi Kleen [this message]
2014-07-13 11:46 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405110310-3555-1-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®