From patchwork Wed May 6 08:35:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xuw2015@gmail.com X-Patchwork-Id: 6347661 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2F9A8BEEE1 for ; Wed, 6 May 2015 08:35:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5CCBD20225 for ; Wed, 6 May 2015 08:35:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D36420142 for ; Wed, 6 May 2015 08:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752896AbbEFIfa (ORCPT ); Wed, 6 May 2015 04:35:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36919 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752893AbbEFIf2 (ORCPT ); Wed, 6 May 2015 04:35:28 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t468ZRVj002800 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2015 04:35:27 -0400 Received: from localhost (dhcp-12-175.nay.redhat.com [10.66.12.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t468ZPaR031261; Wed, 6 May 2015 04:35:26 -0400 From: xuw2015@gmail.com To: linux-btrfs@vger.kernel.org Cc: George Wang Subject: [PATCH] btrfs-progs: replace PAGE_CACHE_SIZE to sysconf(_SC_PAGESIZE) Date: Wed, 6 May 2015 16:35:22 +0800 Message-Id: <1430901322-10133-1-git-send-email-xuw2015@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: George Wang 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 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;