From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C93D23E35F for ; Fri, 20 Mar 2026 20:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774038400; cv=none; b=ZDItzXsdxkJ0zrqVfoYu6BIe5x5mpxRRlVFYlDQ+U/WT/MyFzkEp36QJYPcUIWGSGwTWUXAqrjCh62iRkG+vW0B4QTLyHoVYufuwFQAEvFtTMqioZHxrKGKidav1kGREnofIgGnEcz3xot5f4LYB+uB03cVdh0X8mN08C0VcONs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774038400; c=relaxed/simple; bh=LcbGtTuSpB1/pNmFVKjQFRPwN3oBhlDbUUNemmVaQzA=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=sF6h0XlZdOuzfAfWQnZGIFaDtoP0syrAltHWkKIsbURZo32cFVU/r2yi+gt58x86+qz23Fyjfl94ygXJeN0mH7LLG/NK9GQ+IBogNsSveNfxLZYEec8+P9E6CV3CL8p1Rv3B63//P9bS4XSzk59lqoytSNTgqbq3qqnwINewDzQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cLo486en; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cLo486en" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774038396; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bh7aOD8eVmeMWf72c7UmgdenGSk73cbCb4+ksWaH/Fg=; b=cLo486en7t6zn/2TPzvG+AAeO9S9pGnJOxpnByd9t582oIj8XnpQt3O2ySo7fB3ObggvgL 2QtSQYinD4uzPzeYJfYQU4AwuBDD+AE/JWuTTFXHo8M5nQqsSsCXXX8vLlyqrWO5wv1Nm/ +hdqD4Oy8xG0ZMdsZ3x4scTdiucFOsY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-kuO8f03HNYm3vhJUfRt_Qg-1; Fri, 20 Mar 2026 16:26:32 -0400 X-MC-Unique: kuO8f03HNYm3vhJUfRt_Qg-1 X-Mimecast-MFC-AGG-ID: kuO8f03HNYm3vhJUfRt_Qg_1774038389 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 005071800561; Fri, 20 Mar 2026 20:26:29 +0000 (UTC) Received: from [10.22.65.139] (unknown [10.22.65.139]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 85C0618001FE; Fri, 20 Mar 2026 20:26:24 +0000 (UTC) Message-ID: <056172d8-1e58-4437-9cd6-1239de292574@redhat.com> Date: Fri, 20 Mar 2026 16:26:23 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/7] selftests: memcg: Fix test_memcontrol test failures with large page sizes From: Waiman Long To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Tejun Heo , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Shuah Khan , Mike Rapoport , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Sean Christopherson , James Houghton , Sebastian Chlad , Guopeng Zhang , Li Wang References: <20260319173752.1472864-1-longman@redhat.com> <20260319194347.1048fc8d737b6e8f9d82663d@linux-foundation.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 3/20/26 11:56 AM, Waiman Long wrote: > >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c > >> --- a/mm/memcontrol.c > >> +++ b/mm/memcontrol.c > >> @@ -548,20 +548,20 @@ struct memcg_vmstats { > >>   *    rstat update tree grow unbounded. > >>   * > >>   * 2) Flush the stats synchronously on reader side only when there > are more than > >> - *    (MEMCG_CHARGE_BATCH * nr_cpus) update events. Though this > optimization > >> - *    will let stats be out of sync by atmost (MEMCG_CHARGE_BATCH > * nr_cpus) but > >> - *    only for 2 seconds due to (1). > >> + *    (MEMCG_CHARGE_BATCH * (ilog2(nr_cpus) + 1)) update events. > Though this > >> + *    optimization will let stats be out of sync by up to that > amount but only > >> + *    for 2 seconds due to (1). > > Is this description accurate regarding the maximum out of sync amount? > > Looking at memcg_rstat_updated(), updates are buffered locally on > each CPU > > up to MEMCG_CHARGE_BATCH - 1 before they are added to the global > > vmstats->stats_updates counter. > > Because memcg_vmstats_needs_flush() only checks the global counter, > could > > N CPUs each buffer MEMCG_CHARGE_BATCH - 1 updates without triggering a > > synchronous flush? > > If so, wouldn't the actual worst-case out-of-sync error be > > N * (MEMCG_CHARGE_BATCH - 1) + vmstats_flush_threshold, which remains > > linear with the number of CPUs rather than scaling logarithmically? > > Good point, the worst case scenario can indeed be worse than that. I > will update the comment accordingly. Looking at the code again, the hidden charge in memcg_stock should only affect memory.current, not memory.stat. There is nothing to add to the worst case situation. Cheers, Longman