[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Default to 1MiB alignment when possible (#618255)
From: |
Brian C. Lane |
Subject: |
[PATCH] Default to 1MiB alignment when possible (#618255) |
Date: |
Fri, 10 Dec 2010 11:26:53 -0800 |
NOTE: This applies cleanly to parted-2.1 and parted-2.3
To better support 4k sector drives this changes the
linux_get_optimum_alignment() function to prefer aligning partitions to
DEFAULT_ALIGNMENT (1048576) if possible.
This also modifies the alignment test to take this change into account.
---
include/parted/parted.h | 2 ++
libparted/arch/linux.c | 29 ++++++++++++++++++++++-------
libparted/device.c | 2 +-
tests/t9020-alignment.sh | 2 +-
4 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/include/parted/parted.h b/include/parted/parted.h
index 14bd63e..714d1c6 100644
--- a/include/parted/parted.h
+++ b/include/parted/parted.h
@@ -19,6 +19,8 @@
#ifndef PARTED_H_INCLUDED
#define PARTED_H_INCLUDED
+#define DEFAULT_ALIGNMENT 1048576
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index b506db8..df18439 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2591,13 +2591,28 @@ linux_get_optimum_alignment(const PedDevice *dev)
if (!tp)
return NULL;
- /* If optimal_io_size is 0 _and_ alignment_offset is 0 _and_
- minimum_io_size is a power of 2 then go with the device.c default */
- unsigned long minimum_io_size = blkid_topology_get_minimum_io_size(tp);
- if (blkid_topology_get_optimal_io_size(tp) == 0 &&
- blkid_topology_get_alignment_offset(tp) == 0 &&
- (minimum_io_size & (minimum_io_size - 1)) == 0)
- return NULL;
+ /* When DEFAULT_ALIGNMENT is divisible by the *_io_size or there
+ * are no *_io_size values use the DEFAULT_ALIGNMENT
+ * If one or the other will not divide evenly fall through to
+ * previous logic.
+ */
+ unsigned long optimal_io = blkid_topology_get_optimal_io_size(tp);
+ unsigned long minimum_io = blkid_topology_get_minimum_io_size(tp);
+ if (
+ (!optimal_io && !minimum_io) ||
+ ((optimal_io && (DEFAULT_ALIGNMENT % optimal_io) == 0) &&
+ (minimum_io && (DEFAULT_ALIGNMENT % minimum_io) == 0) ) ||
+ (!minimum_io && optimal_io && (DEFAULT_ALIGNMENT % optimal_io) ==
0) ||
+ (!optimal_io && minimum_io && (DEFAULT_ALIGNMENT % minimum_io) ==
0)
+ ) {
+ /* DASD needs to use minimum alignment */
+ if (dev->type == PED_DEVICE_DASD)
+ return linux_get_minimum_alignment(dev);
+
+ return ped_alignment_new(
+ blkid_topology_get_alignment_offset(tp) / dev->sector_size,
+ DEFAULT_ALIGNMENT / dev->sector_size);
+ }
/* If optimal_io_size is 0 and we don't meet the other criteria
for using the device.c default, return the minimum alignment. */
diff --git a/libparted/device.c b/libparted/device.c
index 64da978..6149f0b 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -544,7 +544,7 @@ ped_device_get_optimum_alignment(const PedDevice *dev)
default:
/* Align to a grain of 1MiB (like vista / win7) */
align = ped_alignment_new(0,
- 1048576 / dev->sector_size);
+ DEFAULT_ALIGNMENT /
dev->sector_size);
}
}
diff --git a/tests/t9020-alignment.sh b/tests/t9020-alignment.sh
index 277fd47..83a5c15 100755
--- a/tests/t9020-alignment.sh
+++ b/tests/t9020-alignment.sh
@@ -36,7 +36,7 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
cat <<EOF > exp || framework_failure
minimum: 7 8
-optimal: 7 64
+optimal: 7 2048
partition alignment: 0 1
EOF
--
1.7.3.2
- [PATCH] Default to 1MiB alignment when possible (#618255),
Brian C. Lane <=