All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: replace PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE)
@ 2015-05-06  8:35 xuw2015
  2015-05-12 15:46 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: xuw2015 @ 2015-05-06  8:35 UTC (permalink / raw)
  To: linux-btrfs; +Cc: George Wang

From: George Wang <xuw2015@gmail.com>

PAGE_CACHE_SIZE is usually 4096. But for some ppc64/ppc64le, it will be 65536.
Just replace this fixed PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE), which will
be more flexible

Signed-off-by: George Wang <xuw2015@gmail.com>

diff --git a/cmds-restore.c b/cmds-restore.c
index e1411e9..bf839f4 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -54,9 +54,13 @@ static int get_xattrs = 0;
 static int dry_run = 0;
 
 #define LZO_LEN 4
-#define PAGE_CACHE_SIZE 4096
 #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
 
+static inline long pagesize(void)
+{
+	return sysconf(_SC_PAGESIZE);
+}
+
 static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
 			   u64 decompress_len)
 {
@@ -125,7 +129,7 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 		inbuf += LZO_LEN;
 		tot_in += LZO_LEN;
 
-		new_len = lzo1x_worst_compress(PAGE_CACHE_SIZE);
+		new_len = lzo1x_worst_compress(pagesize());
 		ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len,
 					    (unsigned char *)outbuf,
 					    (void *)&new_len, NULL);
@@ -142,8 +146,8 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 		 * If the 4 byte header does not fit to the rest of the page we
 		 * have to move to the next one, unless we read some garbage
 		 */
-		mod_page = tot_in % PAGE_CACHE_SIZE;
-		rem_page = PAGE_CACHE_SIZE - mod_page;
+		mod_page = tot_in % pagesize();
+		rem_page = pagesize() - mod_page;
 		if (rem_page < LZO_LEN) {
 			inbuf += rem_page;
 			tot_in += rem_page;
-- 
1.9.3


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

* Re: [PATCH] btrfs-progs: replace PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE)
  2015-05-06  8:35 [PATCH] btrfs-progs: replace PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE) xuw2015
@ 2015-05-12 15:46 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2015-05-12 15:46 UTC (permalink / raw)
  To: xuw2015; +Cc: linux-btrfs

On Wed, May 06, 2015 at 04:35:22PM +0800, xuw2015@gmail.com wrote:
> From: George Wang <xuw2015@gmail.com>
> 
> PAGE_CACHE_SIZE is usually 4096. But for some ppc64/ppc64le, it will be 65536.
> Just replace this fixed PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE), which will
> be more flexible

As implemented in kernel right now, sectorsize must be page size and
this is also part of the compressed data format. So in restore we should
use the sectorsize from the filesystem.

Instead of passing the sectorsize through multiple functions, I suggest
to add a static global variable and set it after open_ctree.

Thanks.

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

end of thread, other threads:[~2015-05-12 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06  8:35 [PATCH] btrfs-progs: replace PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE) xuw2015
2015-05-12 15:46 ` David Sterba

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.