mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC] ramfs: rember last accessed chunk
@ 2012-05-15  9:15 Jan Weitzel
  2012-05-15 19:29 ` Sascha Hauer
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Weitzel @ 2012-05-15  9:15 UTC (permalink / raw)
  To: barebox

Writing big files takes longer and longer because of the chunk list
By storing a pointer of the recent used chunk in the inode, access times are
improved.
Testet on with tftp 10M:
OMAP4 chunk size 4096: 12244ms 8192: 4239ms
	patched        2647ms        2785ms
i.MX35 chunk size 8192: 7225ms
	patched		2691ms

No impact on much smaller files seen

Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
---
 fs/ramfs.c |   46 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index 83ab6df..5c7410b 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -48,6 +48,10 @@ struct ramfs_inode {
 
 	ulong size;
 	struct ramfs_chunk *data;
+	
+	/* Points to recently used chunk */
+	int recent_chunk;
+	struct ramfs_chunk *recent_chunkp;
 };
 
 struct ramfs_priv {
@@ -297,6 +301,34 @@ static int ramfs_close(struct device_d *dev, FILE *f)
 	return 0;
 }
 
+static struct ramfs_chunk *ramfs_find_chunk(struct ramfs_inode *node, int chunk)
+{
+	struct ramfs_chunk *data;
+	int left = chunk;
+
+	if (chunk == 0)
+		return node->data;
+
+	if (node->recent_chunk == chunk)
+		return node->recent_chunkp;
+
+	if (node->recent_chunk < chunk && node->recent_chunk != 0) {
+		/* Start at last known chunk */
+		data = node->recent_chunkp;
+		left -= node->recent_chunk;
+	} else
+		/* Start at first chunk */
+		data = node->data;
+
+	while (left--)
+		data = data->next;
+
+	node->recent_chunkp = data;
+	node->recent_chunk = chunk;
+
+	return data;
+}
+
 static int ramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
 {
 	struct ramfs_inode *node = (struct ramfs_inode *)f->inode;
@@ -311,11 +343,7 @@ static int ramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
 	debug("%s: reading from chunk %d\n", __FUNCTION__, chunk);
 
 	/* Position ourself in stream */
-	data = node->data;
-	while (chunk) {
-		data = data->next;
-		chunk--;
-	}
+	data = ramfs_find_chunk(node, chunk);
 	ofs = f->pos % CHUNK_SIZE;
 
 	/* Read till end of current chunk */
@@ -364,11 +392,7 @@ static int ramfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t i
 	debug("%s: writing to chunk %d\n", __FUNCTION__, chunk);
 
 	/* Position ourself in stream */
-	data = node->data;
-	while (chunk) {
-		data = data->next;
-		chunk--;
-	}
+	data = ramfs_find_chunk(node, chunk);
 	ofs = f->pos % CHUNK_SIZE;
 
 	/* Write till end of current chunk */
@@ -429,6 +453,8 @@ static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
 			ramfs_put_chunk(data);
 			data = tmp;
 		}
+		if (node->recent_chunk > newchunks) 
+			node->recent_chunk = 0;
 	}
 
 	if (newchunks > oldchunks) {
-- 
1.7.0.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC] ramfs: rember last accessed chunk
  2012-05-15  9:15 [RFC] ramfs: rember last accessed chunk Jan Weitzel
@ 2012-05-15 19:29 ` Sascha Hauer
  2012-05-16  6:10   ` [PATCH] " Jan Weitzel
  0 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2012-05-15 19:29 UTC (permalink / raw)
  To: Jan Weitzel; +Cc: barebox

Hi Jan,

On Tue, May 15, 2012 at 11:15:46AM +0200, Jan Weitzel wrote:
> Writing big files takes longer and longer because of the chunk list
> By storing a pointer of the recent used chunk in the inode, access times are
> improved.
> Testet on with tftp 10M:
> OMAP4 chunk size 4096: 12244ms 8192: 4239ms
> 	patched        2647ms        2785ms
> i.MX35 chunk size 8192: 7225ms
> 	patched		2691ms
> 

The numbers look good and the code looks sane. We can give it a try. Two
nitpicks below.

> No impact on much smaller files seen
> 
> Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
> ---
>  fs/ramfs.c |   46 ++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 36 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/ramfs.c b/fs/ramfs.c
> index 83ab6df..5c7410b 100644
> --- a/fs/ramfs.c
> +++ b/fs/ramfs.c
> @@ -48,6 +48,10 @@ struct ramfs_inode {
>  
>  	ulong size;
>  	struct ramfs_chunk *data;
> +	

Trailing whitespace here.

> +	/* Points to recently used chunk */
> +	int recent_chunk;
> +	struct ramfs_chunk *recent_chunkp;
>  };
>  
>  struct ramfs_priv {
> @@ -297,6 +301,34 @@ static int ramfs_close(struct device_d *dev, FILE *f)
>  	return 0;
>  }
>  
> +static struct ramfs_chunk *ramfs_find_chunk(struct ramfs_inode *node, int chunk)
> +{
> +	struct ramfs_chunk *data;
> +	int left = chunk;
> +
> +	if (chunk == 0)
> +		return node->data;
> +
> +	if (node->recent_chunk == chunk)
> +		return node->recent_chunkp;
> +
> +	if (node->recent_chunk < chunk && node->recent_chunk != 0) {
> +		/* Start at last known chunk */
> +		data = node->recent_chunkp;
> +		left -= node->recent_chunk;
> +	} else
> +		/* Start at first chunk */
> +		data = node->data;

if you have brackets in the if path you should add them in the else path
aswell.

>  		}
> +		if (node->recent_chunk > newchunks) 

Also trailing whitespace

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] ramfs: rember last accessed chunk
  2012-05-15 19:29 ` Sascha Hauer
