From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JJFh0HuvmrOsu8Ff1hJJPhjlw/F2FDgyJ+hp2Gtgy4M=; b=WVYmR03zoVTwedr95rbsC5mpK8rC9tKmp0x6jCBC1YDafQThmbxx6jAGdh44qraK9e 8UeuiaANp83PMHaZYz7ebgdrlwCqqZjcYxks0FlwhH8pf/U0wW9cMPVe+BdaYZgxuSY2 nT4WsN4kyBED1e0Pp5xRvVmwWMy09O772cauSFFr476xdWVV6fjy1S1ayNycLDH3EMBQ Xfp+quTrN5SrN0aij2OUoyyEvbhbaC5PBJX9H+iIHe37ujBwxJHW3nArl6bTHTpR8D3K BO4IDzMnGssKGFTZZHshXlPHnmTaJwNn+9vg98sRJzJ4NTM9xboo5G3TfokfyoUlaLxJ p8LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JJFh0HuvmrOsu8Ff1hJJPhjlw/F2FDgyJ+hp2Gtgy4M=; b=LPg2+qrzMRIdz3cAbOZcCKby6xZGxtOu5ga65GB/8ra/1GbHOBMS08fJSOwIa8dT4z 6KR3rc7GQKrHK5GLB1ts+nLikauvedCtiz/e2EzGegyn5bz7XO028mnQucRMtWrlyLu1 /f6tepEP0fS4s/4hZk1N8Es6ncS1VdVDVwdw/vcD881iCSt1Lz4ImtFFDnn2Tp0z52BX QMPG2lUjLgxueXZ94tqPI4YQvSpAZ8tuTyLs36fv9JOVJopu+PPrd+AHPjXw5sMYldUS CSIRirba8jNjylGU6qkKdcgei6A3eyGMeNpKtKQg5WvRwL1G40+slMCeMP8d44FV9qdy uduA== X-Gm-Message-State: AOAM531/7sOSm4Mw0cAcGVf2FGXmz0vu3ueNH+6bS0HSB0QLDEE/m+fh ve30JfEXttSQYe/iMZu3okFUTLdcoJck1A== X-Google-Smtp-Source: ABdhPJx4vDHpxxoGjZgrbPiHueO2IJX7lQ4svt7j6r3G3LOwwJ53N5OAmlPpArKQZD8Jl6/hbENGjA== X-Received: by 2002:a19:be14:: with SMTP id o20mr4314260lff.305.1608417833662; Sat, 19 Dec 2020 14:43:53 -0800 (PST) From: Alexey Tourbin To: devel@lists.altlinux.org Date: Sun, 20 Dec 2020 01:43:47 +0300 Message-Id: <20201219224347.230119-1-alexey.tourbin@gmail.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Alexey Tourbin Subject: [devel] [PATCH] pack.c: downgrade XZ->LZMA automatically for small payloads X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Dec 2020 22:43:56 -0000 Archived-At: List-Archive: List-Post: Recent changes left downgradeLzmaLevel dysfunctional (because it does not recognize 'T'). In my view, the only advantage of XZ over LZMA is that XZ can can split input into blocks and compress them in parallel (resulting in a speed-up). Other advantages, such as a checksum, are immaterial for our purpose (because the package manager must verify the integrity of a package beforehand). Therefore, downgradeLzmaLevel will also downgrade XZ->LZMA automatically, for payloads smaller than 5*dictSize (the default blockSize being 3*dictSize, so that there are at least two blocks, the second block not too small). --- build/pack.c | 54 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/build/pack.c b/build/pack.c index 23ad89e72..a779e7918 100644 --- a/build/pack.c +++ b/build/pack.c @@ -416,30 +416,60 @@ static uint64_t calcArchiveSize(TFI_t fi) // which is 8-64M. For smaller inputs, levels 7-9 are downgraded automatically. static void downgradeLzmaLevel(char *mode, uint64_t archiveSize) { -#define C(c) if (!(c)) return - C(mode[1] == '7' || mode[1] == '8' || mode[1] == '9'); - C(mode[2] == '.'); - C(mode[3] == 'l' || mode[3] == 'x'); - C(mode[4] == 'z'); + if (!(mode[1] >= '0' && mode[1] <= '9')) + return; + char *p = &mode[2]; + if (*p == 'T') { + do + p++; + while (*p >= '0' && *p <= '9'); + } + if (!(*p == '.' && (p[1] != 'l' || p[1] == 'x') && p[2] == 'z')) + return; #define S(m) ((m << 20) + (m << 10)) + // For small payloads, downgrade XZ->LZMA automatically. XZ only makes + // sense in multi-threaded mode (to speed up compression). The default + // block size in multi-threaded mode is three times the dictionary size. + // There has to be at least two blocks, the second block not too small, + // so we require at least five times the dictionary size. +#define T(m) ((m << 20) * 5) +#define ForceLzma memcpy(&mode[2], ".lzdio", 7) switch (mode[1]) { case '9': - if (archiveSize > S(32)) - break; + if (archiveSize < T(64)) ForceLzma; + if (archiveSize > S(32)) break; mode[1] = '8'; /*@fallthrough@*/ case '8': - if (archiveSize > S(16)) - break; + if (archiveSize < T(32)) ForceLzma; + if (archiveSize > S(16)) break; mode[1] = '7'; /*@fallthrough@*/ case '7': - if (archiveSize > S(8)) - break; + if (archiveSize < T(16)) ForceLzma; + if (archiveSize > S(8)) break; mode[1] = '6'; + /*@fallthrough@*/ + case '6': + case '5': + if (archiveSize < T(8)) ForceLzma; + break; + case '4': + case '3': + if (archiveSize < T(4)) ForceLzma; + break; + case '2': + if (archiveSize < T(2)) ForceLzma; + break; + case '1': + if (archiveSize < T(1)) ForceLzma; + break; + case 0: + // Dictionary size is 256K, but block size is 1M. + if (archiveSize < (7<<18)) ForceLzma; } -#undef C #undef S +#undef T } int writeRPM(Header *hdrp, const char *fileName, int type, -- 2.25.4