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 1gwoOy-0003IP-5N for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Feb 2019 13:28:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwoOw-0007aW-QX for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Feb 2019 13:28:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwoOw-0007aP-EE for pgsql-hackers@lists.postgresql.org; Thu, 21 Feb 2019 13:28:34 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwoOt-0007Wj-TF for pgsql-hackers@postgresql.org; Thu, 21 Feb 2019 13:28:34 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 7C7EB21CC462; Thu, 21 Feb 2019 16:28:30 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.237] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 3895921CC436; Thu, 21 Feb 2019 16:28:30 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1550755710; bh=RsbITSf1DdOmkaJZkYXQs/BESE55aobSe5HTvCOvhII=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=cnfMaxcalW4o4c+PEADb/FY2drEq2Kuf14Z93tZVKxtaelqpywJV5MNL6xgKn2/Ew lzsPIlwzJTg4RqkUFRTLuqCG+SH3nW35ZjbAJbGhqc/nB0mrCaFTWsS6RJizrpAXgE YqA3ajwozlXe2+W2wv5ihIN/HpHd3obGtpH+B0Go= Subject: Re: [PROPOSAL] Shared Ispell dictionaries To: Robert Haas Cc: Tomas Vondra , Andres Freund , Tom Lane , Pavel Stehule , pgsql-hackers References: <27296.1522078068@sss.pgh.pa.us> <20180516113631.GA29544@zakirov.localdomain> <20180614084015.GA12451@zakirov.localdomain> <20181001092204.GA5071@zakirov.localdomain> <68aaaff6-0efe-c14b-7aee-fb110bb97f69@2ndquadrant.com> <337f7a55-58b8-4fcc-a933-5e7799fa6882@postgrespro.ru> <42b1ded6-fd44-5975-77e4-72ada1f134a2@2ndquadrant.com> <20190120222121.ehistvcr4wsu2su5@alap3.anarazel.de> <95aea959-97a1-2ded-c881-eede4e5a1f0c@2ndquadrant.com> <5113daa6-b6e7-59f6-c4a8-96b5b81474fb@postgrespro.ru> <1932084f-167a-8893-be24-c4c06afe113b@2ndquadrant.com> <26e59c3b-3598-cc2c-6b8d-81d24d6d0930@postgrespro.ru> From: Arthur Zakirov Message-ID: <4c321cb7-899f-0548-ecf4-5e965dd71335@postgrespro.ru> Date: Thu, 21 Feb 2019 16:28:29 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 21.02.2019 15:45, Robert Haas wrote: > On Wed, Feb 20, 2019 at 9:33 AM Arthur Zakirov wrote: >> I'm working on the (b) approach. I thought about a priority queue >> structure. There no such ready structure within PostgreSQL sources >> except binaryheap.c, but it isn't for concurrent algorithms. > > I don't see why you need a priority queue or, really, any other fancy > data structure. It seems like all you need to do is somehow set it up > so that a backend which doesn't use a dictionary for a while will > dsm_detach() the segment. Eventually an unused dictionary will have > no remaining references and will go away. Hm, I didn't think in this way. Agree that using a new data structure is overengineering. Now in the current patch all DSM segments are pinned (and therefore dsm_pin_segment() is called). So a dictionary lives in shared memory even if nobody have the reference to it. I thought about periodically scanning the shared hash table and unpinning old and unused dictionaries. But this approach needs sequential scan facility for dshash. Happily there is the patch from Kyotaro-san (the v16-0001-sequential-scan-for-dshash.patch part): https://www.postgresql.org/message-id/20190221.160555.191280262.horiguchi.kyotaro@lab.ntt.co.jp Your approach looks simpler. It is necessary just to periodically scan dictionaries' cache hash table and not call dsm_pin_segment() when a DSM segment initialized. It also means that a dictionary is loaded into DSM only while there is a backend which attached the dictionary's DSM. -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company