[WIP] Backport high-priority patch

This commit is contained in:
Daniel Zatovic 2024-04-10 14:19:17 +02:00
parent e8fd491bd7
commit c76f6b3d1c

View File

@ -16,24 +16,27 @@ Subject: [PATCH] WIP: Add support for high-priority dm-crypt flag.
tests/device-test | 28 +++++++++++++++++++++++++--- tests/device-test | 28 +++++++++++++++++++++++++---
10 files changed, 69 insertions(+), 8 deletions(-) 10 files changed, 69 insertions(+), 8 deletions(-)
diff --git a/lib/libcryptsetup.h b/lib/libcryptsetup.h Index: cryptsetup-2.3.7/lib/libcryptsetup.h
index 88d03bab..72bc12fc 100644 ===================================================================
--- a/lib/libcryptsetup.h --- cryptsetup-2.3.7.orig/lib/libcryptsetup.h
+++ b/lib/libcryptsetup.h +++ cryptsetup-2.3.7/lib/libcryptsetup.h
@@ -1517,6 +1517,8 @@ int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot); @@ -1113,6 +1113,11 @@ int crypt_keyslot_destroy(struct crypt_d
#define CRYPT_ACTIVATE_RECALCULATE_RESET (UINT32_C(1) << 26) #define CRYPT_ACTIVATE_NO_READ_WORKQUEUE (1 << 24)
/** dm-verity: try to use tasklets */ /** dm-crypt: bypass internal workqueue and process write requests synchronously. */
#define CRYPT_ACTIVATE_TASKLETS (UINT32_C(1) << 27) #define CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE (1 << 25)
+#define CRYPT_ACTIVATE_RECALCULATE_RESET (UINT32_C(1) << 26)
+/** dm-verity: try to use tasklets */
+#define CRYPT_ACTIVATE_TASKLETS (UINT32_C(1) << 27)
+/** dm-crypt: use high-priority workqueues */ +/** dm-crypt: use high-priority workqueues */
+#define CRYPT_ACTIVATE_HIGH_PRIORITY (UINT32_C(1) << 28) +#define CRYPT_ACTIVATE_HIGH_PRIORITY (UINT32_C(1) << 28)
/** /**
* Active device runtime attributes * Active device runtime attributes
diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c Index: cryptsetup-2.3.7/lib/libdevmapper.c
index ebee542a..2e77849c 100644 ===================================================================
--- a/lib/libdevmapper.c --- cryptsetup-2.3.7.orig/lib/libdevmapper.c
+++ b/lib/libdevmapper.c +++ cryptsetup-2.3.7/lib/libdevmapper.c
@@ -170,6 +170,9 @@ static void _dm_set_crypt_compat(struct crypt_device *cd, @@ -177,6 +177,9 @@ static void _dm_set_crypt_compat(struct
if (_dm_satisfies_version(1, 22, 0, crypt_maj, crypt_min, crypt_patch)) if (_dm_satisfies_version(1, 22, 0, crypt_maj, crypt_min, crypt_patch))
_dm_flags |= DM_CRYPT_NO_WORKQUEUE_SUPPORTED; _dm_flags |= DM_CRYPT_NO_WORKQUEUE_SUPPORTED;
@ -43,7 +46,7 @@ index ebee542a..2e77849c 100644
_dm_crypt_checked = true; _dm_crypt_checked = true;
} }
@@ -571,19 +574,22 @@ static char *get_dm_crypt_params(const struct dm_target *tgt, uint32_t flags) @@ -568,19 +571,22 @@ static char *get_dm_crypt_params(const s
num_options++; num_options++;
if (flags & CRYPT_ACTIVATE_IV_LARGE_SECTORS) if (flags & CRYPT_ACTIVATE_IV_LARGE_SECTORS)
num_options++; num_options++;
@ -68,7 +71,7 @@ index ebee542a..2e77849c 100644
(tgt->u.crypt.sector_size != SECTOR_SIZE) ? (tgt->u.crypt.sector_size != SECTOR_SIZE) ?
_uf(sector_feature, sizeof(sector_feature), "sector_size", tgt->u.crypt.sector_size) : "", _uf(sector_feature, sizeof(sector_feature), "sector_size", tgt->u.crypt.sector_size) : "",
integrity_dm); integrity_dm);
@@ -1593,6 +1599,14 @@ static int check_retry(struct crypt_device *cd, uint32_t *dmd_flags, uint32_t dm @@ -1586,6 +1592,14 @@ static int check_retry(struct crypt_devi
ret = 1; ret = 1;
} }
@ -83,7 +86,7 @@ index ebee542a..2e77849c 100644
return ret; return ret;
} }
@@ -1986,6 +2000,8 @@ static int _dm_target_query_crypt(struct crypt_device *cd, uint32_t get_flags, @@ -1941,6 +1955,8 @@ static int _dm_target_query_crypt(struct
*act_flags |= CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE; *act_flags |= CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE;
else if (!strcasecmp(arg, "iv_large_sectors")) else if (!strcasecmp(arg, "iv_large_sectors"))
*act_flags |= CRYPT_ACTIVATE_IV_LARGE_SECTORS; *act_flags |= CRYPT_ACTIVATE_IV_LARGE_SECTORS;
@ -92,11 +95,11 @@ index ebee542a..2e77849c 100644
else if (sscanf(arg, "integrity:%u:", &val) == 1) { else if (sscanf(arg, "integrity:%u:", &val) == 1) {
tgt->u.crypt.tag_size = val; tgt->u.crypt.tag_size = val;
rintegrity = strchr(arg + strlen("integrity:"), ':'); rintegrity = strchr(arg + strlen("integrity:"), ':');
diff --git a/lib/luks2/luks2_json_metadata.c b/lib/luks2/luks2_json_metadata.c Index: cryptsetup-2.3.7/lib/luks2/luks2_json_metadata.c
index 22f3e3df..00f111f4 100644 ===================================================================
--- a/lib/luks2/luks2_json_metadata.c --- cryptsetup-2.3.7.orig/lib/luks2/luks2_json_metadata.c
+++ b/lib/luks2/luks2_json_metadata.c +++ cryptsetup-2.3.7/lib/luks2/luks2_json_metadata.c
@@ -1566,6 +1566,7 @@ static const struct { @@ -1386,6 +1386,7 @@ static const struct {
{ CRYPT_ACTIVATE_NO_JOURNAL, "no-journal" }, { CRYPT_ACTIVATE_NO_JOURNAL, "no-journal" },
{ CRYPT_ACTIVATE_NO_READ_WORKQUEUE, "no-read-workqueue" }, { CRYPT_ACTIVATE_NO_READ_WORKQUEUE, "no-read-workqueue" },
{ CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE, "no-write-workqueue" }, { CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE, "no-write-workqueue" },
@ -104,45 +107,43 @@ index 22f3e3df..00f111f4 100644
{ 0, NULL } { 0, NULL }
}; };
diff --git a/lib/utils_dm.h b/lib/utils_dm.h Index: cryptsetup-2.3.7/lib/utils_dm.h
index dbbd4701..a9ca9add 100644 ===================================================================
--- a/lib/utils_dm.h --- cryptsetup-2.3.7.orig/lib/utils_dm.h
+++ b/lib/utils_dm.h +++ cryptsetup-2.3.7/lib/utils_dm.h
@@ -76,6 +76,7 @@ static inline uint32_t act2dmflags(uint32_t act_flags) @@ -73,6 +73,9 @@ static inline uint32_t act2dmflags(uint3
#define DM_VERITY_PANIC_CORRUPTION_SUPPORTED (1 << 24) /* dm-verity panic on corruption */
#define DM_CRYPT_NO_WORKQUEUE_SUPPORTED (1 << 25) /* dm-crypt suppot for bypassing workqueues */
#define DM_INTEGRITY_FIX_HMAC_SUPPORTED (1 << 26) /* hmac covers also superblock */ #define DM_INTEGRITY_FIX_HMAC_SUPPORTED (1 << 26) /* hmac covers also superblock */
#define DM_INTEGRITY_RESET_RECALC_SUPPORTED (1 << 27) /* dm-integrity automatic recalculation supported */ +#define DM_INTEGRITY_RESET_RECALC_SUPPORTED (1 << 27) /* dm-integrity automatic recalculation supported */
#define DM_VERITY_TASKLETS_SUPPORTED (1 << 28) /* dm-verity tasklets supported */ +#define DM_VERITY_TASKLETS_SUPPORTED (1 << 28) /* dm-verity tasklets supported */
+#define DM_CRYPT_HIGH_PRIORITY_SUPPORTED (1 << 29) /* dm-crypt high priority workqueue flag supported */ +#define DM_CRYPT_HIGH_PRIORITY_SUPPORTED (1 << 29) /* dm-crypt high priority workqueue flag supported */
typedef enum { DM_CRYPT = 0, DM_VERITY, DM_INTEGRITY, DM_LINEAR, DM_ERROR, DM_ZERO, DM_UNKNOWN } dm_target_type; typedef enum { DM_CRYPT = 0, DM_VERITY, DM_INTEGRITY, DM_LINEAR, DM_ERROR, DM_ZERO, DM_UNKNOWN } dm_target_type;
enum tdirection { TARGET_EMPTY = 0, TARGET_SET, TARGET_QUERY }; enum tdirection { TARGET_SET = 1, TARGET_QUERY };
diff --git a/man/common_options.adoc b/man/common_options.adoc Index: cryptsetup-2.3.7/src/cryptsetup.c
index 841929bd..4cba277d 100644 ===================================================================
--- a/man/common_options.adoc --- cryptsetup-2.3.7.orig/src/cryptsetup.c
+++ b/man/common_options.adoc +++ cryptsetup-2.3.7/src/cryptsetup.c
@@ -773,6 +773,17 @@ that it is maximal value, it is decreased automatically if CPU online @@ -87,6 +87,7 @@ static int opt_perf_same_cpu_crypt = 0;
count is lower. This option is not available for PBKDF2. static int opt_perf_submit_from_crypt_cpus = 0;
endif::[] static int opt_perf_no_read_workqueue = 0;
static int opt_perf_no_write_workqueue = 0;
+static int opt_perf_high_priority = 0;
static int opt_test_passphrase = 0;
static int opt_tcrypt_hidden = 0;
static int opt_tcrypt_system = 0;
@@ -219,6 +220,9 @@ static void _set_activation_flags(uint32
if (opt_perf_no_read_workqueue)
*flags |= CRYPT_ACTIVATE_NO_READ_WORKQUEUE;
+ifdef::ACTION_REFRESH,ACTION_OPEN[] + if (opt_perf_high_priority)
+*--perf-high_priority*:: + *flags |= CRYPT_ACTIVATE_HIGH_PRIORITY;
+Set dm-crypt workqueues and the writer thread to high priority.
+This i mproves throughput and latency of dm-crypt while degrading general
+responsiveness of the system.
++
+*NOTE:* This option is available only for low-level dm-crypt
+performance tuning, use only if you need a change to default dm-crypt
+behaviour. Needs kernel 6.10 or later.
+endif::[]
+ +
ifdef::ACTION_REFRESH,ACTION_OPEN[] if (opt_perf_no_write_workqueue)
*--perf-no_read_workqueue, --perf-no_write_workqueue*:: *flags |= CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE;
Bypass dm-crypt internal workqueue and process read or write requests
diff --git a/src/cryptsetup.c b/src/cryptsetup.c @@ -860,13 +864,15 @@ static int action_status(void)
index fd580d73..57344e51 100644
--- a/src/cryptsetup.c
+++ b/src/cryptsetup.c
@@ -1036,13 +1036,15 @@ static int action_status(void)
CRYPT_ACTIVATE_SAME_CPU_CRYPT| CRYPT_ACTIVATE_SAME_CPU_CRYPT|
CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS| CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS|
CRYPT_ACTIVATE_NO_READ_WORKQUEUE| CRYPT_ACTIVATE_NO_READ_WORKQUEUE|
@ -161,50 +162,19 @@ index fd580d73..57344e51 100644
} }
out: out:
crypt_free(cd); crypt_free(cd);
diff --git a/src/cryptsetup_arg_list.h b/src/cryptsetup_arg_list.h @@ -3712,6 +3718,7 @@ int main(int argc, const char **argv)
index 74967487..510b52d4 100644 { "perf-submit_from_crypt_cpus",'\0', POPT_ARG_NONE, &opt_perf_submit_from_crypt_cpus,0,N_("Use dm-crypt submit_from_crypt_cpus performance compatibility option"), NULL },
--- a/src/cryptsetup_arg_list.h { "perf-no_read_workqueue",'\0', POPT_ARG_NONE, &opt_perf_no_read_workqueue,0,N_("Bypass dm-crypt workqueue and process read requests synchronously"), NULL },
+++ b/src/cryptsetup_arg_list.h { "perf-no_write_workqueue",'\0', POPT_ARG_NONE, &opt_perf_no_write_workqueue,0,N_("Bypass dm-crypt workqueue and process write requests synchronously"), NULL },
@@ -141,6 +141,8 @@ ARG(OPT_PBKDF_MEMORY, '\0', POPT_ARG_STRING, N_("PBKDF memory cost limit"), N_(" + { "perf-high_priority", '\0', POPT_ARG_NONE, &opt_perf_high_priority, 0, N_("Set dm-crypt workqueues and the writer thread to high priority"), NULL},
{ "deferred", '\0', POPT_ARG_NONE, &opt_deferred_remove, 0, N_("Device removal is deferred until the last user closes it"), NULL },
ARG(OPT_PBKDF_PARALLEL, '\0', POPT_ARG_STRING, N_("PBKDF parallel cost"), N_("threads"), CRYPT_ARG_UINT32, { .u32_value = DEFAULT_LUKS2_PARALLEL_THREADS }, {}) { "serialize-memory-hard-pbkdf", '\0', POPT_ARG_NONE, &opt_serialize_memory_hard_pbkdf, 0, N_("Use global lock to serialize memory hard PBKDF (OOM workaround)"), NULL },
{ "iter-time", 'i', POPT_ARG_INT, &opt_iteration_time, 0, N_("PBKDF iteration time for LUKS (in ms)"), N_("msecs") },
+ARG(OPT_PERF_HIGH_PRIORITY, '\0', POPT_ARG_NONE, N_("Set dm-crypt workqueues and the writer thread to high priority"), NULL, CRYPT_ARG_BOOL, {}, {}) Index: cryptsetup-2.3.7/tests/device-test
+ ===================================================================
ARG(OPT_PERF_NO_READ_WORKQUEUE, '\0', POPT_ARG_NONE, N_("Bypass dm-crypt workqueue and process read requests synchronously"), NULL, CRYPT_ARG_BOOL, {}, {}) --- cryptsetup-2.3.7.orig/tests/device-test
+++ cryptsetup-2.3.7/tests/device-test
ARG(OPT_PERF_NO_WRITE_WORKQUEUE, '\0', POPT_ARG_NONE, N_("Bypass dm-crypt workqueue and process write requests synchronously"), NULL, CRYPT_ARG_BOOL, {}, {}) @@ -75,6 +75,9 @@ function dm_crypt_features()
diff --git a/src/utils_arg_names.h b/src/utils_arg_names.h
index 4ec5510b..604e1710 100644
--- a/src/utils_arg_names.h
+++ b/src/utils_arg_names.h
@@ -125,6 +125,7 @@
#define OPT_PBKDF_FORCE_ITERATIONS "pbkdf-force-iterations"
#define OPT_PBKDF_MEMORY "pbkdf-memory"
#define OPT_PBKDF_PARALLEL "pbkdf-parallel"
+#define OPT_PERF_HIGH_PRIORITY "perf-high_priority"
#define OPT_PERF_NO_READ_WORKQUEUE "perf-no_read_workqueue"
#define OPT_PERF_NO_WRITE_WORKQUEUE "perf-no_write_workqueue"
#define OPT_PERF_SAME_CPU_CRYPT "perf-same_cpu_crypt"
diff --git a/src/utils_luks.c b/src/utils_luks.c
index 5c51a5a2..95f768b8 100644
--- a/src/utils_luks.c
+++ b/src/utils_luks.c
@@ -92,6 +92,9 @@ void set_activation_flags(uint32_t *flags)
if (ARG_SET(OPT_PERF_NO_WRITE_WORKQUEUE_ID))
*flags |= CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE;
+ if (ARG_SET(OPT_PERF_HIGH_PRIORITY_ID))
+ *flags |= CRYPT_ACTIVATE_HIGH_PRIORITY;
+
if (ARG_SET(OPT_INTEGRITY_NO_JOURNAL_ID))
*flags |= CRYPT_ACTIVATE_NO_JOURNAL;
diff --git a/tests/device-test b/tests/device-test
index 9aaf03c8..212cc865 100755
--- a/tests/device-test
+++ b/tests/device-test
@@ -106,6 +106,9 @@ function dm_crypt_features()
[ $VER_MIN -lt 22 ] && return [ $VER_MIN -lt 22 ] && return
DM_PERF_NO_WORKQUEUE=1 DM_PERF_NO_WORKQUEUE=1
@ -213,28 +183,27 @@ index 9aaf03c8..212cc865 100755
+ DM_PERF_HIGH_PRIORITY=1 + DM_PERF_HIGH_PRIORITY=1
} }
format() # format function dm_crypt_keyring_support()
@@ -183,12 +186,18 @@ else @@ -157,11 +160,17 @@ else
$CRYPTSETUP status $DEV_NAME | grep -q same_cpu_crypt && fail $CRYPTSETUP status $DEV_NAME | grep -q same_cpu_crypt && fail
echo -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT $DEV $DEV_NAME2 2>/dev/null && fail echo -e "$PWD1" | $CRYPTSETUP refresh --hash sha256 $DEV $DEV_NAME2 2>/dev/null && fail
if [ -n "$DM_PERF_NO_WORKQUEUE" ]; then if [ -n "$DM_PERF_NO_WORKQUEUE" ]; then
- echo -n "no_read_workqueue no_write_workqueue" - echo -n "no_read_workqueue no_write_workqueue"
+ echo -n "no_read_workqueue no_write_workqueue " + echo -n "no_read_workqueue no_write_workqueue "
echo -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue || fail echo -e "$PWD1" | $CRYPTSETUP refresh --hash sha256 -q $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue || fail
$CRYPTSETUP status $DEV_NAME | grep -q no_read_workqueue || fail $CRYPTSETUP status $DEV_NAME | grep -q no_read_workqueue || fail
$CRYPTSETUP status $DEV_NAME | grep -q no_write_workqueue || fail $CRYPTSETUP status $DEV_NAME | grep -q no_write_workqueue || fail
check_io
fi fi
+ if [ -n "$DM_PERF_HIGH_PRIORITY" ]; then + if [ -n "$DM_PERF_HIGH_PRIORITY" ]; then
+ echo -n "high_priority " + echo -n "high_priority "
+ echo -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME --perf-high_priority || fail + echo -e "$PWD1" | $CRYPTSETUP refresh --hash sha256 -q $DEV_NAME --perf-high_priority || fail
+ $CRYPTSETUP status $DEV_NAME | grep -q high_priority || fail + $CRYPTSETUP status $DEV_NAME | grep -q high_priority || fail
+ check_io
+ fi + fi
+
$CRYPTSETUP close $DEV_NAME || fail $CRYPTSETUP close $DEV_NAME || fail
echo echo
@@ -215,11 +224,16 @@ else @@ -187,11 +196,16 @@ else
$CRYPTSETUP status $DEV_NAME | grep -q same_cpu_crypt && fail $CRYPTSETUP status $DEV_NAME | grep -q same_cpu_crypt && fail
echo -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME2 2>/dev/null && fail echo -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME2 2>/dev/null && fail
if [ -n "$DM_PERF_NO_WORKQUEUE" ]; then if [ -n "$DM_PERF_NO_WORKQUEUE" ]; then
@ -252,8 +221,8 @@ index 9aaf03c8..212cc865 100755
$CRYPTSETUP close $DEV_NAME || fail $CRYPTSETUP close $DEV_NAME || fail
echo echo
@@ -280,7 +294,7 @@ else @@ -249,7 +263,7 @@ else
fi $CRYPTSETUP status $DEV_NAME | grep -q keyring || fail
fi fi
if [ -n "$DM_PERF_NO_WORKQUEUE" ]; then if [ -n "$DM_PERF_NO_WORKQUEUE" ]; then
- echo -n "no_read_workqueue no_write_workqueue" - echo -n "no_read_workqueue no_write_workqueue"
@ -261,7 +230,7 @@ index 9aaf03c8..212cc865 100755
echo -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue --persistent || fail echo -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue --persistent || fail
$CRYPTSETUP status $DEV_NAME | grep -q no_read_workqueue || fail $CRYPTSETUP status $DEV_NAME | grep -q no_read_workqueue || fail
$CRYPTSETUP status $DEV_NAME | grep -q no_write_workqueue || fail $CRYPTSETUP status $DEV_NAME | grep -q no_write_workqueue || fail
@@ -289,6 +303,14 @@ else @@ -258,6 +272,14 @@ else
$CRYPTSETUP status $DEV_NAME | grep -q no_read_workqueue || fail $CRYPTSETUP status $DEV_NAME | grep -q no_read_workqueue || fail
$CRYPTSETUP status $DEV_NAME | grep -q no_write_workqueue || fail $CRYPTSETUP status $DEV_NAME | grep -q no_write_workqueue || fail
fi fi
@ -276,6 +245,3 @@ index 9aaf03c8..212cc865 100755
echo -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME2 2>/dev/null && fail echo -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME2 2>/dev/null && fail
$CRYPTSETUP close $DEV_NAME || fail $CRYPTSETUP close $DEV_NAME || fail
echo echo
--
2.44.0