From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 19A08385BF9E for ; Tue, 23 Mar 2021 20:01:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 19A08385BF9E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-HJHwVQbQMqOqx6q7jiSing-1; Tue, 23 Mar 2021 16:01:37 -0400 X-MC-Unique: HJHwVQbQMqOqx6q7jiSing-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C705881283; Tue, 23 Mar 2021 20:01:37 +0000 (UTC) Received: from rhel8.vm.delorie.com (ovpn-112-40.rdu2.redhat.com [10.10.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E423460BE5; Tue, 23 Mar 2021 20:01:36 +0000 (UTC) Received: from rhel8.vm.redhat.com (localhost [127.0.0.1]) by rhel8.vm.delorie.com (8.15.2/8.15.2) with ESMTP id 12NK1ZuE047476; Tue, 23 Mar 2021 16:01:35 -0400 From: DJ Delorie To: Szabolcs Nagy Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 1/6] malloc: Use memsize instead of CHUNK_AVAILABLE_SIZE In-Reply-To: <4af59f688a0c79487187441c3257466037164221.1616155129.git.szabolcs.nagy@arm.com> (message from Szabolcs Nagy on Fri, 19 Mar 2021 13:26:09 +0000) Date: Tue, 23 Mar 2021 16:01:35 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Mar 2021 20:01:41 -0000 Szabolcs Nagy writes: > This is a pure refactoring change that does not affect behaviour. You hope :-) LGTM. Reviewed-by: DJ Delorie > - for (size = CHUNK_AVAILABLE_SIZE (p) - 1; > + for (size = CHUNK_HDR_SZ + memsize (p) - 1; Ok. > - max_sz = CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ; > + max_sz = memsize (p); Ok. > - for (sz = CHUNK_AVAILABLE_SIZE (p) - 1; > + for (sz = CHUNK_HDR_SZ + memsize (p) - 1; Ok. Odd that it's not chunksize() but that would affect behavior ;-) > - for (sz = CHUNK_AVAILABLE_SIZE (p) - 1; > + for (sz = CHUNK_HDR_SZ + memsize (p) - 1; Ok. > - (void)tag_region (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p) > - - CHUNK_HDR_SZ); > + (void)tag_region (chunk2rawmem (p), memsize (p)); Ok. > -/* Available size of chunk. This is the size of the real usable data > - in the chunk, plus the chunk header. Note: If memory tagging is > - enabled the layout changes to accomodate the granule size, this is > - wasteful for small allocations so not done by default. The logic > - does not work if chunk headers are not granule aligned. */ > -_Static_assert (__MTAG_GRANULE_SIZE <= CHUNK_HDR_SZ, > - "memory tagging is not supported with large granule."); > -#define CHUNK_AVAILABLE_SIZE(p) \ > - (__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \ > - chunksize (p) : \ > - chunksize (p) + (chunk_is_mmapped (p) ? 0 : SIZE_SZ)) > - Dropped, ok. > +/* This is the size of the real usable data in the chunk. Not valid for > + dumped heap chunks. */ > +#define memsize(p) \ > + (__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \ > + chunksize (p) - CHUNK_HDR_SZ : \ > + chunksize (p) - CHUNK_HDR_SZ + (chunk_is_mmapped (p) ? 0 : SIZE_SZ)) > + > +/* If memory tagging is enabled the layout changes to accomodate the granule > + size, this is wasteful for small allocations so not done by default. > + Both the chunk header and user data has to be granule aligned. */ > +_Static_assert (__MTAG_GRANULE_SIZE <= CHUNK_HDR_SZ, > + "memory tagging is not supported with large granule."); > + New, ok. > - ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr), > - CHUNK_AVAILABLE_SIZE (cp) - CHUNK_HDR_SZ); > + ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr), memsize (cp)); Ok. > - (void)tag_region (chunk2rawmem (p), > - CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ); > + (void)tag_region (chunk2rawmem (p), memsize (p)); Ok. > - size_t sz = CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ; > + size_t sz = memsize (oldp); Ok. > - return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ); > + return tag_new_zero_region (mem, memsize (p)); Ok. > - size_t sz = CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ; > + size_t sz = memsize (oldp); Ok. > - result = CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ; > + result = memsize (p); Ok.