@ 2012-05-16  6:10   ` Jan Weitzel
  2012-05-16 11:20     ` Sascha Hauer
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Weitzel @ 2012-05-16  6:10 UTC (permalink / raw)
  To: barebox

Writing big files takes longer and longer because of the chunk list
By storing a pointer of the recent used chunk in the inode, access times are
improved.
Testet on with tftp 10M:
OMAP4 chunk size 4096: 12244ms 8192: 4239ms
	patched        2647ms        2785ms
i.MX35 chunk size 8192: 7225ms
	patched		2691ms

No impact on much smaller files seen

Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
---
v2: I will use checkpatch

 fs/ramfs.c |   47 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index 83ab6df..cec5e76 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -48,6 +48,10 @@ struct ramfs_inode {
 
 	ulong size;
 	struct ramfs_chunk *data;
+
+	/* Points to recently used chunk */
+	int recent_chunk;
+	struct ramfs_chunk *recent_chunkp;
 };
 
 struct ramfs_priv {
@@ -297,6 +301,35 @@ static int ramfs_close(struct device_d *dev, FILE *f)
 	return 0;
 }
 
+static struct ramfs_chunk *ramfs_find_chunk(struct ramfs_inode *node, int chunk)
+{
+	struct ramfs_chunk *data;
+	int left = chunk;
+
+	if (chunk == 0)
+		return node->data;
+
+	if (node->recent_chunk == chunk)
+		return node->recent_chunkp;
+
+	if (node->recent_chunk < chunk && node->recent_chunk != 0) {
+		/* Start at last known chunk */
+		data = node->recent_chunkp;
+		left -= node->recent_chunk;
+	} else {
+		/* Start at first chunk */
+		data = node->data;
+	}
+
+	while (left--)
+		data = data->next;
+
+	node->recent_chunkp = data;
+	node->recent_chunk = chunk;
+
+	return data;
+}
+
 static int ramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
 {
 	struct ramfs_inode *node = (struct ramfs_inode *)f->inode;
@@ -311,11 +344,7 @@ static int ramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
 	debug("%s: reading from chunk %d\n", __FUNCTION__, chunk);
 
 	/* Position ourself in stream */
-	data = node->data;
-	while (chunk) {
-		data = data->next;
-		chunk--;
-	}
+	data = ramfs_find_chunk(node, chunk);
 	ofs = f->pos % CHUNK_SIZE;
 
 	/* Read till end of current chunk */
@@ -364,11 +393,7 @@ static int ramfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t i
 	debug("%s: writing to chunk %d\n", __FUNCTION__, chunk);
 
 	/* Position ourself in stream */
-	data = node->data;
-	while (chunk) {
-		data = data->next;
-		chunk--;
-	}
+	data = ramfs_find_chunk(node, chunk);
 	ofs = f->pos % CHUNK_SIZE;
 
 	/* Write till end of current chunk */
@@ -429,6 +454,8 @@ static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
 			ramfs_put_chunk(data);
 			data = tmp;
 		}
