From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 0A3C43858C00 for ; Thu, 23 Feb 2023 16:39:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A3C43858C00 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ot1-x32e.google.com with SMTP id c2-20020a9d6842000000b0068bc93e7e34so2379842oto.4 for ; Thu, 23 Feb 2023 08:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677170348; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=+PxCqOzbOLj7p2N+OATA8oBKb2W9t3BLt6RblmcMi48=; b=nWVxIu8psEpd56Fg4rYUgynA+YZlcFzkT6sspvxuifI3ODs7Hw1l2QgmtqAY1vbZ3I le1VUzw5eScaboEsZcHI7OZcM+wpHiVu6caq6RIOb6LUQ7lTnDajUnlrqosP+COkXVsU KEBLSBCWt2fVVgdvtQI/NSNYnDQJHjYsaLAZ6wkfobBWME20cZJBQiKxmZ84DSaQjyzt Q6+zrBF2C8yZpeTZhGAqEadX3wNRRpFlgYrnzHlHWj6UAEhiOj2LRSWcj7vjkfXqn9ux COWifopBx6hdedMfsXqDkV9yZnWtrmVwSXKCdRctOzeF2QnFzDUQN2SLXp5vvWCTkYZt draw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677170348; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+PxCqOzbOLj7p2N+OATA8oBKb2W9t3BLt6RblmcMi48=; b=3pCDDLZptBwWhPiY7YzwG73OU/YZlr16gUF1sadGeDjgrULsQVFPuYj1dPlM3svBOJ 0sm+osdC/A9S84mWgXMfRRjztYkyO/zz/+CRU1waw/PilxgFwui7i9Y6r6jSG3dD+3Be 2UErqB6kWO8GTQXC4gQDAYayddWtTpo80awvXOl+1eQu/JWTZT9LZExI9JzQRsy4M9kJ Ix4uEGMbWVYH+otR/Ov81MQopATURL2ZxoqPRDgOXj8QxbCex3JsfM5856rpVXnqZWs+ XUlUvBNdUXPR39eG9OGTb4eqMAlHcFwvh0UeK0ZN50c1Oc7DaaTHWfD1sTAVHksyh60S be7A== X-Gm-Message-State: AO0yUKVxorQqL7+o/c1MRn4hSVpTPqmpgwlI/MU+IFOEDl6jwjR0+LjT J28ZGzx0ag0E4OwLKlSHt2NklFDrLut9tAtPDxQ= X-Google-Smtp-Source: AK7set9FBAev7aAZkTdjjMKoy8Owbf8M9CE/z37HM4fLRUIaDCiKNXoPPSR/ybqhONoGQtY5RjP/aA== X-Received: by 2002:a05:6830:4127:b0:68b:e5da:4201 with SMTP id w39-20020a056830412700b0068be5da4201mr3557984ott.21.1677170348162; Thu, 23 Feb 2023 08:39:08 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c3:89be:8c1b:4e8b:6072:80c5? ([2804:1b3:a7c3:89be:8c1b:4e8b:6072:80c5]) by smtp.gmail.com with ESMTPSA id i2-20020a9d4a82000000b0068d542f630fsm2872803otf.76.2023.02.23.08.39.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Feb 2023 08:39:07 -0800 (PST) Message-ID: <2a430a50-4c14-d986-014f-8c816f105f52@linaro.org> Date: Thu, 23 Feb 2023 13:39:05 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH] malloc: Use C11 like atomics on memusage Content-Language: en-US To: DJ Delorie Cc: libc-alpha@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: Hi D.J, Wilco has objected that these should be relaxed MO [1], so I plan to send an updated version to fix it. [1] https://sourceware.org/pipermail/libc-alpha/2023-February/145665.html On 23/02/23 01:20, DJ Delorie wrote: > > 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. >