develooper Front page | perl.perl5.porters | Postings from August 2009

Re: [patch 2/3] - private arenas - track allocs by reqid

From:
Jim Cromie
Date:
August 26, 2009 17:22
Subject:
Re: [patch 2/3] - private arenas - track allocs by reqid
Message ID:
cfe85dfa0908261722y7f558776x745f1dab3a140e58@mail.gmail.com
BTW, in case it wasnt obvious, these are related to this 1st post
(which istm got separated by editing the subject)

http://www.nntp.perl.org/group/perl.perl5.porters/2009/08/msg150259.html



> 0002-add-reqid-field-to-arena-descriptor-and-arg-to-get_.patch
>




[jimc@harpo perl]$ more
0002-add-reqid-field-to-arena-descriptor-and-arg-to-get_.patch

From f3d0623084340194ac03968802eb7002525b19bb Mon Sep 17 00:00:00 2001
From: Jim Cromie <jim.cromie@gmail.com>
Date: Fri, 21 Aug 2009 15:52:28 -0600
Subject: [PATCH 2/7] add reqid field to arena descriptor, and arg to
get_arena

this field will allow get-arena to remember the requestor of the
arenas it serves out.  Later, release_arenas() will use the field
to find and free arenas.

get-arena() requires that caller pass a NN void* request-id so that
arenas allocated by it can be tracked, then found later by release_arenas().
The type promises no derefs, so pass +1 as NN default reqid,
until plumbing is added.  Also cleanup obfuscated arg-names and types.
---
 embed.fnc |    3 ++-
 hv.c      |    2 +-
 proto.h   |    7 +++++--
 sv.c      |   21 +++++++++++++--------
 4 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/embed.fnc b/embed.fnc
index 3e829b6..8799f31 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1354,7 +1354,8 @@ s    |HV*    |require_tie_mod|NN GV *gv|NN const char
*varpv|NN SV* namesv \

 : #if defined(PERL_IN_HV_C) || defined(PERL_IN_SV_C) ||
defined(PERL_DECL_PROT)
 : Used in hv.c
-paRxo    |void*    |get_arena    |const size_t svtype|const U32 misc
+paRxo    |void*    | get_arena    | const size_t arena_size | const svtype
bodytype \
+                | NN void * const reqid
 : #endif

 #if defined(PERL_IN_HV_C) || defined(PERL_DECL_PROT)
diff --git a/hv.c b/hv.c
index ee3a67e..17dd148 100644
--- a/hv.c
+++ b/hv.c
@@ -47,7 +47,7 @@ S_more_he(pTHX)
     /* We could generate this at compile time via (another) auxiliary C
        program?  */
     const size_t arena_size = Perl_malloc_good_size(PERL_ARENA_SIZE);
-    HE* he = (HE*) Perl_get_arena(aTHX_ arena_size, HE_SVSLOT);
+    HE* he = (HE*) Perl_get_arena(aTHX_ arena_size, HE_SVSLOT,
&PL_body_roots[HE_SVSLOT]);
     HE * const heend = &he[arena_size / sizeof(HE) - 1];

     PL_body_roots[HE_SVSLOT] = he;
diff --git a/proto.h b/proto.h
index 8c52f5a..528e5f8 100644
--- a/proto.h
+++ b/proto.h
@@ -4245,9 +4245,12 @@ STATIC HV*    S_require_tie_mod(pTHX_ GV *gv, const
char *varpv, SV* namesv, const

 #endif

-PERL_CALLCONV void*    Perl_get_arena(pTHX_ const size_t svtype, const U32
misc)
+PERL_CALLCONV void*    Perl_get_arena(pTHX_ const size_t arena_size, const
svtype bodytype, void * const req
id)
             __attribute__malloc__
-            __attribute__warn_unused_result__;
+            __attribute__warn_unused_result__
+            __attribute__nonnull__(pTHX_3);
+#define PERL_ARGS_ASSERT_GET_ARENA    \
+    assert(reqid)


 #if defined(PERL_IN_HV_C) || defined(PERL_DECL_PROT)
diff --git a/sv.c b/sv.c
index b938891..4ba2319 100644
--- a/sv.c
+++ b/sv.c
@@ -606,9 +606,10 @@ Perl_sv_clean_all(pTHX)
   in body_details_by_type[] below.
 */
 struct arena_desc {
-    char       *arena;        /* the raw storage, allocated aligned */
-    size_t      size;        /* its size ~4k typ */
-    U32        misc;        /* type, and in future other things. */
+    char*    arena;    /* the raw storage, allocated aligned */
+    size_t    size;    /* its size ~4k typ, private users may want more */
+    svtype    utype;    /* user body type on the arena */
+    void const *reqid;    /* request-id */
 };

 struct arena_set;
@@ -714,11 +715,14 @@ Perl_sv_free_arenas(pTHX)
   contexts below (line ~10k)
 */

-/* get_arena(size): this creates custom-sized arenas
-   TBD: export properly for hv.c: S_more_he().
-*/
+/* get_arena(arena_size, svtype, reqid): creates custom-sized arenas,
+   tracked by a 'userid', which is saved in arena-desc.reqid, before
+   the arena is returned.  When its time to free the ptr-table, we
+   know that ptes were held privately, so their container slabs can be
+   freed directly, and not just returned to the global freelist.
+   TBD: export properly for hv.c: S_more_he(). */
 void*
-Perl_get_arena(pTHX_ const size_t arena_size, const U32 misc)
+Perl_get_arena(pTHX_ const size_t arena_size, const svtype bodytype, void *
const reqid)
 {
     dVAR;
     struct arena_desc* adesc;
@@ -747,6 +751,7 @@ Perl_get_arena(pTHX_ const size_t arena_size, const U32
misc)

     Newx(adesc->arena, arena_size, char);
     adesc->size = arena_size;
+    adesc->reqid = reqid;
     adesc->utype = bodytype;
     DEBUG_m(PerlIO_printf(Perl_debug_log, "arena %d added: %p size
%"UVuf"\n",
               curr, (void*)adesc->arena, (UV)arena_size));
@@ -1099,7 +1104,7 @@ S_more_bodies (pTHX_ const svtype sv_type)

     assert(bdp->arena_size);

-    start = (char*) Perl_get_arena(aTHX_ arena_size, sv_type);
+    start = (char*) Perl_get_arena(aTHX_ arena_size, sv_type,
(void*)NULL+1);

     end = start + arena_size - 2 * body_size;

-- 
1.6.2.5

[jimc@harpo perl]$



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About