Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBaDk-0006Dh-1U for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 07:22:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBaDh-0005Uv-Up for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 07:22:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBaDh-0005Uo-Ad for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 07:22:01 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBaDe-0001nw-Nm for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 07:22:00 +0000 Received: by mail-pg1-x542.google.com with SMTP id y3so7841030pgk.12 for ; Wed, 03 Apr 2019 00:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=ifiNM2viQgXs5opCuNJRPkcb9rapae69rbPWpvP05Wc=; b=jryOwvGHh38y4uz1MBEMPRvsQlyjVLEiHaOl/HHc7nyc5rY06YhGMNoN1/OKEcnnzH dvhotNk5TQQ36QMzwArDb+pwYE9OA9illVkG38q40dkpzwLdV9c8eGCY0w7U6FizynOr MsPzyeBoJ3SZxi6GhrUY4T67Jlq7a7+hj61nirNyWVToJnt5X5BQBxMVE+C85VqW22UU U9yFVCpilx9K42g5QqmKQeUKHXLKnLDavID8roeQTeK1JlH2uTo2pzYFmQdiEyvgQhxc AyaaneKpRnL1QYQHF+S8Kl/NWRCduCX4R4GZFbt7EFJ2cUQz34d6RSHvZtG9Zwh/uwbp E49Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ifiNM2viQgXs5opCuNJRPkcb9rapae69rbPWpvP05Wc=; b=jcxcpvxUltna8eA+e/uKRq46QJKItFvTcirIIZOZVBulcDM/4Phv1kesEui4A5JGMC UlD0rRtvyP4SavEN1Fl7J0sHYIp+uBokFm/CvwBHK6dj0W9KfpMYM6mrpl62x29XBya7 eN6Lr1PPHc2R9jT2hquE6Qd3vaZ1n4BsAtUAEaHxmD2npGttyZFJ7Ys75O7pyTLBdGpb 25Hm2+0LWQ4kpT2TGPrKJ1ZvOWhMXCE3ZGGqaHr+/sEg4srNCuhED+xuh+dyDlfnHU8w q6Vs56ctHRujTi1QY/ccTn9lXo5TALN/cgAj9cIAxjuB3IqbiVQYdfdlDEgH0RkoEZ9c OELw== X-Gm-Message-State: APjAAAUyv8jI50wqAoypjhLyfFaHF569dot7BBySZEEWQwfb/hq0gFkW mRk3ffW8WOSoLQBw1Uh7QEydeJj/xtQ= X-Google-Smtp-Source: APXvYqy/fwMZTTx4QApJXnDJshB6lPMpWX73Va+nQ1qacjAmhOp6ekHxmZ27rfZQ5nxgMWvALIwAWg== X-Received: by 2002:aa7:920b:: with SMTP id 11mr71617839pfo.3.1554276116978; Wed, 03 Apr 2019 00:21:56 -0700 (PDT) Received: from [192.168.43.209] ([42.111.145.121]) by smtp.gmail.com with ESMTPSA id a8sm26544851pfo.144.2019.04.03.00.21.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 00:21:56 -0700 (PDT) Subject: Re: New LLVM JIT Features To: Andres Freund Cc: pgsql-general@lists.postgresql.org References: <20190402215021.q7e7xjmobakkgan5@alap3.anarazel.de> <859aa673-8303-2a1b-cc23-0dadfd412ec1@gmail.com> <20190403052344.t5cwzrfh4hkquv4b@alap3.anarazel.de> From: preejackie Message-ID: Date: Wed, 3 Apr 2019 12:51:46 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190403052344.t5cwzrfh4hkquv4b@alap3.anarazel.de> Content-Type: multipart/alternative; boundary="------------1736B08B8810B1583A696C14" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------1736B08B8810B1583A696C14 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Andres, Thanks for your thoughts , please see my comments inline. On 03/04/19 10:53 AM, Andres Freund wrote: > On 2019-04-03 10:44:06 +0530, preejackie wrote: >> Hi Andres, >> >> Thanks for the reply! Please see my comments inline. >> >> On 03/04/19 3:20 AM, Andres Freund wrote: >>> Hi, >>> >>> On 2019-04-02 00:51:51 +0530, preejackie wrote: >>>> As LLVM ORC supports compiling in multiple backend threads, it would be >>>> effective if we compile the functions speculatively before they are called >>>> by the executing function. So when we request JIT to compile a function, JIT >>>> will immediately returns the function address for raw executable bits. This >>>> will greatly reduce the JIT latencies in modern multi-core machines. >>> I personally think this should be approached somewhat differently - >>> putting patchpoints into code reduces the efficiency of the generated >>> code, so I don't think that's the right approach. What I think we should >>  What do you mean by patch points here? To my knowledge, LLVM symbols have >> arbitrary stub associated which resolve to function address at function >> address. > I was assuming that you'd want to improve latency by not compiling all > the functions at the start of the executor (like we currently do), but > have sub-functions compiled in the background. That'd require > patchpoints to be able to initially redirect to a function to wait for > compilation, which then can be changed to directly jump to the function. > Because we already just compile all the functions reachable at the start > of execution in one go, so it's not a one-by-one function affair. >   Compiling the whole module will increase your start-up time of the application right? Is there any techniques applied in Pgsql to handle this ? Sometimes, you will compile functions that you don't need immediately or even it will not called in run time. This is the trade-off between different JIT implementations.  Also adding patch points in the generated code will degrade performance only when we didn't compile the function ahead-of-time, theoretically this will patch points miss will go down when we increase the number of compiler threads. And practically every computer have at least 4 cores nowadays. >>> do is to, if we decide it's worthwhile at plan time, generate the LLVM >>> IR time at the beginning of execution, but continue to use interpreted >>> execution initially. The generated IR would then be handed over to a >>> background [process|thread|whatnot] for optimization of code >>> generation. Then, when finished, I'd switch over from interpreted to JIT >>> compiled execution. That approach will, in my view, yield better >>> latency behaviour because we can actually evaluate quals etc for which >>> we've not yet finished code generation. >>> >>> >>>> And also I'm working on designing a ORC in-place dynamic profiling support, by >>>> this JIT will automatically able to identify the hot functions, and compile >>>> it in higher optimization level to achieve good performance. >>> I think that's a nice concept, but at the moment the generated code is >>> so bad that it's much more likely to get big benefits by improving the >>> generated IR, compared to giving more hints to the optimizer. >> By improving the generated IR, you mean by turning pgsql queries into LLVM >> IR? If it is the case, this design doesn't handles that, it works only when >> the given program representation is in LLVM IR. > My point is that we generate IR that's hard for LLVM to optimize. And > that fixing that is going to give you way bigger wins than profile > guided optimization.   I hope this is problem of Pgsql, but I'm proposing this project for LLVM Community. > > Greetings, > > Andres Freund -- Have a great day! PreeJackie --------------1736B08B8810B1583A696C14 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Andres,

