<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>296902</bug_id>
          
          <creation_ts>2025-08-04 15:55:12 -0700</creation_ts>
          <short_desc>[libpas] bmalloc_heap.h should support aligned-zeroed allocations</short_desc>
          <delta_ts>2025-08-08 16:48:51 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>bmalloc</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Marcus Plutowski">marcus_plutowski</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ggaren</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2134285</commentid>
    <comment_count>0</comment_count>
    <who name="Marcus Plutowski">marcus_plutowski</who>
    <bug_when>2025-08-04 15:55:12 -0700</bug_when>
    <thetext>rdar://157510912

Currently, we support both aligned allocations (e.g. bmalloc_allocate_with_alignment) and zeroed allocations (e.g. bmalloc_allocate_zeroed); however, we do not support simultaneously-aligned-and-zeroed allocations (e.g. bmalloc_allocate_zeroed_with_alignment).

The consumer of the API can just zero it themselves, but libpas is careful to optimize out that zeroing operation if it knows it’s not necessary, e.g. if the page was newly mmap’d (c.f. pas_allocation_result_zero). 
This comes up when allocating wasm memory, as we basically
  1. Ask for a huge allocation
  2. Mmap over it to ensure it’s zero
This is probably not itself a huge performance problem, but it does show up when I tried to switch that #2 over to madvise(MADV_ZERO): normally this would be preferable because this subsequent mmap would fragment the backing vm-objects (and acquire more locks), but in the case that we’re just replacing the entire vm-object anyways the first downside goes away, while the actual effort of going page-by-page and making sure they’re zeroed begins to dominate.
Creating this new bmalloc_allocate_zeroed_with_alignment family of functions will allow us to avoid that unnecessary mmap and unblock migrating it to use madvise(MADV_ZERO) instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2134294</commentid>
    <comment_count>1</comment_count>
    <who name="Marcus Plutowski">marcus_plutowski</who>
    <bug_when>2025-08-04 16:05:35 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/48928</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2135344</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-08-08 16:48:50 -0700</bug_when>
    <thetext>Committed 298428@main (2ea1c1850d3a): &lt;https://commits.webkit.org/298428@main&gt;

Reviewed commits have been landed. Closing PR #48928 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>