From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 803E5C433F5 for ; Fri, 10 Dec 2021 16:30:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA3386B0072; Fri, 10 Dec 2021 11:29:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D51436B0073; Fri, 10 Dec 2021 11:29:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C19566B0074; Fri, 10 Dec 2021 11:29:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id B47F96B0072 for ; Fri, 10 Dec 2021 11:29:49 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7DCEE86311 for ; Fri, 10 Dec 2021 16:29:39 +0000 (UTC) X-FDA: 78902420478.24.188C1A2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id CB986160009 for ; Fri, 10 Dec 2021 16:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639153778; 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=f5El+Q3eIgzJBovVYIEGNnx5wIrj3Zs25homqjZk9cI=; b=Zswuym1IO5b51GyFnOONZEVSOBK+Wo6yStoxjaY0+5g6IAvsBISNesLXv+1RDdXzJEx34e 2sllmq1dvB8+Dq2O4SnOS/gEdxYKNNpY85pbL68WyxA570Ud1mqn7RsiZoTWHjNlHIwIXL 16r6d1M3RaYBWk0TYJxIpTmZHRLWiG4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-280-YLOBJioWPJSSEzJxl9TEmQ-1; Fri, 10 Dec 2021 11:29:35 -0500 X-MC-Unique: YLOBJioWPJSSEzJxl9TEmQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B770192CC41; Fri, 10 Dec 2021 16:29:33 +0000 (UTC) Received: from [10.22.33.49] (unknown [10.22.33.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 423E85DF4B; Fri, 10 Dec 2021 16:29:32 +0000 (UTC) Message-ID: <80ee87bb-f36c-4a16-9095-43ea84818375@redhat.com> Date: Fri, 10 Dec 2021 11:29:31 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH-next v2] mm/memcg: Properly handle memcg_stock access for PREEMPT_RT Content-Language: en-US To: Sebastian Andrzej Siewior Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Thomas Gleixner , Peter Zijlstra References: <20211210025228.158196-1-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CB986160009 X-Stat-Signature: uf7xpoqwdie4a9nah1yfpwbpg95f9why Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zswuym1I; spf=none (imf08.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1639153777-621953 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 12/10/21 08:01, Sebastian Andrzej Siewior wrote: > On 2021-12-09 21:52:28 [-0500], Waiman Long wrote: > =E2=80=A6 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c > =E2=80=A6 >> @@ -2210,7 +2211,7 @@ static void refill_stock(struct mem_cgroup *memc= g, unsigned int nr_pages) >> struct memcg_stock_pcp *stock; >> unsigned long flags; >> =20 >> - local_irq_save(flags); >> + local_lock_irqsave(&memcg_stock.lock, flags); > Why is this one using the lock? It isn't accessing irq_obj, right? Well, the lock isn't just for irq_obj. It protects the whole memcg_stock=20 structure which include irq_obj. Sometimes, data in irq_obj (or=20 task_obj) will get transfer to nr_pages and vice versa. So it is easier=20 to use one single lock for the whole thing. > >> stock =3D this_cpu_ptr(&memcg_stock); >> if (stock->cached !=3D memcg) { /* reset if necessary */ >> @@ -2779,29 +2780,28 @@ static struct mem_cgroup *get_mem_cgroup_from_= objcg(struct obj_cgroup *objcg) >> * which is cheap in non-preempt kernel. The interrupt context objec= t stock >> * can only be accessed after disabling interrupt. User context code= can >> * access interrupt object stock, but not vice versa. >> + * >> + * This task and interrupt context optimization is disabled for PREEM= PT_RT >> + * as there is no performance gain in this case. >> */ >> static inline struct obj_stock *get_obj_stock(unsigned long *pflags) >> { >> - struct memcg_stock_pcp *stock; >> - >> - if (likely(in_task())) { >> + if (likely(in_task()) && !IS_ENABLED(CONFIG_PREEMPT_RT)) { >> *pflags =3D 0UL; >> preempt_disable(); >> - stock =3D this_cpu_ptr(&memcg_stock); >> - return &stock->task_obj; >> + return this_cpu_ptr(&memcg_stock.task_obj); >> } > We usually add the local_lock_t to the object it protects, struct > obj_stock it this case. > That would give you two different locks (instead of one) so you wouldn'= t > have to use preempt_disable() to avoid lockdep's complains. Also it > would warn you if you happen to use that obj_stock in !in_task() which > is isn't possible now. > The only downside would be that drain_local_stock() needs to acquire tw= o > locks. > As said above, having separate locks will complicate the interaction=20 between irq_obj and the broader memcg_stock fields. Besides throughput=20 is a less important matrix for PREEMPT_RT, so I am not trying to=20 optimize throughput performance for PREEMPT_RT here. Cheers, Longman