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 ESMTPS id 362113858D33 for ; Thu, 23 Feb 2023 04:20:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 362113858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677126055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=D9K0m+wyQrYJynZa4t2i5py+P8Pgk3kld8WtQO8P+TU=; b=IXUvXIbg/20vntl2/fR4OV0RDRxlRhc1Jo5i2GRzX6w2sVNE4Wayzz/xSkZwVVqVAYtQKC iLFdCltDqc6GSrFgyHRUsMgwO3d6JctiN07tg59nNzsss245sT/ku751ePKixKkMoyDRKX LjYpRyMFsdVdpg2IemJhwCa9LNXZPMo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-1M9u4vSEPW6r43hR2UYyBQ-1; Wed, 22 Feb 2023 23:20:54 -0500 X-MC-Unique: 1M9u4vSEPW6r43hR2UYyBQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5EE7803493; Thu, 23 Feb 2023 04:20:53 +0000 (UTC) Received: from greed.delorie.com (unknown [10.22.8.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC6A3492B05; Thu, 23 Feb 2023 04:20:53 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 31N4KqTT1074439; Wed, 22 Feb 2023 23:20:52 -0500 From: DJ Delorie To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] malloc: Use C11 like atomics on memusage In-Reply-To: <20220831181435.3875859-1-adhemerval.zanella@linaro.org> Date: Wed, 22 Feb 2023 23:20:52 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: LGTM. Reviewed-by: DJ Delorie Adhemerval Zanella via Libc-alpha writes: > +static inline void > +peak_atomic_max (size_t *peak, size_t val) > +{ > + size_t v; > + do > + { > + v = atomic_load_relaxed (peak); > + if (v >= val) > + break; > + } > + while (! atomic_compare_exchange_weak_acquire (peak, &v, val)); > +} > + This is the only call without a direct replacement. This inline replicates what does. Ok. > - = catomic_exchange_and_add (¤t_heap, len - old_len) + len - old_len; > - catomic_max (&peak_heap, heap); > + = atomic_fetch_add_acquire (¤t_heap, len - old_len) + len - old_len; > + peak_atomic_max (&peak_heap, heap); Ok. > - catomic_max (&peak_stack, current_stack); > + peak_atomic_max (&peak_stack, current_stack); Ok. > - catomic_max (&peak_total, heap + current_stack); > + peak_atomic_max (&peak_total, heap + current_stack); Ok. > - uint32_t idx = catomic_exchange_and_add (&buffer_cnt, 1); > + uint32_t idx = atomic_fetch_add_acquire (&buffer_cnt, 1); Ok. > - catomic_compare_and_exchange_val_acq (&buffer_cnt, reset, idx + 1); > + uint32_t expected = idx + 1; > + atomic_compare_exchange_weak_acquire (&buffer_cnt, &expected, reset); Ok. > - catomic_increment (&calls[idx_malloc]); > + atomic_fetch_add_acquire (&calls[idx_malloc], 1); Ok. > - catomic_add (&total[idx_malloc], len); > + atomic_fetch_add_acquire (&total[idx_malloc], len); Ok. > - catomic_add (&grand_total, len); > + atomic_fetch_add_acquire (&grand_total, len); Ok. > if (len < 65536) > - catomic_increment (&histogram[len / 16]); > + atomic_fetch_add_acquire (&histogram[len / 16], 1); > else > - catomic_increment (&large); > + atomic_fetch_add_acquire (&large, 1); Ok. > - catomic_increment (&calls_total); > + atomic_fetch_add_acquire (&calls_total, 1); Ok. > - catomic_increment (&failed[idx_malloc]); > + atomic_fetch_add_acquire (&failed[idx_malloc], 1); Ok. > - catomic_increment (&calls[idx_realloc]); > + atomic_fetch_add_acquire (&calls[idx_realloc], 1); Ok. > - catomic_add (&total[idx_realloc], len - old_len); > + atomic_fetch_add_acquire (&total[idx_realloc], len - old_len); Ok. > - catomic_add (&grand_total, len - old_len); > + atomic_fetch_add_acquire (&grand_total, len - old_len); Ok. > - catomic_increment (&realloc_free); > + atomic_fetch_add_acquire (&realloc_free, 1); Ok. > - catomic_add (&total[idx_free], real->length); > + atomic_fetch_add_acquire (&total[idx_free], real->length); Ok. > if (len < 65536) > - catomic_increment (&histogram[len / 16]); > + atomic_fetch_add_acquire (&histogram[len / 16], 1); > else > - catomic_increment (&large); > + atomic_fetch_add_acquire (&large, 1); Ok. > - catomic_increment (&calls_total); > + atomic_fetch_add_acquire (&calls_total, 1); Ok. > - catomic_increment (&failed[idx_realloc]); > + atomic_fetch_add_acquire (&failed[idx_realloc], 1); Ok. > - catomic_increment (&inplace); > + atomic_fetch_add_acquire (&inplace, 1); Ok. > - catomic_increment (&decreasing); > + atomic_fetch_add_acquire (&decreasing, 1); Ok. > - catomic_increment (&calls[idx_calloc]); > + atomic_fetch_add_acquire (&calls[idx_calloc], 1); Ok. > - catomic_add (&total[idx_calloc], size); > + atomic_fetch_add_acquire (&total[idx_calloc], size); Ok. > - catomic_add (&grand_total, size); > + atomic_fetch_add_acquire (&grand_total, size); Ok. > if (size < 65536) > - catomic_increment (&histogram[size / 16]); > + atomic_fetch_add_acquire (&histogram[size / 16], 1); > else > - catomic_increment (&large); > + atomic_fetch_add_acquire (&large, 1); Ok. > - catomic_increment (&failed[idx_calloc]); > + atomic_fetch_add_acquire (&failed[idx_calloc], 1); Ok. > - catomic_increment (&calls[idx_free]); > + atomic_fetch_add_acquire (&calls[idx_free], 1); Ok. > - catomic_increment (&calls[idx_free]); > + atomic_fetch_add_acquire (&calls[idx_free], 1); Ok. > - catomic_add (&total[idx_free], real->length); > + atomic_fetch_add_acquire (&total[idx_free], real->length); Ok. > - catomic_increment (&calls[idx]); > + atomic_fetch_add_acquire (&calls[idx], 1); Ok. > - catomic_add (&total[idx], len); > + atomic_fetch_add_acquire (&total[idx], len); Ok. > - catomic_add (&grand_total, len); > + atomic_fetch_add_acquire (&grand_total, len); Ok. > if (len < 65536) > - catomic_increment (&histogram[len / 16]); > + atomic_fetch_add_acquire (&histogram[len / 16], 1); > else > - catomic_increment (&large); > + atomic_fetch_add_acquire (&large, 1); Ok. > - catomic_increment (&calls_total); > + atomic_fetch_add_acquire (&calls_total, 1); Ok. > - catomic_increment (&failed[idx]); > + atomic_fetch_add_acquire (&failed[idx], 1); Ok. > - catomic_increment (&calls[idx]); > + atomic_fetch_add_acquire (&calls[idx], 1); Ok. > - catomic_add (&total[idx], len); > + atomic_fetch_add_acquire (&total[idx], len); Ok. > - catomic_add (&grand_total, len); > + atomic_fetch_add_acquire (&grand_total, len); Ok. > if (len < 65536) > - catomic_increment (&histogram[len / 16]); > + atomic_fetch_add_acquire (&histogram[len / 16], 1); > else > - catomic_increment (&large); > + atomic_fetch_add_acquire (&large, 1); Ok. > - catomic_increment (&calls_total); > + atomic_fetch_add_acquire (&calls_total, 1); Ok. > - catomic_increment (&failed[idx]); > + atomic_fetch_add_acquire (&failed[idx], 1); Ok. > - catomic_increment (&calls[idx_mremap]); > + atomic_fetch_add_acquire (&calls[idx_mremap], 1); Ok. > - catomic_add (&total[idx_mremap], len - old_len); > + atomic_fetch_add_acquire (&total[idx_mremap], len - old_len); Ok. > - catomic_add (&grand_total, len - old_len); > + atomic_fetch_add_acquire (&grand_total, len - old_len); Ok. > if (len < 65536) > - catomic_increment (&histogram[len / 16]); > + atomic_fetch_add_acquire (&histogram[len / 16], 1); > else > - catomic_increment (&large); > + atomic_fetch_add_acquire (&large, 1); Ok. > - catomic_increment (&calls_total); > + atomic_fetch_add_acquire (&calls_total, 1); Ok. > - catomic_increment (&failed[idx_mremap]); > + atomic_fetch_add_acquire (&failed[idx_mremap], 1); Ok. > - catomic_increment (&inplace_mremap); > + atomic_fetch_add_acquire (&inplace_mremap, 1); Ok. > - catomic_increment (&decreasing_mremap); > + atomic_fetch_add_acquire (&decreasing_mremap, 1); Ok. > - catomic_increment (&calls[idx_munmap]); > + atomic_fetch_add_acquire (&calls[idx_munmap], 1); Ok. > - catomic_add (&total[idx_munmap], len); > + atomic_fetch_add_acquire (&total[idx_munmap], len); Ok. > - catomic_increment (&failed[idx_munmap]); > + atomic_fetch_add_acquire (&failed[idx_munmap], 1); Ok.