From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Subject: [PATCH 2/2] device.h: reorganize struct device
Date: Tue, 26 Feb 2019 15:41:08 +0100 [thread overview]
Message-ID: <20190226144108.25891-2-gregkh@linuxfoundation.org> (raw)
In-Reply-To: <20190226144108.25891-1-gregkh@linuxfoundation.org>
struct device is big, around 760 bytes on x86_64. It's not a critical
structure, but it is embedded everywhere, so making it smaller is always
a good thing.
With a recent patch that moved a field from struct device to the private
structure, some benchmarks showed a very odd regression, despite this
structure having nothing to do with those benchmarks. That caused me to
look into the layout of the structure. Using 'pahole', it showed a
number of holes and ways that the structure could be reordered in order
to align some cachelines better, as well as reduce the size of the
overall structure.
This patch removes 16 bytes from 'struct device' on a 64bit system, just
by moving things around. Given we know there are systems with at least
30k devices in memory at once, every little byte counts, and this change
could be a savings of 480k of kernel memory for them. On "normal"
systems the overall memory savings would be much less.
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/device.h | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index b63165276a09..4e6b9a2ab8d0 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -967,18 +967,14 @@ struct dev_links_info {
* a higher-level representation of the device.
*/
struct device {
+ struct kobject kobj;
struct device *parent;
struct device_private *p;
- struct kobject kobj;
const char *init_name; /* initial name of the device */
const struct device_type *type;
- struct mutex mutex; /* mutex to synchronize calls to
- * its driver.
- */
-
struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this
device */
@@ -986,7 +982,14 @@ struct device {
core doesn't touch it */
void *driver_data; /* Driver data, set and get with
dev_set/get_drvdata */
+ struct mutex mutex; /* mutex to synchronize calls to
+ * its driver.
+ */
+
struct dev_links_info links;
+ spinlock_t devres_lock;
+ struct list_head devres_head;
+
struct dev_pm_info power;
struct dev_pm_domain *pm_domain;
@@ -1000,9 +1003,6 @@ struct device {
struct list_head msi_list;
#endif
-#ifdef CONFIG_NUMA
- int numa_node; /* NUMA node this device is close to */
-#endif
const struct dma_map_ops *dma_ops;
u64 *dma_mask; /* dma mask (if dma'able device) */
u64 coherent_dma_mask;/* Like dma_mask, but for
@@ -1032,9 +1032,6 @@ struct device {
dev_t devt; /* dev_t, creates the sysfs "dev" */
u32 id; /* device instance */
- spinlock_t devres_lock;
- struct list_head devres_head;
-
struct klist_node knode_class;
struct class *class;
const struct attribute_group **groups; /* optional groups */
@@ -1043,6 +1040,9 @@ struct device {
struct iommu_group *iommu_group;
struct iommu_fwspec *iommu_fwspec;
+#ifdef CONFIG_NUMA
+ int numa_node; /* NUMA node this device is close to */
+#endif
bool offline_disabled:1;
bool offline:1;
bool of_node_reused:1;
--
2.21.0
next prev parent reply other threads:[~2019-02-26 14:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-26 14:41 [PATCH 1/2] device.h: pack struct dev_links_info Greg Kroah-Hartman
2019-02-26 14:41 ` Greg Kroah-Hartman [this message]
2019-02-26 15:40 ` Rafael J. Wysocki
2019-02-27 9:23 ` Johan Hovold
2019-02-27 9:31 ` Greg Kroah-Hartman
2019-02-27 9:40 ` Johan Hovold
2019-02-27 9:54 ` Greg Kroah-Hartman
2019-02-27 10:59 ` Johan Hovold
2019-02-27 12:06 ` Greg Kroah-Hartman
2019-02-27 13:32 ` Johan Hovold
2019-02-28 8:35 ` Greg Kroah-Hartman
2019-02-28 23:43 ` Rafael J. Wysocki
2019-02-28 13:58 ` [PATCH v2] device.h: reorganize struct device Greg Kroah-Hartman
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=20190226144108.25891-2-gregkh@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).