+		if (node->recent_chunk > newchunks)
+			node->recent_chunk = 0;
 	}
 
 	if (newchunks > oldchunks) {
-- 
1.7.0.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ramfs: rember last accessed chunk
  2012-05-16  6:10   ` [PATCH] " Jan Weitzel
@ 2012-05-16 11:20     ` Sascha Hauer
  2012-05-16 18:42       ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2012-05-16 11:20 UTC (permalink / raw)
  To: Jan Weitzel; +Cc: barebox

On Wed, May 16, 2012 at 08:10:16AM +0200, Jan Weitzel wrote:
> Writing big files takes longer and longer because of the chunk list
> By storing a pointer of the recent used chunk in the inode, access times are
> improved.
> Testet on with tftp 10M:
> OMAP4 chunk size 4096: 12244ms 8192: 4239ms
> 	patched        2647ms        2785ms
> i.MX35 chunk size 8192: 7225ms
> 	patched		2691ms
> 
> No impact on much smaller files seen
> 
> Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>

Applied, thanks

Sascha

> ---
> v2: I will use checkpatch
> 
>  fs/ramfs.c |   47 +++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 37 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/ramfs.c b/fs/ramfs.c
> index 83ab6df..cec5e76 100644
> --- a/fs/ramfs.c
> +++ b/fs/ramfs.c
> @@ -48,6 +48,10 @@ struct ramfs_inode {
>  
>  	ulong size;
>  	struct ramfs_chunk *data;
> +
> +	/* Points to recently used chunk */
> +	int recent_chunk;
> +	struct ramfs_chunk *recent_chunkp;
>  };
>  
>  struct ramfs_priv {
> @@ -297,6 +301,35 @@ static int ramfs_close(struct device_d *dev, FILE *f)
>  	return 0;
>  }
>  
> +static struct ramfs_chunk *ramfs_find_chunk(struct ramfs_inode *node, int chunk)
> +{
> +	struct ramfs_chunk *data;
> +	int left = chunk;
> +
> +	if (chunk == 0)
> +		return node->data;
> +
> +	if (node->recent_chunk == chunk)
> +		return node->recent_chunkp;
> +
> +	if (node->recent_chunk < chunk && node->recent_chunk != 0) {
> +		/* Start at last known chunk */
> +		data = node->recent_chunkp;
> +		left -= node->recent_chunk;
> +	} else {
> +		/* Start at first chunk */
> +		data = node->data;
> +	}
> +
> +	while (left--)
> +		data = data->next;
> +
> +	node->recent_chunkp = data;
> +	node->recent_chunk = chunk;
> +
> +	return data;
> +}
> +
>  static int ramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
>  {
>  	struct ramfs_inode *node = (struct ramfs_inode *)f->inode;
> @@ -311,11 +344,7 @@ static int ramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
>  	debug("%s: reading from chunk %d\n", __FUNCTION__, chunk);
>  
>  	/* Position ourself in stream */
> -	data = node->data;
> -	while (chunk) {
> -		data = data->next;
> -		chunk--;
> -	}
> +	data = ramfs_find_chunk(node, chunk);
>  	ofs = f->pos % CHUNK_SIZE;
>  
>  	/* Read till end of current chunk */
> @@ -364,11 +393,7 @@ static int ramfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t i
>  	debug("%s: writing to chunk %d\n", __FUNCTION__, chunk);
>  
>  	/* Position ourself in stream */
> -	data = node->data;
> -	while (chunk) {
> -		data = data->next;
> -		chunk--;
> -	}
> +	data = ramfs_find_chunk(node, chunk);
>  	ofs = f->pos % CHUNK_SIZE;
>  
>  	/* Write till end of current chunk */
> @@ -429,6 +454,8 @@ static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
>  			ramfs_put_chunk(data);
>  			data = tmp;
>  		}
> +		if (node->recent_chunk > newchunks)
> +			node->recent_chunk = 0;
>  	}
>  
>  	if (newchunks > oldchunks) {
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ramfs: rember last accessed chunk
  2012-05-16 11:20     ` Sascha Hauer
@ 2012-05-16 18:42       ` Uwe Kleine-König
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2012-05-16 18:42 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Wed, May 16, 2012 at 01:20:25PM +0200, Sascha Hauer wrote:
> On Wed, May 16, 2012 at 08:10:16AM +0200, Jan Weitzel wrote:
> > Writing big files takes longer and longer because of the chunk list
> > By storing a pointer of the recent used chunk in the inode, access times are
> > improved.
> > Testet on with tftp 10M:
> > OMAP4 chunk size 4096: 12244ms 8192: 4239ms
> > 	patched        2647ms        2785ms
> > i.MX35 chunk size 8192: 7225ms
> > 	patched		2691ms
> > 
> > No impact on much smaller files seen
> > 
> > Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
> 
> Applied, thanks
Don't know if it's already too late:

	$Subject ~= s/rember/remember/

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-16 18:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-15  9:15 [RFC] ramfs: rember last accessed chunk Jan Weitzel
2012-05-15 19:29 ` Sascha Hauer
2012-05-16  6:10   ` [PATCH] " Jan Weitzel
2012-05-16 11:20     ` Sascha Hauer
2012-05-16 18:42       ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox