From patchwork Thu Aug 15 10:22:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11095513 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 9791E6C5 for ; Thu, 15 Aug 2019 10:22:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85A952886E for ; Thu, 15 Aug 2019 10:22:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78743288A7; Thu, 15 Aug 2019 10:22:48 +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=-7.9 required=2.0 tests=BAYES_00,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 68D932886E for ; Thu, 15 Aug 2019 10:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726352AbfHOKWq (ORCPT ); Thu, 15 Aug 2019 06:22:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:45270 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726109AbfHOKWq (ORCPT ); Thu, 15 Aug 2019 06:22:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9ABCBB626; Thu, 15 Aug 2019 10:22:45 +0000 (UTC) From: Nikolay Borisov To: guaneryu@gmail.com Cc: fstests@vger.kernel.org, sandeen@sandeen.net, Nikolay Borisov Subject: [PATCH] generic: Optimize generic/519 Date: Thu, 15 Aug 2019 13:22:40 +0300 Message-Id: <20190815102240.31110-1-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently generic/519 takes around 5-10 minutes for me. This is mainly due to the fact it uses a bunch of commands which spawn processes. This, coupled by the fact the algorithm is O(n^2) in the number of lines (624) for the sparse file and that test feels like it's hung. Fix this by re-implementing the existing logic in awk. This causes a s single processes to be spawned and the rest of the processing is done in-memory. This makes the test complete in 2 seconds for me. Signed-off-by: Nikolay Borisov --- tests/generic/519 | 67 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/tests/generic/519 b/tests/generic/519 index d1a3c1711ec1..b7ef1d9c5008 100755 --- a/tests/generic/519 +++ b/tests/generic/519 @@ -42,8 +42,6 @@ testfile="$SCRATCH_MNT/$seq-testfile" # the FIEMAP ioctl. Then verify if there's map overlap. verify_filefrag() { - local n=1 - # record details in .full file ${FILEFRAG_PROG} -Bes -v $testfile >> $seqres.full @@ -52,36 +50,41 @@ verify_filefrag() ${FILEFRAG_PROG} -Be $testfile | _filter_filefrag | \ cut -d# -f1-2 > $tmp.filefrag - # Verify there's not physical address overlay - for i in `cat $tmp.filefrag`; do - # Get the start(v1) and end(v2) addresses will be verified - v1=`sed -n "${n}p" $tmp.filefrag | cut -d# -f1` - v2=`sed -n "${n}p" $tmp.filefrag | cut -d# -f2` - # The 2nd value is length, so the real end is: - v2=$((v1 + v2)) - - # Remove the line need to be verified ($i), compare with other - # lines one by one - sed -e "${n}d" $tmp.filefrag > $tmp.filefrag.tmp - for j in `cat $tmp.filefrag.tmp`; do - # Get 'next' line start(e1) and end(e2) addresses - e1=`echo $j | cut -d# -f1` - e2=`echo $j | cut -d# -f2` - # The 2nd value is length, so the real end is: - e2=$((e1 + e2)) - - # Verify there's not: - # [ e1 ... e2 ] - # [ v1 ... v2 ] - # Or: - # [ e1 ... e2 ] - # [ v1 ... v2 ] - if ! [ ${v1} -ge ${e2} -o ${v2} -le ${e1} ]; then - echo "find physical addr overlap [$i] vs [$j]" - fi - done - ((n++)) - done + # Verify there's no physical address overlay + awk ' + BEGIN {i=0} + { + # create a lines array of the form begin#end offsets + split($0,res,"#") + begin=res[1] + end=begin+res[2] + lines[i++]=begin"#"end + } + END { + for (i in lines) { + for (j in lines) { + # Dont check i-th line against itself + if (i == j) + continue + + split(lines[i],i_line,"#") + split(lines[j],j_line,"#") + v1=i_line[1] + v2=i_line[2] + e1=j_line[1] + e2=j_line[2] + # Verify there is not: + # [ e1 ... e2 ] + # [ v1 ... v2 ] + # Or: + # [ e1 ... e2 ] + # [ v1 ... v2 ] + if (! (v1 >= e2 || v2 <= e1)) + print "find physical addr overlap " lines[i] " vs " lines[j] + } + } + } + ' $tmp.filefrag } _scratch_mkfs > $seqres.full 2>&1