* [RFC PATCH 0/4] Adding useful information into swap partition header
@ 2012-10-22 16:57 Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 1/4] libblkid/topology: add preferred_erase_size to topology probe Venkatraman S
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Venkatraman S @ 2012-10-22 16:57 UTC (permalink / raw)
To: kzak; +Cc: util-linux, arnd.bergmann, Venkatraman S
Trying some of the ideas bounced around in lkml for
optimizing swap on flash (eMMC / SD) media [1], we can start
to add useful information into swapheader without breaking
compatibility.
Such information can help the kernel swap management algo
to tune itself to the geometry of flash devices (erase block
size and page size etc).
Some more features (like command line override) are still
under development. In long term, libblkid/mkswap can be extended
to even detect this information by timing attacks,
even if sysfs parameters are not present.
Venkatraman S (4):
libblkid/topology: add preferred_erase_size to topology probe
mkswap: refactor header preparation
mkswap: Add additional fields in swapheader
mkswap: Probe and embed useful block device info into swapheader
disk-utils/mkswap.c | 77 ++++++++++++++++++++++++++++++++--------
include/swapheader.h | 7 +++-
libblkid/src/topology/sysfs.c | 1 +
libblkid/src/topology/topology.c | 19 ++++++++++
libblkid/src/topology/topology.h | 1 +
5 files changed, 90 insertions(+), 15 deletions(-)
--
1.7.11.1.25.g0e18bef
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH 1/4] libblkid/topology: add preferred_erase_size to topology probe
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
@ 2012-10-22 16:57 ` Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 2/4] mkswap: refactor header preparation Venkatraman S
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Venkatraman S @ 2012-10-22 16:57 UTC (permalink / raw)
To: kzak; +Cc: util-linux, arnd.bergmann, Venkatraman S
Add device/preferred_erase_size into sysfs params to lookup.
Add blkid_topology_get/set interface for access.
Not-yet-Signed-off-by: Venkatraman S <venkat@linaro.org>
---
libblkid/src/topology/sysfs.c | 1 +
libblkid/src/topology/topology.c | 19 +++++++++++++++++++
libblkid/src/topology/topology.h | 1 +
3 files changed, 21 insertions(+)
diff --git a/libblkid/src/topology/sysfs.c b/libblkid/src/topology/sysfs.c
index a04b20a..e080a18 100644
--- a/libblkid/src/topology/sysfs.c
+++ b/libblkid/src/topology/sysfs.c
@@ -37,6 +37,7 @@ static struct topology_val {
{ "queue/minimum_io_size", blkid_topology_set_minimum_io_size },
{ "queue/optimal_io_size", blkid_topology_set_optimal_io_size },
{ "queue/physical_block_size", blkid_topology_set_physical_sector_size },
+ { "device/preferred_erase_size", blkid_topology_set_erase_block_size },
};
static int probe_sysfs_tp(blkid_probe pr,
diff --git a/libblkid/src/topology/topology.c b/libblkid/src/topology/topology.c
index 73a397a..bae2a1e 100644
--- a/libblkid/src/topology/topology.c
+++ b/libblkid/src/topology/topology.c
@@ -67,6 +67,7 @@ struct blkid_struct_topology {
unsigned long optimal_io_size;
unsigned long logical_sector_size;
unsigned long physical_sector_size;
+ unsigned long erase_block_size;
};
/*
@@ -309,6 +310,14 @@ int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val)
val);
}
+int blkid_topology_set_erase_block_size(blkid_probe pr, unsigned long val)
+{
+ return topology_set_value(pr,
+ "ERASE_BLOCK_SIZE",
+ offsetof(struct blkid_struct_topology, erase_block_size),
+ val);
+}
+
/**
* blkid_topology_get_alignment_offset:
* @tp: topology
@@ -364,3 +373,13 @@ unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
return tp ? tp->physical_sector_size : 0;
}
+/**
+ * blkid_topology_get_erase_block_size
+ * @tp: topology
+ * Returns: Erase block size property of flash devices in bytes or 0.
+ */
+unsigned long blkid_topology_get_erase_block_size(blkid_topology tp)
+{
+ return tp ? tp->erase_block_size: 0;
+}
+
diff --git a/libblkid/src/topology/topology.h b/libblkid/src/topology/topology.h
index 6d2f433..7b61dec 100644
--- a/libblkid/src/topology/topology.h
+++ b/libblkid/src/topology/topology.h
@@ -7,6 +7,7 @@ extern int blkid_topology_set_alignment_offset(blkid_probe pr, int val);
extern int blkid_topology_set_minimum_io_size(blkid_probe pr, unsigned long val);
extern int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val);
extern int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val);
+extern int blkid_topology_set_erase_block_size(blkid_probe pr, unsigned long val);
/*
* topology probers
--
1.7.11.1.25.g0e18bef
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH 2/4] mkswap: refactor header preparation
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 1/4] libblkid/topology: add preferred_erase_size to topology probe Venkatraman S
@ 2012-10-22 16:57 ` Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 3/4] mkswap: Add additional fields in swapheader Venkatraman S
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Venkatraman S @ 2012-10-22 16:57 UTC (permalink / raw)
To: kzak; +Cc: util-linux, arnd.bergmann, Venkatraman S
Move opencoded swap header populating code to a separate
function. No functional changes.
Signed-off-by: Venkatraman S <venkat@linaro.org>
---
disk-utils/mkswap.c | 42 +++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 0144921..f090121 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -75,6 +75,8 @@ static unsigned long badpages = 0;
static int check = 0;
#define SELINUX_SWAPFILE_TYPE "swapfile_t"
+#define MAX_BADPAGES ((pagesize-1024-128*sizeof(int)-10)/sizeof(int))
+#define MIN_GOODPAGES 10
#ifdef __sparc__
# ifdef __arch64__
@@ -271,8 +273,6 @@ It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips,
128GB on alpha and 3TB on sparc64.
*/
-#define MAX_BADPAGES ((pagesize-1024-128*sizeof(int)-10)/sizeof(int))
-#define MIN_GOODPAGES 10
static void __attribute__ ((__noreturn__)) usage(FILE *out)
{
@@ -362,6 +362,29 @@ new_prober(int fd)
}
#endif
+static void prepare_header(struct swap_header_v1_2 *hdr,
+ unsigned char *uuid, char *volume_name)
+{
+ unsigned long long goodpages;
+
+ hdr->version = 1;
+ hdr->last_page = PAGES - 1;
+ hdr->nr_badpages = badpages;
+
+ if (badpages > PAGES - MIN_GOODPAGES)
+ errx(EXIT_FAILURE, _("Unable to set up swap-space: unreadable"));
+
+ goodpages = PAGES - badpages - 1;
+ printf(_("Setting up swapspace version 1, size = %llu KiB\n"),
+ goodpages * pagesize / 1024);
+
+ write_signature("SWAPSPACE2");
+ write_uuid_and_label(uuid, volume_name);
+
+}
+
+
+
static void
wipe_device(int fd, const char *devname, int force)
{
@@ -441,7 +464,7 @@ main(int argc, char **argv) {
struct swap_header_v1_2 *hdr;
int c;
unsigned long long maxpages;
- unsigned long long goodpages;
+
unsigned long long sz;
off_t offset;
int force = 0;
@@ -599,19 +622,8 @@ main(int argc, char **argv) {
wipe_device(DEV, device_name, force);
hdr = (struct swap_header_v1_2 *) signature_page;
- hdr->version = 1;
- hdr->last_page = PAGES - 1;
- hdr->nr_badpages = badpages;
- if (badpages > PAGES - MIN_GOODPAGES)
- errx(EXIT_FAILURE, _("Unable to set up swap-space: unreadable"));
-
- goodpages = PAGES - badpages - 1;
- printf(_("Setting up swapspace version 1, size = %llu KiB\n"),
- goodpages * pagesize / 1024);
-
- write_signature("SWAPSPACE2");
- write_uuid_and_label(uuid, opt_label);
+ prepare_header(hdr, uuid, opt_label);
offset = 1024;
if (lseek(DEV, offset, SEEK_SET) != offset)
--
1.7.11.1.25.g0e18bef
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [RFC PATCH 3/4] mkswap: Add additional fields in swapheader
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 1/4] libblkid/topology: add preferred_erase_size to topology probe Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 2/4] mkswap: refactor header preparation Venkatraman S
@ 2012-10-22 16:57 ` Venkatraman S
2012-10-22 16:57 ` [PATCH 4/4] mkswap: Probe and embed useful block device info into swapheader Venkatraman S
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Venkatraman S @ 2012-10-22 16:57 UTC (permalink / raw)
To: kzak; +Cc: util-linux, arnd.bergmann, Venkatraman S
Use the padding section to add useful information in
swap header. This is backward compatible with
SWAPSPACE2 headers.
Signed-off-by: Venkatraman S <venkat@linaro.org>
---
| 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
--git a/include/swapheader.h b/include/swapheader.h
index 42d521a..90d13ef 100644
--- a/include/swapheader.h
+++ b/include/swapheader.h
@@ -21,7 +21,12 @@ struct swap_header_v1_2 {
unsigned int nr_badpages;
unsigned char uuid[SWAP_UUID_LENGTH];
char volume_name[SWAP_LABEL_LENGTH];
- unsigned int padding[117];
+ union {
+ struct {
+ unsigned int erase_blk_size;
+ } blkdevinfo;
+ unsigned int padding[117];
+ } swp_headerinfo ;
unsigned int badpages[1];
};
--
1.7.11.1.25.g0e18bef
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] mkswap: Probe and embed useful block device info into swapheader
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
` (2 preceding siblings ...)
2012-10-22 16:57 ` [RFC PATCH 3/4] mkswap: Add additional fields in swapheader Venkatraman S
@ 2012-10-22 16:57 ` Venkatraman S
2012-10-22 17:04 ` [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-23 12:16 ` Karel Zak
5 siblings, 0 replies; 9+ messages in thread
From: Venkatraman S @ 2012-10-22 16:57 UTC (permalink / raw)
To: kzak; +Cc: util-linux, arnd.bergmann, Venkatraman S
As first step, embed preferred_erase_size into swap header, by probing
the topology.
Not-yet-Signed-off-by: Venkatraman S <venkat@linaro.org>
---
disk-utils/mkswap.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index f090121..aa61488 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -59,6 +59,7 @@
#include "c.h"
#include "closestream.h"
#include "ismounted.h"
+#include "bitops.h"
#ifdef HAVE_LIBUUID
# include <uuid.h>
@@ -148,6 +149,7 @@ is_sparc64(void)
*
*/
static unsigned int user_pagesize;
+static unsigned int user_ebsize;
static unsigned int pagesize;
static unsigned long *signature_page = NULL;
@@ -360,6 +362,39 @@ new_prober(int fd)
errx(EXIT_FAILURE, _("unable to assign device to libblkid probe"));
return pr;
}
+
+static void
+add_blkdev_info(struct swap_header_v1_2 *hdr, int fd)
+{
+ char *type = NULL;
+ unsigned long eb_size = 0;
+ blkid_probe pr = new_prober(fd);
+
+ if (user_ebsize) {
+ hdr->swp_headerinfo.blkdevinfo.erase_blk_size = user_ebsize;
+ return;
+ }
+
+ blkid_probe_enable_superblocks(pr, 1);
+ blkid_probe_enable_partitions(pr, 1);
+ blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);
+ blkid_probe_enable_topology(pr, 1);
+
+ while (blkid_do_probe(pr) == 0) {
+ if (blkid_probe_lookup_value(pr, "ERASE_BLOCK_SIZE",
+ (const char **) &type, NULL) == 0 && type) {
+ eb_size = strtou32_or_err(type, _("Invalid erase blk size"));
+ hdr->swp_headerinfo.blkdevinfo.erase_blk_size = eb_size;
+ break;
+ }
+ }
+
+}
+
+#else
+static inline void add_blkdev_info(struct swap_header_v1_2 *hdr, int fd)
+{}
+
#endif
static void prepare_header(struct swap_header_v1_2 *hdr,
@@ -625,6 +660,8 @@ main(int argc, char **argv) {
prepare_header(hdr, uuid, opt_label);
+ add_blkdev_info(hdr, DEV);
+
offset = 1024;
if (lseek(DEV, offset, SEEK_SET) != offset)
errx(EXIT_FAILURE, _("unable to rewind swap-device"));
--
1.7.11.1.25.g0e18bef
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] Adding useful information into swap partition header
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
` (3 preceding siblings ...)
2012-10-22 16:57 ` [PATCH 4/4] mkswap: Probe and embed useful block device info into swapheader Venkatraman S
@ 2012-10-22 17:04 ` Venkatraman S
2012-10-23 12:16 ` Karel Zak
5 siblings, 0 replies; 9+ messages in thread
From: Venkatraman S @ 2012-10-22 17:04 UTC (permalink / raw)
To: kzak; +Cc: util-linux, arnd.bergmann, Venkatraman S
On 22 October 2012 22:27, Venkatraman S <venkat@linaro.org> wrote:
> Trying some of the ideas bounced around in lkml for
> optimizing swap on flash (eMMC / SD) media [1], we can start
> to add useful information into swapheader without breaking
> compatibility.
> Such information can help the kernel swap management algo
> to tune itself to the geometry of flash devices (erase block
> size and page size etc).
> Some more features (like command line override) are still
> under development. In long term, libblkid/mkswap can be extended
> to even detect this information by timing attacks,
> even if sysfs parameters are not present.
>
Oops: Some reference links were missed in the cover letter..
[1] https://lkml.org/lkml/2012/3/30/410
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] Adding useful information into swap partition header
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
` (4 preceding siblings ...)
2012-10-22 17:04 ` [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
@ 2012-10-23 12:16 ` Karel Zak
2012-10-23 13:37 ` Venkatraman S
5 siblings, 1 reply; 9+ messages in thread
From: Karel Zak @ 2012-10-23 12:16 UTC (permalink / raw)
To: Venkatraman S; +Cc: util-linux, arnd.bergmann
On Mon, Oct 22, 2012 at 10:27:23PM +0530, Venkatraman S wrote:
> Venkatraman S (4):
> libblkid/topology: add preferred_erase_size to topology probe
> mkswap: refactor header preparation
> mkswap: Add additional fields in swapheader
> mkswap: Probe and embed useful block device info into swapheader
I don't see a problem to support additional information in the swap
header, but our rule is pretty simple: first in Linus' tree, after
that in userspace.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] Adding useful information into swap partition header
2012-10-23 12:16 ` Karel Zak
@ 2012-10-23 13:37 ` Venkatraman S
2012-11-08 9:44 ` Karel Zak
0 siblings, 1 reply; 9+ messages in thread
From: Venkatraman S @ 2012-10-23 13:37 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, arnd.bergmann
On 23 October 2012 17:46, Karel Zak <kzak@redhat.com> wrote:
> On Mon, Oct 22, 2012 at 10:27:23PM +0530, Venkatraman S wrote:
>> Venkatraman S (4):
>> libblkid/topology: add preferred_erase_size to topology probe
>> mkswap: refactor header preparation
>> mkswap: Add additional fields in swapheader
>> mkswap: Probe and embed useful block device info into swapheader
>
> I don't see a problem to support additional information in the swap
> header, but our rule is pretty simple: first in Linus' tree, after
> that in userspace.
>
Thanks Karl - that's understood. I posted the patches to better explain the
issue I faced - this new parameter I introduced in topology.c is accessible
only when I pass the root disk dev node to mkswap (as /dev/mmcblkX)
and not when invoked with /dev/mmcblkXpY) (i.e a partition with the device).
So how should the topology probe be invoked in this case ?
Thanks,
Venkat.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC PATCH 0/4] Adding useful information into swap partition header
2012-10-23 13:37 ` Venkatraman S
@ 2012-11-08 9:44 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-11-08 9:44 UTC (permalink / raw)
To: Venkatraman S; +Cc: util-linux, arnd.bergmann
On Tue, Oct 23, 2012 at 07:07:42PM +0530, Venkatraman S wrote:
> On 23 October 2012 17:46, Karel Zak <kzak@redhat.com> wrote:
> > On Mon, Oct 22, 2012 at 10:27:23PM +0530, Venkatraman S wrote:
> >> Venkatraman S (4):
> >> libblkid/topology: add preferred_erase_size to topology probe
> >> mkswap: refactor header preparation
> >> mkswap: Add additional fields in swapheader
> >> mkswap: Probe and embed useful block device info into swapheader
> >
> > I don't see a problem to support additional information in the swap
> > header, but our rule is pretty simple: first in Linus' tree, after
> > that in userspace.
> >
>
> Thanks Karl - that's understood. I posted the patches to better explain the
> issue I faced - this new parameter I introduced in topology.c is accessible
> only when I pass the root disk dev node to mkswap (as /dev/mmcblkX)
> and not when invoked with /dev/mmcblkXpY) (i.e a partition with the device).
Well, the problem is that sysfs_{open,stat}() functions in
lib/sysfs.c reads attributes from parent only for "queue/" directory
attributes. It's trivial to fix this problem.
> So how should the topology probe be invoked in this case ?
The question is if we really need to extend libblkid if the attribute
is necessary only for mkswap.
I think it would be better to read the sysfs attribute directly in
mkswap (by lib/sysfs.c functions). The result will be one small patch
for mkswap.
Anyway, all this is trivial and maybe implemented very quickly --
what we need is to have support in kernel.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-11-08 9:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-22 16:57 [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 1/4] libblkid/topology: add preferred_erase_size to topology probe Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 2/4] mkswap: refactor header preparation Venkatraman S
2012-10-22 16:57 ` [RFC PATCH 3/4] mkswap: Add additional fields in swapheader Venkatraman S
2012-10-22 16:57 ` [PATCH 4/4] mkswap: Probe and embed useful block device info into swapheader Venkatraman S
2012-10-22 17:04 ` [RFC PATCH 0/4] Adding useful information into swap partition header Venkatraman S
2012-10-23 12:16 ` Karel Zak
2012-10-23 13:37 ` Venkatraman S
2012-11-08 9:44 ` Karel Zak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.