From users-return-116782-archive-asf-public=cust-asf.ponee.io@httpd.apache.org Thu Jan 11 16:12:23 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 40FBA180656 for ; Thu, 11 Jan 2018 16:12:23 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 307F3160C20; Thu, 11 Jan 2018 15:12:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 75CE8160C1F for ; Thu, 11 Jan 2018 16:12:22 +0100 (CET) Received: (qmail 63060 invoked by uid 500); 11 Jan 2018 15:12:20 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 63050 invoked by uid 99); 11 Jan 2018 15:12:20 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jan 2018 15:12:20 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 76740C00B5 for ; Thu, 11 Jan 2018 15:12:20 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.121 X-Spam-Level: X-Spam-Status: No, score=-0.121 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id pS04TWeZexb8 for ; Thu, 11 Jan 2018 15:12:19 +0000 (UTC) Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id D79655F36C for ; Thu, 11 Jan 2018 15:12:18 +0000 (UTC) Received: by mail-qk0-f195.google.com with SMTP id j185so4667069qkc.5 for ; Thu, 11 Jan 2018 07:12:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=P4f4itqm2nBsrk7s1HTJl1kedJzKVSqfn8XjuZlU2Fk=; b=iL/9evgkSk2srSMC2dUzn8j+eRCPNJznIxLQngkOsS/AJnnsjToGe/1k7Va8PdUT6Y bA24EP0DL4bT2q/Scz72j41BMbRIN3/rEko3E8h2goXHGRWSwKF8XPxfC/yimvP5NjB4 tZtZG7kcxYtmv/stcafxdoSzG8yfteSzQh/jo9VoRGhpjt3d6tP+3Bf7tG5rXIsgnApY ycAQUvbDAR/2a81k2251VnhuK4s0brnPckNQSfOmDIWYwPJ6yLgonx3GaZC1Jm3sa4XS x+FD3B/bvN/8BZJY8CrHbl/USt2B6/ndUWvWxY7aC9tMn4nXtswzCI2McC/Ls8kkv8nT paeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=P4f4itqm2nBsrk7s1HTJl1kedJzKVSqfn8XjuZlU2Fk=; b=h1rxLaNgw5RfxTaRhRUIi05xA8AY6kHmTFihI/pxF8kBqyjkKmtgxOVzMoABeuh6kG Im+vzSx+567I6UpX0eESPVUIVCvwNU3PlJqbQ5p/9I1SqUk9QlbPJ61DwhigDlAvMYYa tRSJGOJS7fSTKP4YQqGdzHSRlabClqmcvRSoIVjLiZ1y2eCQLc9EHfx4L5T8To8xObqB fujljUjCxNc2Hb/CIpdQYlpIMMahBTsbixahh+bhQYIz5uQYhn8aMIGDgTp/VVsTb7u1 NLHohTCUpNhvkXB9w69tTqUsTebUokvg9jO7x90oHS6KvR//Davjv2hVGgLqMuZaYmqS qsCw== X-Gm-Message-State: AKwxytfutkKLpNGzPSbi2b79zp9uIM/sGKKQZ2LvjmVRzioZaFWnCvk8 aRAQQuTt96Lje31De7ctwS2NNtE0u7mITUGykFrQ/g== X-Google-Smtp-Source: ACJfBouFawwqmzsMdXt5EJ3/gtfXRPICgBtGtryLg2qRnUaT6mS00/j7J1h2EigfGr7z0QurQj5zwn/mCq+b8/JEcvU= X-Received: by 10.55.64.84 with SMTP id n81mr13534409qka.95.1515683532056; Thu, 11 Jan 2018 07:12:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.55.27.144 with HTTP; Thu, 11 Jan 2018 07:12:11 -0800 (PST) In-Reply-To: References: <672304a1-da89-ab13-1ebf-2ff10e06dc86@gikaku.com> From: Yann Ylavic Date: Thu, 11 Jan 2018 16:12:11 +0100 Message-ID: To: users@httpd.apache.org Content-Type: text/plain; charset="UTF-8" Subject: Re: [users@httpd] dumb apr_pool question On Thu, Jan 11, 2018 at 3:05 PM, Eric Covener wrote: > On Thu, Jan 11, 2018 at 3:55 AM, Simon Walter wrote: >> >> I suppose that the pool is keeping track of all it's allocations and if >> something is still referenced, it will not free it. > > No the only tracking is done by whoever manages the lifecycle of the > pool itself -- no magic. > > apr_pool_destroy will call free() or munmap or any underlying > allocation on the way out, returning it to the OS. Actually the memory is returned to the (apr_)allocator, which itself may cache for further reuse. One can use apr_allocator_max_free_set() to limit the number of pages cached (no limit by default), e.g. something like the following code based on Simon's (not even compile tested...): int main(int ArgCount, char * Arg[]) { char * String; apr_pool_t * Pool = NULL; apr_allocator_t * Alloc = NULL; apr_initialize(); /* New allocator (not the default/unlimited one) */ apr_allocator_create(&Alloc); /* Cache one page only (may be 4K pages, not system's), * zero is unlimited, so the cache is always 1 page min... */ apr_allocator_max_free_set(Alloc, 1/*page*/); /* Use this allocator for the pool */ apr_pool_create_ex(&Pool, NULL, NULL, Alloc); /* Destroy Alloc when destroying Pool */ apr_allocator_owner_set(Alloc, Pool); /* Won't crash (possibly), don't do that for real... */ String = apr_pstrdup(Pool, "small alloc"); apr_pool_clear(Pool); printf("String: %s\n", String); /* Should crash */ (void)apr_palloc(Pool, 4100); (void)apr_palloc(Pool, 4100); (void)apr_palloc(Pool, 4100); String = apr_pstrdup(Pool, "small alloc"); apr_pool_clear(Pool); printf("String: %s\n", String); /* Should also crash */ String = apr_pstrdup(Pool, "small alloc"); apr_pool_destroy(Pool); /* + Alloc */ printf("String: %s\n", String); apr_terminate(); return 0; } --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org For additional commands, e-mail: users-help@httpd.apache.org