From patchwork Sun Jul 21 19:40:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 11051149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E656E14DB for ; Sun, 21 Jul 2019 19:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D47462856B for ; Sun, 21 Jul 2019 19:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C610D205F8; Sun, 21 Jul 2019 19:41:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69F96205F8 for ; Sun, 21 Jul 2019 19:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727101AbfGUTk4 (ORCPT ); Sun, 21 Jul 2019 15:40:56 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43896 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbfGUTkz (ORCPT ); Sun, 21 Jul 2019 15:40:55 -0400 Received: by mail-pg1-f194.google.com with SMTP id f25so16575612pgv.10 for ; Sun, 21 Jul 2019 12:40:55 -0700 (PDT) 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=R78c7j/BB3KJT+dajb12nN7wpnV8ZjF26Tk9qXthWIs=; b=o93os3ukCFBzwgCjjCR/tFw4UvW2wGq5QHwvEx89mvp0Nb4rSzt62EuMtqVm75NCUu w7DwjNyoJFfzZlvnM3WtLr8X82ki/7C4vdbtm5xy1YJo10MMQk/g680isqVamQ8wuEXZ wzVGUhH2wArKpRqOTVRrHYyLorZWKqtF0si1maPefaUl5lStkuj5ZLRRYdOMqz9Hwisq YBKN/RX2mdYKdzvWMZh92KU/34WE17OXFwmgm2xOnBtjZG5U8TxcYXCY5X1MUdTGDcS6 zL5U3zVZm+b6E8mXTO34K75aH+bJDappnVF+br/mc7tg73d/xNRJOdys+OZBwmegcdtg masA== 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=R78c7j/BB3KJT+dajb12nN7wpnV8ZjF26Tk9qXthWIs=; b=YUx8Y0tr9udStca9FTivndvUfgVKAG9hDmmLARsbmnpkyrBmmo5h5//TrlKjR57/fs pcc6vsQUHxD4vfBvaexuQUeD49GSLYSPYa6KvKJW8QboVGUwtXM2OnzR01ckdv/pG9s4 Uvi4cwwNSvSROFNipfKySlmM6bEQu6d89Z8AeSSkP02H3QLLLuKcYvnP7IYzEkpkslci wpVVZKDnXVZNbx7X1LyJVd/Wl5pSPOJ1K2QOi3PXQ5982DyaEsxK/a0FNDRUI+w7OGv8 ggvOmKWMd59iTny0MpTGKec7J/II2SIuwBFUxx98ARIxc2jG2sZyuwBNcr4oYI3qC5s8 GDCw== X-Gm-Message-State: APjAAAWP1tYo98WvjQTcCtPtLUK/6oB5KBPklnGNSSCrSmDTlDZogyBX QfqcLt2GLQ5AkPxJNk83NfP/RaTJ X-Google-Smtp-Source: APXvYqz+60VgwEdtiA2yBseTBhHYHpl/hniOa80AYvf1/2b6VcLTu1yymyIL4MblfKYj297kab5Z0A== X-Received: by 2002:a63:f452:: with SMTP id p18mr42086254pgk.373.1563738054832; Sun, 21 Jul 2019 12:40:54 -0700 (PDT) Received: from localhost.localdomain (c-67-188-192-166.hsd1.ca.comcast.net. [67.188.192.166]) by smtp.gmail.com with ESMTPSA id m11sm26839477pgl.8.2019.07.21.12.40.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 21 Jul 2019 12:40:54 -0700 (PDT) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: avarab@gmail.com Subject: [PATCH] grep: use custom JIT stack with pcre2 Date: Sun, 21 Jul 2019 12:40:52 -0700 Message-Id: <20190721194052.15440-1-carenas@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 94da9193a6 ("grep: add support for PCRE v2", 2017-06-01) allocate a stack and assign it to a match context, but never pass it to pcre2_jit_match, using instead the default. Signed-off-by: Carlo Marcelo Arenas Belón --- This might have positive performance consequences (per the comments) but haven't tested them; if there is no difference might be better instead to remove the stack and match_context and save the related memory, since it seems the default was working fine anyway. grep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grep.c b/grep.c index 146093f590..ff76907ceb 100644 --- a/grep.c +++ b/grep.c @@ -564,7 +564,7 @@ static int pcre2match(struct grep_pat *p, const char *line, const char *eol, if (p->pcre2_jit_on) ret = pcre2_jit_match(p->pcre2_pattern, (unsigned char *)line, eol - line, 0, flags, p->pcre2_match_data, - NULL); + p->pcre2_match_context); else ret = pcre2_match(p->pcre2_pattern, (unsigned char *)line, eol - line, 0, flags, p->pcre2_match_data, From patchwork Wed Jul 24 15:14:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11057089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C981398 for ; Wed, 24 Jul 2019 15:14:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1C13288D7 for ; Wed, 24 Jul 2019 15:14:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D57BC288E8; Wed, 24 Jul 2019 15:14:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4F33288D7 for ; Wed, 24 Jul 2019 15:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387560AbfGXPOx (ORCPT ); Wed, 24 Jul 2019 11:14:53 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50863 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387551AbfGXPOx (ORCPT ); Wed, 24 Jul 2019 11:14:53 -0400 Received: by mail-wm1-f65.google.com with SMTP id v15so42212307wml.0 for ; Wed, 24 Jul 2019 08:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JCUeVJXfORPUBQ2JLBbL5WWUQ7HNqlFE03QUXcWCw+c=; b=QdPXCJ0eS0L5kOmbSo4h7N86Q1fAY94caHau2oPHRCYXN/9lYmSCW1R6SSTS5w02Fx 3oCtJuGkS7aWAot16cOqC/95qwN18X5pG+fa+HLkce0kP2N5oCHxEfZTaIEGI8qr5ong 5v/E3CkEfxixWb1P1PTzu1MhA1o3OiDpMzS8XI5d+CKJOs/3QVIgD9z42dptGCOPzl+g OgBcdBAzX1MsUYqeG+gTzkdEocat2NUWljN89sYceapLvSiqB33rVFT/Bue/owlh9m6P dPDI1iH1LU+2qIo/sVI/Ng0uerRlys3PO3lQszPVXVVpNCz8kZNbxuAucYGaqDwAQJ0X zywQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=JCUeVJXfORPUBQ2JLBbL5WWUQ7HNqlFE03QUXcWCw+c=; b=rYEP0+tqfaq5VVZ/7w3ShzCttMHkuDbBDjj/x/AZiiSEEohQfhfPlfsggmDDfZKYm2 2bgEQgNHHCyZcYjA6SORTyCffOZ/QCfEikEmVvQF6PgnYBnngqY8WzzUgddRJbYaYeQ2 8ZflNrJAPULrxZDc7b7CevTGLNl9t8uquNJMI1lwr/CsW+UUEWlFvKSE9h/U+YKKq2y1 /xPOBEJQTilqyIEf/Wbvza3w5puwEBMRYo2Xv1KQOUHBxhU9dc+ZK2nd7BlBRqoM1+zu 01t2zVEYExhWHOTkmO56lSfFZeFagLlCi/7+l65NINzTBcsWuc9qd0EYsvdykT0PDqgK 7VUw== X-Gm-Message-State: APjAAAVRTKCrk5Y5ULFC9BYyTRFXDOenkTip8S5WJvIiSH9W+fTu57H4 UAkfwKS3TSdjXByfRTWIVEfsUqGiGUM= X-Google-Smtp-Source: APXvYqyNhcMWSNkxCJ2tcKK8Q0K6emZii6y5MpNtlyeVfsU18iThbHOxGKT8ly9C+xn5z7hQRCDtEg== X-Received: by 2002:a1c:a942:: with SMTP id s63mr73957743wme.76.1563981289961; Wed, 24 Jul 2019 08:14:49 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c78sm66970530wmd.16.2019.07.24.08.14.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 08:14:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Carlo_Marcelo_Arenas_Bel?= =?utf-8?q?=C3=B3n?= , Beat Bolli , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/3] grep: stop "using" a custom JIT stack with PCRE v2 Date: Wed, 24 Jul 2019 17:14:14 +0200 Message-Id: <20190724151415.3698-3-avarab@gmail.com> X-Mailer: git-send-email 2.22.0.455.g172b71a6c5 In-Reply-To: <20190721194052.15440-1-carenas@gmail.com> References: <20190721194052.15440-1-carenas@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As reported in [1] the code I added in 94da9193a6 ("grep: add support for PCRE v2", 2017-06-01) to use a custom JIT stack has never worked. It was incorrectly copy/pasted from code I added in fbaceaac47 ("grep: add support for the PCRE v1 JIT API", 2017-05-25), which did work. Thus our intention of starting with 1 byte of stack at a maximum of 1 MB didn't happen, we'd always use the 32 KB stack provided by PCRE v2's jit_machine_stack_exec()[2]. The reason I allocated a custom stack at all was this advice in pcrejit(3) (same in pcre2jit(3)): "By default, it uses 32KiB on the machine stack. However, some large or complicated patterns need more than this" Since we've haven't had any reports of users running into PCRE2_ERROR_JIT_STACKLIMIT in the wild I think we can safely assume that we can just use the library defaults instead and drop this code. This won't change with the wider use of PCRE v2 in ed0479ce3d ("Merge branch 'ab/no-kwset' into next", 2019-07-15), a fixed string search is not a "large or complicated pattern". For good measure I ran the performance test noted in 94da9193a6, although the command is simpler now due to my 0f50c8e32c ("Makefile: remove the NO_R_TO_GCC_LINKER flag", 2019-05-17): GIT_PERF_REPEAT_COUNT=30 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_MAKE_OPTS='-j8 USE_LIBPCRE2=Y CFLAGS=-O3 LIBPCREDIR=/home/avar/g/pcre2/inst' ./run HEAD~ HEAD p7820-grep-engines.sh Just the /perl/ results are: Test HEAD~ HEAD --------------------------------------------------------------------------------------- 7820.3: perl grep 'how.to' 0.17(0.27+0.65) 0.17(0.24+0.68) +0.0% 7820.7: perl grep '^how to' 0.16(0.23+0.66) 0.16(0.23+0.67) +0.0% 7820.11: perl grep '[how] to' 0.18(0.35+0.62) 0.18(0.33+0.65) +0.0% 7820.15: perl grep '(e.t[^ ]*|v.ry) rare' 0.17(0.45+0.54) 0.17(0.49+0.50) +0.0% 7820.19: perl grep 'm(ú|u)lt.b(æ|y)te' 0.16(0.33+0.58) 0.16(0.29+0.62) +0.0% So, as expected there's no change, and running with valgrind reveals that we have fewer allocations now. 1. https://public-inbox.org/git/20190721194052.15440-1-carenas@gmail.com/ 2. I didn't really intend to start with 1 byte, looking at the PCRE v2 code again what happened is that I cargo-culted some of PCRE v2's own test code which was meant to test re-allocations. It's more sane to start with say 32 KB with a max of 1 MB, as pcre2grep.c does. Reported-by: Carlo Marcelo Arenas Belón Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 10 ---------- grep.h | 4 ---- 2 files changed, 14 deletions(-) diff --git a/grep.c b/grep.c index be4282fef3..20ce95270a 100644 --- a/grep.c +++ b/grep.c @@ -546,14 +546,6 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt p->pcre2_jit_on = 0; return; } - - p->pcre2_jit_stack = pcre2_jit_stack_create(1, 1024 * 1024, NULL); - if (!p->pcre2_jit_stack) - die("Couldn't allocate PCRE2 JIT stack"); - p->pcre2_match_context = pcre2_match_context_create(NULL); - if (!p->pcre2_match_context) - die("Couldn't allocate PCRE2 match context"); - pcre2_jit_stack_assign(p->pcre2_match_context, NULL, p->pcre2_jit_stack); } } @@ -597,8 +589,6 @@ static void free_pcre2_pattern(struct grep_pat *p) pcre2_compile_context_free(p->pcre2_compile_context); pcre2_code_free(p->pcre2_pattern); pcre2_match_data_free(p->pcre2_match_data); - pcre2_jit_stack_free(p->pcre2_jit_stack); - pcre2_match_context_free(p->pcre2_match_context); } #else /* !USE_LIBPCRE2 */ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt) diff --git a/grep.h b/grep.h index 1875880f37..a65f4a1ae1 100644 --- a/grep.h +++ b/grep.h @@ -29,8 +29,6 @@ typedef int pcre_jit_stack; typedef int pcre2_code; typedef int pcre2_match_data; typedef int pcre2_compile_context; -typedef int pcre2_match_context; -typedef int pcre2_jit_stack; #endif #include "kwset.h" #include "thread-utils.h" @@ -94,8 +92,6 @@ struct grep_pat { pcre2_code *pcre2_pattern; pcre2_match_data *pcre2_match_data; pcre2_compile_context *pcre2_compile_context; - pcre2_match_context *pcre2_match_context; - pcre2_jit_stack *pcre2_jit_stack; uint32_t pcre2_jit_on; kwset_t kws; unsigned fixed:1; From patchwork Wed Jul 24 15:14:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11057093 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1797513AC for ; Wed, 24 Jul 2019 15:14:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 061E0288D9 for ; Wed, 24 Jul 2019 15:14:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEDF0288E6; Wed, 24 Jul 2019 15:14:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78AD1288D9 for ; Wed, 24 Jul 2019 15:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387562AbfGXPO4 (ORCPT ); Wed, 24 Jul 2019 11:14:56 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43669 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387503AbfGXPOy (ORCPT ); Wed, 24 Jul 2019 11:14:54 -0400 Received: by mail-wr1-f66.google.com with SMTP id p13so47379910wru.10 for ; Wed, 24 Jul 2019 08:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pF3nbeSRno6FpOr1XD6hB9MoXJBaQiNhzoKP63+gqFk=; b=J1Lnm8qenq1iF0qZcBw2kXJXf5RFccIeiEXcze55FKT3fKXg0I+x0/sdHxObCNTPl3 rnu4OtLazaxFxda/py1ACTJufApXzbNgZ8kahJHzQEJJv0zDQNY/hJIdYC1XmuSV7j+g x6df35r78XYR9Z/4UKJ6O2ucxDVNUgAYLP9gvmr3+jXlxZE0XQLZ6XbTJITeCv2P7Yaa gelGtp9cBo4d6d+QUhrBfPEwOJUkXRbF6rtdSemVvaX6qO9LuplLPpPoLftwWIlZXBxx U2Fctzc4GbOL8Bo0s7EropT31tfzs1RXfhcnZ3V2F5qDthBRL5WS0ymJkgkZXEwwfnxn wFFw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=pF3nbeSRno6FpOr1XD6hB9MoXJBaQiNhzoKP63+gqFk=; b=VcYCahTLrX9sVw2loO3gbHVSZPmzpC0GZHs/y13cS5EMXruGi+LXY7pocrwz7oNfEn ST8Gz29PEatH9+wjZlAwUYOB7m8YEiZRtaUHFcr3tczqyxDS5mTq4CWh8DNRcgPlm5hZ OIQ9WLdw29XUJbYQPXQgMHmWWrWj2ukApEh+lMKt8MJenHNiPCZmRVRIJ6pFnBc4wknb UqVl/r1Oo5wMBn7Pnw42JJ3ARzrUyexXucg42CwgSAHvjbqSRaMgwMPidjPu1bz1vOKa DhFwN2rzXlVZepJmSaJ1FOa3en4Udum6NsOe01Oe6i2pfCxrJZDvrwNK+bczYs6tdX0d hCRA== X-Gm-Message-State: APjAAAXGvUaE7m80SKbNmF/gUk3hCeDBC0m+ZOVoBahWqat7QIfGhEqZ Gibd4cUZYi4hjRM3KUFtW1iaGwItNUA= X-Google-Smtp-Source: APXvYqz30i1Co1lElL9+i26IHbGlt3SbM/M7vu/YwFc2X/2h387ZezzCLww94WnWTVdPug+5YEuENw== X-Received: by 2002:adf:fd08:: with SMTP id e8mr91446782wrr.147.1563981291291; Wed, 24 Jul 2019 08:14:51 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c78sm66970530wmd.16.2019.07.24.08.14.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 08:14:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Carlo_Marcelo_Arenas_Bel?= =?utf-8?q?=C3=B3n?= , Beat Bolli , Johannes Schindelin , =?utf-8?b?w4Z2YXIgQXJu?= =?utf-8?b?ZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/3] grep: stop using a custom JIT stack with PCRE v1 Date: Wed, 24 Jul 2019 17:14:15 +0200 Message-Id: <20190724151415.3698-4-avarab@gmail.com> X-Mailer: git-send-email 2.22.0.455.g172b71a6c5 In-Reply-To: <20190721194052.15440-1-carenas@gmail.com> References: <20190721194052.15440-1-carenas@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify the PCRE v1 code for the same reasons as for the PCRE v2 code in the last commit. Unlike with v2 we actually used the custom stack in v1, but let's use PCRE's built-in 32 KB one instead, since experience with v2 shows that's enough. Most distros are already using v2 as a default, and the underlying sljit code is the same. Unfortunately we can't just pass a NULL to pcre_jit_exec() as with pcre2_jit_match(). Unlike the v2 function it doesn't support that. Instead we need to use the fatter pcre_exec() if we'd like the same behavior. This will make things slightly slower than on the fast-path function, but it's OK since we care less about v1 performance these days since we have and recommend v2. Running a similar performance test as what I ran in fbaceaac47 ("grep: add support for the PCRE v1 JIT API", 2017-05-25) via: GIT_PERF_REPEAT_COUNT=30 GIT_PERF_LARGE_REPO=~/g/linux GIT_PERF_MAKE_OPTS='-j8 USE_LIBPCRE1=Y CFLAGS=-O3 LIBPCREDIR=/home/avar/g/pcre/inst' ./run HEAD~ HEAD p7820-grep-engines.sh Gives us this, just the /perl/ results: Test HEAD~ HEAD --------------------------------------------------------------------------------------- 7820.3: perl grep 'how.to' 0.19(0.67+0.52) 0.19(0.65+0.52) +0.0% 7820.7: perl grep '^how to' 0.19(0.78+0.44) 0.19(0.72+0.49) +0.0% 7820.11: perl grep '[how] to' 0.39(2.13+0.43) 0.40(2.10+0.46) +2.6% 7820.15: perl grep '(e.t[^ ]*|v.ry) rare' 0.44(2.55+0.37) 0.45(2.47+0.41) +2.3% 7820.19: perl grep 'm(ú|u)lt.b(æ|y)te' 0.23(1.06+0.42) 0.22(1.03+0.43) -4.3% Signed-off-by: Ævar Arnfjörð Bjarmason --- grep.c | 28 +++++----------------------- grep.h | 5 ----- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/grep.c b/grep.c index 20ce95270a..6b52fed53a 100644 --- a/grep.c +++ b/grep.c @@ -406,12 +406,6 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt) #ifdef GIT_PCRE1_USE_JIT pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on); - if (p->pcre1_jit_on) { - p->pcre1_jit_stack = pcre_jit_stack_alloc(1, 1024 * 1024); - if (!p->pcre1_jit_stack) - die("Couldn't allocate PCRE JIT stack"); - pcre_assign_jit_stack(p->pcre1_extra_info, NULL, p->pcre1_jit_stack); - } #endif } @@ -423,18 +417,9 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol, if (eflags & REG_NOTBOL) flags |= PCRE_NOTBOL; -#ifdef GIT_PCRE1_USE_JIT - if (p->pcre1_jit_on) { - ret = pcre_jit_exec(p->pcre1_regexp, p->pcre1_extra_info, line, - eol - line, 0, flags, ovector, - ARRAY_SIZE(ovector), p->pcre1_jit_stack); - } else -#endif - { - ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line, - eol - line, 0, flags, ovector, - ARRAY_SIZE(ovector)); - } + ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line, + eol - line, 0, flags, ovector, + ARRAY_SIZE(ovector)); if (ret < 0 && ret != PCRE_ERROR_NOMATCH) die("pcre_exec failed with error code %d", ret); @@ -451,14 +436,11 @@ static void free_pcre1_regexp(struct grep_pat *p) { pcre_free(p->pcre1_regexp); #ifdef GIT_PCRE1_USE_JIT - if (p->pcre1_jit_on) { + if (p->pcre1_jit_on) pcre_free_study(p->pcre1_extra_info); - pcre_jit_stack_free(p->pcre1_jit_stack); - } else + else #endif - { pcre_free(p->pcre1_extra_info); - } pcre_free((void *)p->pcre1_tables); } #else /* !USE_LIBPCRE1 */ diff --git a/grep.h b/grep.h index a65f4a1ae1..a405fc870c 100644 --- a/grep.h +++ b/grep.h @@ -14,13 +14,9 @@ #ifndef GIT_PCRE_STUDY_JIT_COMPILE #define GIT_PCRE_STUDY_JIT_COMPILE 0 #endif -#if PCRE_MAJOR <= 8 && PCRE_MINOR < 20 -typedef int pcre_jit_stack; -#endif #else typedef int pcre; typedef int pcre_extra; -typedef int pcre_jit_stack; #endif #ifdef USE_LIBPCRE2 #define PCRE2_CODE_UNIT_WIDTH 8 @@ -86,7 +82,6 @@ struct grep_pat { regex_t regexp; pcre *pcre1_regexp; pcre_extra *pcre1_extra_info; - pcre_jit_stack *pcre1_jit_stack; const unsigned char *pcre1_tables; int pcre1_jit_on; pcre2_code *pcre2_pattern;