Thanks for your thoughts , please see my comments inline.

On 03/04/19 10:53 AM, Andres Freund wrote:
On 2019-04-03 10:44:06 +0530, preejackie wrote:
Hi Andres,

Thanks for the reply! Please see my comments inline.

On 03/04/19 3:20 AM, Andres Freund wrote:
Hi,

On 2019-04-02 00:51:51 +0530, preejackie wrote:
As LLVM ORC supports compiling in multiple backend threads, it would be
effective if we compile the functions speculatively before they are called
by the executing function. So when we request JIT to compile a function, JIT
will immediately returns the function address for raw executable bits. This
will greatly reduce the JIT latencies in modern multi-core machines.
I personally think this should be approached somewhat differently -
putting patchpoints into code reduces the efficiency of the generated
code, so I don't think that's the right approach. What I think we should
 What do you mean by patch points here? To my knowledge, LLVM symbols have
arbitrary stub associated which resolve to function address at function
address.
I was assuming that you'd want to improve latency by not compiling all
the functions at the start of the executor (like we currently do), but
have sub-functions compiled in the background. That'd require
patchpoints to be able to initially redirect to a function to wait for
compilation, which then can be changed to directly jump to the function.
Because we already just compile all the functions reachable at the start
of execution in one go, so it's not a one-by-one function affair.

  Compiling the whole module will increase your start-up time of the application right? Is there any techniques applied in Pgsql to handle this ? Sometimes, you will compile functions that you don't need immediately or even it will not called in run time. This is the trade-off between different JIT implementations.  Also adding patch points in the generated code will degrade performance only when we didn't compile the function ahead-of-time, theoretically this will patch points miss will go down when we increase the number of compiler threads. And practically every computer have at least 4 cores nowadays.


      
do is to, if we decide it's worthwhile at plan time, generate the LLVM
IR time at the beginning of execution, but continue to use interpreted
execution initially. The generated IR would then be handed over to a
background [process|thread|whatnot] for optimization of code
generation. Then, when finished, I'd switch over from interpreted to JIT
compiled execution.  That approach will, in my view, yield better
latency behaviour because we can actually evaluate quals etc for which
we've not yet finished code generation.


And also I'm working on designing a ORC in-place dynamic profiling support, by
this JIT will automatically able to identify the hot functions, and compile
it in higher optimization level to achieve good performance.
I think that's a nice concept, but at the moment the generated code is
so bad that it's much more likely to get big benefits by improving the
generated IR, compared to giving more hints to the optimizer.
By improving the generated IR, you mean by turning pgsql queries into LLVM
IR? If it is the case, this design doesn't handles that, it works only when
the given program representation is in LLVM IR.
My point is that we generate IR that's hard for LLVM to optimize. And
that fixing that is going to give you way bigger wins than profile
guided optimization.
  I hope this is problem of Pgsql, but I'm proposing this project for LLVM Community.  

Greetings,

Andres Freund
-- 
Have a great day!
PreeJackie
--------------1736B08B8810B1583A696C14--